Example #1
0
 public static Config ReadFrom(string file)
 {
     Config rv = new Config();
     XDocument xd = XDocument.Load(XmlReader.Create(file));
     foreach (var el in xd.Root.Elements())
     {
         switch (el.Name.LocalName.ToLower())
         {
             case "imagepath":
                 rv.ImagePath = el.Value;
                 break;
             case "workingdirectory":
                 rv.WorkingDirectory = el.Value;
                 break;
             case "arguments":
                 rv.Arguments = el.Elements()
                     .Select(arg => arg.Value)
                     .ToArray();
                 break;
             case "maxnumberoflogbackups":
                 rv.MaxNumberOfLogBackups = int.Parse(el.Value);
                 break;
             case "buffersize":
                 rv.BufferSize = int.Parse(el.Value);
                 break;
             case "logfile":
                 rv.LogFile = el.Value;
                 break;
             case "maxlogsize":
                 rv.MaxLogSize = long.Parse(el.Value);
                 break;
             case "reliablelogging":
                 rv.ReliableLogging = bool.Parse(el.Value);
                 break;
             default:
                 throw new ConfigurationErrorsException("Unknown config property: " + el.Name.LocalName);
         }
     }
     return rv;
 }
Example #2
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     if (args != null && args.Length > 0 && args[0].ToLower().StartsWith("-debug"))
     {
         TestLog();
         TestServiceRunner();
     }
     else if (args != null && args.Length > 0)
     {
         Config config = new Config();
         config.Arguments = new[] { "get", ".", "-recursive" };
         config.BufferSize = 1024;
         config.ImagePath = @"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe";
         config.LogFile = @"D:\foo.txt";
         config.MaxLogSize = 2048;
         config.MaxNumberOfLogBackups = 1;
         config.WorkingDirectory = @"D:\_tfs";
         try
         {
             config.WriteTo(args[0]);
             Console.Out.WriteLine("Wrote a sample config file to " + args[0] + ".  The full path to this file should be placed in the config file's <appSettings> section with the key 'ServiceDefinition'.");
         }
         catch (Exception ex)
         {
             Console.Error.WriteLine(ex.ToString());
             Console.Error.WriteLine();
             Console.Error.WriteLine();
             Console.Error.WriteLine("usage: service-runner [path-to-write-config-file]");
         }
     }
     else
     {
         ServiceBase[] ServicesToRun;
         ServicesToRun = new ServiceBase[]
         {
             new Service1()
         };
         ServiceBase.Run(ServicesToRun);
     }
 }