public void ReadOperation_DoesNotDelegateToSourceDictionary_OnceDictionaryIsModified() { // Arrange var values = new List <object>(); var sourceDictionary = new Dictionary <string, object> { { "key1", "value1" }, { "key2", "value2" } }; var copyOnWriteDictionary = new CopyOnWriteDictionary <string, object>( sourceDictionary, StringComparer.OrdinalIgnoreCase ); // Act copyOnWriteDictionary.Add("key3", "value3"); copyOnWriteDictionary.Remove("key1"); // Assert Assert.Equal(2, sourceDictionary.Count); Assert.Equal("value1", sourceDictionary["key1"]); Assert.Equal(2, copyOnWriteDictionary.Count); Assert.Equal("value2", copyOnWriteDictionary["KeY2"]); Assert.Equal("value3", copyOnWriteDictionary["key3"]); }
private void RemoveSequence(int sequenceId) { lock (_objLock) { Sequence sequence = GetSequence(sequenceId); if (sequence != null) { if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.SequenceManager_Remove, sequence.Id)); } for (int i = sequence.Count - 1; i >= 0; i--) { Identity identity = sequence[i]; RemoveIdentityFromSequence(sequence, identity, i, null); } if (sequence.Parameters != null) { _parametersToSequenceIdHash.Remove(sequence.Parameters); } _sequenceIdToSequenceHash.Remove(sequenceId); //clear entry if (log.IsDebugEnabled) { log.Debug(__Res.GetString(__Res.SequenceManager_RemoveStatus, _dataDestination.Id, _sequenceIdToSequenceHash.Count)); } } } }
/// <summary> /// Removes a MessageClient created listener. /// </summary> /// <param name="listener">The listener to remove.</param> public static void RemoveMessageClientCreatedListener(IMessageClientListener listener) { if (_messageClientCreatedListeners.Contains(listener)) { _messageClientCreatedListeners.Remove(listener); } }
/// <summary> /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code. /// </summary> /// <param name="connection"></param> public void Unregister(IConnection connection) { _connectionToScope.Remove(connection); if (_connectionToScope.Count == 0) { // This client is not connected to any scopes, remove from registry. //Invalidate();//through Sessions } }
/// <summary> /// Removes an attribute. /// </summary> /// <param name="name">The attribute name.</param> /// <returns>true if the attribute was found and removed otherwise false.</returns> public virtual bool RemoveAttribute(string name) { if (HasAttribute(name)) { _attributes.Remove(name); return(true); } return(false); }
public void Unregister(IConnection connection) { _connectionToScope.Remove(connection); if (_connectionToScope.Count == 0) { // This client is not connected to any scopes, remove from registry. Disconnect(); } }
/// <summary> /// Removes a MessageClient destroyed listener. /// </summary> /// <param name="listener">The listener to remove.</param> public void RemoveMessageClientDestroyedListener(IMessageClientListener listener) { if (_messageClientDestroyedListeners != null) { if (_messageClientDestroyedListeners.Contains(listener)) { _messageClientDestroyedListeners.Remove(listener); } } }
/// <summary> /// Removes scope from the children scope list. /// </summary> /// <param name="scope">Removes the specified scope.</param> public void RemoveChildScope(IBasicScope scope) { //Synchronize retrieval of the child scope (with removal) Monitor.Enter(SyncRoot); try { // Don't remove if reference if we have another one if (HasChildScope(scope.Name) && GetScope(scope.Name) != scope) { #if !SILVERLIGHT log.Warn(string.Format("Being asked to remove wrong scope reference child scope is {0} not {1}", GetScope(scope.Name), scope)); #endif return; } #if !SILVERLIGHT if (log != null && log.IsDebugEnabled) { log.Debug(string.Format("Remove child scope: {0} path: {1}", scope, scope.Path)); } #endif if (scope is IScope) { if (HasHandler) { Handler.Stop((IScope)scope); } _subscopeStats.Decrement(); } string child = scope.Type + Separator + scope.Name; if (_children.ContainsKey(child)) { _children.Remove(child); } } finally { Monitor.Exit(SyncRoot); } if (HasHandler) { #if !SILVERLIGHT if (log != null && log.IsDebugEnabled) { log.Debug("Remove child scope"); } #endif Handler.RemoveChildScope(scope); } if (scope is Scope) { //Chain service containers (scope as Scope).ServiceContainer.Container = null; } }
public void UnregisterServiceHandler(string name) { if (name == null) { name = string.Empty; } if (_handlers.ContainsKey(name)) { _handlers.Remove(name); } }
/// <summary> /// Unregisters an IEndpointPushHandler from the specified endpoint. /// </summary> /// <param name="handler">The IEndpointPushHandler to unregister.</param> /// <param name="endpointId">The endpoint identity to unregister from.</param> public void UnregisterEndpointPushHandler(IEndpointPushHandler handler, string endpointId) { lock (this.SyncRoot) { if (_endpointPushHandlers == null) { return; } if (_endpointPushHandlers[endpointId] == handler) { _endpointPushHandlers.Remove(endpointId); } } }
public void CopyOnWriteDictionary_Should_Add_And_Remove() { var map = new CopyOnWriteDictionary<string, int> { {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4} }; Assert.AreEqual(4, map.Count); CollectionAssert.AreEquivalent(new[] { "one", "two", "three", "four" }, map.Keys); CollectionAssert.AreEquivalent(new[] { 1, 2, 3, 4 }, map.Values); map.Remove("three"); Assert.AreEqual(3, map.Count); map.Remove("one"); Assert.AreEqual(2, map.Count); CollectionAssert.AreEquivalent(new[] { "two", "four" }, map.Keys); CollectionAssert.AreEquivalent(new[] { 2, 4 }, map.Values); map.Add("ten", 10); Assert.AreEqual(3, map.Count); CollectionAssert.AreEquivalent(new[] { "two", "four", "ten" }, map.Keys); CollectionAssert.AreEquivalent(new[] { 2, 4, 10 }, map.Values); }
/// <summary> /// Removes one of the arbitrary metadata on the item. /// </summary> /// <param name="metadataName">Name of metadata to remove.</param> public void RemoveMetadata ( string metadataName ) { ErrorUtilities.VerifyThrowArgumentNull(metadataName, "metadataName"); ErrorUtilities.VerifyThrowArgument(!FileUtilities.ItemSpecModifiers.IsItemSpecModifier(metadataName), "Shared.CannotChangeItemSpecModifiers", metadataName); if (_metadata == null) { return; } _metadata.Remove(metadataName); }
public void CopyOnWriteDictionary_Should_Allow_Parallel_Calls_To_Remove() { var actions = new List<Action>(); var map = new CopyOnWriteDictionary<int, int>(); for (var i = 0; i < 100; i++) { map.Add(i, i * 2000); } Assert.AreEqual(100, map.Count); //remove everything except 0 and 1 for (var i = 2; i < 100; i++) { var item = i; actions.Add(() => { map.Remove(item); }); } TestHelper.ParallelInvoke(actions); Assert.AreEqual(2, map.Count); Assert.AreEqual(0, map[0]); Assert.AreEqual(2000, map[1]); }
/// <summary> /// Disconnects the specified connection. /// </summary> /// <param name="connection">The connection.</param> public void Disconnect(IConnection connection) { // We call the disconnect handlers in reverse order they were called during connection, i.e. roomDisconnect is called before appDisconnect. IClient client = connection.Client; if (client == null) { // Early bail out RemoveEventListener(connection); _connectionStats.Decrement(); if (HasParent) { Parent.Disconnect(connection); } return; } if (_clients.ContainsKey(client)) { CopyOnWriteArraySet <IConnection> connections = _clients[client]; connections.Remove(connection); IScopeHandler handler = null; if (HasHandler) { handler = Handler; try { handler.Disconnect(connection, this); } catch (Exception ex) { #if !SILVERLIGHT if (log != null && log.IsErrorEnabled) { log.Error("Error while executing \"disconnect\" for connection " + connection + " on handler " + handler, ex); } #endif } } if (connections.Count == 0) { _clients.Remove(client); _clientStats.Decrement(); if (handler != null) { try { // there may be a timeout here ? handler.Leave(client, this); } catch (Exception ex) { #if !SILVERLIGHT if (log != null && log.IsErrorEnabled) { log.Error("Error while executing \"leave\" for client " + client + " on handler " + handler, ex); } #endif } } } RemoveEventListener(connection); _connectionStats.Decrement(); } if (HasParent) { Parent.Disconnect(connection); } }
public void ReadOperation_DoesNotDelegateToSourceDictionary_OnceDictionaryIsModified() { // Arrange var values = new List<object>(); var sourceDictionary = new Dictionary<string, object> { { "key1", "value1" }, { "key2", "value2" } }; var copyOnWriteDictionary = new CopyOnWriteDictionary<string, object>( sourceDictionary, StringComparer.OrdinalIgnoreCase); // Act copyOnWriteDictionary.Add("key3", "value3"); copyOnWriteDictionary.Remove("key1"); // Assert Assert.Equal(2, sourceDictionary.Count); Assert.Equal("value1", sourceDictionary["key1"]); Assert.Equal(2, copyOnWriteDictionary.Count); Assert.Equal("value2", copyOnWriteDictionary["KeY2"]); Assert.Equal("value3", copyOnWriteDictionary["key3"]); }