Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

89 řádky
3.7 KiB

  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 System;
  22. using System.Globalization;
  23. namespace Alphaleonis.Win32.Network
  24. {
  25. /// <summary>Contains the identification number and other pertinent information about files, devices, and pipes. This class cannot be inherited.</summary>
  26. [SerializableAttribute]
  27. public sealed class OpenResourceInfo
  28. {
  29. #region Constructor
  30. /// <summary>Create a OpenResourceInfo instance.</summary>
  31. internal OpenResourceInfo(string host, NativeMethods.FILE_INFO_3 fileInfo)
  32. {
  33. Host = host;
  34. Id = fileInfo.fi3_id;
  35. Permissions = fileInfo.fi3_permissions;
  36. TotalLocks = fileInfo.fi3_num_locks;
  37. PathName = fileInfo.fi3_pathname.Replace(@"\\", @"\");
  38. UserName = fileInfo.fi3_username;
  39. }
  40. #endregion // Constructor
  41. #region Methods
  42. /// <summary>Forces the open resource to close.</summary>
  43. /// <remarks>You should this method with caution because it does not write data cached on the client system to the file before closing the file.</remarks>
  44. public void Close()
  45. {
  46. uint lastError = NativeMethods.NetFileClose(Host, (uint) Id);
  47. if (lastError != Win32Errors.NERR_Success && lastError != Win32Errors.NERR_FileIdNotFound)
  48. NativeError.ThrowException(lastError, Host, PathName);
  49. }
  50. /// <summary>Returns the full path to the share.</summary>
  51. /// <returns>A string that represents this instance.</returns>
  52. public override string ToString()
  53. {
  54. return Id.ToString(CultureInfo.InvariantCulture);
  55. }
  56. #endregion // Methods
  57. #region Properties
  58. /// <summary>The local or remote Host.</summary>
  59. public string Host { get; private set; }
  60. /// <summary>The identification number assigned to the resource when it is opened.</summary>
  61. public long Id { get; private set; }
  62. /// <summary>The path of the opened resource.</summary>
  63. public string PathName { get; private set; }
  64. /// <summary>The access permissions associated with the opening application. This member can be one or more of the following <see cref="AccessPermissions"/> values.</summary>
  65. public AccessPermissions Permissions { get; private set; }
  66. /// <summary>The number of file locks on the file, device, or pipe.</summary>
  67. public long TotalLocks { get; private set; }
  68. /// <summary>Specifies which user (on servers that have user-level security) or which computer (on servers that have share-level security) opened the resource.</summary>
  69. public string UserName { get; private set; }
  70. #endregion // Properties
  71. }
  72. }