Exemplo n.º 1
0
 private static void PullNotifications()
 {
     try
     {
         var message = DataTransport.GetRequest <string>(PullNotificationsQuery + Guid.NewGuid(), true, 120000);
         if (!message.Contains("Timeout"))
         {
             if (NotificationRecivedEvent != null)
             {
                 Application.Current.Dispatcher.BeginInvoke(new Action(() => NotificationRecivedEvent(message)));
             }
         }
         if (IsStarted)
         {
             PullNotifications();
         }
     }
     catch (Exception ex)
     {
         EventAggregator.GetEvent <ShowErrorEvent>().Publish(new Exception("Ошибка при попытке получения уведомлений.", ex));
         Thread.Sleep(60000);
         if (IsStarted)
         {
             PullNotifications();
         }
     }
 }
Exemplo n.º 2
0
        private static void GetChanges(string query = null)
        {
            try
            {
                var result = DataTransport.GetRequest <UpdateInfo>(query ?? PullValuesChangesQuery, true, 120000, new PlanObjectConverter());
                if (result != null && (result.ChangedValues.Count > 0 || result.UpdateObjectTree))
                {
                    OnValuesChangedEvent(result);
                }

                if (IsStarted)
                {
                    GetChanges();
                }
            }
            catch (Exception ex)
            {
                EventAggregator.GetEvent <ShowErrorEvent>().Publish(new Exception("Ошибка при попытке получения значений датчиков.", ex));
                Thread.Sleep(60000);
                if (IsStarted)
                {
                    GetChanges(query);
                }
            }
        }
Exemplo n.º 3
0
        private void GetPeople()
        {
            ObservableCollection <Person> peoples;
            ObservableCollection <Person> guests;

            peoples = _dataTransport.GetRequest <ObservableCollection <Person> >(Urls.People, true, 30000);
            guests  = _dataTransport.GetRequest <ObservableCollection <Person> >(Urls.Guests, true, 30000);

            if (peoples == null || guests == null)
            {
                return;
            }
            var allPeople = peoples.AddRange(guests);

            People = StaticPeopleList = new ObservableCollection <Person>(allPeople);

            OnDataReceivedEvent();
        }
Exemplo n.º 4
0
        private bool CheckUpdates()
        {
            if (_serverInfo.UpdateNeed)
            {
                UpdatesChecked(true);
                return(false);
            }

            var    queryUrl = "/updates/?client-version=" + _serverInfo.UpdateVersion;
            string updateUrl;

            try
            {
                updateUrl = _dataTransport.GetRequest <string>(queryUrl, false);
            }
            catch (Exception ex)
            {
                Application.Current.Dispatcher.Invoke(() => _eventAggregator.GetEvent <ShowErrorEvent>().Publish(
                                                          new Exception("Ошибка при проверке обновлений.", ex)));
                _logger.ErrorException("Ошибка при проверке обновлений", ex);
                UpdatesChecked(false);
                return(true);
            }
            if (!string.IsNullOrEmpty(updateUrl))
            {
                Stream responseStream;
                try
                {
                    WebRequest  request  = WebRequest.Create(_serverInfo.CommonServerAddress + updateUrl + "?apikey=" + _sessionInfo.ApiKey);
                    WebResponse response = request.GetResponse();
                    responseStream = response.GetResponseStream();
                }
                catch (Exception ex)
                {
                    Application.Current.Dispatcher.Invoke(() => _eventAggregator.GetEvent <ShowErrorEvent>().Publish(
                                                              new Exception("Ошибка при загрузке обновлений.", ex)));
                    _logger.ErrorException("Ошибка при загрузке обновления", ex);
                    UpdatesChecked(false);
                    return(true);
                }
                if (responseStream == null)
                {
                    return(true);
                }
                var unzipped = UnZipUpdate(responseStream);
                UpdatesChecked(unzipped);
                return(!unzipped);
            }
            return(true);
        }
Exemplo n.º 5
0
        private void GetPlanObjects()
        {
            try
            {
                RootObjects = new ObservableCollection <BaseObject>(_dataTransport.GetRequest <List <BaseObject> >(Urls.Data, true, 100000, new PlanObjectConverter()));
                PlanObjects.Clear();
                FillPlanObjects(PlanObjects, RootObjects);

                if (!ValuesLongPull.IsStarted)
                {
                    ValuesLongPull.Start();
                }

                OnDataReceivedEvent();
            }
            catch (Exception ex)
            {
                throw new Exception("Ошибка при получении планов.", ex);
            }
        }
Exemplo n.º 6
0
 private static void PullLogs()
 {
     try
     {
         var item = DataTransport.GetRequest <LogItem>(LogsNotificationsQuery, true, 120000);
         if (!item.Equals(new LogItem()))
         {
             Application.Current.Dispatcher.BeginInvoke(new Action(() => LogItemRecivedEvent(item)));
         }
         if (IsStarted)
         {
             PullLogs();
         }
     }
     catch (Exception ex)
     {
         EventAggregator.GetEvent <ShowErrorEvent>().Publish(new Exception("Ошибка во время выполнения подписки на события.", ex));
         Thread.Sleep(60000);
         if (IsStarted)
         {
             PullLogs();
         }
     }
 }