示例#1
0
 /// <summary>
 /// Returns the value for a given attribute.
 /// </summary>
 /// <param name="name">The attribute name.</param>
 /// <returns>The attribute value.</returns>
 public virtual object GetAttribute(string name)
 {
     if (name == null)
         return null;
     if (_attributes.ContainsKey(name))
         return _attributes[name];
     return null;
 }
示例#2
0
 /// <summary>
 /// Check to see if this scope has a child scope matching a given name.
 /// </summary>
 /// <param name="name">The name of the child scope.</param>
 /// <returns>
 /// true if a child scope exists, otherwise false.
 /// </returns>
 public bool HasChildScope(string name)
 {
     // Synchronize removal and retrieval of child scopes
     Monitor.Enter(SyncRoot);
     try {
         return(_children.ContainsKey(ScopeType + Separator + name));
     } finally {
         Monitor.Exit(SyncRoot);
     }
 }
示例#3
0
 public void UnregisterServiceHandler(string name)
 {
     if (name == null)
     {
         name = string.Empty;
     }
     if (_handlers.ContainsKey(name))
     {
         _handlers.Remove(name);
     }
 }
示例#4
0
 /// <summary>
 /// Returns the value for a given attribute.
 /// </summary>
 /// <param name="name">The attribute name.</param>
 /// <returns>The attribute value.</returns>
 public virtual object GetAttribute(string name)
 {
     if (name == null)
     {
         return(null);
     }
     if (_attributes.ContainsKey(name))
     {
         return(_attributes[name]);
     }
     return(null);
 }
示例#5
0
 public bool ContainsType(string typeName)
 {
     if (string.IsNullOrEmpty(typeName))
     {
         return(false);
     }
     return(_typeCache.ContainsKey(typeName));
 }
示例#6
0
        /// <summary>
        /// Adds given connection to the scope.
        /// </summary>
        /// <param name="connection">Connection object.</param>
        /// <param name="parameters">Parameters passed.</param>
        /// <returns>
        /// true on success, false if the specified connection already belongs to this scope.
        /// </returns>
        public bool Connect(IConnection connection, object[] parameters)
        {
            if (HasParent && !Parent.Connect(connection, parameters))
            {
                return(false);
            }
            if (HasHandler && !Handler.Connect(connection, this, parameters))
            {
                return(false);
            }
            IClient client = connection.Client;

            if (!connection.IsConnected)
            {
                // Timeout while connecting client
                return(false);
            }
            //We would not get this far if there is no handler
            if (HasHandler && !Handler.Join(client, this))
            {
                return(false);
            }
            if (!connection.IsConnected)
            {
                // Timeout while connecting client
                return(false);
            }

            CopyOnWriteArraySet <IConnection> connections;

            if (_clients.ContainsKey(client))
            {
                connections = _clients[client];
            }
            else
            {
                connections      = new CopyOnWriteArraySet <IConnection>();
                _clients[client] = connections;
            }
            connections.Add(connection);
            _clientStats.Increment();
            AddEventListener(connection);
            _connectionStats.Increment();
            return(true);
        }
示例#7
0
 /// <summary>
 /// Registers an IEndpointPushHandler for the specified endpoint to handle pushing messages.
 /// </summary>
 /// <param name="handler">The IEndpointPushHandler to register.</param>
 /// <param name="endpointId">The endpoint identity to register for.</param>
 public void RegisterEndpointPushHandler(IEndpointPushHandler handler, string endpointId)
 {
     if (_endpointPushHandlers == null)
     {
         lock (this.SyncRoot) {
             if (_endpointPushHandlers == null)
             {
                 _endpointPushHandlers = new CopyOnWriteDictionary(1);
             }
         }
     }
     if (_endpointPushHandlers.ContainsKey(endpointId))
     {
         MessageException me = new MessageException();
         me.FaultCode = EndpointPushHandlerAlreadyRegistered.ToString();
         throw me;
     }
     _endpointPushHandlers.Add(endpointId, handler);
 }
示例#8
0
        public void TryGetValue_ReferenceNotFound()
        {
            var dictionary = new CopyOnWriteDictionary <object, object>();

            object v;
            bool   result = dictionary.TryGetValue(new Object(), out v);

            Assert.AreEqual(false, result);
            Assert.AreEqual(null, v);
            Assert.AreEqual(false, dictionary.ContainsKey(new Object()));
        }
示例#9
0
        public void TryGetValue_ReferenceNotFound()
        {
            var dictionary = new CopyOnWriteDictionary <object>();

            object v;
            bool   result = dictionary.TryGetValue(string.Empty, out v);

            Assert.False(result);
            Assert.Null(v);
            Assert.False(dictionary.ContainsKey(string.Empty));
        }
        public void Indexer_ReferenceFound()
        {
            object k1 = new Object();
            object v1 = new Object();

            var dictionary = new CopyOnWriteDictionary<object, object>();
            dictionary[k1] = v1;

            // Now look for the same key we inserted
            object v2 = dictionary[k1];

            Assert.AreEqual(true, Object.ReferenceEquals(v1, v2));
            Assert.AreEqual(true, dictionary.ContainsKey(k1));
        }
示例#11
0
        public void Indexer_ReferenceFound()
        {
            object k1 = new Object();
            object v1 = new Object();

            var dictionary = new CopyOnWriteDictionary <object, object>();

            dictionary[k1] = v1;

            // Now look for the same key we inserted
            object v2 = dictionary[k1];

            Assert.AreEqual(true, Object.ReferenceEquals(v1, v2));
            Assert.AreEqual(true, dictionary.ContainsKey(k1));
        }
示例#12
0
        public void Indexer_ReferenceFound()
        {
            string k1 = new string(nameof(Indexer_ReferenceFound).ToCharArray()); // force create new string
            object v1 = new Object();

            var dictionary = new CopyOnWriteDictionary <object>();

            dictionary[k1] = v1;

            // Now look for the same key we inserted
            object v2 = dictionary[k1];

            Assert.True(Object.ReferenceEquals(v1, v2));
            Assert.True(dictionary.ContainsKey(k1));
        }
    public void ReadOperation_DelegatesToSourceDictionary_IfNoMutationsArePerformed()
    {
        // Arrange
        var values           = new List <object>();
        var enumerator       = Mock.Of <IEnumerator <KeyValuePair <string, object> > >();
        var sourceDictionary = new Mock <IDictionary <string, object> >(MockBehavior.Strict);

        sourceDictionary
        .SetupGet(d => d.Count)
        .Returns(100)
        .Verifiable();
        sourceDictionary
        .SetupGet(d => d.Values)
        .Returns(values)
        .Verifiable();
        sourceDictionary
        .Setup(d => d.ContainsKey("test-key"))
        .Returns(value: true)
        .Verifiable();
        sourceDictionary
        .Setup(d => d.GetEnumerator())
        .Returns(enumerator)
        .Verifiable();
        sourceDictionary
        .Setup(d => d["key2"])
        .Returns("key2-value")
        .Verifiable();
        object value;

        sourceDictionary.Setup(d => d.TryGetValue("different-key", out value))
        .Returns(false)
        .Verifiable();

        var copyOnWriteDictionary = new CopyOnWriteDictionary <string, object>(sourceDictionary.Object,
                                                                               StringComparer.OrdinalIgnoreCase);

        // Act and Assert
        Assert.Equal("key2-value", copyOnWriteDictionary["key2"]);
        Assert.Equal(100, copyOnWriteDictionary.Count);
        Assert.Same(values, copyOnWriteDictionary.Values);
        Assert.True(copyOnWriteDictionary.ContainsKey("test-key"));
        Assert.Same(enumerator, copyOnWriteDictionary.GetEnumerator());
        Assert.False(copyOnWriteDictionary.TryGetValue("different-key", out value));
        sourceDictionary.Verify();
    }
        public void ReadOperation_DelegatesToSourceDictionary_IfNoMutationsArePerformed()
        {
            // Arrange
            var values = new List<object>();
            var enumerator = Mock.Of<IEnumerator<KeyValuePair<string, object>>>();
            var sourceDictionary = new Mock<IDictionary<string, object>>(MockBehavior.Strict);
            sourceDictionary
                .SetupGet(d => d.Count)
                .Returns(100)
                .Verifiable();
            sourceDictionary
                .SetupGet(d => d.Values)
                .Returns(values)
                .Verifiable();
            sourceDictionary
                .Setup(d => d.ContainsKey("test-key"))
                .Returns(value: true)
                .Verifiable();
            sourceDictionary
                .Setup(d => d.GetEnumerator())
                .Returns(enumerator)
                .Verifiable();
            sourceDictionary
                .Setup(d => d["key2"])
                .Returns("key2-value")
                .Verifiable();
            object value;
            sourceDictionary.Setup(d => d.TryGetValue("different-key", out value))
                            .Returns(false)
                            .Verifiable();

            var copyOnWriteDictionary = new CopyOnWriteDictionary<string, object>(sourceDictionary.Object,
                                                                                  StringComparer.OrdinalIgnoreCase);

            // Act and Assert
            Assert.Equal("key2-value", copyOnWriteDictionary["key2"]);
            Assert.Equal(100, copyOnWriteDictionary.Count);
            Assert.Same(values, copyOnWriteDictionary.Values);
            Assert.True(copyOnWriteDictionary.ContainsKey("test-key"));
            Assert.Same(enumerator, copyOnWriteDictionary.GetEnumerator());
            Assert.False(copyOnWriteDictionary.TryGetValue("different-key", out value));
            sourceDictionary.Verify();
        }
        public void TryGetValue_ReferenceNotFound()
        {
            var dictionary = new CopyOnWriteDictionary<object, object>();

            object v;
            bool result = dictionary.TryGetValue(new Object(), out v);

            Assert.AreEqual(false, result);
            Assert.AreEqual(null, v);
            Assert.AreEqual(false, dictionary.ContainsKey(new Object()));
        }