You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

89 rivejä
4.0 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. using Alphaleonis.Win32.Filesystem;
  24. namespace Alphaleonis.Win32.Network
  25. {
  26. /// <summary>Contains the identification number of a connection, number of open files, connection time, number of users on the connection, and the type of connection.</summary>
  27. [SerializableAttribute]
  28. public sealed class OpenConnectionInfo
  29. {
  30. #region Constructor
  31. /// <summary>Create a OpenConnectionInfo instance.</summary>
  32. internal OpenConnectionInfo(string host, NativeMethods.CONNECTION_INFO_1 connectionInfo)
  33. {
  34. Host = host;
  35. Id = connectionInfo.coni1_id;
  36. ShareType = connectionInfo.coni1_type;
  37. TotalOpenFiles = connectionInfo.coni1_num_opens;
  38. TotalUsers = connectionInfo.coni1_num_users;
  39. ConnectedSeconds = connectionInfo.coni1_time;
  40. UserName = connectionInfo.coni1_username;
  41. NetName = connectionInfo.oni1_netname.Replace(Path.LongPathUncPrefix, string.Empty).Replace(Path.UncPrefix, string.Empty);
  42. }
  43. #endregion // Constructor
  44. #region Methods
  45. /// <summary>Returns the full path to the share.</summary>
  46. /// <returns>A string that represents this instance.</returns>
  47. public override string ToString()
  48. {
  49. return Id.ToString(CultureInfo.InvariantCulture);
  50. }
  51. #endregion // Methods
  52. #region Properties
  53. /// <summary>The local or remote Host.</summary>
  54. public string Host { get; private set; }
  55. /// <summary>Specifies a connection identification number.</summary>
  56. public long Id { get; private set; }
  57. /// <summary>The type of share.</summary>
  58. public ShareType ShareType { get; private set; }
  59. /// <summary>Specifies the number of files currently open as a result of the connection.</summary>
  60. public long TotalOpenFiles { get; private set; }
  61. /// <summary>Specifies the number of users on the connection.</summary>
  62. public long TotalUsers { get; private set; }
  63. /// <summary>Specifies the number of seconds that the connection has been established.</summary>
  64. public long ConnectedSeconds { get; private set; }
  65. /// <summary>If the server sharing the resource is running with user-level security, the UserName member describes which user made the connection. If the server is running with share-level security, coni1_username describes which computer (computername) made the connection.</summary>
  66. public string UserName { get; private set; }
  67. /// <summary>String that specifies either the share name of the server's shared resource or the computername of the client. The value of this member depends on which name was specified as the qualifier parameter to the NetConnectionEnum function.</summary>
  68. public string NetName { get; private set; }
  69. #endregion // Properties
  70. }
  71. }