/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the value to convert into an instance of <see cref="VmResources" />.</param> /// <returns> /// an instance of <see cref="VmResources" />, or <c>null</c> if there is no suitable conversion. /// </returns> public static object ConvertFrom(dynamic sourceValue) { if (null == sourceValue) { return(null); } try { VmResources.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString()); } catch { // Unable to use JSON pattern } try { return(new VmResources { BootConfig = VmBootConfigTypeConverter.ConvertFrom(sourceValue.BootConfig), DiskList = sourceValue.DiskList, GpuList = sourceValue.GpuList, GuestCustomization = GuestCustomizationTypeConverter.ConvertFrom(sourceValue.GuestCustomization), GuestOsId = sourceValue.GuestOsId, GuestTools = GuestToolsSpecTypeConverter.ConvertFrom(sourceValue.GuestTools), HardwareClockTimezone = sourceValue.HardwareClockTimezone, MemorySizeMib = sourceValue.MemorySizeMib, NicList = sourceValue.NicList, NumSockets = sourceValue.NumSockets, NumVcpusPerSocket = sourceValue.NumVcpusPerSocket, ParentReference = ReferenceTypeConverter.ConvertFrom(sourceValue.ParentReference), PowerState = sourceValue.PowerState, PowerStateMechanism = VmPowerStateMechanismTypeConverter.ConvertFrom(sourceValue.PowerStateMechanism), VgaConsoleEnabled = sourceValue.VgaConsoleEnabled, VnumaConfig = VmVnumaConfigTypeConverter.ConvertFrom(sourceValue.VnumaConfig), }); } catch { } return(null); }
public ActionResult <VmResources> PostTemplateVmResource(VmResources vmResource) { Console.WriteLine("Inside PostTemplateVmResource!!"); String vmName = ""; Console.WriteLine("Inside PostSDKVmResource - vmResource.Name: " + vmResource.Name); Console.WriteLine("Inside PostSDKVmResource - vmResource.LunchType: " + vmResource.LunchType); if (vmResource.Name.Equals("winVM")) { Console.WriteLine("Windows VM selected"); vmName = createWindowsVMviaTemplate(); } else { Console.WriteLine("Linux VM selected"); vmName = createLinuxVMviaTemplate(); } return(CreatedAtAction(nameof(GetVmResources), new { id = vmResource.Id, name = vmName }, vmResource)); }