private void OK_Click(object sender, RoutedEventArgs e) { if (this.gridTenants.SelectedItem == null) { MessageBox.Show("Tenant is not selected.", null, MessageBoxButton.OK, MessageBoxImage.Error); return; } this.SelectedTenant = ((TenantModel)this.gridTenants.SelectedItem).Context; this.DialogResult = true; }
private async Task <List <ImageModel> > GetImagesAsync(AzureSphereTenant tenant, AzureSphereDeployment deployment) { List <ImageModel> imageModels = new List <ImageModel>(); try { foreach (string imageId in deployment.DeployedImages) { AzureSphereImage image = await Api.GetImageAsync(tenant, imageId, cancellationTokenSource.Token); imageModels.Add(ParseImageModel(image)); } } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); return(null); } return(imageModels); }
private void gridTenants_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var element = e.MouseDevice.DirectlyOver as FrameworkElement; if (element == null) { return; } var cell = element.Parent as DataGridCell; if (cell == null) { cell = element.TemplatedParent as DataGridCell; } if (cell == null) { return; } this.SelectedTenant = ((TenantModel)cell.DataContext).Context; this.DialogResult = true; }
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 Task <List <UserModel> > GetUsersAsync(AzureSphereTenant tenant) { List <AzureSphereUser> users = await Api.GetUsersAsync(tenant, cancellationTokenSource.Token); return(this.UsersModels = ParseUsersModel(users)); }
public async Task <List <string> > GetRolesAsync(AzureSphereTenant tenant, string username) { List <string> roles = await Api.GetRolesAsync(tenant, username, cancellationTokenSource.Token); return(roles); }
private async Task <List <DeviceInsightModel> > GetDeviceInsightsAsync(AzureSphereTenant tenant) { List <AzureSphereDeviceInsight> insights = await Api.GetDeviceInsightsAsync(tenant, cancellationTokenSource.Token); return(this.DeviceInsightModels = ParseDeviceInsightModel(insights)); }
private async Task <List <DeploymentModel> > GetDeploymentsAsync(AzureSphereTenant tenant, AzureSphereDeviceGroup group) { List <AzureSphereDeployment> deployments = await Api.GetDeploymentsAsync(tenant, group, cancellationTokenSource.Token); return(ParseDeploymentModel(deployments)); }
private async Task <List <DeviceModel> > GetDevicesAsync(AzureSphereTenant tenant) { List <AzureSphereDevice> devices = await Api.GetDevicesAsync(tenant, cancellationTokenSource.Token); return(ParseDeviceModel(devices)); }
private async Task <bool> DeleteDeviceGroupAsync(AzureSphereTenant tenant, AzureSphereDeviceGroup group) { return(await Api.DeleteDeviceGroupAsync(tenant, group, cancellationTokenSource.Token)); }
private async Task <bool> DeleteProductAsync(AzureSphereTenant tenant, AzureSphereProduct product) { return(await Api.DeleteProductAsync(tenant, product, cancellationTokenSource.Token)); }
private async Task <List <ProductModel> > GetProductsAsync(AzureSphereTenant tenant) { List <AzureSphereProduct> products = await Api.GetProductsAsync(tenant, cancellationTokenSource.Token); return(ParseProductModel(products)); }
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(); }