static void Main()
        {
            #if DEBUG
            System.Diagnostics.Debugger.Launch();
            string           comands   = "c: \n cd c:\\Windows\\System32 \n net start service1 \n";
            string[]         lines     = comands.Split('\n');
            Process          myProcess = new Process();
            ProcessStartInfo startInfo =
                new ProcessStartInfo();
            startInfo.FileName               = "cmd.exe";
            startInfo.Verb                   = "open";
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardInput  = true;
            startInfo.RedirectStandardOutput = true;
            // start cmd
            //appoint startInfo for process
            myProcess.StartInfo = startInfo;
            myProcess.Start();
            //
            StreamWriter cmdWriter = myProcess.StandardInput;
            if (cmdWriter.BaseStream.CanWrite)
            {
                foreach (var line in lines)
                {
                    cmdWriter.WriteLine(line);
                }
            }

            cmdWriter.Close();
        #endif


            // Create an Instance of ServiceController
            ServiceController myService = new ServiceController();
            // Define the name of your service here.
            // I am using the 'Service1' for this example

            // After this point, myService is now refering to "MonitoringSitesService"
            myService.ServiceName = "Service1";

            // array of services
            ServiceBase[] ServicesToRun;

            using (WebApp.Start <Startup>(url: host_address))
            {
                ServicesToRun = new ServiceBase[]
                {
                    new Service1()
                };
                var controller = new StatusController();
                ServiceBase.Run(ServicesToRun);
            }


            // Get the status of myService
            // Possible Status Returns: { StartPending, Running, PausePending, Paused,
            // StopPending, Stopped, ContinuePending }
        }
Exemple #2
0
 protected override void OnStop()
 {
     //  _provider.StopEventsManager();
     myThread.Abort();
     generalThread.Abort();
     _provider.StopEventsManager();
     Thread.Sleep(1000);
     StatusController.setServiceStatus(false);
     AddLog("stop");
 }
Exemple #3
0
        protected override void OnStart(string[] args)
        {
            myThread.Start();
            generalThread.Start();
            //  string address = "http://localhost:9000/";
            //  run host
            //  using (WebApp.Start<Startup>(url: address))
            //  { }

            StatusController.setServiceStatus(true);
            AddLog("start");
        }
Exemple #4
0
        //private Thread webAppThread;


        public Service1()
        {
            InitializeComponent();
            this.CanStop             = true;
            this.CanPauseAndContinue = true;
            this.AutoLog             = true;

            // set status of service
            StatusController.setServiceStatus(true);

            // create provider
            _provider              = new EventsManager();
            _provider.RisingTimer += _provider_RisingTimer;

            // create threads
            myThread = new Thread(IsWork);
            myThread.SetApartmentState(ApartmentState.STA);

            generalThread = new Thread(_provider.RunEventsManager);
            generalThread.SetApartmentState(ApartmentState.STA);

            /*webAppThread = new Thread(WebApp.Start<Startup>(url: host_address));
             * webAppThread.SetApartmentState(ApartmentState.STA);*/
        }
Exemple #5
0
 protected override void OnContinue()
 {
     _provider.RunEventsManager();
     StatusController.setServiceStatus(true);
     AddLog("start");
 }
Exemple #6
0
 protected override void OnPause()
 {
     _provider.StopEventsManager();
     StatusController.setServiceStatus(false);
     AddLog("stop");
 }