Exemplo n.º 1
0
 private static void Main(string[] args)
 {
     Console.Title = "Task Scheduler Runner";
     args          = new string[] { "0AA##0PV7M#AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAABOimvGWmYk+OwElU3xgGewQAAAACAAAAAAADZgAAwAAAABAAAAA+yg5rxV+6laCj+NmjyzUUAAAAAASAAACgAAAAEAAAALBk/IjhAvXRv7AKRVRSFxIIAAAA0wsOxFN3pAAUAAAALS5bfTs3WJzAPK4Tn+V3EK5mLC8=Ukx5N0AlazM=" };
     Console.WriteLine("Press any key to start...");
     Console.ReadKey(false);
     try
     {
         try
         {
             Console.WriteLine("Program Started");
             LogExtension.RegisterCustomLogLevels();
             XmlConfigurator.Configure();
             LogExtension.EnterMethod(Program.logger, MethodBase.GetCurrentMethod(), args);
             string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Schedules");
             Console.WriteLine(string.Concat("Schedules Path: ", path));
             int jobId = Convert.ToInt32(CryptographyHelper.DecryptFromLocalMachine(args[0]));
             Console.WriteLine(string.Format("Job ID: {0}", jobId));
             path = Path.Combine(path, string.Concat("task", jobId.ToString(), ".txt"));
             if (!File.Exists(path))
             {
                 Console.WriteLine(string.Concat("Path ", path, " does not exists."));
                 Program.InitializeSystemSecurityContext();
                 Helper.IsSystemSecurityContext = true;
             }
             else
             {
                 Console.WriteLine(string.Concat("Path ", path, " exists."));
                 using (StreamReader data = File.OpenText(path))
                 {
                     string[] container = data.ReadToEnd().Split(new string[] { "<#!#>" }, StringSplitOptions.None);
                     jobId = Convert.ToInt32(CryptographyHelper.DecryptFromLocalMachine(container[0]));
                     Console.WriteLine(string.Format("Job ID from job file: {0}", jobId));
                     Program.InitializeSecurityContext(CryptographyHelper.DecryptFromLocalMachine(container[2]));
                     Helper.IsSystemSecurityContext = false;
                 }
             }
             Console.WriteLine("System security context initialized");
             LicensingProvider licensingProvider = new LicensingProvider();
             if ((licensingProvider.HasValidProductLicense(1) ? false : !licensingProvider.HasValidProductLicense(3)))
             {
                 if (!licensingProvider.HasValidProductLicense(8))
                 {
                     Console.WriteLine("License error. Returning...");
                     Program.logger.Error("Invalid License");
                     return;
                 }
                 else
                 {
                     TaskScheduling task = (new ServicesSchedulingServiceClient(true)).GetScheduledJob((long)jobId);
                     if (task == null)
                     {
                         return;
                     }
                     else if (task.get_JobType() != 13)
                     {
                         Program.logger.Error("Invalid License");
                         Console.WriteLine("License error. Returning...");
                         return;
                     }
                 }
             }
             JobProcessor jobProcessor = new JobProcessor();
             Console.WriteLine(string.Format("Ready to process job {0}", jobId));
             jobProcessor.ProcessJob((long)jobId);
             Console.WriteLine(string.Format("Job {0} processed.", jobId));
         }
         catch (CryptographicException cryptographicException1)
         {
             CryptographicException cryptographicException = cryptographicException1;
             string message = string.Concat(cryptographicException.Message, " Error in initializing security context for the Scheduled job. Possible reason may be, that a required windows service is not running. Please make sure that 'CNG Key Isolation' windows service is running.");
             Console.WriteLine(string.Format("Exception {0}: {1}. Details: {2}. Trace:", cryptographicException.GetType(), cryptographicException.Message, message));
             Console.WriteLine(cryptographicException.StackTrace);
             LogExtension.LogException(Program.logger, message, cryptographicException, 1, "Logging.Const.LoggingConstants.jobUpdate");
         }
         catch (Exception exception)
         {
             Exception ex = exception;
             Console.WriteLine(string.Format("Exception {0}: {1}. Trace:", ex.GetType(), ex.Message));
             Console.WriteLine(ex.StackTrace);
             LogExtension.LogException(Program.logger, ex.Message, ex, 1, "Logging.Const.LoggingConstants.jobUpdate");
         }
     }
     finally
     {
         LogExtension.ExitMethod(Program.logger, MethodBase.GetCurrentMethod(), args);
     }
 }