Beispiel #1
0
        /// <summary>
        /// Initialize ServiceApplication.
        /// </summary>
        static ServiceApplication()
        {
            _baseLogic = new BaseLogic(new DataLogic(), new CommunicationLogic());
            _clock = new System.Windows.Forms.Timer();

            _clock.Interval = 15000;

            _messageWindow = new ServiceMessageWindow();
            _messageWindow.OnRegisteredMessage += OnMessageWindowRegisteredMessage;
            _clock.Tick += OnTimerTick;
        }
Beispiel #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();
        }
Beispiel #3
0
 /// <summary>
 /// Инициализация класса. Не использован статический конструктор, т.к. принято решение
 /// инстанцировать синглтоны из одного места (сейчас в Program.cs, в перспективе может добавиться 
 /// инициализация в тестовых методах
 /// </summary>
 /// <param name="baseLogic"></param>
 public static void Init(BaseLogic baseLogic)
 {
     BaseLogic = baseLogic;
 }