Пример #1
0
        private void LoadDeviceListData()
        {
            _deviceSummaries = new List <DeviceSummary>();

            RegistryKey key = Registry.CurrentUser.OpenSubKey(DMConstants.RegistryStore);

            if (key == null)
            {
                return;
            }

            string[] valueNames = key.GetSubKeyNames();
            foreach (string valueName in valueNames)
            {
                RegistryKey subKey = Registry.CurrentUser.OpenSubKey(DMConstants.RegistryStore + "\\" + valueName);
                if (subKey == null)
                {
                    continue;
                }
                DeviceSummary ds = new DeviceSummary();
                ds.DeviceId         = valueName;
                ds.ConnectionString = (string)subKey.GetValue(DMConstants.RegistryConnectionString);

                _deviceSummaries.Add(ds);
            }
        }
Пример #2
0
        private void OnSaveDeviceInfo(object sender, RoutedEventArgs e)
        {
            string deviceId = DeviceNameBox.Text.ToLower();

            if (deviceId.Length == 0 || DeviceConnectionStringBox.Text.Length == 0)
            {
                MessageBox.Show("Both the device name and the connection string must to be filled.");
                return;
            }

            foreach (DeviceSummary deviceSummary in _deviceSummaries)
            {
                if (deviceSummary.DeviceId.ToLower() == deviceId)
                {
                    MessageBox.Show("Duplicate device id. Choose a unique device id.");
                    return;
                }
            }

            SaveDeviceListData(DeviceNameBox.Text, DeviceConnectionStringBox.Text);

            DeviceSummary ds = new DeviceSummary();

            ds.DeviceId         = DeviceNameBox.Text;
            ds.ConnectionString = DeviceConnectionStringBox.Text;

            _deviceSummaries.Add(ds);
            _deviceSummaries.Sort((x, y) => x.DeviceId.CompareTo(y.DeviceId));

            RebuildDeviceList();
            DeviceList.SelectedItem = ds;
        }
Пример #3
0
        private async void GetPropertiesAsync()
        {
            if (DeviceList.SelectedItems.Count != 1)
            {
                MessageBox.Show("Only one device can be selected.");
                return;
            }

            DeviceSummary ds = (DeviceSummary)DeviceList.SelectedItem;

            DeviceClient     deviceClient     = DeviceClient.CreateFromConnectionString(ds.ConnectionString, TransportType.Mqtt);
            DeviceTwinClient deviceTwinClient = new DeviceTwinClient(deviceClient);

            JObject root = await deviceTwinClient.GetRootAsync();

            DesiredPropertyValueBox.Text  = root["properties"]["desired"].ToString();
            ReportedPropertyValueBox.Text = root["properties"]["reported"].ToString();
        }
Пример #4
0
        private void OnSelectedDeviceChanged(object sender, SelectionChangedEventArgs e)
        {
            if (DeviceList.SelectedItems.Count == 0)
            {
                return;
            }

            if (DeviceList.SelectedItems.Count == 1)
            {
                DeviceSummary ds = (DeviceSummary)DeviceList.SelectedItem;

                DeviceNameBox.Text             = ds.DeviceId;
                DeviceConnectionStringBox.Text = ds.ConnectionString;

                GetPropertiesAsync();
            }
            else
            {
                ClearDeviceDetails("<multiple>");
            }
        }