public static void Main(string[] args) { MinHeap processes = new MinHeap(); RunThread r1 = new RunThread("Consumer-1", processes, RUN_SLEEP_INTERVAL); RunThread r2 = new RunThread("Consumer-2", processes, RUN_SLEEP_INTERVAL); Thread rt1 = new Thread(new ThreadStart(r1.run)); Thread rt2 = new Thread(new ThreadStart(r2.run)); rt1.Start(); rt2.Start(); AddThread a1 = new AddThread(processes, ADD_BATCH_NUM, ADD_BATCH_SIZE, ADD_PRIORITY_MIN, ADD_PRIORITY_MAX, ADD_SLEEP_INTERVAL, ADD_SLEEP_MIN, ADD_SLEEP_MAX); Thread at1 = new Thread(new ThreadStart(a1.run)); at1.Start(); at1.Join(); r1.noNewWork(); r2.noNewWork(); rt1.Join(); rt2.Join(); }
public static void startThread(RunThread run) { if (thread != null) { thread.Join(); } switch (run) { case RunThread.Init: thread = new Thread(new ThreadStart(loadMaps)); break; case RunThread.LoadLayer: thread = new Thread(new ThreadStart(loadLayers)); break; case RunThread.Update: thread = new Thread(new ThreadStart(loadImage)); break; case RunThread.SaveLayer: thread = new Thread(new ThreadStart(saveLayers)); break; } if (thread != null) { thread.Start(); } }
public void Start() { Log.LogInformation("Loading queues from persistant storage"); int queueCount = 0; int messageCount = 0; foreach (var queueName in Persistence.GetQueueNames()) { var queue = Persistence.LoadQueue(queueName); Log.LogInformation($"Loading messages for {queueName}"); foreach (var message in Persistence.LoadMessages(queueName)) { queue.Enqueue(message); messageCount = 0; } Queues.Add(queue); queueCount++; } Log.LogInformation($"Loaded {queueCount} queues with a total of {messageCount} messages"); Log.LogInformation("Starting listener"); ServerSocket.Bind(EndPoint); RunThread.Start(); QueueProcessThread.Start(); }
public CustomScreenVignette(Session session, XmlElement xml = null, MapMetaCompleteScreen meta = null) { this.session = session; session.Audio.Apply(); this.meta = meta; this.xml = xml; RunThread.Start(LoadCompleteThread, "SUMMIT_VIGNETTE"); }
/// <summary> /// Do not use outside of multiplayer mods. Allows more than 2 processes to communicate. /// </summary> /// <param name="target"></param> /// <returns></returns> public static StudioCommunicationClient RunExternal(string target) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { return(null); } var client = new StudioCommunicationClient(target); RunThread.Start(instance.UpdateLoop, "StudioCom Client_" + target); return(client); }
[Slow] // (occasionally) public virtual void TestIndexing() { Directory mainDir = NewDirectory(); var wrapper = mainDir as MockDirectoryWrapper; if (wrapper != null) { wrapper.AssertNoDeleteOpenFile = true; } var writer = new IndexWriter(mainDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(10).SetMergePolicy(NewLogMergePolicy(false, 2))); IndexReader reader = writer.GetReader(); // start pooling readers reader.Dispose(); var indexThreads = new RunThread[4]; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x] = new RunThread(this, x % 2, writer); indexThreads[x].Name = "Thread " + x; indexThreads[x].Start(); } long startTime = J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond; // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results long duration = 1000; while (((J2N.Time.NanoTime() / J2N.Time.MillisecondsPerNanosecond) - startTime) < duration) // LUCENENET: Use NanoTime() rather than CurrentTimeMilliseconds() for more accurate/reliable results { Thread.Sleep(100); } int delCount = 0; int addCount = 0; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].run = false; Assert.IsNull(indexThreads[x].ex, "Exception thrown: " + indexThreads[x].ex); addCount += indexThreads[x].addCount; delCount += indexThreads[x].delCount; } for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].Join(); } for (int x = 0; x < indexThreads.Length; x++) { Assert.IsNull(indexThreads[x].ex, "Exception thrown: " + indexThreads[x].ex); } //System.out.println("addCount:"+addCount); //System.out.println("delCount:"+delCount); writer.Dispose(); mainDir.Dispose(); }
public virtual void TestIndexing() { Directory mainDir = NewDirectory(); var wrapper = mainDir as MockDirectoryWrapper; if (wrapper != null) { wrapper.AssertNoDeleteOpenFile = true; } var writer = new IndexWriter(mainDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMaxBufferedDocs(10).SetMergePolicy(NewLogMergePolicy(false, 2))); IndexReader reader = writer.GetReader(); // start pooling readers reader.Dispose(); var indexThreads = new RunThread[4]; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x] = new RunThread(this, x % 2, writer); indexThreads[x].Name = "Thread " + x; indexThreads[x].Start(); } long startTime = Environment.TickCount; long duration = 1000; while ((Environment.TickCount - startTime) < duration) { Thread.Sleep(100); } int delCount = 0; int addCount = 0; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].Run_Renamed = false; Assert.IsNull(indexThreads[x].Ex, "Exception thrown: " + indexThreads[x].Ex); addCount += indexThreads[x].AddCount; delCount += indexThreads[x].DelCount; } for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].Join(); } for (int x = 0; x < indexThreads.Length; x++) { Assert.IsNull(indexThreads[x].Ex, "Exception thrown: " + indexThreads[x].Ex); } //System.out.println("addCount:"+addCount); //System.out.println("delCount:"+delCount); writer.Dispose(); mainDir.Dispose(); }
public static bool Run() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { return(false); } instance = new StudioCommunicationClient(); #if DEBUG SetupDebugVariables(); #endif RunThread.Start(instance.UpdateLoop, "StudioCom Client"); return(true); }
public virtual void TestIndexing() { Directory mainDir = NewDirectory(); MockDirectoryWrapper wrapper = mainDir as MockDirectoryWrapper; if (wrapper != null) { wrapper.AssertNoDeleteOpenFile = true; } IndexWriter writer = new IndexWriter(mainDir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetMaxBufferedDocs(10).SetMergePolicy(NewLogMergePolicy(false, 2))); IndexReader reader = writer.Reader; // start pooling readers reader.Dispose(); RunThread[] indexThreads = new RunThread[4]; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x] = new RunThread(this, x % 2, writer); indexThreads[x].Name = "Thread " + x; indexThreads[x].Start(); } long startTime = DateTime.Now.Millisecond; long duration = 1000; while ((DateTime.Now.Millisecond - startTime) < duration) { Thread.Sleep(100); } int delCount = 0; int addCount = 0; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].Run_Renamed = false; Assert.IsNull(indexThreads[x].Ex, "Exception thrown: " + indexThreads[x].Ex); addCount += indexThreads[x].AddCount; delCount += indexThreads[x].DelCount; } for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].Join(); } for (int x = 0; x < indexThreads.Length; x++) { Assert.IsNull(indexThreads[x].Ex, "Exception thrown: " + indexThreads[x].Ex); } //System.out.println("addCount:"+addCount); //System.out.println("delCount:"+delCount); writer.Dispose(); mainDir.Dispose(); }
public WallbouncePresentation(EventInstance usingSfx = null, string dialogKeyPrefix = "WAVEDASH", string graphicsKeyPrefix = "", string playbackKeyPrefix = "") { GraphicsKeyPrefix = graphicsKeyPrefix; DialogKeyPrefix = dialogKeyPrefix; PlaybackKeyPrefix = playbackKeyPrefix; ScaleInPoint = new Vector2(1920f, 1080f) / 2f; ScreenWidth = 1920; ScreenHeight = 1080; pages = new List <WallbouncePresentationPage>(); verts = new VertexPositionColorTexture[6]; Tag = Tags.HUD; Viewing = true; loading = true; Add(new Coroutine(Routine(), true)); this.usingSfx = usingSfx; RunThread.Start(new Action(LoadingThread), "Wallbounce Presentation Loading", true); }
/// <summary> /// Save all mod and user settings. Use this instead of UserIO.SaveHandler(false, true) /// </summary> /// <returns>The routine enumerator.</returns> public static IEnumerator SaveSettings() { bool saving = true; RunThread.Start(() => { Invoke("SaveSettings"); saving = false; }, "MOD_IO", false); SaveLoadIcon.Show(Engine.Scene); while (saving) { yield return(null); } yield return(UserIO.SaveHandler(false, true)); SaveLoadIcon.Hide(); }
public virtual void TestIndexing() { Directory mainDir = new MockRAMDirectory(); IndexWriter writer = new IndexWriter(mainDir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED); writer.UseCompoundFile = false; IndexReader reader = writer.GetReader(); // start pooling readers reader.Close(); writer.MergeFactor = 2; writer.SetMaxBufferedDocs(10); RunThread[] indexThreads = new RunThread[4]; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x] = new RunThread(this, x % 2, writer); indexThreads[x].Name = "Thread " + x; indexThreads[x].Start(); } long startTime = (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond); long duration = 5 * 1000; while (((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - startTime) < duration) { System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 100)); } int delCount = 0; int addCount = 0; for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].run_Renamed_Field = false; Assert.IsTrue(indexThreads[x].ex == null); addCount += indexThreads[x].addCount; delCount += indexThreads[x].delCount; } for (int x = 0; x < indexThreads.Length; x++) { indexThreads[x].Join(); } //System.out.println("addCount:"+addCount); //System.out.println("delCount:"+delCount); writer.Close(); mainDir.Close(); }
private static IEnumerator _SaveSettings() { bool saving = true; RunThread.Start(() => { foreach (EverestModule mod in _Modules) { mod.SaveSettings(); } saving = false; }, "MOD_IO", false); SaveLoadIcon.Show(Engine.Scene); while (saving) { yield return(null); } yield return(patch_UserIO.SaveHandlerLegacy(false, true)); SaveLoadIcon.Hide(); _SavingSettings = false; }
public static bool Run() { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { return(false); } instance = new StudioCommunicationClient(); #if DEBUG //SetupDebugVariables(); #endif RunThread.Start(Setup, "StudioCom Client"); void Setup() { instance.thread = Thread.CurrentThread; Celeste.Celeste.Instance.Exiting += (o, e) => Destroy(); instance.UpdateLoop(); } return(true); }
public static void startThread( RunThread run ) { if( thread != null ) thread.Join(); switch( run ) { case RunThread.Init: thread = new Thread( new ThreadStart( loadMaps )); break; case RunThread.LoadLayer: thread = new Thread( new ThreadStart( loadLayers )); break; case RunThread.Update: thread = new Thread( new ThreadStart( loadImage )); break; case RunThread.SaveLayer: thread = new Thread( new ThreadStart( saveLayers )); break; } if( thread != null ) thread.Start(); }
public static void Main(string[] args) { try { string serverName = System.Environment.MachineName; string configurationFilename = null; foreach (string arg in args.ToList <string>()) { if (arg.StartsWith("/s:", StringComparison.InvariantCultureIgnoreCase)) { serverName = Regex.Replace(arg, @"^/s\:", "", RegexOptions.IgnoreCase).ToUpper(); } if (arg.StartsWith("/f:", StringComparison.InvariantCultureIgnoreCase)) { configurationFilename = Regex.Replace(arg, @"^/f\:", "", RegexOptions.IgnoreCase); } } #region Syntax information if (string.IsNullOrEmpty(configurationFilename)) { Console.WriteLine("Management Agent Run Profile Scheduler"); Console.WriteLine("Copyright (c) 2011-2016 Soren Granfeldt. All rights reserved."); Console.WriteLine(); Console.WriteLine("Description: Uses an XML input file to run management agents in a"); Console.WriteLine("specified sequence. Functionality is based on Microsoft Identity"); Console.WriteLine("Integration Server MASequencer Utility."); Console.WriteLine(); Console.WriteLine("Syntax: MARunScheduler /f:filename"); Console.WriteLine(); Console.WriteLine("Parameters:"); Console.WriteLine(); Console.WriteLine("Value Description"); Console.WriteLine(); Console.WriteLine("/f: filename Specifies the XML input file that contain"); Console.WriteLine(" the configuration details for running the"); Console.WriteLine(" management agents."); Console.WriteLine(); Console.WriteLine("Example:"); Console.WriteLine(); Console.WriteLine("To run MASequencer on the server {0} using the input file", serverName); Console.WriteLine("MARunScheduler.xml, use the following command:"); Console.WriteLine(); Console.WriteLine("MARunScheduler.exe /f:MARunScheduler.xml"); Console.WriteLine(); Console.WriteLine("For more information on parameters, see MARunScheduler.xml."); return; } #endregion configuration = MARunScheduler.Deserialize(Path.GetFullPath(configurationFilename)); Log("Started"); Log(string.Format("Running against server '{0}'", serverName)); ManagementScope WMInamespace; ConnectionOptions connOpt = new ConnectionOptions(); connOpt.Authentication = AuthenticationLevel.PacketPrivacy; WMInamespace = new ManagementScope(String.Format(@"\\{0}\{1}", serverName, FIMWMINamespace), connOpt); Action <object> action = (object runThread) => { RunThread thread = (RunThread)runThread; int repeatCount = thread.RepeatCount - 1; DateTime defaultThreadRunAfter = DateTime.MinValue; DateTime defaultThreadRunBefore = DateTime.MaxValue.AddSeconds(-1); DateTime threadRunBefore; DateTime threadRunAfter; if (!DateTime.TryParse(thread.RunBefore, out threadRunBefore)) { threadRunBefore = defaultThreadRunBefore; } if (!DateTime.TryParse(thread.RunAfter, out threadRunAfter)) { threadRunAfter = defaultThreadRunAfter; } while (thread.LoopIndefinitely || thread.RepeatCount > 0) { LogThread(thread.Name, string.Format("It's now {0}", DateTime.Now.TimeOfDay)); LogThread(thread.Name, string.Format("Thread should run before {0}", threadRunBefore.TimeOfDay)); LogThread(thread.Name, string.Format("Thread should after {0}", threadRunAfter.TimeOfDay)); LogThread(thread.Name, string.Format("Thread should on {0}", string.IsNullOrEmpty(thread.RunOnDays) ? "all days" : thread.RunOnDays)); if (DateTime.Now.TimeOfDay > threadRunAfter.TimeOfDay && DateTime.Now.TimeOfDay < threadRunBefore.TimeOfDay && RunToday(thread.RunOnDays)) { LogThread(thread.Name, string.Format("Starting cycle #{0}", (repeatCount - thread.RepeatCount) + 1)); DateTime defaultItemRunAfter = DateTime.MinValue; DateTime defaultItemRunBefore = DateTime.MaxValue.AddSeconds(-1); foreach (RunItem ri in thread.Item) { DateTime runItemRunBefore; DateTime runItemRunAfter; if (!DateTime.TryParse(ri.RunBefore, out runItemRunBefore)) { runItemRunBefore = defaultItemRunBefore; } if (!DateTime.TryParse(ri.RunAfter, out runItemRunAfter)) { runItemRunAfter = defaultItemRunAfter; } LogThreadMA(thread.Name, ri.MA, string.Format("Run Profile item should run before {0}", runItemRunBefore.TimeOfDay)); LogThreadMA(thread.Name, ri.MA, string.Format("Run Profile item should after {0}", runItemRunAfter.TimeOfDay)); LogThreadMA(thread.Name, ri.MA, string.Format("Run Profile item should on {0}", string.IsNullOrEmpty(ri.RunOnDays) ? "all days" : ri.RunOnDays)); if ((DateTime.Now.TimeOfDay > runItemRunAfter.TimeOfDay && DateTime.Now.TimeOfDay < runItemRunBefore.TimeOfDay && RunToday(ri.RunOnDays))) { #region Pre processing if (!(string.IsNullOrEmpty(ri.Preprocessing))) { ExecuteCommand(thread.Name, ri.Preprocessing, ri.PreprocessingArguments, ""); } #endregion #region Run profile string managementAgentQueryString = String.Format("SELECT * FROM MIIS_ManagementAgent WHERE Name='{0}'", ri.MA); ObjectQuery managementAgentQuery = new ObjectQuery(managementAgentQueryString); ManagementObjectSearcher MASearcher = new ManagementObjectSearcher(WMInamespace, managementAgentQuery); ManagementObjectCollection MAObjects = MASearcher.Get(); string result = "management-agent-not-found"; if (MAObjects.Count == 1) { ManagementObjectCollection.ManagementObjectEnumerator Enum = MAObjects.GetEnumerator(); Enum.MoveNext(); ManagementObject MAObject = (ManagementObject)Enum.Current; LogThreadMA(thread.Name, ri.MA, string.Format("Connected to MA '{0}' (Type: {1}, GUID: {2})", MAObject["name"].ToString(), MAObject["type"].ToString(), MAObject["Guid"].ToString())); List <string> param = new List <string>(); if (!string.IsNullOrEmpty(ri.RunProfile)) { param.Add(ri.RunProfile); } long NumCSObjects = long.Parse((string)MAObject.InvokeMethod("NumCSObjects", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Number of CS object(s): {0:n0}", NumCSObjects)); long NumTotalConnectors = long.Parse((string)MAObject.InvokeMethod("NumTotalConnectors", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Number of connectors: {0:n0}", NumTotalConnectors)); long NumTotalDisconnectors = long.Parse((string)MAObject.InvokeMethod("NumTotalDisconnectors", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Number of disconnectors: {0:n0}", NumTotalDisconnectors)); // pending imports long PendingImportAdds = long.Parse((string)MAObject.InvokeMethod("NumImportAdd", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Pending Import Add(s): {0:n0}", PendingImportAdds)); long PendingImportUpdates = long.Parse((string)MAObject.InvokeMethod("NumImportUpdate", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Pending Import Update(s): {0:n0}", PendingImportUpdates)); long PendingImportDeletes = long.Parse((string)MAObject.InvokeMethod("NumImportDelete", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Pending Import Delete(s): {0:n0}", PendingImportDeletes)); // pending exports long PendingExportAdds = long.Parse((string)MAObject.InvokeMethod("NumExportAdd", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Pending Export Add(s): {0:n0}", PendingExportAdds)); long PendingExportUpdates = long.Parse((string)MAObject.InvokeMethod("NumExportUpdate", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Pending Export Update(s): {0:n0}", PendingExportUpdates)); long PendingExportDeletes = long.Parse((string)MAObject.InvokeMethod("NumExportDelete", null)); LogThreadMA(thread.Name, ri.MA, string.Format("Pending Export Delete(s): {0:n0}", PendingExportDeletes)); bool thresholdsMet = false; if (ri.ThresholdLimits != null) { thresholdsMet = IsThresholdMet("Import Adds", thread.Name, NumTotalConnectors, ri.ThresholdLimits.MaximumPendingImportAdds, PendingImportAdds) || IsThresholdMet("Import Updates", thread.Name, NumTotalConnectors, ri.ThresholdLimits.MaximumPendingImportUpdates, PendingImportUpdates) || IsThresholdMet("Import Deletes", thread.Name, NumTotalConnectors, ri.ThresholdLimits.MaximumPendingImportDeletes, PendingImportDeletes) || IsThresholdMet("Export Adds", thread.Name, NumTotalConnectors, ri.ThresholdLimits.MaximumPendingExportAdds, PendingExportAdds) || IsThresholdMet("Export Updates", thread.Name, NumTotalConnectors, ri.ThresholdLimits.MaximumPendingExportUpdates, PendingExportUpdates) || IsThresholdMet("Export Deletes", thread.Name, NumTotalConnectors, ri.ThresholdLimits.MaximumPendingExportDeletes, PendingExportDeletes); } if (thresholdsMet) { LogThreadMA(thread.Name, ri.MA, "One or more thresholds met. Skipping run profile"); } else { LogThreadMA(thread.Name, ri.MA, string.Format("Only run on pending imports: {0:n0}", ri.OnlyRunIfPendingImports)); LogThreadMA(thread.Name, ri.MA, string.Format("Only run on pending exports: {0:n0}", ri.OnlyRunIfPendingExports)); if (((ri.OnlyRunIfPendingExports && (PendingExportAdds + PendingExportUpdates + PendingExportDeletes) > 0) || !ri.OnlyRunIfPendingExports) && ((ri.OnlyRunIfPendingImports && (PendingImportAdds + PendingImportUpdates + PendingImportDeletes) > 0) || !ri.OnlyRunIfPendingImports)) { LogThreadMA(thread.Name, ri.MA, string.Format("Running: '{0}'", ri.RunProfile)); result = (string)MAObject.InvokeMethod("Execute", param.ToArray()); LogThreadMA(thread.Name, ri.MA, string.Format("Run result: {0}", result)); } else { LogThreadMA(thread.Name, ri.MA, string.Format("There are no pending imports/exports; skipping run")); } } Enum.Dispose(); } else { Log(new Exception("Error connecting to MA"), ERROR_COULDNOTCONNECTOMANAGEMENTAGENT); LogThreadMA(thread.Name, ri.MA, string.Format("Error: Unable to connect to Management Agent '{0}'", ri.MA)); } #endregion #region RunDetails /* * // Check Run For Errors * switch (maResult.ToLower()) { * case "success": * case "completed-no-objects": * case "completed-warnings": * break; * case "completed-export-errors": * throw( new ApplicationException( "The Management Agent '" + maName + * "' reported import errors on execution. " + * "You will need to use the Identity Manager to determine the problem(s)." ) ); * default: * throw( new ApplicationException( "The Management Agent '" + maName + * "' failed on execution. The error returned is '" + maResult + "'" ) ); * } * // Fetch the run details for the ma * object xmlContent = ma.InvokeMethod( "RunDetails", null ); * XmlDocument xmlDoc = new XmlDocument(); * xmlDoc.LoadXml( xmlContent.ToString() ); * // Check Run Stage Count * int runStateCount = 0; * runStateCount += GetNodeCount( xmlDoc, "stage-add" ); * runStateCount += GetNodeCount( xmlDoc, "stage-update" ); * runStateCount += GetNodeCount( xmlDoc, "stage-rename" ); * runStateCount += GetNodeCount( xmlDoc, "stage-delete" ); * runStateCount += GetNodeCount( xmlDoc, "stage-delete-add" ); * // Check Export Count * int exportCount = 0; * exportCount += GetNodeCount( xmlDoc, "export-add" ); * exportCount += GetNodeCount( xmlDoc, "export-update" ); * exportCount += GetNodeCount( xmlDoc, "export-rename" ); * exportCount += GetNodeCount( xmlDoc, "export-delete" ); * exportCount += GetNodeCount( xmlDoc, "export-delete-add" ); * public static int GetNodeCount(XmlDocument xmlDoc, string nodeName) { * int returnCount = 0; * XmlNodeList nodes = xmlDoc.DocumentElement.GetElementsByTagName( nodeName ); * if ((nodes != null) && (nodes.Count > 0)) { * foreach (XmlNode node in nodes) { * if (node.InnerText.Length > 0) { * returnCount += int.Parse( node.InnerText ); * } * } * } * return returnCount; * } * */ #endregion #region Post processing if (!(string.IsNullOrEmpty(ri.Postprocessing))) { if ((result.Equals("success", StringComparison.InvariantCultureIgnoreCase)) || (ri.ContinueOnFailure)) { ExecuteCommand(thread.Name, ri.Postprocessing, ri.PostprocessingArguments, result); } else { Log("Post-processing not run because of run error"); } } #endregion #region Wait minutes if (ri.WaitMinutes > 0) { LogThreadMA(thread.Name, ri.MA, ri.WaitMinutes.ToString("Start: Waiting 0 minute(s)")); Thread.Sleep(ri.WaitMinutes * 60000); LogThreadMA(thread.Name, ri.MA, ri.WaitMinutes.ToString("End: Waiting 0 minute(s)")); } #endregion } else { LogThreadMA(thread.Name, ri.MA, string.Format("Item '{0}' won't run due to day or time restrictions", ri.MA)); } } LogThread(thread.Name, string.Format("Ending cycle #{0}", repeatCount - thread.RepeatCount)); } else { LogThread(thread.Name, string.Format("Thread '{0}' won't run due to day or time restrictions", thread.Name)); } if (thread.WaitMinutes > 0) { LogThread(thread.Name, thread.WaitMinutes.ToString("Start: Thread waiting 0 minute(s)")); Thread.Sleep(thread.WaitMinutes * 60000); LogThread(thread.Name, thread.WaitMinutes.ToString("End: Thread waiting 0 minute(s)")); } thread.RepeatCount--; } }; List <Task> tasks = new List <Task>(); foreach (RunThread thread in configuration.Thread) { tasks.Add(new Task(action, thread)); } foreach (Task t in tasks) { t.Start(); } foreach (Task t in tasks) { t.Wait(); } tasks = null; #region Clearing run histories if (configuration.ClearRunHistory.ClearRuns) { ObjectQuery cleartAgentQuery = new ObjectQuery(string.Format("SELECT * FROM MIIS_Server", serverName)); ManagementObjectSearcher clearRunsMASearcher = new ManagementObjectSearcher(WMInamespace, cleartAgentQuery); ManagementObjectCollection clearRunsMAObjects = clearRunsMASearcher.Get(); if (clearRunsMAObjects.Count == 0) { throw new Exception("Unable to find server: " + serverName); } else { foreach (ManagementObject oReturn in clearRunsMAObjects) { DateTime clearDate = DateTime.Now.AddMinutes(-configuration.ClearRunHistory.AgeInMinutes); Log(string.Format("Clearing runs older than {0}", clearDate.ToLocalTime().ToLocalTime())); object[] methodArgs = { clearDate.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:00") }; string clearRunsResult = (string)oReturn.InvokeMethod("ClearRuns", methodArgs); Log(string.Format("Clear Runs Result: {0}", string.Format("Run result: {0}", clearRunsResult))); if (clearRunsResult.ToString().ToLower() != "success") { throw new Exception("Failed to delete old operation logs: " + clearRunsResult.ToString()); } } } } #endregion Log("Ended"); } catch (FileNotFoundException fileNotFoundException) { string error = string.Format("File Not Found: {0}", fileNotFoundException.FileName); Console.WriteLine(error); Log(new Exception(error), ERROR_CONFIGURATIONFILENOTFOUND); } catch (Exception ex) { string error = string.Format("{0}-{1}", ex.GetType().ToString(), ex.Message); Log(new Exception(error), ERROR_UNSPECIFIEDERROR); } }
public void Start() { RunThread.Start(); }