ClassesDefinition.cs (8768B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 4 namespace Microsoft.Management.Deployment.Projection 5 { 6 using System; 7 using System.Collections.Generic; 8 9 internal static class ClassesDefinition 10 { 11 private static Dictionary<Type, ClassModel> Classes { get; set; } = new() 12 { 13 [typeof(PackageManager)] = new() 14 { 15 ProjectedClassType = typeof(PackageManager), 16 InterfaceType = typeof(IPackageManager), 17 Clsids = new Dictionary<ClsidContext, Guid>() 18 { 19 [ClsidContext.InProc] = new Guid("2DDE4456-64D9-4673-8F7E-A4F19A2E6CC3"), 20 [ClsidContext.OutOfProc] = new Guid("C53A4F16-787E-42A4-B304-29EFFB4BF597"), 21 [ClsidContext.OutOfProcDev] = new Guid("74CB3139-B7C5-4B9E-9388-E6616DEA288C"), 22 } 23 }, 24 25 [typeof(FindPackagesOptions)] = new() 26 { 27 ProjectedClassType = typeof(FindPackagesOptions), 28 InterfaceType = typeof(IFindPackagesOptions), 29 Clsids = new Dictionary<ClsidContext, Guid>() 30 { 31 [ClsidContext.InProc] = new Guid("96B9A53A-9228-4DA0-B013-BB1B2031AB3D"), 32 [ClsidContext.OutOfProc] = new Guid("572DED96-9C60-4526-8F92-EE7D91D38C1A"), 33 [ClsidContext.OutOfProcDev] = new Guid("1BD8FF3A-EC50-4F69-AEEE-DF4C9D3BAA96"), 34 } 35 }, 36 37 [typeof(CreateCompositePackageCatalogOptions)] = new() 38 { 39 ProjectedClassType = typeof(CreateCompositePackageCatalogOptions), 40 InterfaceType = typeof(ICreateCompositePackageCatalogOptions), 41 Clsids = new Dictionary<ClsidContext, Guid>() 42 { 43 [ClsidContext.InProc] = new Guid("768318A6-2EB5-400D-84D0-DF3534C30F5D"), 44 [ClsidContext.OutOfProc] = new Guid("526534B8-7E46-47C8-8416-B1685C327D37"), 45 [ClsidContext.OutOfProcDev] = new Guid("EE160901-B317-4EA7-9CC6-5355C6D7D8A7"), 46 } 47 }, 48 49 [typeof(InstallOptions)] = new() 50 { 51 ProjectedClassType = typeof(InstallOptions), 52 InterfaceType = typeof(IInstallOptions), 53 Clsids = new Dictionary<ClsidContext, Guid>() 54 { 55 [ClsidContext.InProc] = new Guid("E2AF3BA8-8A88-4766-9DDA-AE4013ADE286"), 56 [ClsidContext.OutOfProc] = new Guid("1095F097-EB96-453B-B4E6-1613637F3B14"), 57 [ClsidContext.OutOfProcDev] = new Guid("44FE0580-62F7-44D4-9E91-AA9614AB3E86"), 58 } 59 }, 60 61 [typeof(UninstallOptions)] = new() 62 { 63 ProjectedClassType = typeof(UninstallOptions), 64 InterfaceType = typeof(IUninstallOptions), 65 Clsids = new Dictionary<ClsidContext, Guid>() 66 { 67 [ClsidContext.InProc] = new Guid("869CB959-EB54-425C-A1E4-1A1C291C64E9"), 68 [ClsidContext.OutOfProc] = new Guid("E1D9A11E-9F85-4D87-9C17-2B93143ADB8D"), 69 [ClsidContext.OutOfProcDev] = new Guid("AA2A5C04-1AD9-46C4-B74F-6B334AD7EB8C"), 70 } 71 }, 72 73 [typeof(DownloadOptions)] = new() 74 { 75 ProjectedClassType = typeof(DownloadOptions), 76 InterfaceType = typeof(IDownloadOptions), 77 Clsids = new Dictionary<ClsidContext, Guid>() 78 { 79 [ClsidContext.InProc] = new Guid("4288DF96-FDC9-4B68-B403-193DBBF56A24"), 80 [ClsidContext.OutOfProc] = new Guid("4CBABE76-7322-4BE4-9CEA-2589A80682DC"), 81 [ClsidContext.OutOfProcDev] = new Guid("8EF324ED-367C-4880-83E5-BB2ABD0B72F6"), 82 } 83 }, 84 85 [typeof(PackageMatchFilter)] = new() 86 { 87 ProjectedClassType = typeof(PackageMatchFilter), 88 InterfaceType = typeof(IPackageMatchFilter), 89 Clsids = new Dictionary<ClsidContext, Guid>() 90 { 91 [ClsidContext.InProc] = new Guid("57DC8962-7343-42CD-B91C-04F6A25DB1D0"), 92 [ClsidContext.OutOfProc] = new Guid("D02C9DAF-99DC-429C-B503-4E504E4AB000"), 93 [ClsidContext.OutOfProcDev] = new Guid("3F85B9F4-487A-4C48-9035-2903F8A6D9E8"), 94 } 95 }, 96 97 [typeof(AuthenticationArguments)] = new() 98 { 99 ProjectedClassType = typeof(AuthenticationArguments), 100 InterfaceType = typeof(IAuthenticationArguments), 101 Clsids = new Dictionary<ClsidContext, Guid>() 102 { 103 [ClsidContext.InProc] = new Guid("8D593114-1CF1-43B9-8722-4DBB30103296"), 104 [ClsidContext.OutOfProc] = new Guid("BA580786-BDE3-4F6C-B8F3-44698AC8711A"), 105 [ClsidContext.OutOfProcDev] = new Guid("6484A61D-50FA-41F0-B71E-F4370C6EB37C"), 106 } 107 }, 108 109 [typeof(PackageManagerSettings)] = new() 110 { 111 ProjectedClassType = typeof(PackageManagerSettings), 112 InterfaceType = typeof(IPackageManagerSettings), 113 Clsids = new Dictionary<ClsidContext, Guid>() 114 { 115 [ClsidContext.InProc] = new Guid("80CF9D63-5505-4342-B9B4-BB87895CA8BB"), 116 } 117 }, 118 119 [typeof(RepairOptions)] = new () 120 { 121 ProjectedClassType = typeof(RepairOptions), 122 InterfaceType = typeof(IRepairOptions), 123 Clsids = new Dictionary<ClsidContext, Guid>() 124 { 125 [ClsidContext.InProc] = new Guid("30C024C4-852C-4DD4-9810-1348C51EF9BB"), 126 [ClsidContext.OutOfProc] = new Guid("0498F441-3097-455F-9CAF-148F28293865"), 127 [ClsidContext.OutOfProcDev] = new Guid("E62BB1E7-C7B2-4AEC-9E28-FB649B30FF03"), 128 } 129 }, 130 131 [typeof(AddPackageCatalogOptions)] = new() 132 { 133 ProjectedClassType = typeof(AddPackageCatalogOptions), 134 InterfaceType = typeof(IAddPackageCatalogOptions), 135 Clsids = new Dictionary<ClsidContext, Guid>() 136 { 137 [ClsidContext.InProc] = new Guid("24E6F1FA-E4C3-4ACD-965D-DF213FD58F15"), 138 [ClsidContext.OutOfProc] = new Guid("DB9D012D-00D7-47EE-8FB1-606E10AC4F51"), 139 [ClsidContext.OutOfProcDev] = new Guid("D58C7E4C-70E6-476C-A5D4-80341ED80252"), 140 } 141 }, 142 143 [typeof(RemovePackageCatalogOptions)] = new() 144 { 145 ProjectedClassType = typeof(RemovePackageCatalogOptions), 146 InterfaceType = typeof(IRemovePackageCatalogOptions), 147 Clsids = new Dictionary<ClsidContext, Guid>() 148 { 149 [ClsidContext.InProc] = new Guid("1125D3A6-E2CE-479A-91D5-71A3F6F8B00B"), 150 [ClsidContext.OutOfProc] = new Guid("032B1C58-B975-469B-A013-E632B6ECE8D8"), 151 [ClsidContext.OutOfProcDev] = new Guid("87A96609-1A39-4955-BE72-7174E147B7DC"), 152 } 153 } 154 }; 155 156 /// <summary> 157 /// Get CLSID based on the provided context for the specified type 158 /// </summary> 159 /// <typeparam name="T">Projected class type</typeparam> 160 /// <param name="context">Context</param> 161 /// <returns>CLSID for the provided context and type, or throw an exception if not found.</returns> 162 public static Guid GetClsid<T>(ClsidContext context) 163 { 164 ValidateType(typeof(T)); 165 return Classes[typeof(T)].GetClsid(context); 166 } 167 168 /// <summary> 169 /// Get IID corresponding to the COM object 170 /// </summary> 171 /// <typeparam name="T">Projected class type</typeparam> 172 /// <returns>IID or throw an exception if not found.</returns> 173 public static Guid GetIid<T>() 174 { 175 ValidateType(typeof(T)); 176 return Classes[typeof(T)].GetIid(); 177 } 178 179 /// <summary> 180 /// Validate that the provided type is defined. 181 /// </summary> 182 /// <param name="type">Projected class type</param> 183 /// <exception cref="InvalidOperationException"></exception> 184 private static void ValidateType(Type type) 185 { 186 if (!Classes.ContainsKey(type)) 187 { 188 throw new InvalidOperationException($"{type.Name} is not a projected class type."); 189 } 190 } 191 } 192 }