/// <summary> /// Adds the specified <see cref="OperationDescription"/> to this catalog. /// </summary> /// <param name="operation">The <see cref="OperationDescription"/> to be added. /// This value is not <c>null</c>.</param> /// <returns> /// <c>true</c> if the <paramref name="operation"/> is added successfully; /// <c>false</c>, if it is not added because the operation which has same id already exists. /// </returns> protected override bool AddCore( OperationDescription operation ) { try { this._catalog.Add( operation.Id, operation ); return true; } catch ( ArgumentException ) { // It is more efficient because dictionary may be big. return false; } }
/// <summary> /// Removes the specified <see cref="OperationDescription"/> from this catalog. /// </summary> /// <param name="operation">The <see cref="OperationDescription"/> to be removed. /// This value is not <c>null</c>.</param> /// <returns> /// <c>true</c> if the <paramref name="operation"/> is removed successfully; /// <c>false</c>, if it is not removed because the operation does not exist in this catalog. /// </returns> protected override bool RemoveCore( OperationDescription operation ) { return this._catalog.Remove( operation.Id ); }
/// <summary> /// Removes the specified <see cref="OperationDescription"/> from this catalog. /// </summary> /// <param name="operation">The <see cref="OperationDescription"/> to be removed. /// This value is not <c>null</c>.</param> /// <returns> /// <c>true</c> if the <paramref name="operation"/> is removed successfully; /// <c>false</c>, if it is not removed because the operation does not exist in this catalog. /// </returns> protected override bool RemoveCore( OperationDescription operation ) { string methodName; string scope; int version; GetKeys( operation, out methodName, out scope, out version ); return this.RemoveCore( methodName, scope, version ); }
private bool AddCore( string methodName, string scope, int version, OperationDescription operation ) { bool mayExist = true; var methods = this.PrivateGetMethodsInScope( scope ); if ( methods == null ) { mayExist = false; methods = new Dictionary<string, SortedList<int, OperationDescription>>( _expectedMethodInTheScope ); this._catalog.Add( scope, methods ); } var versions = PrivateGetVersionedMethods( methods, methodName ); if ( versions == null ) { mayExist = false; versions = new SortedList<int, OperationDescription>( 1 ); methods.Add( methodName, versions ); } // Generally, there are few version to the method, so search twise is OK. if ( mayExist && versions.ContainsKey( version ) ) { return false; } versions.Add( version, operation ); return true; }
private static void GetKeys( OperationDescription operation, out string methodName, out string scope, out int version ) { methodName = operation.Id; scope = operation.Service.Name; version = operation.Service.Version; }
private static bool TestAddCore( OperationDescription adding, params OperationDescription[] existents ) { var target = new VersionedOperationCatalog(); foreach ( var existent in existents ) { Assert.That( target.Add( existent ), "Failed to add existent '{0}'.", existent ); } return target.Add( adding ); }