예제 #1
0
        private void LoadCollection()
        {
            try
            {
                openFileDialog = new OpenFileDialog();
                // ------------------------------------
                openFileDialog.Filter      = "Json file (.json)|*.json|All Files(.*)|*.*";
                openFileDialog.FileName    = "Путь до файла";
                openFileDialog.Title       = "Загрузить данные с файла";
                openFileDialog.FilterIndex = 0;
                openFileDialog.DefaultExt  = FileManager.FilePath;
                // ------------------------------------

                bool?isOk = openFileDialog.ShowDialog() ?? false;
                if (isOk.Value)
                {
                    Sensors.Clear();
                    FileManager.FilePath = Path.GetDirectoryName(openFileDialog.FileName);
                    LogView = $"Load data from {FileManager.FilePath}";

                    List <Sensor> collection = FileManager.Read(FileManager.FilePath);
                    collection.ForEach(sensor => Sensors.Add(new SensorViewModel(sensor)));
                    UpdateCharts();
                }
            }
            catch (Exception ex)
            {
                var log = ExceptionHandler.Handler(ex);
                Log.WriteLog(log);
                MessageBox.Show(log, "Error! ", MessageBoxButton.OK, MessageBoxImage.Error);
                LogView = $"Error! {log}";
            }
        }
예제 #2
0
 /// <summary>
 /// Clears the configurations.
 /// </summary>
 private void ClearConfig()
 {
     Positions.Clear();
     Relays.Clear();
     Sections.Clear();
     Sensors.Clear();
     Switchs.Clear();
 }
예제 #3
0
 public void ClearAll()
 {
     Parallel.ForEach(Sensors, sensor =>
     {
         sensor.Dispose();
         while (!sensor.IsDisposed)
         {
             Thread.Sleep(PediatricSoftConstants.StateHandlerSleepTime);
         }
     });
     Sensors.Clear();
     RaisePropertyChanged("SensorCount");
 }
예제 #4
0
 private void GenerateCollection()
 {
     try
     {
         LogView = $"Generate new Charts";
         Sensors.Clear();
         Generator.GetSensors().ForEach(item => Sensors.Add(new SensorViewModel(item)));
         UpdateCharts();                 //Строим графики
     }
     catch (Exception ex)
     {
         var log = ExceptionHandler.Handler(ex);
         Log.WriteLog(log);
         MessageBox.Show(log, "Error! ", MessageBoxButton.OK, MessageBoxImage.Error);
         LogView = $"Error! {log}";
     }
 }
예제 #5
0
        private void Disconnect()
        {
            IsConnected = false;

            _sensorsReader?.StopPolling();
            Sensors?.Clear();

            if (_iotHubDeviceGateways?.Values == null)
            {
                return;
            }

            foreach (var iotHubDeviceGateway in _iotHubDeviceGateways.Values)
            {
                iotHubDeviceGateway?.Disconnect();
            }
        }
예제 #6
0
        static public void ReloadConfiguration()
        {
            Sensors.Clear();
            SensorsConfiguration = SensorsConfiguration.Load();

            foreach (var sensorConfiguration in SensorsConfiguration.Sensors)
            {
                switch (sensorConfiguration.SensorType)
                {
                case Configuration.SensorType.GrovePi:

                    var grovePiSensorConfiguration = sensorConfiguration as GrovePiSensorConfiguration;

                    Sensors.Add(GrovePiSensorBuilder.CreateSensor(
                                    grovePiSensorConfiguration.GroveSensorType,
                                    grovePiSensorConfiguration.GrovePort,
                                    grovePiSensorConfiguration.Name,
                                    grovePiSensorConfiguration.SensorId,
                                    grovePiSensorConfiguration.RgbDisplay
                                    ));
                    break;

                case Configuration.SensorType.OpenWeatherMap:

                    var openWeatherMapSensorConfiguration = sensorConfiguration as OpenWeatherMapSensorConfiguration;

                    Sensors.Add(WeatherSensorBuilder.GetSensor(
                                    openWeatherMapSensorConfiguration.SensorWeatherType,
                                    openWeatherMapSensorConfiguration.Name,
                                    openWeatherMapSensorConfiguration.SensorId,
                                    openWeatherMapSensorConfiguration.RgbDisplay
                                    ));
                    break;

                default:
                    throw new Exception("Unsupported SensorType in SensorsManager");
                }
            }
        }
예제 #7
0
 private void Port_UpdateCommandSended(object sender, EventArgs e)
 {
     Sensors.Clear();
 }