/// <summary> /// Send a message back to the Deployment Controller that issued this InstructionSet /// </summary> /// <param name="message"></param> /// <returns>True if delivered</returns> public bool ReportMessage(Message message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (message is InstructionMessage) { InstructionMessage m = (InstructionMessage)message; m.DeploymentControllerID = DeploymentControllerID; m.InstructionSetID = ID; } try { return(SurgeBranchManager.SendMessage(message, Connection, BranchManager)); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("_InstructionSet.Report", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } return(false); }
public void Execute(SurgeBranchManager branchManager) { try { DateTime start = DateTime.UtcNow; List <MessageConnection> managers; lock (DeploymentManagers) managers = DeploymentManagers.ToList(); List <string> results = null; foreach (string dir in STEM.Sys.IO.Path.ExpandRangedPath(Directory)) { if (System.IO.Directory.Exists(dir)) { if (TargetType == PollerTarget.Files) { results = STEM.Sys.IO.Directory.STEM_GetFiles(dir, FileFilter, DirectoryFilter, Recurse ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly, false); } else { results = STEM.Sys.IO.Directory.STEM_GetDirectories(dir, DirectoryFilter, Recurse ? System.IO.SearchOption.AllDirectories : System.IO.SearchOption.TopDirectoryOnly, false); } STEM.Sys.Serialization.Dictionary <string, List <string> > ret = new Sys.Serialization.Dictionary <string, List <string> >(); foreach (string d in results.Select(i => System.IO.Path.GetDirectoryName(i)).Distinct()) { ret[d] = results.Where(i => System.IO.Path.GetDirectoryName(i) == d).Select(i => System.IO.Path.GetFileName(i)).ToList(); } PollResult p = new PollResult() { PollTimeMilliseconds = (DateTime.UtcNow - start).TotalMilliseconds, Listing = ret, DeploymentControllerID = DeploymentControllerID, PollError = "" }; foreach (MessageConnection d in managers) { d.Send(p); } } else { PollResult p = new PollResult() { PollTimeMilliseconds = (DateTime.UtcNow - start).TotalMilliseconds, Listing = new Sys.Serialization.Dictionary <string, List <string> >(), DeploymentControllerID = DeploymentControllerID, PollError = dir + " does not exist." }; foreach (MessageConnection d in managers) { d.Send(p); } } } } catch { } }
protected void Run(SurgeBranchManager branchManager, MessageConnection connection, string cacheDirectory, KeyManager keyManager) { BranchManager = branchManager; Connection = connection; try { KeyManager = keyManager; Started = DateTime.UtcNow; if (cacheDirectory != null) { ReportMessage(new ExecutionStarted(this)); } this.PostMortemMetaData["ManagedThreadId"] = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString(System.Globalization.CultureInfo.CurrentCulture); PrepareSet(); int iNum = 0; while (true) { if (_Instructions.Count <= iNum) { break; } if (_Stop) { return; } PrepareSet(); _Instructions[iNum].Message = ""; _Instructions[iNum].Start = DateTime.UtcNow; if (_Instructions[iNum].Stage == STEM.Surge.Stage.Skip || _Instructions[iNum].Stage == STEM.Surge.Stage.Completed) { string xml = SerializeWithLimitedRefresh(iNum - 1); if (cacheDirectory != null) { File.WriteAllText(Path.Combine(cacheDirectory, ID.ToString() + ".is"), xml); } _Instructions[iNum].Finish = DateTime.UtcNow; iNum++; continue; } else { string xml = SerializeWithLimitedRefresh(iNum - 1, iNum); if (cacheDirectory != null) { File.WriteAllText(Path.Combine(cacheDirectory, ID.ToString() + ".is"), xml); } } try { _Instructions[iNum].PopulatePostMortemMeta = _Instructions[iNum].PopulatePostMortemMeta && CachePostMortem; _Instructions[iNum].Run(); } catch (Exception ex) { _Instructions[iNum].Exceptions.Add(ex); STEM.Sys.EventLog.WriteEntry(ProcessName, ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } _Instructions[iNum].Finish = DateTime.UtcNow; iNum++; } SerializeWithLimitedRefresh(iNum - 1, iNum); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("_InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } finally { Completed = DateTime.UtcNow; _Stop = true; if (cacheDirectory != null) { try { ExecutionCompleted ec = new ExecutionCompleted(this); foreach (Instruction i in _Instructions) { foreach (Exception e in i.Exceptions) { STEM.Sys.EventLog.WriteEntry(ProcessName, e.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } } ReportMessage(ec); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("_InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } } bool error = false; try { foreach (Instruction i in _Instructions) { if (i.Exceptions.Count > 0) { error = true; break; } } } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } if (branchManager != null) { try { branchManager.EndRun(this, error); } catch (Exception ex) { STEM.Sys.EventLog.WriteEntry("InstructionSet.Run", ex.ToString(), STEM.Sys.EventLog.EventLogEntryType.Error); } } Dispose(); } }
public abstract void Run(SurgeBranchManager branchManager, MessageConnection connection, string cacheDirectory, KeyManager keyManager, string clientAddress);