/// <summary> /// /// </summary> /// <returns></returns> protected virtual int Execute() { if (_failedToStart) { int timeDiff = m_tickCount.CompareTo(DateTime.Now); if (timeDiff <= 0) { try { _failedToStart = !startServiceTask(); if (_failedToStart) { setTickCountInMin(1); // This make startService() to be called every minute if it fails } } catch (Exception e) { ServiceLogger.LogException(String.Format(@"Error starting {0} service", ServiceName), e); } } } return(-1); }
/// <summary> /// /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { //AQUI ServiceLogger.Log(String.Format(@"Starting {0}.", ServiceName)); setTickCountInSec(0.001); // 1 milisec // create our threadstart object to wrap our delegate method ThreadStart ts = new ThreadStart(this.ServiceMain); // create the manual reset event and // set it to an initial state of unsignaled m_shutdownEvent = new ManualResetEvent(false); // create the worker thread m_thread = new Thread(ts); // go ahead and start the worker thread m_thread.Start(); // call the base class so it has a chance // to perform any work it needs to base.OnStart(args); ServiceLogger.Log(String.Format(@"{0} started.", ServiceName)); }
/// <summary> /// Virtual method: This method must be implemented in every directly derived class /// </summary> /// <returns></returns> protected virtual bool startServiceTask() { //AQUI ServiceLogger.Log(String.Format(@"virtual startServiceTask {0}.", @"MenumateService")); return(true); }
/// <summary> /// /// </summary> /// <param name="inServiceHost"></param> /// <returns></returns> protected bool OpenServiceHost(ServiceHost inServiceHost) { bool result = false; try { inServiceHost.Open(); LogServiceInformation(inServiceHost); result = true; } catch (SystemException e) { ServiceLogger.LogException(String.Format("{0} Service Host failed to open.", inServiceHost.Description.Name), e); } catch (Exception e) { ServiceLogger.LogException(String.Format("{0} Service Host Service failed to open: {1}", inServiceHost.Description.Name, e.Message), e); } finally { //inServiceHost.Close(); } return(result); }
/// <summary> /// /// </summary> public MenumateService() { //AQUI ServiceLogger.Log(String.Format(@"Creating {0}.", @"MenumateService")); InitializeComponent(); // create a new timespan object // with a default of 10 seconds delay. m_delay = new TimeSpan(0, 0, 0, 10, 0); }
private void AddService(List <ServiceBase> services, MenumateServicesIdentifier serviceIdentifier) { try { services.Add(LoadService(serviceIdentifier)); } catch (Exception e) { ServiceLogger.LogException(String.Format(@"Error loading Service {0}. Does this file really exist?", serviceName(serviceIdentifier)), e); } }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="inServiceHost"></param> protected void LogEndPointsInformation <T>(T inServiceHost) where T : ServiceHost { if (inServiceHost.Description.Endpoints.Count > 0) { ServiceLogger.Log("Endpoints:"); foreach (ServiceEndpoint se in inServiceHost.Description.Endpoints) { ServiceLogger.Log(String.Format("\t{0} ({1})", se.Name, se.ListenUri)); } } }
/// <summary> /// /// </summary> protected override void OnStop() { // signal the event to shutdown m_shutdownEvent.Set(); // wait for the thread to stop giving it 10 seconds m_thread.Join(10000); // call the base class base.OnStop(); ServiceLogger.Log(String.Format(@"{0} stopped.", ServiceName)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="inServiceHost"></param> protected void LogBaseAddressesInformation <T>(T inServiceHost) where T : ServiceHost { if (inServiceHost.BaseAddresses.Count == 0) { ServiceLogger.Log("No base addresses defined"); } else { foreach (Uri uri in inServiceHost.BaseAddresses) { ServiceLogger.Log(uri.ToString()); } } }
//::::::::::::::::::::::::::::::::: /// <summary> /// Load all WCF Services: The Service IDs are in an XML configuration file /// </summary> /// <param name="inConfigFilename"></param> /// <returns></returns> public List <ServiceHost> LoadWebServices(string inConfigFilename) { try { return(LoadWebServicesFromXML(ServiceInfo.GetXMLDocFromFile(inConfigFilename))); } catch (System.Xml.XmlException xe) { string message = String.Format("Error loading Menumate.WinServices config file: {0} (problem with XML format?)", inConfigFilename); ServiceLogger.LogException(message, xe); return(defaultWebService()); } catch (Exception e) { ServiceLogger.LogException("Error loading Menumate.WinServices config file", e); return(defaultWebService()); } }
/// <summary> /// /// </summary> /// <returns></returns> public List <ServiceBase> LoadServices() { var serviceList = new List <ServiceBase>(); AddService(serviceList, MenumateServicesIdentifier.AccountingIntegration); // Standard Windows Service: AccountingIntegration AddService(serviceList, MenumateServicesIdentifier.LoyaltyMate); // WCF Service: LoyaltyMate AddService(serviceList, MenumateServicesIdentifier.WebMate); // WCF Service: WebMate AddService(serviceList, MenumateServicesIdentifier.ChefMate); // WCF Service: ChefMate AddService(serviceList, MenumateServicesIdentifier.ClippIntegration); // WCF Service: Clipp AddService(serviceList, MenumateServicesIdentifier.SmartLink); AddService(serviceList, MenumateServicesIdentifier.ThorLink); AddService(serviceList, MenumateServicesIdentifier.PocketVoucher); AddService(serviceList, MenumateServicesIdentifier.SalesForceIntegration); if (serviceList.Count == 0) { ServiceLogger.Log(@"No Menumate Services to be loaded."); } return(serviceList); }
public List <ServiceBase> LoadServices(string configFilename) { ServiceLogger.Log(string.Format(@"Loading Config File: {0} ...", configFilename)); try { return(LoadServicesFromXML(ServiceInfo.Instance.GetXmlDocumentFromFile(configFilename))); } catch (XmlException xe) { string message = String.Format("Error loading Service Loader config file: {0} (problem with XML format?)", configFilename); ServiceLogger.LogException(message, xe); return(defaultService()); } catch (Exception e) { ServiceLogger.LogException("Error loading Service Loader config file", e); return(defaultService()); } }
static void StartServiceEndPoint(ServiceController serviceController) { ServiceInfo serviceInfo = ServiceInfo.Instance; ServiceLogger.Log(string.Format(@"Menumate Services: Loading config file: {0}", serviceInfo.CinfigurationFilePath())); ServiceController[] svcs = ServiceController.GetServices(); int srvCounter = 0; foreach (ServiceController svc in svcs) { if (IsMenumateService(svc.ServiceName)) { srvCounter++; try { svc.Start(); } catch (Exception exc) { Console.WriteLine(string.Format(@"Failed to start Service: {0}: {1}", svc.DisplayName, exc.Message)); ServiceLogger.Log(string.Format(@"Failed to start Service: {0}: {1}", svc.DisplayName, exc.Message)); } if (srvCounter == ServiceCount) { break; } } } Console.WriteLine("The \"Menumate Service App\" service has started."); ServiceLogger.Log("The \"Menumate Service App\" service has started."); }
//::::::::::::::::::::::::::::::::: /// <summary> /// Load all WCF Services: The Service IDs are in an XmlDocument object /// </summary> /// <param name="inDoc"></param> /// <returns></returns> public List <ServiceHost> LoadWebServicesFromXML(XmlDocument inDoc) { List <ServiceHost> result = new List <ServiceHost>(); //:::::::::::::::::::::::::::::::::::::: XmlNodeList serviceNodeList = null; string serviceName = ""; serviceNodeList = inDoc.DocumentElement.SelectNodes("WebServices/WebService"); foreach (XmlNode serviceNode in serviceNodeList) { serviceName = serviceNode.Attributes["name"].Value; try { string loadThisService = serviceNode.Attributes["load"].Value; if (loadThisService.ToUpper() == @"YES") { result.Add(LoadWebService(strToServiceID(serviceNode.Attributes["id"].Value))); ServiceLogger.Log(String.Format(@"Web Service {0} created.", serviceName)); } } catch (Exception e) { ServiceLogger.LogException(String.Format(@"Error loading Web Service {0}. Does this file really exist?", serviceName), e); } } if (result.Count == 0) { //result.Add(new ServiceBase()); ServiceLogger.Log(@"No Menumate Web Services to be loaded."); } return(result); }
static void InstallServiceEndPoint(ServiceController serviceController) { try { Console.WriteLine(string.Format(@"Installing Service App: {0} ...", Assembly.GetCallingAssembly().Location)); ServiceLogger.Log(string.Format(@"Installing Service App: {0} ...", Assembly.GetCallingAssembly().Location)); ManagedInstallerClass.InstallHelper(new string[] { "/i", Assembly.GetCallingAssembly().Location }); Console.WriteLine("The \"Menumate Service App\" service has been installed."); ServiceLogger.Log("The \"Menumate Service App\" service has been installed."); } catch (Exception exc) { Console.WriteLine(string.Format(@"Failed to install Service App: {0}: {1}", Assembly.GetCallingAssembly().Location, exc.Message)); ServiceLogger.Log(string.Format(@"Failed to install Service App: {0}: {1}", Assembly.GetCallingAssembly().Location, exc.Message)); } }
static void StopServiceEndPoint(ServiceController serviceController) { ServiceController[] serviceControllers = ServiceController.GetServices(); int srvCounter = 0; foreach (ServiceController svc in serviceControllers) { if (IsMenumateService(svc.ServiceName)) { srvCounter++; try { svc.Stop(); } catch (Exception exc) { Console.WriteLine(string.Format(@"Failed to stop Service: {0}: {1}", svc.DisplayName, exc.Message)); ServiceLogger.Log(string.Format(@"Failed to stop Service: {0}: {1}", svc.DisplayName, exc.Message)); } if (srvCounter == ServiceCount) { break; } } } Console.WriteLine("The \"Menumate Service App\" service has been stopped."); ServiceLogger.Log("The \"Menumate Service App\" service has been stopped."); }
public ServiceBase LoadService(MenumateServicesIdentifier serviceIdentifier) { ServiceLogger.Log(string.Format(@"Loading Service: {0} ...", serviceName(serviceIdentifier))); switch (serviceIdentifier) { case MenumateServicesIdentifier.AccountingIntegration: return(new MenumateServiceAccounting()); case MenumateServicesIdentifier.LoyaltyMate: return(new MenumateServiceLoyaltyMate()); case MenumateServicesIdentifier.WebMate: return(new MenumateServiceWebMate()); case MenumateServicesIdentifier.ChefMate: return(new MenumateServiceChefMate()); case MenumateServicesIdentifier.ClippIntegration: return(new MenumateServiceClippIntegration()); case MenumateServicesIdentifier.SmartLink: return(new MenumateServiceSmartLink()); case MenumateServicesIdentifier.ThorLink: return(new MenumateServiceThorlink()); case MenumateServicesIdentifier.PocketVoucher: return(new MenumateServicePocketVoucher()); case MenumateServicesIdentifier.SalesForceIntegration: return(new MenumateServiceSalesForce()); default: throw new Exception(String.Format("Unknown Service: {0}", serviceIdentifier)); } }
/// <summary> /// /// </summary> protected override void OnContinue() { ServiceLogger.Log(String.Format(@"Resuming {0}.", ServiceName)); resumeMRunner(); ServiceLogger.Log(String.Format(@"{0} resumed.", ServiceName)); }
/// <summary> /// /// </summary> protected override void OnPause() { ServiceLogger.Log(String.Format(@"Pausing {0}.", ServiceName)); pauseMRunner(); ServiceLogger.Log(String.Format(@"{0} paused.", ServiceName)); }
/// <summary> /// /// </summary> protected override void OnStop() { ServiceLogger.Log(String.Format(@"Stopping {0}.", ServiceName)); stopMRunner(); ServiceLogger.Log(String.Format(@"{0} stopped.", ServiceName)); }
/// <summary> /// /// </summary> /// <param name="args"></param> protected override void OnStart(string[] args) { ServiceLogger.Log(String.Format(@"Starting {0}.", ServiceName)); startMRunner(); ServiceLogger.Log(String.Format(@"{0} started.", ServiceName)); }
/// <summary> /// /// </summary> protected override void OnPause() { ServiceLogger.Log(String.Format(@"{0} paused.", ServiceName)); }
/// <summary> /// /// </summary> protected override void OnContinue() { ServiceLogger.Log(String.Format(@"{0} continued.", ServiceName)); }