Exemple #1
0
        public async Task <bool> ChangeDeviceGroup(TenantModel tenantModel, DeviceGroupModel targetDeviceGroup, List <DeviceModel> deviceModels, string json)
        {
            bool ret     = false;
            bool changed = false;

            try
            {
                foreach (DeviceModel deviceModel in deviceModels)
                {
                    HttpContent jsonContent = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
                    if (await Api.PutChangeDeviceGroupAsync(tenantModel.Context, deviceModel.Id, jsonContent, cancellationTokenSource.Token))
                    {
                        int i = this.DeviceModels.IndexOf(deviceModel);
                        deviceModel.Product     = targetDeviceGroup.Product;
                        deviceModel.DeviceGroup = targetDeviceGroup.DeviceGroup;
                        this.DeviceModels.RemoveAt(i);
                        this.DeviceModels.Insert(i, deviceModel);
                        changed = true;
                    }
                }
                ret = true;

                if (changed)
                {
                    NotificationChangeDevice?.Invoke(this, null);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return(ret);
            }
            return(ret);
        }
        private void gridDeviceGroups_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            DeviceGroupModel model = this.gridDeviceGroups.SelectedItem as DeviceGroupModel;
            ItemCollection   items = this.gridDeviceGroups.ContextMenu.Items;

            if (model == null)
            {
                foreach (MenuItem item in items)
                {
                    item.IsEnabled = false;
                }

                this.gridDevices.ItemsSource = null;
                this.gridDevices.Items.Refresh();

                return;
            }
            else
            {
                foreach (MenuItem item in items)
                {
                    item.IsEnabled = true;
                }
            }

            this.CurrDeviceGroup = model;
            ViewDevices(CurrDeviceGroup);
        }
        private void menuitemDeviceGroupExtract_Click(object sender, RoutedEventArgs e)
        {
            DeviceGroupModel currDeviceGroup = this.gridDeviceGroups.SelectedItem as DeviceGroupModel;

            var dialog = new ExtractWindow();

            dialog.Owner           = this;
            dialog.CurrTenant      = this.CurrentTenantModel;
            dialog.CurrProduct     = null;
            dialog.CurrDeviceGroup = currDeviceGroup;

            var dialogResult = dialog.ShowDialog();

            dialog = null;
        }
Exemple #4
0
        private List <DeviceGroupModel> ParseDeviceGroupModel(List <AzureSphereDeviceGroup> groups)
        {
            List <DeviceGroupModel> groupsModels = new List <DeviceGroupModel>();

            foreach (AzureSphereDeviceGroup group in groups)
            {
                DeviceGroupModel model = new DeviceGroupModel();
                model.Context               = group;
                model.DeviceGroup           = group.Name;
                model.Description           = group.Description;
                model.Product               = GetProductNameForId(group.ProductId);
                model.OsFeedType            = group.OsFeedTypeStr;
                model.UpdatePolicy          = group.UpdatePolicyStr;
                model.CurrentDeploymentDate = group.CurrentDeployment?.DeploymentDateUtc.ToLocalTime();
                groupsModels.Add(model);
            }
            return(groupsModels);
        }
        private void ViewDevices(DeviceGroupModel model)
        {
            List <DeviceModel> newObj = new List <DeviceModel>();

            foreach (DeviceModel device in this.Devices)
            {
                if (device.DeviceGroup == model.DeviceGroup && device.Product == model.Product)
                {
                    newObj.Add(device);
                }
            }
            this.gridDevices.ItemsSource = newObj;
            this.gridDevices.Items.Refresh();

            if (newObj.Count > 0)
            {
                ViewDeviceMenu(true);
            }
        }
Exemple #6
0
        public async Task <bool> DeleteDeviceGroup(TenantModel tenantModel, DeviceGroupModel deviceGroupModel)
        {
            bool ret = false;

            try
            {
                if (await DeleteDeviceGroupAsync(tenantModel.Context, deviceGroupModel.Context))
                {
                    ret = true;
                    this.DeviceGroupModels = await GetDeviceGroupsAsync(tenantModel.Context);

                    NotificationChangeDeviceGroup?.Invoke(this, null);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return(false);
            }
            return(ret);
        }
Exemple #7
0
        private List <DeviceModel> ParseDeviceModel(List <AzureSphereDevice> devices)
        {
            List <DeviceModel> devicesModels = new List <DeviceModel>();

            foreach (AzureSphereDevice device in devices)
            {
                DeviceModel      model = new DeviceModel();
                DeviceGroupModel group = GetDeviceGroupModel(device.DeviceGroupId);

                model.Context = device;
                model.ChipSku = device.ChipSkuStr;
                model.Id      = device.Id;
                if (group != null)
                {
                    model.DeviceGroup = group.DeviceGroup;
                    model.Product     = group.Product;
                }
                devicesModels.Add(model);
            }
            return(devicesModels);
        }
Exemple #8
0
        public async Task <bool> Deployment(TenantModel tenantModel, DeviceGroupModel deviceGroupModel, string json)
        {
            bool ret = false;

            try
            {
                HttpContent jsonContent = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
                if (await Api.PostDeployAsync(tenantModel.Context, deviceGroupModel.Context, jsonContent, cancellationTokenSource.Token))
                {
                    this.DeviceGroupModels = await GetDeviceGroupsAsync(tenantModel.Context);

                    NotificationChangeDeviceGroup?.Invoke(this, null);
                    NotificationChangeDeployment?.Invoke(this, null);
                    ret = true;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return(ret);
            }
            return(ret);
        }
Exemple #9
0
        private async void Deploy_Click(object sender, RoutedEventArgs e)
        {
            bool isUploadButtonChecked = this.UploadButton.IsEnabled;

            Cursor = System.Windows.Input.Cursors.Wait;
            this.SelectButton.IsEnabled = false;
            this.UploadButton.IsEnabled = false;
            this.DeployButton.IsEnabled = false;
            this.CloseButton.IsEnabled  = false;
            try
            {
                ModelManager     modelManager = ModelManager.GetInstance();
                DeviceGroupModel dev          = deployWindow.SelectDeviceGroupModel;
                string           req          = ImageIdList.Text;

                if (await modelManager.Deployment(deployWindow.CurrentTenantModel, dev, req))
                {
                    MessageBox.Show("Deployment is success.",
                                    "Ok", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("Deployment is failure.",
                                    "Error", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Cursor = null;
            this.SelectButton.IsEnabled = true;
            this.UploadButton.IsEnabled = isUploadButtonChecked;
            this.DeployButton.IsEnabled = true;
            this.CloseButton.IsEnabled  = true;
        }
Exemple #10
0
        // Deployment list
        public async Task <List <DeploymentModel> > GetDeploymentModels(TenantModel tenantModel, DeviceGroupModel deviceGroupModel)
        {
            List <DeploymentModel> deploymentModels;

            if (deviceGroupModel == null)
            {
                return(null);
            }

            try
            {
                deploymentModels = await GetDeploymentsAsync(tenantModel.Context, deviceGroupModel.Context);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
                return(null);
            }
            return(deploymentModels);
        }