PageRenderTime 95ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/ClusterAware/ClusterAwareProperties/NetworkTranslate.cs

#
C# | 73 lines | 47 code | 4 blank | 22 comment | 12 complexity | ca0999ec7f2ebdd333f32296f2c22cbb MD5 | raw file
  1. using System;
  2. using System.Management;
  3. namespace ClusterAwareProperties
  4. {
  5. /// <summary>
  6. /// Convert a network ManagementObject to Network Class
  7. /// </summary>
  8. public static class NetworkTranslate
  9. {
  10. /// <summary>
  11. /// Convert Network ManagementObject to Network Class
  12. /// </summary>
  13. /// <param name="clsnet">Network class</param>
  14. /// <param name="queryObj">ManagementObject Group</param>
  15. /// <returns>NEtwork class with properties converted</returns>
  16. public static NetworkProperty Convert(this NetworkProperty clsnet, ManagementObject queryObj)
  17. {
  18. clsnet.Address = queryObj.PropertyValue<string>("Address");
  19. clsnet.AddressMask = queryObj.PropertyValue<string>("AddressMask");
  20. //item nof found (win 2003 and win2008)
  21. //clsnet.AutoMetric = queryObj.PropertyValue<bool>("AutoMetric");
  22. clsnet.Caption = queryObj.PropertyValue<string>("Caption");
  23. clsnet.Characteristics = queryObj.PropertyEnum<UInt32, CharacteristisNetwork>("Characteristics",CharacteristisNetwork.Unknown);
  24. clsnet.Description = queryObj.PropertyValue<string>("Description");
  25. clsnet.Flags = queryObj.PropertyValue<UInt32>("Flags");
  26. clsnet.InstallDate = queryObj.PropertyValue<DateTime?>("InstallDate");
  27. clsnet.Ipv4Addresses = queryObj.PropertyValue<string[]>("Ipv4Addresses");
  28. clsnet.Ipv4PrefixLengths = queryObj.PropertyValue<string[]>("Ipv4PrefixLengths");
  29. clsnet.Ipv6Addresses = queryObj.PropertyValue<string[]>("Ipv6Addresses");
  30. clsnet.Ipv6PrefixLengths = queryObj.PropertyValue<string[]>("Ipv6PrefixLengths");
  31. //item not found (win2003 and win2008)
  32. //clsnet.Metric = queryObj.PropertyValue<UInt32>("Metric");
  33. clsnet.Name = queryObj.PropertyValue<string>("Name");
  34. clsnet.PrivateProperties = new PrivatePropertiesData(queryObj);
  35. clsnet.Role = queryObj.PropertyEnum<UInt32, RolesNetwork>("Role",RolesNetwork.Both);
  36. clsnet.State = queryObj.PropertyEnum<UInt32,StateNetwork>("State",StateNetwork.Unknown);
  37. clsnet.Status = queryObj.PropertyEnum<string, StatusResource>("Status",StatusResource.Unknown);
  38. return clsnet;
  39. }
  40. ///<summary>
  41. /// Convert Network class to ManagementObject and Save on Cluster
  42. ///</summary>
  43. ///<param name="clsnet">Network class to converter</param>
  44. ///<param name="opSystem">Operation System where cluster is running</param>
  45. public static void SaveManagementObject(this NetworkProperty clsnet, WindowsOperationSystem opSystem)
  46. {
  47. if (opSystem == WindowsOperationSystem.Windows2003 || opSystem == WindowsOperationSystem.Windows2003R2)
  48. {
  49. //clsnet.Instance["AutoMetric"] = clsnet.AutoMetric;
  50. //item not found (windows 2003 and windows 2008)
  51. }
  52. clsnet.Instance["Characteristics"] = (UInt32)clsnet.Characteristics;
  53. clsnet.Instance["Description"] = clsnet.Description;
  54. clsnet.Instance["Flags"] = clsnet.Flags;
  55. clsnet.Instance["Characteristics"] = (UInt32)clsnet.Characteristics;
  56. if (opSystem == WindowsOperationSystem.Windows2003 || opSystem == WindowsOperationSystem.Windows2003R2)
  57. {
  58. //clsnet.Instance["Metric"] = clsnet.Metric;
  59. //item not found (windows 2003 and windows 2008)
  60. }
  61. if (opSystem == WindowsOperationSystem.Windows2008 || opSystem == WindowsOperationSystem.Windows2008R2)
  62. {
  63. clsnet.Instance["PrivateProperties"] = clsnet.PrivateProperties.ConvertToManagemenBasetObject();
  64. }
  65. clsnet.Instance["Role"] = clsnet.Role;
  66. clsnet.Instance.Put();
  67. }
  68. }
  69. }