Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Add updates to allow for Dev Box creation in Dev Home #2639

Merged
merged 10 commits into from
Apr 17, 2024
10 changes: 10 additions & 0 deletions HyperVExtension/src/HyperVExtension/Models/HyperVVirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,21 @@ public override string ToString()

private string OperationErrorString(ComputeSystemOperations operation)
{
if (operation == ComputeSystemOperations.Delete)
{
return $"Failed to complete {operation} operation on {DateTime.Now}: for VM {DisplayName}";
}

return $"Failed to complete {operation} operation on {DateTime.Now}: VM details: {this}";
}

private string OperationSuccessString(ComputeSystemOperations operation)
{
if (operation == ComputeSystemOperations.Delete)
{
return $"Successfully completed {operation} operation on {DateTime.Now}: for VM {DisplayName}";
}

return $"Successfully completed {operation} operation on {DateTime.Now}: VM details: {this}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
},
{
"type": "ActionSet",
"id": "DevHomeTopLevelActionSet",
"actions": [
{
"id": "DevHomeMachineConfigurationNextButton",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
},
{
"type": "ActionSet",
"id": "DevHomeTopLevelActionSet",
"actions": [
{
"id": "DevHomeMachineConfigurationNextButton",
Expand Down
27 changes: 27 additions & 0 deletions common/DevHomeAdaptiveCards/CardModels/DevHomeChoicesData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;

namespace DevHome.Common.DevHomeAdaptiveCards.CardModels;

/// <summary>
/// Represents a choice in an adaptive card choice set. This is the same as the adaptive card choices
/// type in the adaptive card schema with an added subtitle property. This can be updated in the future
/// to add other properties.
/// </summary>
/// <remarks>
/// This class should be kept in sync with the Adaptive card Input.Choice.
/// See: https://www.adaptivecards.io/explorer/Input.Choice.html
/// </remarks>
public class DevHomeChoicesData
{
[JsonPropertyName("title")]
public string Title { get; set; } = string.Empty;

[JsonPropertyName("subtitle")]
public string Subtitle { get; set; } = string.Empty;

[JsonPropertyName("value")]
public string Value { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Globalization;
using AdaptiveCards.ObjectModel.WinUI3;
using AdaptiveCards.Rendering.WinUI3;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace DevHome.Common.DevHomeAdaptiveCards.InputValues;

public class CustomComboBoxInputValue : IAdaptiveInputValue
{
private readonly ComboBox _comboBox;

public CustomComboBoxInputValue(IAdaptiveInputElement input, ComboBox comboBox)
{
InputElement = input;
_comboBox = comboBox;
}

/// <summary>
/// Gets the current value of the input element. This is the index of the current item.
/// </summary>
public string CurrentValue => _comboBox.SelectedIndex.ToString(CultureInfo.InvariantCulture);

public UIElement? ErrorMessage { get; set; }

public IAdaptiveInputElement InputElement { get; set; }

public void SetFocus()
{
_comboBox.Focus(FocusState.Keyboard);
}

public bool Validate()
{
return _comboBox.SelectedIndex >= 0;
}
}
10 changes: 5 additions & 5 deletions common/Environments/CustomControls/CardBody.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<devEnvConverters:CardStateColorToBrushConverter x:Key="CardStateColorToBrushConverter"/>
<devEnvConverters:CardStateToLocalizedTextConverter x:Key="CardStateToLocalizedTextConverter"/>
<converters:BoolToVisibilityConverter x:Key="NegatedBoolToVisibilityConverter" TrueValue="Collapsed" FalseValue="Visible" />
<converters:EmptyObjectToObjectConverter x:Key="EmptyObjectToVisibleConverter" NotEmptyValue="Visible" EmptyValue="Collapsed"/>
<converters:EmptyObjectToObjectConverter x:Key="EmptyObjectToCollapsedConverter" NotEmptyValue="Collapsed" EmptyValue="Visible"/>
<converters:EmptyStringToObjectConverter x:Key="EmptyStringToVisibleConverter" NotEmptyValue="Visible" EmptyValue="Collapsed"/>
<converters:EmptyStringToObjectConverter x:Key="EmptyStringToCollapsedConverter" NotEmptyValue="Collapsed" EmptyValue="Visible"/>
</UserControl.Resources>

<Grid
Expand Down Expand Up @@ -71,14 +71,14 @@
<!-- String that indicates the internal state of the compute system. -->
<TextBlock
Grid.Column="1"
Visibility="{x:Bind ComputeSystemCreationStatus, Mode=OneWay, Converter={StaticResource EmptyObjectToCollapsedConverter}}"
Visibility="{x:Bind ComputeSystemOperationStatus, Mode=OneWay, Converter={StaticResource EmptyStringToCollapsedConverter}}"
Text="{x:Bind CardState, Converter={StaticResource CardStateToLocalizedTextConverter}, Mode=OneWay}"
Style="{StaticResource CardBodyStateTextBlockStyle}"
IsTextSelectionEnabled="True"/>
<TextBlock
Grid.Column="1"
Visibility="{x:Bind ComputeSystemCreationStatus, Mode=OneWay, Converter={StaticResource EmptyObjectToVisibleConverter}}"
Text="{x:Bind ComputeSystemCreationStatus, Mode=OneWay}"
Visibility="{x:Bind ComputeSystemOperationStatus, Mode=OneWay, Converter={StaticResource EmptyStringToVisibleConverter}}"
Text="{x:Bind ComputeSystemOperationStatus, Mode=OneWay}"
Style="{StaticResource CardBodyStateTextBlockStyle}"
TextWrapping="Wrap"
TextTrimming="CharacterEllipsis"
Expand Down
8 changes: 4 additions & 4 deletions common/Environments/CustomControls/CardBody.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public string ComputeSystemAlternativeTitle
set => SetValue(ComputeSystemAlternativeTitleProperty, value);
}

public string ComputeSystemCreationStatus
public string ComputeSystemOperationStatus
{
get => (string)GetValue(ComputeSystemCreationStatusProperty);
set => SetValue(ComputeSystemCreationStatusProperty, value);
get => (string)GetValue(ComputeSystemOperationStatusProperty);
set => SetValue(ComputeSystemOperationStatusProperty, value);
}

public BitmapImage ComputeSystemImage
Expand Down Expand Up @@ -103,7 +103,7 @@ private static void OnCardBodyChanged(CardBody cardBody, BitmapImage args)
private static readonly DependencyProperty ComputeSystemPropertiesProperty = DependencyProperty.Register(nameof(ComputeSystemProperties), typeof(ObservableCollection<CardProperty>), typeof(CardBody), new PropertyMetadata(null));
private static readonly DependencyProperty ComputeSystemPropertyTemplateProperty = DependencyProperty.Register(nameof(ComputeSystemPropertyTemplate), typeof(DataTemplate), typeof(CardBody), new PropertyMetadata(null));

private static readonly DependencyProperty ComputeSystemCreationStatusProperty = DependencyProperty.Register(nameof(ComputeSystemCreationStatus), typeof(string), typeof(CardBody), new PropertyMetadata(null));
private static readonly DependencyProperty ComputeSystemOperationStatusProperty = DependencyProperty.Register(nameof(ComputeSystemOperationStatus), typeof(string), typeof(CardBody), new PropertyMetadata(null));

private static readonly DependencyProperty ShouldShowInDefiniteProgressProperty = DependencyProperty.Register(nameof(ShouldShowInDefiniteProgress), typeof(bool), typeof(CardBody), new PropertyMetadata(false));
}
17 changes: 15 additions & 2 deletions common/Environments/Models/ComputeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ public class ComputeSystem

public string DisplayName { get; private set; } = string.Empty;

public ComputeSystemOperations SupportedOperations { get; private set; }
public ComputeSystemOperations SupportedOperations
{
get
{
try
{
return _computeSystem.SupportedOperations;
}
catch (Exception ex)
{
_log.Error(ex, $"Failed to get supported operations for {DisplayName}");
return ComputeSystemOperations.None;
}
}
}

public string SupplementalDisplayName { get; private set; } = string.Empty;

Expand All @@ -44,7 +58,6 @@ public ComputeSystem(IComputeSystem computeSystem)
_computeSystem = computeSystem;
Id = new string(computeSystem.Id);
DisplayName = new string(computeSystem.DisplayName);
SupportedOperations = computeSystem.SupportedOperations;
SupplementalDisplayName = new string(computeSystem.SupplementalDisplayName);
AssociatedDeveloperId = computeSystem.AssociatedDeveloperId;
AssociatedProviderId = new string(computeSystem.AssociatedProviderId);
Expand Down
5 changes: 4 additions & 1 deletion common/Renderers/DevHomeActionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class DevHomeActionSet : IDevHomeActionSetRender
/// </summary>
private readonly TopLevelCardActionSetVisibility _actionSetVisibility;

private const string TopLevelCardActionId = "DevHomeTopLevelActionSet";

/// <summary>
/// Gets the adaptive card object that will invoke an action within the action set.
/// </summary>
Expand Down Expand Up @@ -73,7 +75,8 @@ public DevHomeActionSet(TopLevelCardActionSetVisibility cardActionSetVisibility)
ActionButtonInvoker = context.ActionInvoker;
OriginalAdaptiveCard = renderArgs.ParentCard;

if (_actionSetVisibility == TopLevelCardActionSetVisibility.Hidden)
if (_actionSetVisibility == TopLevelCardActionSetVisibility.Hidden &&
actionSet.Id.Equals(TopLevelCardActionId, System.StringComparison.OrdinalIgnoreCase))
{
// the page in Dev Home does not want to show the action set in the card.
// So we return null to prevent the adaptive card buttons from appearing.
Expand Down
Loading