private async Task RefreshAllGrids()
        {
            Cursor = Cursors.Wait;
            try
            {
                if (this.CurrentTenantModel != null)
                {
                    ModelManager modelMgr = ModelManager.GetInstance();
                    this.Title = $"Azure Sphere Explorer - {CurrentTenantModel.Tenant}";
                    List <ProductModel> productModel = await modelMgr.GetProductModels(CurrentTenantModel, true);

                    List <DeviceGroupModel> deviceGroupModel = await modelMgr.GetDeviceGroupModels(CurrentTenantModel, true);

                    List <DeviceModel> deviceModels = await modelMgr.GetDeviceModels(CurrentTenantModel, true);

                    this.gridProducts.ItemsSource     = productModel;
                    this.gridDeviceGroups.ItemsSource = deviceGroupModel;
                    this.gridDevices.ItemsSource      = deviceModels;
                }
            }
            finally
            {
                Cursor = null;
            }
        }
Exemple #2
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ModelManager modelManager = ModelManager.GetInstance();

            this.DeviceGroupModels = await modelManager.GetDeviceGroupModels(CurrentTenantModel, false);

            this.DeviceModels = await modelManager.GetDeviceModels(CurrentTenantModel, false);

            foreach (DeviceGroupModel group in DeviceGroupModels)
            {
                DeviceGroupBox.Items.Add(group.DeviceGroup + "/" + group.Product);
            }

            foreach (DeviceModel model in this.DeviceModels)
            {
                DeviceModelEx newObj;
                if (model == CurrDevice)
                {
                    newObj = new DeviceModelEx(model, true);
                }
                else
                {
                    newObj = new DeviceModelEx(model, false);
                }
                DeviceModelIces.Add(newObj);
            }
            gridDeviceGroups.ItemsSource = this.DeviceModelIces;
        }
        private async void NotificationChangeDevice(object sender, EventArgs e)
        {
            ModelManager modelMgr = ModelManager.GetInstance();

            Console.Write("called NotificationChangeDevice()");
            this.Devices = await modelMgr.GetDeviceModels(CurrTenant, false);

            ViewDevices(CurrDeviceGroup);
        }
        private async void NotificationChangeDevice(object sender, EventArgs e)
        {
            ModelManager modelMgr = ModelManager.GetInstance();

            Console.Write("called NotificationChangeDevice()");
            List <DeviceModel> deviceModels = await modelMgr.GetDeviceModels(CurrentTenantModel, false);

            this.gridDevices.ItemsSource = deviceModels;
            this.gridDevices.Items.Refresh();
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ModelManager modelMgr = ModelManager.GetInstance();

            List <ProductModel> products = await modelMgr.GetProductModels(CurrTenant, false);

            this.DeviceGroups = await modelMgr.GetDeviceGroupModels(CurrTenant, false);

            this.Devices = await modelMgr.GetDeviceModels(CurrTenant, false);

            this.gridProducts.ItemsSource = products;

            if (CurrProduct != null)
            {
                int index = products.IndexOf(CurrProduct);
                this.gridProducts.SelectedIndex = index;

                ViewProduct(index);
                ViewDeviceGroups(CurrProduct);
            }

            if (CurrDeviceGroup != null)
            {
                foreach (ProductModel model in products)
                {
                    if (model.Product == this.CurrDeviceGroup.Product)
                    {
                        CurrProduct = model;
                        break;
                    }
                }

                int indexP = products.IndexOf(CurrProduct);
                this.gridProducts.SelectedIndex = indexP;

                ViewProduct(indexP);
                ViewDeviceGroups(CurrProduct);
                ViewDevices(CurrDeviceGroup);
            }
            modelMgr.NotificationChangeDevice      += NotificationChangeDevice;
            modelMgr.NotificationChangeDeviceGroup += NotificationChangeDeviceGroup;
        }
Exemple #6
0
        private async void Change_Click(object sender, RoutedEventArgs e)
        {
            List <DeviceModel> changeDeviceModels = new List <DeviceModel>();
            ModelManager       modelManager       = ModelManager.GetInstance();
            var index             = DeviceGroupBox.SelectedIndex;
            var targetDeviceGroup = DeviceGroupModels[index];
            var req = "\"" + targetDeviceGroup.Context.Id + "\"";

            bool changed = false;

            Cursor = System.Windows.Input.Cursors.Wait;
            this.ChangeButton.IsEnabled = false;
            this.LoadButton.IsEnabled   = false;
            this.CloseButton.IsEnabled  = false;
            foreach (DeviceModelEx model in this.DeviceModelIces)
            {
                if (model.IsChecked)
                {
                    changeDeviceModels.Add(model.DeviceModel);
                }
            }

            if (changeDeviceModels.Count >= 1)
            {
                if (await modelManager.ChangeDeviceGroup(CurrentTenantModel, targetDeviceGroup, changeDeviceModels, req))
                {
                    changed = true;
                }
            }
            else
            {
                Cursor = null;
                this.ChangeButton.IsEnabled = true;
                this.LoadButton.IsEnabled   = true;
                this.CloseButton.IsEnabled  = true;
                return;
            }

            if (changed)
            {
                this.DeviceModels = await modelManager.GetDeviceModels(CurrentTenantModel, false);

                foreach (DeviceModel model in this.DeviceModels)
                {
                    DeviceModelEx newObj = GetDeviceModelEx(model.Id);
                    if (newObj != null)
                    {
                        DeviceModelIces.Remove(newObj);
                        newObj.Product     = model.Product;
                        newObj.DeviceGroup = model.DeviceGroup;
                        newObj.DeviceModel = model;
                        DeviceModelIces.Add(newObj);
                    }
                }
                gridDeviceGroups.ItemsSource = this.DeviceModelIces;
                this.gridDeviceGroups.Items.Refresh();
            }
            Cursor = null;
            this.ChangeButton.IsEnabled = true;
            this.LoadButton.IsEnabled   = true;
            this.CloseButton.IsEnabled  = true;
        }