コード例 #1
0
        public DeviceConfigPanel(DeviceType deviceType, [CanBeNull] TemplateWithArgs <DeviceTemplate> device,
                                 [CanBeNull] IEnumerable <TemplateWithArgs <ConsumerTemplate> > consumers)
        {
            InitializeComponent();

            _deviceType = deviceType;

            _deviceViewModel = new DeviceConfigViewModel(DeviceConfigContainer, GetDeviceList(_deviceType));
            _deviceViewModel.ComboBox.SelectionChanged += DeviceComboBox_OnSelectionChanged;
            _deviceViewModel.ComboBox.FindAndSelectFirstByString(device?.Template.Identifier, 0);
            _deviceViewModel.ParamPanel.Context        = device?.Args ?? EmptyContext.Instance;
            _deviceViewModel.ParamPanel.LayoutChanged += ConfigurationPanel_OnLayoutChanged;
            _deviceViewModel.Current = device?.Template;

            if (consumers != null)
            {
                foreach (var consumer in consumers)
                {
                    if (string.IsNullOrWhiteSpace(consumer?.Template.Identifier))
                    {
                        continue;
                    }
                    AppendConsumerConfig(consumer);
                }
            }

            if (!_consumerViewModels.Any())
            {
                AppendConsumerConfig();
            }
        }
コード例 #2
0
        private async Task <DeviceConfigViewModel> GetConfig(string deviceId)
        {
            string receivedJson = await restService.GetRequest($"/api/configuration/{deviceId}");

            DeviceConfigViewModel model = new DeviceConfigViewModel();

            try
            {
                JToken parsedJson = JToken.Parse(receivedJson);
                foreach (JToken token in parsedJson)
                {
                    var property = (JProperty)token;
                    if (property.Name.Equals("Intervals"))
                    {
                        model.Intervals = JsonConvert.DeserializeObject <Dictionary <string, object> >(
                            parsedJson["Intervals"]
                            .ToString());
                        continue;
                    }

                    List <Dictionary <string, object> > childNodes = property.Children().Children()
                                                                     .Select(node => node.ToObject <Dictionary <string, object> >()).ToList();

                    switch (property.Name)
                    {
                    case "IOControllers":
                        model.IOControllers = childNodes;
                        break;

                    case "PowerSupplies":
                        model.PowerSupplies = childNodes;
                        break;

                    case "Programs":
                        model.Programs = childNodes;
                        break;

                    default:
                        continue;
                    }
                }
            }
            catch (JsonReaderException e)
            {
                Logger.Error(e, $"Unable to parse the JSON string for device {deviceId}", receivedJson);
                throw;
            }

            return(model);
        }
コード例 #3
0
        public async void LoadConfigTest()
        {
            FakeResponseHandler fakeConfig = new FakeResponseHandler();

            fakeConfig.AddFakeResponse(
                new Uri($"{ApplicationURLS.Backend}/api/configuration/TestingDevice"),
                new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(mockJsonData)
            });
            RestService restService = new RestService(new HttpClient(fakeConfig), mockTokenAcquisition,
                                                      mockConfiguration);
            DeviceConfigViewController deviceDetailViewController = new DeviceConfigViewController(restService);
            ViewResult viewResult = await deviceDetailViewController.Index("TestingDevice");

            DeviceConfigViewModel model = viewResult.Model as DeviceConfigViewModel;

            Assert.NotNull(model);
            Assert.Equal(1, model.NumberOfPrograms);
            Assert.Single(model.Programs);
            Assert.Equal("TestingDevice", viewResult.ViewData["DeviceID"]);
        }
コード例 #4
0
 public DeviceWindow()
 {
     InitializeComponent();
     vm = new DeviceConfigViewModel();
     this.DataContext = vm;
 }
コード例 #5
0
        private void btnDeleteDevice_Click(object sender, RoutedEventArgs e)
        {
            DeviceConfigViewModel dc = this.DataContext as DeviceConfigViewModel;

            dc.Data.Remove(this.lbDevices.SelectedItem as DeviceInfo);
        }
コード例 #6
0
        private void btnAddDevice_Click(object sender, RoutedEventArgs e)
        {
            DeviceConfigViewModel dc = this.DataContext as DeviceConfigViewModel;

            dc.Data.Add(new Core.Models.DeviceInfo(this.tbModel.Text, this.tbManufacturer.Text));
        }
コード例 #7
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            DeviceConfigViewModel dc = this.DataContext as DeviceConfigViewModel;

            WorkspaceService.Instance.Settings.DeviceInfoList = dc.Data.ToList <Core.Models.DeviceInfo>();
        }