Exemple #1
0
        public static void DoWork(object body)
        {
            ServiceBody srv = (ServiceBody)body;
            Thread      importThread = null, exportThread = null;

            //srv.GetInfo();
            while (!Program.killAll)
            {
                if (srv.GetInfo())
                {
                    break;
                }
                Thread.Sleep(10000); // Ждем 10 секунд, похоже нет подключения
            }

            exportThread = new Thread(DoExportData);
            exportThread.Start(srv);

            importThread = new Thread(DoImportData);
            importThread.Start(srv);

            while (!Program.killAll)
            {
                Thread.Sleep(500);
            }
        }
Exemple #2
0
        public static void DoImportData(object body)
        {
            int         nDelay = Convert.ToInt32(Program.cfg["TimeoutReadKKM"]);
            ServiceBody srv    = (ServiceBody)body;
            int         nSec   = 0;

            Program.WriteLogName(Program.logNameImport, " ");
            Program.WriteLogName(Program.logNameImport, "Thread( Импорт данных из УКМ используя MySQL) beg");

            while (!Program.killAll)
            {
                if (nSec >= (nDelay * 2))
                {
                    srv.RunImportData();
                    nSec = 0;
                }
                Thread.Sleep(500);
                nSec++;
            }
            Program.WriteLogName(Program.logNameImport, "Kill (Импорт данных из УКМ используя MySQL) detected");
            Program.WriteLogName(Program.logNameImport, "Thread(Импорт данных из УКМ используя MySQL) end");
        }
Exemple #3
0
 protected override void OnStart(string[] args)
 {
     // TODO: Add code here to start your service.
     srv = new ServiceBody();
     srv.ServiceStart(args);
 }
Exemple #4
0
        static void Main(string[] args)
        {
            ServiceBase[] ServicesToRun;

            String path = System.Reflection.Assembly.GetExecutingAssembly().Location;

            cfgFile       = Path.ChangeExtension(path, ".cfg");
            logMain       = Path.ChangeExtension(path, ".log");
            logNameExport = Path.Combine(Path.GetDirectoryName(path), "Sms.WriteKKM.NET.log");
            logNameImport = Path.Combine(Path.GetDirectoryName(path), "Sms.ReadKKM.NET.log");

            Load(cfgFile);

            commandTimeout = Convert.ToInt32(Program.GetValue("CommandTimeOut", "1000"));
            lSizeLogFile   = Convert.ToInt32(Program.GetValue("SizeLogFile", "104857600"));

            if (args.Length >= 2)
            {
                if ((args[0].ToLower() == "-install") || (args[0].ToLower() == "-i"))
                {
                    sms_new.SCM.CreateService(args[1]);
                    return;
                }
                else
                if ((args[0].ToLower() == "-remove") || (args[0].ToLower() == "-r"))
                {
                    sms_new.SCM.RemoveService(args[1]);
                    return;
                }
                else
                if (args.Length >= 1)
                {
                    if ((args[0].ToLower() == "-debug") || (args[0].ToLower() == "-d"))
                    {
                        string fileStop = Path.Combine(Path.GetDirectoryName(path), "Sms_stop.t-m");

                        bDebugMode = true;

                        WriteLog("");
                        WriteLog("==============================================================================");
                        WriteLog("Режим отладки сервиса...");
                        //Console.WriteLine("Режим отладки сервиса...");

                        signalHandler += HandleConsoleSignal;
                        ConsoleHelper.SetSignalHandler(signalHandler, true);

                        ServiceBody srv = new ServiceBody();
                        srv.ServiceStart(args);

                        while (!File.Exists(fileStop))
                        {
                            Thread.Sleep(200);
                        }
                        File.Delete(fileStop);
                        killAll = true;

                        srv.ServiceStop();

                        WriteLog("Режим отладки сервиса остановлен");

                        return;
                    }
                }
            }

            // More than one user Service may run within the same process. To add
            // another service to this process, change the following line to
            // create a second service object. For example,
            //
            //   ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
            //
            ServicesToRun = new ServiceBase[] { new ServiceSMS("Service1") };

            ServiceBase.Run(ServicesToRun);
        }