Wednesday, 7 January 2015

Visual Studio Configuration to use Beyond Compare to compare word docs

To use Beyond compare amend the Visual Studio Configuration as follows...

Perform either of the following sets of steps.
1.      In Visual Studio, on the menu bar, choose Tools, Options.
2.      In the Options dialog box, expand Source Control, choose Visual Studio Team Foundation Server, and then choose Configure User Tools.
--or--
1.      In Windows, choose Start, All Programs, Microsoft Visual Studio 2012, Visual Studio Tools, Developer Command Prompt .
2.      Type tf diff /configure.
3.      In the Configure User Tools dialog box, choose Add.


The Configure Tool dialog box appears.
4.      In the Extension box, specify the extension (for example, .docx).
5.      In the Operation list, choose Compare.
6.      In the Command box type the path and name of your tool on your PC, e.g.
C:\Program Files\Beyond Compare 3\BComp.exe
7.      In the Arguments box, type any arguments that your tool requires e.g.
%1 %2 /title1=%6 /title2=%7
Note:
o    %1: The path to the source file.
o    %2: The path to the target file.
o    %5: The options that the user specified by using the /option option of the Difference command.
o    %6: Label ("friendly name") of the source file.

o    %7: Label ("friendly name") of the target file.

Thursday, 27 February 2014

De-Serialize Object from file

public static DatabaseColumns Load(string sScopesFilePath)
{
    // Console.WriteLine(System.IO.Path.GetFullPath(sScopesFilePath));

    DatabaseColumns AllColumns = null;
    try
    {
        using (XmlReader reader = XmlReader.Create(sScopesFilePath))
        {
            XmlSerializer serializer = new XmlSerializer(typeof(DatabaseColumns));
            AllColumns = serializer.Deserialize(reader) as DatabaseColumns;
        }
    }
    catch (Exception ex)
    {
        throw new ConfigurationErrorsException("Invalid DatabaseColumns.xml file supplied. See inner exception for details.", ex);
    }

    return AllColumns;

  }



Or

public static object Deserialize(string xml, Type toType)
{
    using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
    {
        System.IO.StreamReader str = new System.IO.StreamReader(memoryStream);
        System.Xml.Serialization.XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(toType);
        return xSerializer.Deserialize(str);
    }

}



Or

// You must apply a DataContractAttribute or SerializableAttribute 
// to a class to have it serialized by the DataContractSerializer.
[DataContract(Name = "Customer", Namespace = "http://www.contoso.com")]
class Person : IExtensibleDataObject
{
        [DataMember()]
        public string FirstName;
        [DataMember]
        public string LastName;
        [DataMember()]
        public int ID;

etc

}

public static object Deserialize(string xml, Type toType)
{
    using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
    {
        XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(memoryStream, Encoding.UTF8, new XmlDictionaryReaderQuotas(), null);
        DataContractSerializer serializer = new DataContractSerializer(toType);
        return serializer.ReadObject(reader);
    }

}





Get Command Line Arguments

private static string getArg(string[] args, string keyword, string defVal)
{
  string getArg;
  try
  {
  // always lower case
      getArg = args.Single(srch => srch.StartsWith(keyword.ToLower())).Substring(keyword.Length);
  }
  catch (Exception)
  {
      getArg = defVal;
  }
  return getArg;

}

Then to get the arguments

directory = getArg(args, "-d=",String.Empty);
fromString = getArg(args, "-f=", String.Empty);

Wednesday, 28 March 2012

Singleton

// Not thread safe


public class Singleton1
{
private static Singleton1 instance = new Singleton1();
private Singleton1(){}
public static Singleton1 GetInstance()
{ return instance;
}
}

eg


// Implement runParameters as Singleton
public sealed class RunParameters
{
// Private constructor to ensure singleton (Static ensure singleton)
private static readonly RunParameters _instance = new RunParameters();

// Private contructor used above
private RunParameters(){}

// Get method - returns pointer to instance object.
public static RunParameters GetInstance() { return _instance; }