Using the built-in support for Git in Visual Studio 2013 is great... to a certain extent. Because eventually it will happen that you need to do some Git operation that is simply not supported. Having used Git on only one project so far it happened two times already that the built-in functionality wasn't enough.
The first situation was when I needed to revert a pushed commit. So I looked and looked in VS to locate such an action, but to no avail. Searching the Internet turned out people recommend using the command prompt. I opened a standard command prompt from Windows start menu and tried out the recommended Git commands, only to find out that it didn't work because it wasn't in a context of a repository (or something like that), and as I remembered it this was the case even if I navigated to the correct 'workspace' folder. After some more research it turns out that it is possible to open a Git-ish command prompt from VS (it is in the 'action' menu, available many places in the built-in Git client). Opening the command prompt this way places it in the correct context (not entirely sure how - maybe some environment variable is set). Anyway I was able to do the revert from there.
But this is really not what this article is about :-) No, what I want to describe here is how to synchronize a forked Git repository with changes in the original repository. So again I start a Git-ish command prompt, e.g. from 'Unsynched Commits' page in the Git client in VS. From there I execute the following commands:
First, link our repository with the remote (the original):
git remote add upstream [full-git-url-to-remote-repo]
Now, fetch changes:
git fetch upstream
Finally, do a merge, where [branch] can be master or some other branch:
git merge upstream/[branch]
That should do the trick. If there are any conflicts, they will now show up in VS and you can resolve them from there.
Tuesday, December 10, 2013
Syncing a forked git repository with changes in the original repository
Posted by Maze at 2:41 PM 0 comments
Thursday, October 24, 2013
Installing Solr 4.5 as a Windows service
I've recently had the good fortune to use the Solr search platform for a project. One thing, though, that is not straight forward is how to install Solr as a Windows service. There are several articles on the internet, but I couldn't find any that worked with Solr 4.5. So I gathered information from a number of out-dated articles and came up with the following approach, which has worked fine for me:
- Download Solr 4.5 (http://lucene.apache.org/solr/)
- Download the Non-Sucking Service Manager NSSM (http://nssm.cc/)
- Create a folder to be used for the Solr service (e.g. D:\solr). From now on this will be called <solrdir>
- From the example folder of the Solr package copy the following files and folders to <solrdir>:
- etc
- lib
- logs
- solr
- webapps
- start.jar
- In a command prompt go to <solrdir> and run the command
java -jar start.jarto check that the Solr installation works. If it works then just stop it again. - From the NSSM package copy nssm.exe to <solrdir>
- In a command prompt go to <solrdir> and run the command below. Note: it may be necessary to replace back-slashes in <solrdir> with forward-slashes.
nssm.exe install Solr C:\Windows\System32\java.exe "-Dsolr.solr.home=<solrdir>/solr -Djetty.home=<solrdir>/ -Djetty.logs=<solrdir>/logs/ -cp <solrdir>/lib/*.jar;<solrdir>/start.jar -jar <solrdir>/start.jar"
nssm.exe remove Solr
For convenience I've created the following batch script, which performs the nssm.exe install part. The script should be placed in <solrdir>.
@echo off
set currentdir=%~dp0
set parameters=-Dsolr.solr.home=""%currentdir%solr"" -Djetty.home=""%currentdir%"" -Djetty.logs=""%currentdir%logs/"" -cp ""%currentdir%lib/*.jar;%currentdir%start.jar"" -jar ""%currentdir%start.jar""
REM replace back-slashes with forward-slashes
set javaWeirdnessParameters=%parameters:\=/%
nssm.exe install Solr C:\Windows\System32\java.exe "%javaWeirdnessParameters%"
Posted by Maze at 9:13 AM 0 comments
Labels: Solr, Windows Service
Wednesday, March 23, 2011
NServiceBus and SQLite in .NET 4.0
I've just used the better part of a day trying to figure out how to get System.Data.SQLite.dll to work with NServiceBus in a .NET 4.0 project in VS2010.
http://tech.dir.groups.yahoo.com/group/nservicebus/message/8951
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- This is needed in order to get System.Data.SQLite to work in .NET 4.0, at least
until a .NET 4.0 compatible version of System.Data.SQLite is released. -->
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Posted by Maze at 5:21 PM 0 comments
Labels: .NET 4.0, NServiceBus, SQLite
Friday, March 18, 2011
Fuzzy text in VS2010
So I finally moved to Visual Studio 2010. This is a very nice IDE, but one thing that annoys me is that the text (code) seems fuzzy compared to VS2008. My eyes don't like it.
Posted by Maze at 9:44 AM 0 comments
Labels: VS2010
Tuesday, October 26, 2010
Transforming XML containing namespaces
Whenever I get the task of transforming some XML to some other XML using XSL and namespaces are involved it is always a struggle for some reason. And I've experienced that I'm not the only one having problems with that.
XSL transformation document
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog xmlns="http://schemas.maze-dev.blogspot.com/2010/catalog">
<name>Absolute Whatever Vol. 1</name>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
Output XML document
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://schemas.maze-dev.blogspot.com/2010/archive"
xmlns:cat="http://schemas.maze-dev.blogspot.com/2010/catalog" exclude-result-prefixes="cat">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<archive>
<xsl:apply-templates select="cat:catalog"/>
</archive>
</xsl:template>
<xsl:template match="cat:catalog">
<name><xsl:value-of select="cat:name"/></name>
<xsl:apply-templates select="cat:cd"/>
</xsl:template>
<xsl:template match="cat:cd">
<album>
<title>Title: <xsl:value-of select="cat:title"/></title>
<artist>Artist: <xsl:value-of select="cat:artist"/></artist>
</album>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<archive xmlns="http://schemas.maze-dev.blogspot.com/2010/archive">
<name>Absolute Whatever Vol. 1</name>
<album>
<title>Title: Empire Burlesque</title>
<artist>Artist: Bob Dylan</artist>
</album>
<album>
<title>Title: Hide your heart</title>
<artist>Artist: Bonnie Tyler</artist>
</album>
<album>
<title>Title: Greatest Hits</title>
<artist>Artist: Dolly Parton</artist>
</album>
</archive>
Monday, October 25, 2010
"Specified Cast is Not Valid" - LinqToSql error on submit
Posted by Maze at 10:14 AM 0 comments
Monday, June 14, 2010
DataGridView with Typed DataSet
I was recently working on an assignment creating a Windows Forms application with a DataGridView being fed data from some object collection, and NOT (as is the case with virtually all samples that can be found on the Internet) using the SqlDataAdapter.
Even though this is a pretty simple task once you've found out how to do it, I did find it a bit tricky to get to work. So here's how it can be done.
- Start Visual Studio and create a new Windows Forms application.
- Add a DataSet to the project by right-clicking on the project and selecting Add -> New Item and selecting the DataSet template naming it ContactDataSet. This should bring up the DataSet designer.
- Add a new DataTable to the designer area using the Toolbox. Name it Contact and add some columns to table (see details such as column data types in the sample code)

- Add a new class to the project and name it Address:
public class Address
{
public long Id { get; set; }
public string Street { get; set; }
public int HouseNumber { get; set; }
public string PostalCode { get; set; }
public string PostalDistrict { get; set; }
} - Add another new class to the project and name it Contact:
public class Contact
{
public long Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int? Age { get; set; }
public Address Address { get; set; }
} - In Form1.cs add this private member:
private ContactDataSet _contactDataSet = new ContactDataSet(); - Also in Form1.cs add this method for generating a collection of test data:
private IList<Contact> GenerateData()
{
IList<Contact> contactList = new List<Contact>();
contactList.Add(new Contact
{
Id = 1,
FirstName = "Peter",
LastName = "Jackson",
Age = 53,
Address = new Address
{
Street = "Long Road",
HouseNumber = 173,
PostalCode = "12345",
PostalDistrict = "Fake Town"
}
});
contactList.Add(new Contact
{
Id = 2,
FirstName = "Pavlov",
LastName = "Ivanowich",
Address = new Address
{
Street = "Park Avenue",
HouseNumber = 1011,
PostalCode = "98765",
PostalDistrict = "Imaginaryville"
}
});
contactList.Add(new Contact
{
Id = 3,
FirstName = "Onslow",
LastName = "Bucket",
});
return contactList;
} - Furthermore, add this method for filling the DataSet with data from a collection:
private void FillDataSet(IList<Contact> contactList)
{
foreach (Contact contact in contactList)
{
ContactDataSet.ContactRow row = _contactDataSet.Contact.NewContactRow();
row.FirstName = contact.FirstName;
row.LastName = contact.LastName;
if (contact.Age.HasValue)
{
row.Age = contact.Age.Value;
}
if (contact.Address != null)
{
row.Street = contact.Address.Street;
row.HouseNumber = contact.Address.HouseNumber;
row.PostalCode = contact.Address.PostalCode;
row.PostalDistrict = contact.Address.PostalDistrict;
}
_contactDataSet.Contact.AddContactRow(row);
}
// OK, so we have filled in the data we want to start up with.
// We must now call AcceptChanges so that this data isn't change-tracked.
_contactDataSet.AcceptChanges();
} - Go to the Form Designer and add a BindingSource and name it contactBindingSource. Set the ContactDataSet as DataSource and Contact as DataMember.
- In the Form Designer also add a DataGridView and set contactBindingSource as DataSource.
- In the Form1.cs add this code in the Load event handler:
IList<Contact> contactList = GenerateData();
FillDataSet(contactList);
contactBindingSource.DataSource = _contactDataSet; - Run the application. The DataGridView should now display the test data.
Posted by Maze at 10:14 PM 0 comments
Labels: DataGridView, Typed DataSet, Windows Forms, Winforms