Esempio n. 1
0
        public WindowsService()
        {
            InitializeComponent();

            appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            appPath = System.IO.Path.GetDirectoryName(appPath);

            IniFile file = new IniFile(appPath + "/app.ini");

            //Notification
            notification = file.IniReadValue("Settings", "Notification") == "Yes";
            _redis       = file.IniReadValue("Settings", "Redis");
            _key         = file.IniReadValue("Settings", "Key");
            if (_key != "")
            {
                if (!notification)
                {
                    timer          = new System.Timers.Timer(30000);//30 sec
                    timer.Elapsed += new ElapsedEventHandler(this.ServiceTimer_Tick);
                }
                else
                {
                    try
                    {
                        //ping timer
                        timer          = new System.Timers.Timer(60 * 5 * 1000);//5 minutes
                        timer.Elapsed += new ElapsedEventHandler(this.ServiceTimer_TickPing);


                        subscriberThread = new SubscribeThread(_redis, gotMessage, _key);

                        Thread oThread = new Thread(new ThreadStart(subscriberThread.Start));

                        oThread.Start();
                    }
                    catch (Exception ex)
                    {
                        //no redis
                    }
                }
            }
            this.ServiceName     = "SplickItRemotePrint";
            this.EventLog.Source = "SplickItRemotePrint";
            this.EventLog.Log    = "Application";

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.
            this.CanHandlePowerEvent         = true;
            this.CanHandleSessionChangeEvent = true;
            this.CanPauseAndContinue         = true;
            this.CanShutdown = true;
            this.CanStop     = true;

            if (!EventLog.SourceExists("SplickIt"))
            {
                EventLog.CreateEventSource("SplickIt", "Application");
            }
        }
Esempio n. 2
0
        private void connect()
        {
            if (subscriberThread != null)
            {
                subscriberThread.ok = false;
                oThread.Interrupt();
            }
            // ServiceTimer_TickPing(this, null);
            timer.Start();
            try
            {
                //server
                subscriberThread = new SubscribeThread(_redis, gotMessage, _key);

                oThread = new Thread(new ThreadStart(subscriberThread.Start));

                oThread.Start();
            }
            catch (Exception ex)
            {
                //no redis
            }
        }