Exemple #1
0
 private void Update(Action <bool> callback)
 {
     try
     {
         _serviceClient.BeginGetChangedScenarios(_lastUpdateTime,
                                                 (o) =>
         {
             var result = Handle(() => _serviceClient.EndGetChangedScenarios(o));
             if (result.Success && result.Value != null && result.Value.Any())
             {
                 var changedScenariosLW = result.Value;
                 var changedScenarios   = Scenarios.Where(x => changedScenariosLW.Any(z => z.ScenarioId == x.ScenarioId)).ToArray();
                 foreach (var changedScenario in changedScenariosLW)
                 {
                     var existingScenario = changedScenarios.FirstOrDefault(x => x.ScenarioId.Equals(changedScenario.ScenarioId));
                     if (existingScenario != null)
                     {
                         existingScenario.CurrentValue = changedScenario.CurrentValue;
                         existingScenario.IsAvailable  = changedScenario.IsAvailable;
                     }
                 }
                 _lastUpdateTime = result.ServerTime ?? _lastUpdateTime;
                 ScenariosChanged?.Invoke(changedScenarios);
             }
             callback?.Invoke(result.Success);
         }, null);
     }
     catch
     {
         callback?.Invoke(false);
     }
 }
        private void Handler_HasCome(object sender, Message msg)
        {
            _toServiceMessenger = Utils.GetAnswerMessenger(msg);
            switch ((ServiceOperation)msg.What)
            {
            case ServiceOperation.GetClientSettings:
                _callbacks.Dequeue(ServiceOperation.GetClientSettings, Utils.GetData <ConnectionCredentials>(msg));
                break;

            case ServiceOperation.GetIsConnected:
                _callbacks.Dequeue(ServiceOperation.GetIsConnected, Utils.GetData <ManagerConnectionState>(msg));
                break;

            case ServiceOperation.GetScenarios:
                _callbacks.Dequeue(ServiceOperation.GetScenarios, Utils.GetData <ScenarioInfo[]>(msg));
                break;

            case ServiceOperation.GetNotifications:
                _callbacks.Dequeue(ServiceOperation.GetNotifications, Utils.GetData <LazuriteNotification[]>(msg));
                break;

            case ServiceOperation.ConnectionLost:
                ConnectionLost?.Invoke();
                break;

            case ServiceOperation.ConnectionRestored:
                ConnectionRestored?.Invoke();
                break;

            case ServiceOperation.CredentialsInvalid:
                LoginOrPasswordInvalid?.Invoke();
                break;

            case ServiceOperation.CredentialsLoaded:
                CredentialsLoaded?.Invoke();
                break;

            case ServiceOperation.NeedClientSettings:
                NeedClientSettings?.Invoke();
                break;

            case ServiceOperation.NeedRefresh:
                NeedRefresh?.Invoke();
                break;

            case ServiceOperation.ScenariosChanged:
                ScenariosChanged?.Invoke(Utils.GetData <ScenarioInfo[]>(msg));
                break;

            case ServiceOperation.SecretCodeInvalid:
                SecretCodeInvalid?.Invoke();
                break;

            case ServiceOperation.ConnectionError:
                ConnectionError?.Invoke();
                break;
            }
        }