/// <summary> /// Construct a message from the values. /// </summary> /// <param name="service">The servie the command is for.</param> /// <param name="majorMessage">The MessageCode for this message.</param> /// <param name="customMessage">The custom message code.</param> /// <param name="data">A string for extra data.</param> internal Message(ServiceCtl service, MessageCode majorMessage, int customMessage, string data) { this.service = service; this.majorMessage = majorMessage; this.customMessage = customMessage; this.data = data; }
/// <summary> /// Stop services thread /// </summary> private void StopServicesThread() { // Set that the database is being shut down so that no more changes can be made. logger.Info("The database is being shut down."); Store.GetStore().ShutDown(); for (int i = serviceList.Count; i > 0; --i) { ServiceCtl svc = (ServiceCtl)serviceList[i - 1]; messageDispatcher(new StopMessage(svc)); } servicesStarted.Reset(); servicesStopped.Set(); logger.Info("Services stopped."); stopThread = null; }
/// <summary> /// Construct a Message from a string. /// </summary> /// <param name="service">The servie the command is for.</param> /// <param name="message">The string to parse.</param> internal Message(ServiceCtl service, string message) { this.service = service; string[] args = message.Split(seperator, 4); if (args.Length < 3 || !args[0].Equals(messageSignature)) { throw new InvalidMessageException(); } if (args.Length == 4) { data = args[3]; } customMessage = int.Parse(args[2]); majorMessage = (MessageCode)Enum.Parse(typeof(MessageCode), args[1]); }
/// <summary> /// Dispatching the message /// </summary> /// <param name="msg">Message details</param> private void messageDispatcher(Message msg) { ServiceCtl svcCtl = msg.service; try { lock (this) { switch (msg.MajorMessage) { case MessageCode.Start: if ((svcCtl.State == Simias.Service.State.Stopped) && svcCtl.Enabled) { try { svcCtl.Start(); } catch (Exception ex) { if (RunAsServer == false || String.Compare(ex.Message, "Failed to create Flaim DB.") != 0) { throw ex; } else { logger.Debug("Exception Message {0} recieved", ex.Message); logger.Debug("Exiting from the current process, as process failed to Open FLAIM Database "); StopServices(); Environment.Exit(-1); } } } break; case MessageCode.Stop: if (svcCtl.state == State.Running || svcCtl.state == State.Paused) { svcCtl.Stop(); } break; case MessageCode.Pause: if (svcCtl.state == State.Running) { svcCtl.Pause(); } break; case MessageCode.Resume: if (svcCtl.state == State.Paused) { svcCtl.Resume(); } break; case MessageCode.Custom: svcCtl.Custom(msg.CustomMessage, msg.Data); break; } } } catch (Exception ex) { logger.Error(ex, ex.Message); } }
internal CustomMessage(ServiceCtl service, int message, string data) : base(service, MessageCode.Custom, message, data) { }
internal ResumeMessage(ServiceCtl service) : base(service, MessageCode.Resume, 0, null) { }
internal PauseMessage(ServiceCtl service) : base(service, MessageCode.Pause, 0, null) { }
internal StopMessage(ServiceCtl service) : base(service, MessageCode.Stop, 0, null) { }