Esempio n. 1
0
        /// <summary>
        /// События по таймеру
        /// </summary>
        static void OnTimerTick()
        {
            DebugHelper.WriteLogEntry("Notificator OnTimerTick");
            if (_lastCheckedTime.AddMilliseconds(_checkInterval) > DateTime.Now)
            {
                return;
            }

            //Проверяем, наступило ли время. Если не наступило, то просто выходим
            if (_lastCheckedTime.AddMilliseconds(_checkInterval) > DateTime.Now)
            {
                return;
            }

            //Задаем время, когда в следующий раз разбудить устройство
            try
            {
                WakeupScheduler.ScheduleWakeUp(DateTime.Now.AddMilliseconds(_checkInterval));
                DebugHelper.WriteLogEntry("WakeupScheduler.ScheduleWakeUp " + DateTime.Now.AddMilliseconds(_checkInterval));
            }
            catch (ExternalException exception)
            {
                DebugHelper.WriteLogEntry(exception, exception.Message);
                throw;
            }
            catch (Exception exception)
            {
                DebugHelper.WriteLogEntry(exception, "Error in scheduling wakeup program launch");
                throw;
            }

            //Сохраняем время последней проверки
            _lastCheckedTime = DateTime.Now;

            GetData();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            InitNotification();

            //Определение нотификаций и событий
            _notification                    = new NotificationWithSoftKeys();
            _notification.LeftSoftKey        = new NotificationSoftKey(SoftKeyType.Hide, Properties.Resources.Program_LeftSoftKey);
            _notification.RightSoftKey       = new NotificationSoftKey(SoftKeyType.Dismiss, Properties.Resources.Program_RightSoftKey);
            _notification.RightSoftKeyClick += OnNotificationRightSoftKeyClick;

            //Запуск сервиса и регистрация сообщения для него
            ServiceApplication.Name = Interprocess.ServiceName;
            ServiceApplication.RegisterMessage(Interprocess.WM_QUIT_SERVICE);
            ServiceApplication.RegisterMessage(Interprocess.WM_TIMER_TICK);
            ServiceApplication.OnRegisteredMessage += ServiceApplication_OnRegisteredMessage;

            Cache.InitPath(SystemConfiguration.AppInstallPath + "\\Cache");
            _baseLogic = new BaseLogic(new DataLogic(), new CommunicationLogic());
            //_baseLogic.IDataLogic.ClearNotificationTempDataInCache();
            _eventsGetResponsePrev = new EventsGetResponse();

            //автовход
            if (_baseLogic.IDataLogic.GetToken() != "")
            {
                try
                {
                    _baseLogic.AutoLogin();
                    _eventsGetResponsePrev = _baseLogic.EventsGet(true, false, true);

                    DebugHelper.WriteLogEntry("Notificator AutoLogin success.");

                    /*_eventsGetResponsePrev.CommentsCount = 0;
                    *  _eventsGetResponsePrev.FriendsCount = 0;
                    *  _eventsGetResponsePrev.MessagesCount = 0;*/
                }
                catch (VKException ex)
                {
                    CatchErrors(ex);
                }
                catch (Exception ex)
                {
                    DebugHelper.WriteLogEntry(ex, "Unexpected error.");
                }
            }
            else
            {
                DebugHelper.WriteLogEntry("Notificator service can't be started, there are no token in registry.");
                Application.Exit();
            }

            //Устанавливаем время последней проверки
            _lastCheckedTime = DateTime.Now;

            //Считываем из реестра значение периода проверки
            _checkInterval = GetCheckInterval();

            //Задаем время, когда необходимо будет разбудить устройство
            try
            {
                WakeupScheduler.ScheduleWakeUp(_lastCheckedTime.AddMilliseconds(_checkInterval));
            }
            catch (ExternalException exception)
            {
                DebugHelper.WriteLogEntry(exception, exception.Message);
                throw;
            }
            catch (Exception exception)
            {
                DebugHelper.WriteLogEntry(exception, "Error in scheduling wakeup program launch");
                throw;
            }

            ServiceApplication.Run();
        }