No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

DfsInfo.cs 6.6 KiB

hace 7 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* Copyright (C) 2008-2016 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. using Alphaleonis.Win32.Filesystem;
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Diagnostics.CodeAnalysis;
  25. using System.Runtime.InteropServices;
  26. namespace Alphaleonis.Win32.Network
  27. {
  28. /// <summary>Contains information about a Distributed File System (DFS) root or link. This class cannot be inherited.
  29. /// <para>This structure contains the name, status, GUID, time-out, number of targets, and information about each target of the root or link.</para>
  30. /// </summary>
  31. [SerializableAttribute]
  32. [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dfs")]
  33. public sealed class DfsInfo
  34. {
  35. #region Constructor
  36. /// <summary>Initializes a new instance of the <see cref="DfsInfo"/> class which acts as a wrapper for a DFS root or link target.</summary>
  37. public DfsInfo()
  38. {
  39. }
  40. /// <summary>Initializes a new instance of the <see cref="DfsInfo"/> class, which acts as a wrapper for a DFS root or link target.</summary>
  41. /// <param name="structure">An initialized <see cref="NativeMethods.DFS_INFO_9"/> instance.</param>
  42. internal DfsInfo(NativeMethods.DFS_INFO_9 structure)
  43. {
  44. Comment = structure.Comment;
  45. EntryPath = structure.EntryPath;
  46. State = structure.State;
  47. Timeout = structure.Timeout;
  48. Guid = structure.Guid;
  49. MetadataSize = structure.MetadataSize;
  50. PropertyFlags = structure.PropertyFlags;
  51. SecurityDescriptor = structure.pSecurityDescriptor;
  52. if (structure.NumberOfStorages > 0)
  53. {
  54. var typeOfStruct = typeof (NativeMethods.DFS_STORAGE_INFO_1);
  55. var sizeOfStruct = Marshal.SizeOf(typeOfStruct);
  56. for (int i = 0; i < structure.NumberOfStorages; i++)
  57. _storageInfoCollection.Add(new DfsStorageInfo((NativeMethods.DFS_STORAGE_INFO_1) Marshal.PtrToStructure(new IntPtr(structure.Storage.ToInt64() + i*sizeOfStruct), typeOfStruct)));
  58. }
  59. }
  60. #endregion // Constructor
  61. #region Methods
  62. /// <summary>Returns the Universal Naming Convention (UNC) path of the DFS root or link.</summary>
  63. /// <returns>A string that represents this instance.</returns>
  64. public override string ToString()
  65. {
  66. return EntryPath;
  67. }
  68. #endregion // Methods
  69. #region Properties
  70. private DirectoryInfo _directoryInfo;
  71. /// <summary>The <see cref="DirectoryInfo"/> instance of the DFS root or link.</summary>
  72. public DirectoryInfo DirectoryInfo
  73. {
  74. get
  75. {
  76. // Do not use ?? expression here.
  77. if (_directoryInfo == null)
  78. _directoryInfo = new DirectoryInfo(null, EntryPath, PathFormat.FullPath);
  79. return _directoryInfo;
  80. }
  81. }
  82. /// <summary>The comment of the DFS root or link.</summary>
  83. public string Comment { get; internal set; }
  84. /// <summary>The Universal Naming Convention (UNC) path of the DFS root or link.</summary>
  85. public string EntryPath { get; internal set; }
  86. /// <summary>Specifies the GUID of the DFS root or link.</summary>
  87. public Guid Guid { get; internal set; }
  88. private readonly List<DfsStorageInfo> _storageInfoCollection = new List<DfsStorageInfo>();
  89. /// <summary>The collection of DFS targets of the DFS root or link.</summary>
  90. public IEnumerable<DfsStorageInfo> StorageInfoCollection
  91. {
  92. get { return _storageInfoCollection; }
  93. }
  94. /// <summary>An <see cref="DfsVolumeStates"/> enum that specifies a set of bit flags that describe the DFS root or link.</summary>
  95. public DfsVolumeStates State { get; internal set; }
  96. //DfsVolumeStates flavorBits = (structure3.State & (DfsVolumeStates) DfsNamespaceFlavors.All);
  97. //If (flavorBits == DFS_VOLUME_FLAVOR_STANDALONE) // Namespace is stand-alone DFS.
  98. //else if (flavorBits == DFS_VOLUME_FLAVOR_AD_BLOB) // Namespace is AD Blob.
  99. //else StateBits = (Flavor & DFS_VOLUME_STATES) // Unknown flavor.
  100. // StateBits can be one of the following:
  101. // (DFS_VOLUME_STATE_OK, DFS_VOLUME_STATE_INCONSISTENT,
  102. // DFS_VOLUME_STATE_OFFLINE or DFS_VOLUME_STATE_ONLINE)
  103. //State = flavorBits | structure3.State;
  104. /// <summary>Specifies the time-out, in seconds, of the DFS root or link.</summary>
  105. public long Timeout { get; internal set; }
  106. /// <summary>Specifies a set of flags that describe specific properties of a DFS namespace, root, or link.</summary>
  107. [SuppressMessage("Microsoft.Naming", "CA1726:UsePreferredTerms", MessageId = "Flags")]
  108. public DfsPropertyFlags PropertyFlags { get; internal set; }
  109. /// <summary>For domain-based DFS namespaces, this member specifies the size of the corresponding Active Directory data blob, in bytes.
  110. /// For stand-alone DFS namespaces, this field specifies the size of the metadata stored in the registry,
  111. /// including the key names and value names, in addition to the specific data items associated with them. This field is valid for DFS roots only.
  112. /// </summary>
  113. public long MetadataSize { get; internal set; }
  114. /// <summary>Pointer to a SECURITY_DESCRIPTOR structure that specifies a self-relative security descriptor to be associated with the DFS link's reparse point.
  115. /// This field is valid for DFS links only.
  116. /// </summary>
  117. public IntPtr SecurityDescriptor { get; internal set; }
  118. #endregion // Properties
  119. }
  120. }