private void WriteNullBehaviorToXml(MappingBehavior behavior, XmlElement element) { switch (behavior) { case MappingBehavior.IfNullDefault: element.SetAttribute(ATTR_IFNULL, "default"); break; case MappingBehavior.IfNullSuppress: element.SetAttribute(ATTR_IFNULL, "suppress"); break; default: element.RemoveAttribute(ATTR_IFNULL); break; } }
public override bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Range projectedRange, MappingBehavior mappingBehavior, out Range originalRange) { if (codeDocument is null) { throw new ArgumentNullException(nameof(codeDocument)); } if (projectedRange is null) { throw new ArgumentNullException(nameof(projectedRange)); } if (mappingBehavior == MappingBehavior.Strict) { return(TryMapFromProjectedDocumentRangeStrict(codeDocument, projectedRange, out originalRange)); } else if (mappingBehavior == MappingBehavior.Inclusive) { return(TryMapFromProjectedDocumentRangeInclusive(codeDocument, projectedRange, out originalRange)); } else { throw new InvalidOperationException("Unknown mapping behavior"); } }
public abstract bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Range projectedRange, MappingBehavior mappingBehavior, [NotNullWhen(true)] out Range?originalRange);
private EnvelopeType ConvertFromHyperVXml(Ms_Declarations_Type hvobj, string ovfname, string lang) { EnvelopeType env = CreateEnvelope(ovfname, lang); string systemId = AddVirtualSystem(env, lang, ovfname); string vhsid = AddVirtualHardwareSection(env, systemId, lang); foreach (Ms_WrapperInstance_Type wrap in hvobj.declgroups[0].values) { RASD_Type rasd = new RASD_Type(); switch (wrap.instance.className) { #region CASE: Msvm_VirtualSystemSettingData case "Msvm_VirtualSystemSettingData": { string ElementName = null; string InstanceId = null; string SystemName = null; string VirtualSystemType = null; foreach (Ms_Property_Base_Type prop in wrap.instance.Properties) { switch (prop.Name) { case "ElementName": { ElementName = ((Ms_ParameterValue_Type)prop).Value; break; } case "InstanceID": { InstanceId = ((Ms_ParameterValue_Type)prop).Value; break; } case "SystemName": { SystemName = ((Ms_ParameterValue_Type)prop).Value; break; } case "VirtualSystemType": { VirtualSystemType = ((Ms_ParameterValue_Type)prop).Value; break; } } } AddVirtualSystemSettingData(env, systemId, vhsid, ElementName, ElementName, ElementName, InstanceId, VirtualSystemType); UpdateVirtualSystemName(env, systemId, lang, ElementName); break; } #endregion #region CASE: ResourceAllocationSettingData case "Msvm_ProcessorSettingData": case "Msvm_MemorySettingData": case "Msvm_SyntheticEthernetPortSettingData": case "Msvm_ResourceAllocationSettingData": { foreach (Ms_Property_Base_Type prop in wrap.instance.Properties) { if (prop is Ms_ParameterValue_Type) { if (((Ms_ParameterValue_Type)prop).Value == null || ((Ms_ParameterValue_Type)prop).Value.Length <= 0) { continue; } } else if (prop is Ms_ParameterValueArray_Type) { if (((Ms_ParameterValueArray_Type)prop).Values == null || ((Ms_ParameterValueArray_Type)prop).Values.Length <= 0) { continue; } } PropertyInfo[] properties = rasd.GetType().GetProperties(); foreach (PropertyInfo pi in properties) { if (pi.Name.ToLower().Equals(prop.Name.ToLower())) { object newvalue = null; if (prop is Ms_ParameterValue_Type) { switch (prop.Type.ToLower()) { case "string": { newvalue = new cimString((string)((Ms_ParameterValue_Type)prop).Value); break; } case "boolean": { newvalue = new cimBoolean(); ((cimBoolean)newvalue).Value = Convert.ToBoolean(((Ms_ParameterValue_Type)prop).Value); break; } case "uint16": { newvalue = new cimUnsignedShort(); ((cimUnsignedShort)newvalue).Value = Convert.ToUInt16(((Ms_ParameterValue_Type)prop).Value); break; } case "uint32": { newvalue = new cimUnsignedInt(); ((cimUnsignedInt)newvalue).Value = Convert.ToUInt32(((Ms_ParameterValue_Type)prop).Value); break; } case "uint64": { newvalue = new cimUnsignedLong(); ((cimUnsignedLong)newvalue).Value = Convert.ToUInt64(((Ms_ParameterValue_Type)prop).Value); break; } } } else if (prop is Ms_ParameterValueArray_Type) { switch (prop.Type.ToLower()) { case "string": { List<cimString> sarray = new List<cimString>(); foreach (Ms_ParameterValue_Type svalue in ((Ms_ParameterValueArray_Type)prop).Values) { sarray.Add(new cimString(svalue.Value)); } newvalue = sarray.ToArray(); break; } } } object tmpobject = null; switch (pi.Name.ToLower()) { case "caption": { newvalue = new Caption(((cimString)newvalue).Value); break; } case "changeabletype": { tmpobject = newvalue; newvalue = new ChangeableType(); ((ChangeableType)newvalue).Value = ((cimUnsignedShort)tmpobject).Value; break; } case "consumervisibility": { tmpobject = newvalue; newvalue = new ConsumerVisibility(); ((ConsumerVisibility)newvalue).Value = ((cimUnsignedShort)tmpobject).Value; break; } case "mappingbehavior": { tmpobject = newvalue; newvalue = new MappingBehavior(); ((MappingBehavior)newvalue).Value = ((cimUnsignedShort)tmpobject).Value; break; } case "resourcetype": { tmpobject = newvalue; newvalue = new ResourceType(); ((ResourceType)newvalue).Value = ((cimUnsignedShort)tmpobject).Value; break; } case "connection": case "hostresource": default: { break; } } pi.SetValue(rasd, newvalue, null); } } } if (rasd != null) { if (FillEmptyRequiredFields(rasd)) { if (rasd.ResourceType.Value == 21 && rasd.Caption.Value.ToLower().StartsWith(_ovfrm.GetString("RASD_19_CAPTION").ToLower())) { string filename = Path.GetFileName(rasd.Connection[0].Value); AddFileReference(env, lang, filename, rasd.InstanceID.Value, 0, Properties.Settings.Default.winFileFormatURI); AddRasd(env, systemId, rasd); } else if (rasd.ResourceType.Value == 10) { AddNetwork(env, systemId, lang, rasd.InstanceID.Value, rasd.Caption.Value, rasd.Address.Value); } else { AddRasd(env, systemId, rasd); } } } break; } #endregion #region CASE: Msvm_VLANEndpointSettingData case "Msvm_VLANEndpointSettingData": #endregion #region CASE: SKIPPED / DEFAULT case "Msvm_VirtualSystemExportSettingData": case "Msvm_VirtualSystemGlobalSettingData": case "Msvm_HeartbeatComponentSettingData": case "Msvm_KvpExchangeComponentSettingData": case "Msvm_ShutdownComponentSettingData": case "Msvm_TimeSyncComponentSettingData": case "Msvm_VssComponentSettingData": case "Msvm_SwitchPort": case "Msvm_VirtualSwitch": default: { break; } #endregion } } FinalizeEnvelope(env); return env; }
public abstract bool TryMapFromProjectedDocumentRange(RazorCodeDocument codeDocument, Range projectedRange, MappingBehavior mappingBehavior, out Range originalRange);