Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

7 лет назад
5 лет назад
7 лет назад
5 лет назад
7 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System.Security.AccessControl;
  2. namespace Security2
  3. {
  4. public class SimpleFileSystemAccessRule
  5. {
  6. private string fullName;
  7. private IdentityReference2 identity;
  8. private FileSystemRights2 accessRights;
  9. private AccessControlType type;
  10. public AccessControlType AccessControlType
  11. {
  12. get { return type; }
  13. set { type = value; }
  14. }
  15. public string FullName
  16. {
  17. get { return fullName; }
  18. }
  19. public string Name
  20. {
  21. get
  22. {
  23. return System.IO.Path.GetFileName(fullName);
  24. }
  25. }
  26. public IdentityReference2 Identity
  27. {
  28. get { return identity; }
  29. }
  30. public SimpleFileSystemAccessRights AccessRights
  31. {
  32. get
  33. {
  34. SimpleFileSystemAccessRights result = SimpleFileSystemAccessRights.None;
  35. if ((accessRights & FileSystemRights2.Read) == FileSystemRights2.Read)
  36. { result |= SimpleFileSystemAccessRights.Read; }
  37. if ((accessRights & FileSystemRights2.CreateFiles) == FileSystemRights2.CreateFiles)
  38. { result |= SimpleFileSystemAccessRights.Write; }
  39. if ((accessRights & FileSystemRights2.AppendData) == FileSystemRights2.AppendData)
  40. { result |= SimpleFileSystemAccessRights.Write; }
  41. if ((accessRights & FileSystemRights2.ReadExtendedAttributes) == FileSystemRights2.ReadExtendedAttributes)
  42. { result |= SimpleFileSystemAccessRights.Read; }
  43. if ((accessRights & FileSystemRights2.WriteExtendedAttributes) == FileSystemRights2.WriteExtendedAttributes)
  44. { result |= SimpleFileSystemAccessRights.Write; }
  45. if ((accessRights & FileSystemRights2.ExecuteFile) == FileSystemRights2.ExecuteFile)
  46. { result |= SimpleFileSystemAccessRights.Read; }
  47. if ((accessRights & FileSystemRights2.DeleteSubdirectoriesAndFiles) == FileSystemRights2.DeleteSubdirectoriesAndFiles)
  48. { result |= SimpleFileSystemAccessRights.Delete; }
  49. if ((accessRights & FileSystemRights2.ReadAttributes) == FileSystemRights2.ReadAttributes)
  50. { result |= SimpleFileSystemAccessRights.Read; }
  51. if ((accessRights & FileSystemRights2.WriteAttributes) == FileSystemRights2.WriteAttributes)
  52. { result |= SimpleFileSystemAccessRights.Write; }
  53. if ((accessRights & FileSystemRights2.Delete) == FileSystemRights2.Delete)
  54. { result |= SimpleFileSystemAccessRights.Delete; }
  55. if ((accessRights & FileSystemRights2.ReadPermissions) == FileSystemRights2.ReadPermissions)
  56. { result |= SimpleFileSystemAccessRights.Read; }
  57. if ((accessRights & FileSystemRights2.ChangePermissions) == FileSystemRights2.ChangePermissions)
  58. { result |= SimpleFileSystemAccessRights.Write; }
  59. if ((accessRights & FileSystemRights2.TakeOwnership) == FileSystemRights2.TakeOwnership)
  60. { result |= SimpleFileSystemAccessRights.Write; }
  61. if ((accessRights & FileSystemRights2.Synchronize) == FileSystemRights2.Synchronize)
  62. { result |= SimpleFileSystemAccessRights.Read; }
  63. if ((accessRights & FileSystemRights2.FullControl) == FileSystemRights2.FullControl)
  64. { result = (SimpleFileSystemAccessRights.Write | SimpleFileSystemAccessRights.Read | SimpleFileSystemAccessRights.Delete); }
  65. if ((accessRights & FileSystemRights2.GenericRead) == FileSystemRights2.GenericRead)
  66. { result |= SimpleFileSystemAccessRights.Read; }
  67. if ((accessRights & FileSystemRights2.GenericWrite) == FileSystemRights2.GenericWrite)
  68. { result |= SimpleFileSystemAccessRights.Write; }
  69. if ((accessRights & FileSystemRights2.GenericExecute) == FileSystemRights2.GenericExecute)
  70. { result |= SimpleFileSystemAccessRights.Read; }
  71. if ((accessRights & FileSystemRights2.GenericAll) == FileSystemRights2.GenericAll)
  72. { result = (SimpleFileSystemAccessRights.Write | SimpleFileSystemAccessRights.Read | SimpleFileSystemAccessRights.Delete); }
  73. return result;
  74. }
  75. }
  76. public SimpleFileSystemAccessRule(string path, IdentityReference2 account, FileSystemRights2 access, AccessControlType accessControlType)
  77. {
  78. fullName = path;
  79. accessRights = access;
  80. identity = account;
  81. type = accessControlType;
  82. }
  83. public override bool Equals(object obj)
  84. {
  85. var compareObject = obj as SimpleFileSystemAccessRule;
  86. if (compareObject == null)
  87. {
  88. return false;
  89. }
  90. if (this.AccessRights == compareObject.AccessRights && this.Identity == compareObject.Identity && this.AccessControlType == compareObject.AccessControlType)
  91. {
  92. return true;
  93. }
  94. else
  95. {
  96. return false;
  97. }
  98. }
  99. public override int GetHashCode()
  100. {
  101. return this.Identity.GetHashCode() | this.AccessRights.GetHashCode() | this.AccessControlType.GetHashCode();
  102. }
  103. }
  104. }