Exemplo n.º 1
0
        protected override void OnStart(string[] args)
        {
            String COM    = WINAPI_ServiceManager.GetStringParameterValue(ServiceName, "ComPort", "COM9");
            uint   IPPORT = WINAPI_ServiceManager.GetDWORDParameterValue(ServiceName, "TCPPort", 9998);

            CreateEventSource(ServiceName);
            this.EventLog.Source = this.ServiceName;
            this.EventLog.WriteEntry("Service starting using ComPort: " + COM + " and IP Port: " + IPPORT, EventLogEntryType.Information, 100);

            if (COM == "" || IPPORT == 0)
            {
                throw new Exception("Parameters not configured");
            }

            CreateServer(COM, IPPORT);
            this.EventLog.WriteEntry("Service started using ComPort: " + COM + " and IP Port: " + IPPORT);

            //File.WriteAllText("C:\\Storage\\test.txt", ServiceName + COM + IPPORT);
        }
Exemplo n.º 2
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     if (!System.Environment.UserInteractive)
     {
         if (args.Length > 0)
         {
             if (args[0].StartsWith("-service:"))
             {
                 ServiceBase[] ServicesToRun;
                 ServicesToRun = new ServiceBase[]
                 {
                     new ServiceImplementation(args[0].Substring(9))
                 };
                 ServiceBase.Run(ServicesToRun);
                 return;
             }
         }
     }
     else
     {
         if (args.Length == 1)
         {
             if (args[0] == "-run")
             {
                 ServiceImplementation serviceImplementation = new ServiceImplementation(ServiceName);
                 serviceImplementation.CommandLineStart();
                 Console.ReadLine();
                 serviceImplementation.CommandLineStop();
             }
             else if (args[0] == "-install")
             {
                 Console.WriteLine("Installing service...");
                 if (WINAPI_ServiceManager.CreateService(ServiceName, ServiceName, Assembly.GetExecutingAssembly().Location + " -service:" + ServiceName, "KNXuart TinySerial to TCP Service", true))
                 {
                     ServiceImplementation.CreateEventSource(ServiceName);
                     WINAPI_ServiceManager.SetParameterStringValue(ServiceName, "ComPort", "COM9");
                     WINAPI_ServiceManager.SetParameterDWORDValue(ServiceName, "TCPPort", 9998);
                     Console.WriteLine("OK");
                 }
                 else
                 {
                     Console.WriteLine("Failed");
                 }
                 return;
             }
             else if (args[0] == "-uninstall")
             {
                 Console.WriteLine("Uninstalling service...");
                 if (WINAPI_ServiceManager.RemoveService(ServiceName))
                 {
                     Console.WriteLine("OK");
                 }
                 else
                 {
                     Console.WriteLine("Failed");
                 }
                 return;
             }
         }
         else
         {
             Console.WriteLine("Service Module, use -install to install and -uninstall to remove");
         }
     }
 }