Monday, June 8, 2015
Visual Studio Git
Visual Studio provides Git tools and will automatically detect the presence of a local Git repository even if you have set it up using command line tools. I suggest continuing to use the command line tools if you are comfortable with that. It can be confusing when you start editing a file that you are tracking with Git. All of a sudden there is a check mark next to the file in Solution Explorer. What just happened? The answer is nothing. Visual Studio can compare the file with the most recent commit in the repository and it is just letting you know that the file has changed. If you were to click the Commit button in Team Explorer (remember, I prefer the command line tools), Visual Studio would first stage the files (git add) and immediately commit (git commit) them.
Git Overview
Git is an open-source software version control system.
It is a decentralized system which means that the source code repository resides on your local machine. You make your changes on your local PC, you commit those changes to a repository on your local PC.
You can create a remote repository on GitHub or Assembla and "push" your changes to those sites in order for your teammates to download and "clone" their own local repository.
You can download Git here: http://www.git-scm.com This download includes a couple of GUI tools and Git Bash.
Git is a Unix program. Although many GUI's exist for using Git, it is recommended that you learn to interact with the original program using a command line. If you are using Windows, Git Bash is the program that you will use to give these commands to Git.
First configure Git:
You need to create a local repository. Navigate to the directory that contains the folder to store your repository files. Then run an init command.
To do anything with a repository you have to change the current directory to the directory containing the repository files.
If you change a file in your repository, and you want to commit the change, you have to "stage" the file by adding the file to the "index":
Or, if you have a bunch of files in your repository, and you change a handful, you don't have to add each file individually. Using the following command will add and only add the files you have changed from what is in the last commit:
Add on the dry-run option if you just want to see which files will be added:
Perhaps, you want to see which files you have changed, but not staged:
To commit a file in the index:
At this point, you will probably want to create what is called a "remote repository" hosted on the internet. After signing up on Assembla.com and creating a repository there, follow the instructions that Assembla provides. If you use the https method, you just use the command below. Otherwise if you choose (ssh), you'll probably have to generate a certificate and register it with Assembla and Git.
This creates a remote repository named origin on Assembla. To "push" a commit to the remote repository just:
To "pull" commits down from the remote repository, just:
If you make a change to a file, and before you add it to the index and commit it, you decide to undo it, you would:
I believe this replaces the specified file with the version from the most recent commit. Checkout has a different meaning in Git than in TFS. An easy way to find the path and all files that have been changed is to do a git status.
It is a decentralized system which means that the source code repository resides on your local machine. You make your changes on your local PC, you commit those changes to a repository on your local PC.
You can create a remote repository on GitHub or Assembla and "push" your changes to those sites in order for your teammates to download and "clone" their own local repository.
You can download Git here: http://www.git-scm.com This download includes a couple of GUI tools and Git Bash.
Git is a Unix program. Although many GUI's exist for using Git, it is recommended that you learn to interact with the original program using a command line. If you are using Windows, Git Bash is the program that you will use to give these commands to Git.
First configure Git:
git config --global user.name "Steve Emrick" git config --global user.email steve@steve.com
You need to create a local repository. Navigate to the directory that contains the folder to store your repository files. Then run an init command.
cd c:\users\semrick git init <nameofsubdirectory>
To do anything with a repository you have to change the current directory to the directory containing the repository files.
If you change a file in your repository, and you want to commit the change, you have to "stage" the file by adding the file to the "index":
git add <Name of File>
Or, if you have a bunch of files in your repository, and you change a handful, you don't have to add each file individually. Using the following command will add and only add the files you have changed from what is in the last commit:
git add .
Add on the dry-run option if you just want to see which files will be added:
git add . --dry-run
Perhaps, you want to see which files you have changed, but not staged:
git status
To commit a file in the index:
git commit --message 'A comment'
At this point, you will probably want to create what is called a "remote repository" hosted on the internet. After signing up on Assembla.com and creating a repository there, follow the instructions that Assembla provides. If you use the https method, you just use the command below. Otherwise if you choose (ssh), you'll probably have to generate a certificate and register it with Assembla and Git.
git remote add origin https://git.assembla.com/{repository name goes here}.git
This creates a remote repository named origin on Assembla. To "push" a commit to the remote repository just:
git push origin master
To "pull" commits down from the remote repository, just:
git pull origin master
If you make a change to a file, and before you add it to the index and commit it, you decide to undo it, you would:
git checkout <FilenameWithRelativePath>
I believe this replaces the specified file with the version from the most recent commit. Checkout has a different meaning in Git than in TFS. An easy way to find the path and all files that have been changed is to do a git status.
Wednesday, April 1, 2015
SharePoint 2007 Session Timeout
You can set the timeout of the session in SharePoint 2007 by opening up Central Administration, clicking Application Management, and clicking Manage Session State.
Monday, March 30, 2015
The Distinct Statement in LINQ
The Distinct statement in LINQ is pretty straight-forward:
However, if EntityName is a view, you may notice the Distinct statement might not work. You may find that your results contain duplicate rows. How can this be?
The Distinct capability is only available on columns that aren't set as "unique". And this makes sense, I suppose, because why would anyone want to do a Distinct on a column where duplicates are impossible?
But if your EntityName is a view, and one of the columns comes from a unique table column, then Entity Framework marks it as an "Entity Key" in the EDMX data model. Of course, if your view is joining tables, like they often do, you could certainly expect some duplicates in these key fields. This is exactly the case where a Distinct statement would not work for you.
The lesson here is to open up the EDMX data model, and set the Entity Key property of any non-unique columns in your view to False. Then Distinct should work properly.
Dim SearchResults = (
From a In EntityName
Select a.Column1, a.Column2, a.Column3
).Distinct()
However, if EntityName is a view, you may notice the Distinct statement might not work. You may find that your results contain duplicate rows. How can this be?
The Distinct capability is only available on columns that aren't set as "unique". And this makes sense, I suppose, because why would anyone want to do a Distinct on a column where duplicates are impossible?
But if your EntityName is a view, and one of the columns comes from a unique table column, then Entity Framework marks it as an "Entity Key" in the EDMX data model. Of course, if your view is joining tables, like they often do, you could certainly expect some duplicates in these key fields. This is exactly the case where a Distinct statement would not work for you.
The lesson here is to open up the EDMX data model, and set the Entity Key property of any non-unique columns in your view to False. Then Distinct should work properly.
Tuesday, February 24, 2015
PowerShell
PowerShell is a command line administration tool that comes with Windows. I haven't used it much as a developer, but I have discovered a few little things that make me think it could be useful for discovering what certain .NET objects are capable of without compiling new code.
Check this out:
I created a variable called MyString, and then tested out the SubString function.
Then I wanted to see how the GeneratePassword method of the Membership class worked, so I imported the assembly that contains the Membership class, and called GeneratePassword.
I can see this being useful because I can call .NET code on the fly without first creating a project in Visual Studio.
Check this out:
I created a variable called MyString, and then tested out the SubString function.
Then I wanted to see how the GeneratePassword method of the Membership class worked, so I imported the assembly that contains the Membership class, and called GeneratePassword.
I can see this being useful because I can call .NET code on the fly without first creating a project in Visual Studio.
Thursday, February 19, 2015
ASP.NET Web Api 404 errors
I recently deployed a ASP.NET Web Api web service to a production server and kept getting 404 errors when I made requests. After extensive research I finally traced the problem to the web.config file. I don't totally understand why this fixed it, but it has something to do with how IIS resolves the URL.
In the web.config, you'll find this line:
This needs be changed to:
Notice the removal of the period from the "path" attribute.
In the web.config, you'll find this line:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
This needs be changed to:
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
Notice the removal of the period from the "path" attribute.
Wednesday, February 4, 2015
Response.Redirect
When you redirect to another page using .NET, you normally use the Response.Redirect method. However, if you only supply the URL as the parameter, you'll get a ThreadAbort exception thrown. This can fill the event log pretty darn quick. To avoid this, set the second parameter to False. This will immediately end the response, so no exception is thrown.
The only "exception" to this rule (haha), is when you want code to execute after the Response.Redirect. In this case you can't immediately end the response. In this case, you either have to put up with the exceptions in the log, or catch the ThreadAbort exception and just swallow it.
The only "exception" to this rule (haha), is when you want code to execute after the Response.Redirect. In this case you can't immediately end the response. In this case, you either have to put up with the exceptions in the log, or catch the ThreadAbort exception and just swallow it.
Subscribe to:
Comments (Atom)
