by
0
7
148k
0
Top 1% !
Popular
Pearl of Wisdom
Easy-to-find
Specified
Refined
OpenSource
Popularity: 13068th place

Published on:

InputName0embeddedInstance
InputType0string
LanguageCSharp
LicenseMIT_X11
MethodNameParse
OSWindows
OutputTypeVirtualHardDiskSettingData

Parse: Parses the hard disk SettingData embedded instance returned from the server and           creates a new VirtualHardDiskSettingData with that information.

<summary>
Parses the hard disk SettingData embedded instance returned from the server and
creates a new VirtualHardDiskSettingData with that information.
</summary>
<param name="embeddedInstance">The disk SettingData embedded instance.</param>
<returns>A <see cref="VirtualHardDiskSettingData"/> object with the data contained in
the embedded instance.</returns>
<exception cref="ArgumentNullException">If either param is null.</exception>
<exception cref="FormatException">If there was a problem parsing the embedded instance.
</exception>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/293936/Parse--Parses-the-hard-disk-SettingData-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
/// <summary> /// Parses the hard disk SettingData embedded instance returned from the server and /// creates a new VirtualHardDiskSettingData with that information. /// </summary> /// <param name="embeddedInstance">The disk SettingData embedded instance.</param> /// <returns>A <see cref="VirtualHardDiskSettingData"/> object with the data contained in /// the embedded instance.</returns> /// <exception cref="ArgumentNullException">If either param is null.</exception> /// <exception cref="FormatException">If there was a problem parsing the embedded instance. /// </exception> public static VirtualHardDiskSettingData Parse( string embeddedInstance) { VirtualHardDiskType type = VirtualHardDiskType.Unknown; VirtualHardDiskFormat format = VirtualHardDiskFormat.Unknown; string path = string.Empty; string parentPath = string.Empty; Int64 maxInternalSize = 0; Int32 blockSize = 0; Int32 logicalSectorSize = 0; Int32 physicalSectorSize = 0; XmlDocument doc = new XmlDocument(); doc.LoadXml(embeddedInstance); XmlNodeList nodelist = doc.SelectNodes(@"/INSTANCE/@CLASSNAME"); if (nodelist.Count != 1) { throw new FormatException(); } if (nodelist[0].Value != "Msvm_VirtualHardDiskSettingData") { throw new FormatException(); } // Disk type nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'Type']/VALUE/child::text()"); if (nodelist.Count != 1) { throw new FormatException(); } int itype = int.Parse(nodelist[0].Value, NumberStyles.None, CultureInfo.InvariantCulture); type = (VirtualHardDiskType)itype; if (type != VirtualHardDiskType.Differencing && type != VirtualHardDiskType.DynamicallyExpanding && type != VirtualHardDiskType.FixedSize) { // The type integer returned is of an unrecognized type. throw new FormatException(); } // Disk format nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'Format']/VALUE/child::text()"); if (nodelist.Count != 1) { throw new FormatException(); } int iformat = int.Parse(nodelist[0].Value, NumberStyles.None, CultureInfo.InvariantCulture); format = (VirtualHardDiskFormat)iformat; if (format != VirtualHardDiskFormat.Vhd && format != VirtualHardDiskFormat.Vhdx) { //The format integer returned is of an unrecognized type. throw new FormatException(); } // Path nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'Path']/VALUE/child::text()"); if (nodelist.Count != 1) { // There can not be multiple parents. throw new FormatException(); } path = nodelist[0].Value; // ParentPath nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'ParentPath']/VALUE/child::text()"); // A nodeList.Count == 0 is okay and indicates that there is no parent. if (nodelist.Count == 1) { parentPath = nodelist[0].Value; } else if (nodelist.Count != 0) { // There can not be multiple parents. throw new FormatException(); } if (type == VirtualHardDiskType.Differencing && string.IsNullOrEmpty(parentPath)) { // Parent path must be set if this is a differencing disk. throw new FormatException(); } // MaxInternalSize nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'MaxInternalSize']/VALUE/child::text()"); if (nodelist.Count != 1) { throw new FormatException(); } maxInternalSize = Int64.Parse(nodelist[0].Value, CultureInfo.InvariantCulture); // BlockSize nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'BlockSize']/VALUE/child::text()"); if (nodelist.Count != 1) { throw new FormatException(); } blockSize = Int32.Parse(nodelist[0].Value, CultureInfo.InvariantCulture); // LogicalSectorSize nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'LogicalSectorSize']/VALUE/child::text()"); if (nodelist.Count != 1) { throw new FormatException(); } logicalSectorSize = Int32.Parse(nodelist[0].Value, CultureInfo.InvariantCulture); // PhysicalSectorSize nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'PhysicalSectorSize']/VALUE/child::text()"); if (nodelist.Count != 1) { throw new FormatException(); } physicalSectorSize = Int32.Parse(nodelist[0].Value, CultureInfo.InvariantCulture); return new VirtualHardDiskSettingData(type, format, path, parentPath, maxInternalSize, blockSize, logicalSectorSize, physicalSectorSize); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus