public void ProcessJob(long jobId) { TaskScheduling task = (new ServicesSchedulingServiceClient(true)).GetScheduledJob(jobId); Console.WriteLine(string.Concat("Task ", task.get_TaskSchedulerJobName(), " obtained using scheduling client.")); Console.WriteLine(string.Format("Job ID: {0}", jobId)); Imanami.GroupID.TaskScheduler.Helper.CurrentTask = task; if (Imanami.GroupID.TaskScheduler.Helper.CurrentTask != null) { if ((Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_JobType() == 6 || !Imanami.GroupID.TaskScheduler.Helper.IsSystemSecurityContext || Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_JobType() == 8 ? false : Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_JobType() != 13)) { string exMsg = string.Format("Unable to proceed. Authentication information has been expired for job {0} - {1}.", task.get_JobId(), task.get_Name()); Console.WriteLine(string.Concat("Throwing exception: ", exMsg)); throw new Exception(exMsg); } ServicesSearchServiceClient configurationService = new ServicesSearchServiceClient(false); Imanami.GroupID.TaskScheduler.Helper.AppConfiguration = configurationService.GetAppConfiguration(Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_IdentityStoreId()); if (Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_JobType() != 6) { Imanami.GroupID.TaskScheduler.Helper.KnownProviderAttributes = configurationService.GetKnownAttributes(Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_IdentityStoreId()); } Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_JobId(), Imanami.GroupID.TaskScheduler.Helper.CurrentTask.get_JobName()); if (task.get_JobType() == 9) { IUserLifeCycleJob userLifeCycleProcessor = Imanami.GroupID.UserLifeCycleManagment.Helpers.Helper.GetUserLifeCycleJobProcessor(); Imanami.GroupID.UserLifeCycleManagment.Helpers.Helper.set_KnownProviderAttributes(Imanami.GroupID.TaskScheduler.Helper.KnownProviderAttributes); userLifeCycleProcessor.Process(task); } else if (task.get_JobType() == 1) { Console.WriteLine(string.Format("Job type is {0}", task.get_JobType())); SmartGroupJobProcessor processor = new SmartGroupJobProcessor(); Console.WriteLine("Ready to process smart group job"); processor.ProcessSmartGroupUpdate(task); } else if (task.get_JobType() == 5) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); MembershipJob.RunMembershipLifeCycle(task.get_IdentityStoreId()); } else if (task.get_JobType() == 11) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); ManagedByJobs.RunManagedByLifeCycle(task.get_IdentityStoreId()); } else if (task.get_JobType() == 4) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); (new Imanami.GroupID.TaskScheduler.Glm.JobProcessor()).ProcessJob(task); } else if (task.get_JobType() == 6) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); (new SchemaReplicationProcessor()).ProcessJob(task); } else if (task.get_JobType() == 7) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); (new Imanami.GroupID.TaskScheduler.GUS.JobProcessor()).ProcessGroupUsage(); } else if (task.get_JobType() == 8) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); (new ServicesSchedulingServiceClient(false)).HistoryRetention(task); } else if (task.get_JobType() == 10) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); (new OrphanGroupProcessor()).ProcessJob(task); } else if (task.get_JobType() == 12) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); (new WorkflowApproverAccelerationProcessor()).ProcessJob(task); } else if (task.get_JobType() == 13) { Imanami.GroupID.TaskScheduler.JobProcessor.logger.InfoFormat("Processing job: {0}, Name: {1}", task.get_JobId(), task.get_JobName()); (new PermissionAnalyzer()).ProcessJob(task); } } }
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); } }