VariablesSet.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Collections.ObjectModel; 7 using System.Linq; 8 using System.Text.Json.Serialization; 9 10 using CommunityToolkit.Mvvm.ComponentModel; 11 using EnvironmentVariablesUILib.ViewModels; 12 13 namespace EnvironmentVariablesUILib.Models 14 { 15 public partial class VariablesSet : ObservableObject 16 { 17 public static readonly Guid UserGuid = new Guid("92F7AA9A-AE31-49CD-83C8-80A71E432AA5"); 18 public static readonly Guid SystemGuid = new Guid("F679C74D-DB00-4795-92E1-B1F6A4833279"); 19 20 private static readonly string UserIconPath = "/Assets/EnvironmentVariables/UserIcon.png"; 21 private static readonly string SystemIconPath = "/Assets/EnvironmentVariables/SystemIcon.png"; 22 protected static readonly string ProfileIconPath = "/Assets/EnvironmentVariables/ProfileIcon.png"; 23 24 public Guid Id { get; set; } 25 26 [ObservableProperty] 27 [NotifyPropertyChangedFor(nameof(Valid))] 28 private string _name; 29 30 [JsonIgnore] 31 public VariablesSetType Type { get; set; } 32 33 [JsonIgnore] 34 public string IconPath { get; set; } 35 36 [ObservableProperty] 37 private ObservableCollection<Variable> _variables; 38 39 public bool Valid => Validate(); 40 41 public VariablesSet() 42 { 43 } 44 45 public VariablesSet(Guid id, string name, VariablesSetType type) 46 { 47 Id = id; 48 Name = name; 49 Type = type; 50 Variables = new ObservableCollection<Variable>(); 51 52 IconPath = Type switch 53 { 54 VariablesSetType.User => UserIconPath, 55 VariablesSetType.System => SystemIconPath, 56 VariablesSetType.Profile => ProfileIconPath, 57 _ => throw new NotImplementedException(), 58 }; 59 } 60 61 private bool Validate() 62 { 63 if (string.IsNullOrWhiteSpace(Name)) 64 { 65 return false; 66 } 67 68 return true; 69 } 70 } 71 }