private void Connect()
 {
     try
     {
         if (IsClientCertificateDefault)
         {
             bool isConnected = _sensorsClient.CheckServerAvailable();
             _connectionsStatus = isConnected ? ConnectionsStatus.Ok : ConnectionsStatus.Error;
         }
         else
         {
             var responseObj = _sensorsClient.GetTree();
             _connectionsStatus = ConnectionsStatus.Ok;
             _lastUpdate        = DateTime.Now;
             Update(responseObj);
         }
     }
     catch (Exception e)
     {
         Logger.Error($"ClientMonitoringModel: Connect error: {e}");
         _connectionsStatus = ConnectionsStatus.Error;
         foreach (var node in Nodes)
         {
             node.Status = TextConstants.UpdateError;
         }
     }
     OnConnectionStatusChangedEvent();
 }
 private void StartTreeThread()
 {
     if (_treeThread != null)
     {
         try
         {
             _treeThread.Interrupt();
         }
         catch (ThreadInterruptedException exception)
         { }
         catch (Exception e)
         {
             Logger.Error($"Failed to stop working tree thread, error = {e}");
         }
     }
     _connectionsStatus = ConnectionsStatus.Init;
     _treeThread        = new Thread(MonitoringLoopStep);
     _treeThread.Name   = $"Thread_{DateTime.Now.ToLongTimeString()}";
     _treeThread.Start();
 }
 private void Update()
 {
     try
     {
         var responseObj = _sensorsClient.GetUpdates();
         _connectionsStatus = ConnectionsStatus.Ok;
         _lastUpdate        = DateTime.Now;
         Update(responseObj);
     }
     catch (Exception e)
     {
         Logger.Error($"ClientMonitoringModel: Update error: {e}");
         _connectionsStatus = ConnectionsStatus.Error;
         foreach (var node in Nodes)
         {
             node.Status = TextConstants.UpdateError;
         }
     }
     OnConnectionStatusChangedEvent();
 }
        public ClientMonitoringModel()
        {
            _nameToNode        = new Dictionary <string, MonitoringNodeBase>();
            Nodes              = new ObservableCollection <MonitoringNodeBase>();
            Products           = new ObservableCollection <ProductViewModel>();
            _connectionAddress =
                $"{ConfigProvider.Instance.ConnectionInfo.Address}:{ConfigProvider.Instance.ConnectionInfo.Port}";
            _sensorsClient     = new GrpcClientConnector(_connectionAddress);
            _connectionsStatus = ConnectionsStatus.Init;
            _uiContext         = SynchronizationContext.Current;

            if (IsClientCertificateDefault)
            {
                string defaultCAPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                    CommonConstants.DefaultCertificatesFolderName,
                                                    CommonConstants.DefaultCACrtCertificateName);

                X509Certificate2 defaultCA = new X509Certificate2(defaultCAPath);
                CertificatesProcessor.AddCertificateToTrustedRootCA(defaultCA);
            }

            StartTreeThread();
        }