Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow naming rules for DevBox, Quickstart, DevId, Repo code #224

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AzureExtension/Client/AzureUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DevHomeAzureExtension.Client;
// using. Instead you just check if it's valid and can then use the object and trust the result.
public class AzureUri
{
private static readonly string ValidUriString = "https://www.microsoft.com/";
private const string ValidUriString = "https://www.microsoft.com/";

private readonly bool _validUri;

Expand Down Expand Up @@ -491,7 +491,7 @@ private Uri InitializeConnection()
break;

case AzureHostType.NotHosted:
// Onprem includes the collection.
// OnPrem includes the collection.
var onpremUriString = Uri.Scheme + "://" + Uri.Authority;
onpremUriString = onpremUriString.TrimEnd('/') + '/';
if (!Uri.TryCreate(onpremUriString, UriKind.Absolute, out newUri))
Expand Down
2 changes: 1 addition & 1 deletion src/AzureExtension/Contracts/IDevBoxOperationWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace AzureExtension.Contracts;

/// <summary>
/// Inteface used to watch Dev Box operations asynchronously that take place in the Dev Center.
/// Interface used to watch Dev Box operations asynchronously that take place in the Dev Center.
/// </summary>
public interface IDevBoxOperationWatcher
{
Expand Down
16 changes: 8 additions & 8 deletions src/AzureExtension/DevBox/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public static class Constants
/// <summary>
/// API version used for enumeration and start, stop, and restart APIs
/// </summary>
/// For stable api's <seealso href="https://learn.microsoft.com/rest/api/devcenter/developer/dev-boxes?view=rest-devcenter-developer-2023-04-01"/>
/// for preview api's <seealso cref="https://github.com/Azure/azure-rest-api-specs/tree/main/specification/devcenter/data-plane/Microsoft.DevCenter/preview"/>
/// For stable APIs <seealso href="https://learn.microsoft.com/rest/api/devcenter/developer/dev-boxes?view=rest-devcenter-developer-2023-04-01"/>
/// for preview APIs <seealso cref="https://github.com/Azure/azure-rest-api-specs/tree/main/specification/devcenter/data-plane/Microsoft.DevCenter/preview"/>
public const string APIVersion = "api-version=2024-05-01-preview";

/// <summary>
/// DevCenter API to get all devboxes
/// </summary>
/// for stable api's <seealso href="https://learn.microsoft.com/rest/api/devcenter/developer/dev-boxes/list-dev-boxes-by-user"/>
/// for preview api's <seealso cref="https://github.com/Azure/azure-rest-api-specs/tree/main/specification/devcenter/data-plane/Microsoft.DevCenter/preview"/>
/// for stable APIs <seealso href="https://learn.microsoft.com/rest/api/devcenter/developer/dev-boxes/list-dev-boxes-by-user"/>
/// for preview APIs <seealso cref="https://github.com/Azure/azure-rest-api-specs/tree/main/specification/devcenter/data-plane/Microsoft.DevCenter/preview"/>
public const string DevBoxAPI = "/users/me/devboxes?" + APIVersion;

public const string DevBoxUserSegmentOfUri = "/users/me/devboxes";
Expand Down Expand Up @@ -179,7 +179,7 @@ public static class DevBoxPowerStates
/// Icons should be located in an extensions resource.pri file which is generated at build time.
/// See the MakePri.exe documentation for how you can view what is in the resource.pri file, so you can find the location of your icon.
/// https://learn.microsoft.com/en-us/windows/uwp/app-resources/makepri-exe-command-options. (use MakePri.exe in a VS Developer Command Prompt or
/// Powershell window)
/// PowerShell window)
/// </remarks>
#if CANARY_BUILD
public const string ProviderIcon = "ms-resource://Microsoft.Windows.DevHomeAzureExtension.Canary/Files/AzureExtension/Assets/DevBoxProvider.png";
Expand Down Expand Up @@ -227,17 +227,17 @@ public static class DevBoxPowerStates
public const string DevBoxCheckLogsKey = "DevBox_CheckLogs";

/// <summary>
/// Resource key for the error message when Dev Boxes retrival failed.
/// Resource key for the error message when Dev Boxes retrieval failed.
/// </summary>
public const string RetrivalFailKey = "DevBox_RetrivalFailKey";
public const string RetrievalFailKey = "DevBox_RetrievalFailKey";

/// <summary>
/// Resource key for the error message when there is no default user logged in.
/// </summary>
public const string NoDefaultUserFailKey = "DevBox_NoDefaultUserFailKey";

/// <summary>
/// Resource key for the error message when Dev Boxes retrival failed.
/// Resource key for the error message when Dev Boxes retrieval failed.
/// </summary>
public const string SessionExpiredKey = "DevBox_SessionExpired";

Expand Down
33 changes: 13 additions & 20 deletions src/AzureExtension/DevBox/DevBoxInstance.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Web;
using AzureExtension.Contracts;
using AzureExtension.DevBox.DevBoxJsonToCsClasses;
Expand All @@ -21,10 +18,6 @@
using Windows.ApplicationModel;
using Windows.Foundation;

using Windows.Storage;
using Windows.Storage.Streams;
using Windows.Win32;

namespace AzureExtension.DevBox;

public delegate DevBoxInstance DevBoxInstanceFactory(IDeveloperId developerId, DevBoxMachineState devBoxJson);
Expand Down Expand Up @@ -72,10 +65,10 @@ public class DevBoxInstance : IComputeSystem, IComputeSystem2

private const string DevBoxMultipleConcurrentOperationsNotSupportedKey = "DevBox_MultipleConcurrentOperationsNotSupport";

private static readonly CompositeFormat ProtocolPinString = CompositeFormat.Parse("ms-cloudpc:pin?location={0}&request={1}&cpcid={2}&workspaceName={3}&environment={4}&username={5}&version=0.0&source=DevHome");
private static readonly CompositeFormat _protocolPinString = CompositeFormat.Parse("ms-cloudpc:pin?location={0}&request={1}&cpcid={2}&workspaceName={3}&environment={4}&username={5}&version=0.0&source=DevHome");

// This is the version of the Windows App package that supports protocol associations for pinning
private static readonly PackageVersion MinimumWindowsAppVersion = new(1, 3, 243, 0);
private static readonly PackageVersion _minimumWindowsAppVersion = new(1, 3, 243, 0);

// These exit codes must be kept in sync with WindowsApp
private const int ExitCodeInvalid = -1;
Expand Down Expand Up @@ -243,7 +236,7 @@ private ComputeSystemOperations GetOperations()
if (_packagesService.IsPackageInstalled(Constants.WindowsAppPackageFamilyName))
{
PackageVersion version = _packagesService.GetPackageInstalledVersion(Constants.WindowsAppPackageFamilyName);
if (IsPackageVersionGreaterThan(version, MinimumWindowsAppVersion))
if (IsPackageVersionGreaterThan(version, _minimumWindowsAppVersion))
{
operations |= ComputeSystemOperations.PinToStartMenu | ComputeSystemOperations.PinToTaskbar;
}
Expand Down Expand Up @@ -351,7 +344,7 @@ public void ProvisioningMonitorCompleted(DevBoxMachineState? devBoxMachineState,
{
_log.Information($"Dev Box provisioning failed for '{DisplayName}'");

// If the provisioning failed, we'll set the state to failed and powerstate to unknown.
// If the provisioning failed, we'll set the state to failed and power state to unknown.
// The PowerState being unknown will make the UI show the Dev Box state as unknown.
DevBoxState.ProvisioningState = Constants.DevBoxProvisioningStates.Failed;
DevBoxState.PowerState = Constants.DevBoxPowerStates.Unknown;
Expand Down Expand Up @@ -699,7 +692,7 @@ private string ValidateWindowsAppAndItsParameters()

PackageVersion version = _packagesService.GetPackageInstalledVersion(Constants.WindowsAppPackageFamilyName);

if (!IsPackageVersionGreaterThan(version, MinimumWindowsAppVersion))
if (!IsPackageVersionGreaterThan(version, _minimumWindowsAppVersion))
{
return "Older version of Windows App installed on the system";
}
Expand All @@ -726,10 +719,10 @@ public IAsyncOperation<ComputeSystemOperationResult> DoPinActionAsync(string loc
throw new InvalidDataException(errorString);
}

var exitcode = ExitCodeInvalid;
var exitCode = ExitCodeInvalid;
var psi = new ProcessStartInfo();
psi.UseShellExecute = true;
psi.FileName = string.Format(CultureInfo.InvariantCulture, ProtocolPinString, location, pinAction, WorkspaceId, DisplayName, Environment, Username);
psi.FileName = string.Format(CultureInfo.InvariantCulture, _protocolPinString, location, pinAction, WorkspaceId, DisplayName, Environment, Username);

Process? process = Process.Start(psi);
if (process != null)
Expand All @@ -738,19 +731,19 @@ public IAsyncOperation<ComputeSystemOperationResult> DoPinActionAsync(string loc
AllowSetForegroundWindow(process.Id);

// This signals to the WindowsApp that it has been given foreground rights
EventWaitHandle signalForegroundSet = new EventWaitHandle(false, EventResetMode.AutoReset, WindowsAppEventName);
var signalForegroundSet = new EventWaitHandle(false, EventResetMode.AutoReset, WindowsAppEventName);
signalForegroundSet.Set();

process.WaitForExit();
exitcode = process.ExitCode;
if (exitcode == ExitCodeSuccess)
exitCode = process.ExitCode;
if (exitCode == ExitCodeSuccess)
{
UpdateStateForUI();
return new ComputeSystemOperationResult();
}
}

errorString = $"DoPinActionAsync with location {location} and action {pinAction} failed with exitcode: {exitcode}";
errorString = $"DoPinActionAsync with location {location} and action {pinAction} failed with exitCode: {exitCode}";
throw new NotSupportedException(errorString);
}
catch (Exception ex)
Expand Down Expand Up @@ -805,15 +798,15 @@ public IAsyncOperation<ComputeSystemPinnedResult> GetPinStatusAsync(string locat
var exitcode = ExitCodeInvalid;
var psi = new ProcessStartInfo();
psi.UseShellExecute = true;
psi.FileName = string.Format(CultureInfo.InvariantCulture, ProtocolPinString, location, "status", WorkspaceId, DisplayName, Environment, Username);
psi.FileName = string.Format(CultureInfo.InvariantCulture, _protocolPinString, location, "status", WorkspaceId, DisplayName, Environment, Username);
Process? process = Process.Start(psi);
if (process != null)
{
process.Refresh();
AllowSetForegroundWindow(process.Id);

// This signals to the WindowsApp that it has been given foreground rights
EventWaitHandle signalForegroundSet = new EventWaitHandle(false, EventResetMode.AutoReset, WindowsAppEventName);
var signalForegroundSet = new EventWaitHandle(false, EventResetMode.AutoReset, WindowsAppEventName);
signalForegroundSet.Set();

process.WaitForExit();
Expand Down
24 changes: 11 additions & 13 deletions src/AzureExtension/DevBox/DevBoxProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the MIT License.

using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Text.Json;
using AzureExtension.Contracts;
Expand Down Expand Up @@ -37,7 +35,7 @@ public class DevBoxProvider : IComputeSystemProvider

private readonly Dictionary<string, List<IComputeSystem>> _cachedDevBoxesMap = new();

private ConcurrentBag<IComputeSystem> devBoxes = new();
private readonly ConcurrentBag<IComputeSystem> _devBoxes = new();

public DevBoxProvider(
IDevBoxManagementService mgmtSvc,
Expand Down Expand Up @@ -85,7 +83,7 @@ private async Task ProcessAllDevBoxesInProjectAsync(DevBoxProject devBoxProject,
// If the Dev Box's creation operation or its provisioning state are being tracked by us, then don't make a new instance.
// Add the one we're tracking. This is to avoid adding the same Dev Box twice. E.g User clicks Dev Homes refresh button while
// the Dev Box is being created.
devBoxes.Add(devBox!);
_devBoxes.Add(devBox!);
continue;
}

Expand All @@ -100,12 +98,12 @@ private async Task ProcessAllDevBoxesInProjectAsync(DevBoxProject devBoxProject,
// It was likely created by Dev Portals UI or some other non-Dev Home related UI.
_devBoxCreationManager.StartDevBoxProvisioningStateMonitor(newDevBoxInstance.AssociatedDeveloperId, newDevBoxInstance);
}
else
{
await newDevBoxInstance.LoadWindowsAppParameters();
else
{
await newDevBoxInstance.LoadWindowsAppParameters();
}

devBoxes.Add(newDevBoxInstance);
_devBoxes.Add(newDevBoxInstance);
}
}
}
Expand All @@ -121,7 +119,7 @@ public async Task<IEnumerable<IComputeSystem>> GetDevBoxesAsync(IDeveloperId dev
if (devBoxProjects?.Data != null)
{
_log.Information($"Found {devBoxProjects.Data.Length} projects");
devBoxes.Clear();
_devBoxes.Clear();
var cancellationTokenSource = new CancellationTokenSource();
cancellationTokenSource.CancelAfter(TimeSpan.FromMinutes(2));
var token = cancellationTokenSource.Token;
Expand All @@ -142,7 +140,7 @@ await Parallel.ForEachAsync(devBoxProjects.Data, async (project, token) =>
// update the cache every time we retrieve new Dev Boxes. This is used so in the creation flow we don't need
// to retrieve the Dev Boxes again if the user already retrieved them in the environments page in Dev Home
var uniqueUserId = GetUniqueDeveloperId(developerId);
_cachedDevBoxesMap[uniqueUserId] = devBoxes.ToList();
_cachedDevBoxesMap[uniqueUserId] = _devBoxes.ToList();
return _cachedDevBoxesMap[uniqueUserId];
}

Expand Down Expand Up @@ -172,19 +170,19 @@ public IAsyncOperation<ComputeSystemsResult> GetComputeSystemsAsync(IDeveloperId
var errorMessage = Constants.OperationsDefaultErrorMsg;
if (ex.InnerException != null && ex.InnerException.Message.Contains("Account has previously been signed out of this application"))
{
errorMessage = Resources.GetResource(Constants.RetrivalFailKey, developerId.LoginId) + Resources.GetResource(Constants.SessionExpiredKey);
errorMessage = Resources.GetResource(Constants.RetrievalFailKey, developerId.LoginId) + Resources.GetResource(Constants.SessionExpiredKey);
}
else if (ex.Message.Contains("A passthrough token was detected without proper resource provider context"))
{
errorMessage = Resources.GetResource(Constants.RetrivalFailKey, developerId.LoginId) + Resources.GetResource(Constants.UnconfiguredKey);
errorMessage = Resources.GetResource(Constants.RetrievalFailKey, developerId.LoginId) + Resources.GetResource(Constants.UnconfiguredKey);
}
else if (ex is ArgumentException ae)
{
errorMessage = Resources.GetResource(Constants.NoDefaultUserFailKey);
}
else
{
errorMessage = Resources.GetResource(Constants.RetrivalFailKey, developerId.LoginId) + ex.Message;
errorMessage = Resources.GetResource(Constants.RetrievalFailKey, developerId.LoginId) + ex.Message;
}

_log.Error(ex, errorMessage);
Expand Down
4 changes: 0 additions & 4 deletions src/AzureExtension/DevBox/Helpers/DevBoxOperationHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text;
using AzureExtension.DevBox.Models;
using Microsoft.Windows.DevHome.SDK;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace AzureExtension.DevBox.Helpers;

Expand Down
1 change: 1 addition & 0 deletions src/AzureExtension/DevBox/Helpers/TaskJSONToCSClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace AzureExtension.DevBox.Helpers;
// "startTime": "2024-04-09T20:09:03.0136738+00:00"
// }
//

/// <summary>
/// Represents the classes for the customization task JSON response.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/AzureExtension/DevBox/Helpers/TaskYAMLToCSClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace AzureExtension.DevBox.Helpers;
// - 'Git.Git | Install: Git'
// configurationVersion: 0.2.0
//

/// <summary>
/// Represents the classes for the YAML customization task.
/// </summary>
Expand Down Expand Up @@ -71,7 +72,7 @@ public class Directives
{
public string Description { get; set; } = string.Empty;

public bool? AllowPrerelease { get; set; }
public bool? AllowPrerelease { get; set; }

public string SecurityContext { get; set; } = "current";
}
Expand Down
Loading
Loading