private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ModelManager modelMgr = ModelManager.GetInstance();

            if (!await modelMgr.Initialize())
            {
                MessageBox.Show("Failed to authenticate.", null, MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }

            List <TenantModel> tenantModels = await modelMgr.GetTenantModels();

            if (tenantModels.Count <= 0)
            {
                MessageBox.Show("No azure sphere tenant found.", null, MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }
            else if (tenantModels.Count == 1)
            {
                CurrentTenantModel = tenantModels[0];
            }
            else
            {
                var dialog = new TenantsWindow();
                dialog.Owner        = this;
                dialog.TenantModels = tenantModels;

                var dialogResult = dialog.ShowDialog();
                if (!dialogResult.Value)
                {
                    Close();
                    return;
                }
                CurrentTenantModel = dialog.SelectedTenantModel;
            }

            // EventHandler
            var roles = await modelMgr.GetRolesAsync(CurrentTenantModel.Context, modelMgr.GetUsername());

            if (roles.Contains("Administrator"))
            {
                menuitemUsers.IsEnabled = true;
            }

            modelMgr.NotificationChangeProduct     += NotificationChangeProduct;
            modelMgr.NotificationChangeDeviceGroup += NotificationChangeDeviceGroup;
            modelMgr.NotificationChangeDevice      += NotificationChangeDevice;

            await RefreshAllGrids();
        }
Ejemplo n.º 2
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            try
            {
                Cursor = Cursors.Wait;
                try
                {
                    await Api.AuthenticationAsync(cancellationTokenSource.Token);
                }
                finally
                {
                    Cursor = null;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to authenticate.", null, MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }

            List <AzureSphereTenant> tenants;

            Cursor = Cursors.Wait;
            try
            {
                tenants = await Api.GetTenantsAsync(cancellationTokenSource.Token);
            }
            finally
            {
                Cursor = null;
            }
            if (tenants.Count <= 0)
            {
                MessageBox.Show("No azure sphere tenant found.", null, MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }
            else if (tenants.Count == 1)
            {
                Tenant = tenants[0];
            }
            else
            {
                var dialog = new TenantsWindow();
                dialog.Owner   = this;
                dialog.Tenants = tenants;
                var dialogResult = dialog.ShowDialog();
                if (!dialogResult.Value)
                {
                    Close();
                    return;
                }
                Tenant = dialog.SelectedTenant;
            }

            Cursor = Cursors.Wait;
            try
            {
                this.Title = $"Azure Sphere Explorer - {Tenant.Name}";

                var products = await Api.GetProductsAsync(Tenant, cancellationTokenSource.Token);

                var deviceGroups = await Api.GetDeviceGroupsAsync(Tenant, cancellationTokenSource.Token);

                var devices = await Api.GetDevicesAsync(Tenant, cancellationTokenSource.Token);

                this.gridProducts.ItemsSource = from v in products
                                                select new ProductModel
                {
                    Context     = v,
                    Product     = v.Name,
                    Description = v.Description
                };

                this.gridDeviceGroups.ItemsSource = from v in deviceGroups
                                                    join p in products on v.ProductId equals p.Id
                                                    select new DeviceGroupModel
                {
                    Context               = v,
                    Product               = p.Name,
                    DeviceGroup           = v.Name,
                    Description           = v.Description,
                    OsFeedType            = v.OsFeedTypeStr,
                    UpdatePolicy          = v.UpdatePolicyStr,
                    CurrentDeploymentDate = v.CurrentDeployment?.DeploymentDateUtc.ToLocalTime()
                };

                this.gridDevices.ItemsSource = from v in devices
                                               join dg in deviceGroups on v.DeviceGroupId equals dg.Id into gj
                                               from dg_ in gj.DefaultIfEmpty()
                                               join p in products on dg_?.ProductId equals p.Id into gj2
                                               from p_ in gj2.DefaultIfEmpty()
                                               select new DeviceModel
                {
                    Context     = v,
                    Product     = p_?.Name,
                    DeviceGroup = dg_?.Name,
                    ChipSku     = v.ChipSkuStr,
                    Id          = v.Id
                };
            }
            finally
            {
                Cursor = null;
            }
        }
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            try
            {
                Cursor = Cursors.Wait;
                try
                {
                    await Api.AuthenticationAsync(cancellationTokenSource.Token);
                }
                finally
                {
                    Cursor = null;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to authenticate.", null, MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }

            List <AzureSphereTenant> tenants;

            Cursor = Cursors.Wait;
            try
            {
                tenants = await Api.GetTenantsAsync(cancellationTokenSource.Token);
            }
            finally
            {
                Cursor = null;
            }
            if (tenants.Count <= 0)
            {
                MessageBox.Show("No azure sphere tenant found.", null, MessageBoxButton.OK, MessageBoxImage.Error);
                Close();
                return;
            }
            else if (tenants.Count == 1)
            {
                Tenant = tenants[0];
            }
            else
            {
                var dialog = new TenantsWindow();
                dialog.Owner   = this;
                dialog.Tenants = tenants;
                var dialogResult = dialog.ShowDialog();
                if (!dialogResult.Value)
                {
                    Close();
                    return;
                }
                Tenant = dialog.SelectedTenant;
            }

            var roles = await Api.GetRolesAsync(Tenant, Api.Username, cancellationTokenSource.Token);

            if (roles.Contains("Administrator"))
            {
                menuitemUsers.IsEnabled = true;
            }

            await RefreshAllGrids();
        }