private static Constants.ServiceState GetServiceStateByStateName(string stateName) { Constants.ServiceState result = Constants.ServiceState.Unknown; switch (stateName) { case "Running": result = Constants.ServiceState.Running; break; case "Stopped": result = Constants.ServiceState.Stopped; break; case "Paused": result = Constants.ServiceState.Paused; break; case "Start Pending": result = Constants.ServiceState.StartPending; break; case "Stop Pending": result = Constants.ServiceState.StopPending; break; case "Continue Pending": result = Constants.ServiceState.ContinuePending; break; case "Pause Pending": result = Constants.ServiceState.PausePending; break; } return(result); }
/// <summary> /// create a new Status object encapsulating the state of the service to be /// communicated back to clients /// </summary> /// <param name="ss">the state of the service: Running, Shutting down, or Stopped</param> /// <param name="e">the current epoch</param> /// <param name="v">the current version within the epoch</param> /// <param name="s">a pre-cached XML element describing the state of the processes in the service</param> public Status(Constants.ServiceState ss, UInt64 e, UInt64 v, byte[] s) { state = ss; epoch = e; version = v; status = s; }
private void UpdateStatus(Constants.ServiceState newState, UInt64 newEpoch, UInt64 newVersion) { var outerElement = new XElement("RegisteredProcesses"); outerElement.SetAttributeValue("state", newState); outerElement.SetAttributeValue("epoch", newEpoch); outerElement.SetAttributeValue("version", newVersion); foreach (var pg in processes) { outerElement.Add(MakeProcessGroupElement(pg.Key, pg.Value)); } var statusDoc = new XDocument(); statusDoc.Add(outerElement); using (var ms = new MemoryStream()) { using (var xw = System.Xml.XmlWriter.Create(ms)) { statusDoc.WriteTo(xw); } status = new Status(newState, newEpoch, newVersion, ms.ToArray()); } foreach (var w in waiters.Where(w => w.Value.Ready)) { w.Value.Dispatch(status); } var toRemove = waiters.Where(w => w.Value.Ready).Select(w => w.Key).ToArray(); foreach (var k in toRemove) { waiters.Remove(k); } }