Awesome, Free Software: Core FTP

I had to do some testing for a project that uploads its payload via SFTP. I wanted to setup a basic, no-frills SFTP server that could accept my files. I did a quick Google search and found Core FTP Server–a free download. After about 2 minutes of configuration, I had my SFTP server up & running; it was fantastic.

I also see that they have a free mini sftp server that’s available. It’s a no-install, one-user, one-directory SFTP server, and IT WORKS AWESOMELY! This might be my new favorite way to securely transfer files between sites!

Core FTP Server

Advertisements

XmlSerializer and Namespaces

Need to share some data with another system/program/thing? XML files are a great, easy way to do it! Typically, my process for creating or consuming XML files will be to generate a class from an XML schema definition (XSD) and then serialize to and deserialize from XML as needed.

Usually, you don’t need to do anything above and beyond this, but from time to time you might need to do some additional manipulation with the XML namespaces and associated prefixes. The XmlSerializer class gives you a lot of flexibility to do this, and it’s really easy! Here are some different things you can do along with the output produced.

Here’s my no-frills Person class that I’ll be serializing to XML in the examples that follow:

[XmlType(Namespace = "http://adamprescott/sample")]
public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime? DateOfBirth { get; set; }
}

By default, the serializer will include the XML namespace on each element.

var p = new Person
    {
        LastName = "Sample",
        FirstName = "James Q.",
        DateOfBirth = new DateTime(1970, 1, 1),
    };
var serializer = new XmlSerializer(typeof(Person));
serializer.Serialize(Console.Out, p);
<?xml version="1.0"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <FirstName xmlns="http://adamprescott/sample">James Q.</FirstName>
  <LastName xmlns="http://adamprescott/sample">Sample</LastName>
  <DateOfBirth xmlns="http://adamprescott/sample">1970-01-01T00:00:00</DateOfBirth>
</Person>

Whoa-day! That’s pretty busy. You can clean it up a lot just by declaring the default namespace when you instantiate your XmlSerializer.

var p = new Person
    {
        LastName = "Sample",
        FirstName = "James Q.",
        DateOfBirth = new DateTime(1970, 1, 1),
    };
var serializer = new XmlSerializer(typeof(Person), "http://adamprescott/sample");
serializer.Serialize(Console.Out, p);
<?xml version="1.0"?>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://adamprescott/sample">
  <FirstName>James Q.</FirstName>
  <LastName>Sample</LastName>
  <DateOfBirth>1970-01-01T00:00:00</DateOfBirth>
</Person>

That’s a little nicer, but what if I don’t want those XMLSchema namespaces? That’s easy, too!

var p = new Person
    {
        LastName = "Sample",
        FirstName = "James Q.",
        DateOfBirth = new DateTime(1970, 1, 1),
    };
var serializer = new XmlSerializer(typeof(Person), "http://adamprescott/sample");
var namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, "http://adamprescott/sample");
serializer.Serialize(Console.Out, p, namespaces);
<?xml version="1.0"?>
<Person xmlns="http://adamprescott/sample">
  <FirstName>James Q.</FirstName>
  <LastName>Sample</LastName>
  <DateOfBirth>1970-01-01T00:00:00</DateOfBirth>
</Person>

Note that I made the prefixes all string.Empty. If I were to specify a prefix, it would be included in the serialized XML.

var p = new Person
    {
        LastName = "Sample",
        FirstName = "James Q.",
        DateOfBirth = new DateTime(1970, 1, 1),
    };
var serializer = new XmlSerializer(typeof(Person));
var namespaces = new XmlSerializerNamespaces();
namespaces.Add("ap", "http://adamprescott/sample");
serializer.Serialize(Console.Out, p, namespaces);
<?xml version="1.0"?>
<Person xmlns:ap="http://adamprescott/sample">
  <ap:FirstName>James Q.</ap:FirstName>
  <ap:LastName>Sample</ap:LastName>
  <ap:DateOfBirth>1970-01-01T00:00:00</ap:DateOfBirth>
</Person>

Move Shelvesets Between Branches in TFS

At my company, we do a lot of concurrent development between a number of branches. It’s not uncommon for a change made in one branch to be needed in another branch. TFS Power Tools includes functionality to help you quickly and easily migrate a shelveset from one branch into another.

The usage is simple, too. Go to the command-line and type the following (make sure you run it from a directory mapped to a workspace):

tfpt unshelve "My Shelveset" /migrate /source:$/SourceBranch /target:$/TargetBranch

When you run the command, it will load the changes stored in the shelveset into the specified target branch. Super!