public Equals ( |
||
other | The other instance. | |
Résultat | bool |
/// <summary> /// Deletes an ACL entry. /// </summary> /// <param name="resource">The controlled resource.</param> /// <param name="action">The action on the controlled resource.</param> /// <param name="subject">The subject whose access to the resource/action is controlled.</param> /// <returns><c>true</c> if the entry is deleted, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">If <paramref name="resource"/>, <paramref name="action"/> or <paramref name="subject"/> are <c>null</c>.</exception> /// <exception cref="ArgumentException">If <paramref name="resource"/>, <paramref name="action"/> or <paramref name="subject"/> are empty.</exception> public bool DeleteEntry(string resource, string action, string subject) { if (resource == null) { throw new ArgumentNullException("resource"); } if (resource.Length == 0) { throw new ArgumentException("Resource cannot be empty", "resource"); } if (action == null) { throw new ArgumentNullException("action"); } if (action.Length == 0) { throw new ArgumentException("Action cannot be empty", "action"); } if (subject == null) { throw new ArgumentNullException("subject"); } if (subject.Length == 0) { throw new ArgumentException("Subject cannot be empty", "subject"); } AclEntry result = new AclEntry(resource, action, subject, Value.Deny); lock (this) { int index = entries.FindIndex(delegate(AclEntry x) { return(AclEntry.Equals(x, result)); }); if (index >= 0) { AclEntry entry = entries[index]; entries.RemoveAt(index); OnAclChanged(new AclEntry[] { entry }, Change.EntryDeleted); return(true); } else { return(false); } } }
/// <summary> /// Determines whether two instances of <see cref="T:AclEntry" /> are equal (by value). /// </summary> /// <param name="x">The first instance.</param> /// <param name="y">The second instance.</param> /// <returns><c>true</c> if <b>x</b> equals <b>y</b>, <c>false</c> otherwise.</returns> public static bool Equals(AclEntry x, AclEntry y) { if (object.ReferenceEquals(x, null) && !object.ReferenceEquals(x, null)) { return(false); } if (!object.ReferenceEquals(x, null) && object.ReferenceEquals(x, null)) { return(false); } if (object.ReferenceEquals(x, null) && object.ReferenceEquals(x, null)) { return(true); } return(x.Equals(y)); }
/// <summary> /// Stores a new ACL entry. /// </summary> /// <param name="resource">The controlled resource.</param> /// <param name="action">The action on the controlled resource.</param> /// <param name="subject">The subject whose access to the resource/action is controlled.</param> /// <param name="value">The value of the entry.</param> /// <returns><c>true</c> if the entry is stored, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="resource" />, <paramref name="action" /> or /// <paramref name="subject" /> are <c>null</c>. /// </exception> /// <exception cref="ArgumentException"> /// If <paramref name="resource" />, <paramref name="action" /> or /// <paramref name="subject" /> are empty. /// </exception> public bool StoreEntry(string resource, string action, string subject, Value value) { if (resource == null) { throw new ArgumentNullException("resource"); } if (resource.Length == 0) { throw new ArgumentException("Resource cannot be empty", "resource"); } if (action == null) { throw new ArgumentNullException("action"); } if (action.Length == 0) { throw new ArgumentException("Action cannot be empty", "action"); } if (subject == null) { throw new ArgumentNullException("subject"); } if (subject.Length == 0) { throw new ArgumentException("Subject cannot be empty", "subject"); } var result = new AclEntry(resource, action, subject, value); lock (this) { var index = entries.FindIndex(delegate(AclEntry x) { return(AclEntry.Equals(x, result)); }); if (index >= 0) { var removed = entries[index]; entries.RemoveAt(index); OnAclChanged(new[] { removed }, Change.EntryDeleted); } entries.Add(result); OnAclChanged(new[] { result }, Change.EntryStored); } return(true); }
/// <summary> /// Stores a ACL entry. /// </summary> /// <param name="entry">The entry to store.</param> /// <returns><c>true</c> if the entry was stored, <c>false</c> otherwise.</returns> private bool StoreEntry(AclEntry entry) { ICommandBuilder builder = GetCommandBuilder(); DbConnection connection = builder.GetConnection(connString); DbTransaction transaction = BeginTransaction(connection); QueryBuilder queryBuilder = new QueryBuilder(builder); AclEntry[] allAclEntries = RetrieveAllAclEntries(); for(int i=0;i<allAclEntries.Length;i++) { if(entry.Equals(allAclEntries[i])) return true; } string query = queryBuilder.InsertInto("AclEntry", new string[] { "Resource", "Action", "Subject", "Value" }, new string[] { "Resource", "Action", "Subject", "Value" }); List<Parameter> parameters = new List<Parameter>(3); parameters.Add(new Parameter(ParameterType.String, "Resource", entry.Resource)); parameters.Add(new Parameter(ParameterType.String, "Action", entry.Action)); parameters.Add(new Parameter(ParameterType.String, "Subject", entry.Subject)); parameters.Add(new Parameter(ParameterType.Char, "Value", AclEntryValueToChar(entry.Value))); DbCommand command = builder.GetCommand(transaction, query, parameters); if(ExecuteNonQuery(command, false) != 1) { RollbackTransaction(transaction); return false; } CommitTransaction(transaction); return true; }
/// <summary> /// Determines whether two instances of <see cref="T:AclEntry" /> are equal (by value). /// </summary> /// <param name="x">The first instance.</param> /// <param name="y">The second instance.</param> /// <returns><c>true</c> if <b>x</b> equals <b>y</b>, <c>false</c> otherwise.</returns> public static bool Equals(AclEntry x, AclEntry y) { if(object.ReferenceEquals(x, null) && !object.ReferenceEquals(x, null)) return false; if(!object.ReferenceEquals(x, null) && object.ReferenceEquals(x, null)) return false; if(object.ReferenceEquals(x, null) && object.ReferenceEquals(x, null)) return true; return x.Equals(y); }