コード例 #1
0
ファイル: ImageList.cs プロジェクト: kroll-software/SummerGUI
 public bool AddImage(string key, string filePath)
 {
     try {
         TextureImage image = TextureImage.FromFile(filePath, Context, key, ImageSize);
         return(m_Images.TryAdd(key, image));
     } catch (Exception ex) {
         ex.LogError();
         return(false);
     }
 }
コード例 #2
0
        public bool TryAdd(TKey key, TValue value)
        {
            // key could be null
            if (key == null)
            {
                // ConcurrentDictionary hates null
                throw new ArgumentNullException(nameof(key));
            }

            return(_wrapped.TryAdd(key, value));
        }
コード例 #3
0
        internal RequestResponseCorrelationWrapper <TResponse> RecordRequest <TResponse>(Guid correlationId, DateTimeOffset expiresAfter)
        {
            RecordMessageProcessed();
            var wrapper = new RequestResponseCorrelationWrapper <TResponse>(expiresAfter);

            if (_requestWrappers.TryAdd(correlationId, wrapper))
            {
                return(wrapper);
            }

            throw new InvalidOperationException("A request with CorrelationId '{0}' already exists.".FormatWith(correlationId));
        }
コード例 #4
0
        public static MethodCallCounter CreateInstance(Guid instanceId)
        {
            var instance = new MethodCallCounter();

            _instances.TryAdd(instanceId, instance);
            return(instance);
        }
コード例 #5
0
        /// <summary>
        /// Allows a named service to be mocked using the given <paramref name="implementingType"/>.
        /// </summary>
        /// <param name="serviceRegistry">The target <see cref="IServiceRegistry"/> instance.</param>
        /// <param name="serviceType">The type of service to mock.</param>
        /// <param name="serviceName">The name of the service to mock.</param>
        /// <param name="implementingType">The type that represents the mock to be created.</param>
        public static void StartMocking(this IServiceRegistry serviceRegistry, Type serviceType, string serviceName, Type implementingType)
        {
            Tuple <IServiceRegistry, Type, string> key = CreateServiceKey(serviceRegistry, serviceType, serviceName);
            ILifetime lifeTime            = null;
            var       serviceRegistration = GetExistingServiceRegistration(serviceRegistry, serviceType, serviceName);

            if (serviceRegistration != null)
            {
                MockedServices.TryAdd(key, serviceRegistration);
                lifeTime = CreateLifeTimeBasedOnExistingServiceRegistration(serviceRegistration);
            }

            var mockServiceRegistration = CreateTypeBasedMockServiceRegistration(serviceType, serviceName, implementingType, lifeTime);

            serviceRegistry.Register(mockServiceRegistration);
            ServicesMocks.TryAdd(key, mockServiceRegistration);
        }
コード例 #6
0
 private static Action Add(ThreadSafeDictionary<string, string> dictionary)
 {
     return () =>
         {
             Thread.Sleep(50);
             for (int i = 0; i < 50; i++)
             {
                 dictionary.TryAdd("Key", "Value");
             }
             
         };
 }
コード例 #7
0
 public void Add(Entity entity)
 {
     if (entity == null)
     {
         return;
     }
     if (entities.TryAdd(entity.ID, entity))
     {
         World.Systems.OnEntityAdded(entity);
     }
     else
     {
         this.LogWarning("EntityManager.Add(): Entity already exists {0}", entity.ID);
     }
 }
コード例 #8
0
        public void Subscribe(Observable <T> observable)
        {
            //lock (SyncObject)
            //{
            if (observable == null || observable.IsDisposed || this.IsDisposed)
            {
                return;
            }
            Unsubscriber <T> unsub = observable.Subscribe(this) as Unsubscriber <T>;

            if (unsub != null)
            {
                m_DictObservables.TryAdd(observable, unsub);
            }
            // }
        }
コード例 #9
0
        public void Subscribe(Observable <T> observable)
        {
            if (observable == null || observable.IsDisposed || this.IsDisposed)
            {
                return;
            }
            if (m_DictObservables.Count == 0)
            {
                MessageQueue.ResetStart();
            }
            Unsubscriber <T> unsub = observable.Subscribe(this) as Unsubscriber <T>;

            if (unsub != null)
            {
                m_DictObservables.TryAdd(observable, unsub);
            }
        }
コード例 #10
0
        //public IMonohierarchy<T, TKey> AddChild(IMonohierarchy<T, TKey> child)
        public TChild AddChild <TChild>(TChild child) where TChild : IMonohierarchy <T, TKey>
        {
            if (child == null)
            {
                throw new ArgumentNullException("child");
            }
            if (child.Parent != this)
            {
                throw new ArgumentException("child.Parent");
            }

            if (!DictChildren.TryAdd(child.Key, child))
            {
                return(default(TChild));
            }
            OnChildAdded(child);
            return(child);
        }
コード例 #11
0
            public void TryAddNullFactory()
            {
                var dict = new ThreadSafeDictionary <int, int>();

                dict.TryAdd(1, null);
            }
コード例 #12
0
            public void TryAdd()
            {
                var dict = new ThreadSafeDictionary <int, int>();

                dict[0] = 0;
                Assert.IsTrue(dict.TryAdd(1, 2));
                Assert.IsFalse(dict.TryAdd(1, 9));
                Assert.IsTrue(dict.TryAdd(new KeyValuePair <int, int>(2, 4)));
                Assert.IsFalse(dict.TryAdd(new KeyValuePair <int, int>(2, 9)));
                Assert.IsFalse(dict.TryAdd(2, 20));
                Assert.IsTrue(dict.TryAdd(3, x => x * 2));
                Assert.IsFalse(dict.TryAdd(3, x => x * 4));
                int monitor = 99;

                Assert.IsTrue(dict.TryAdd(4, x => {
                    return(monitor = 8);
                }));
                Assert.AreEqual(8, monitor);
                Assert.IsFalse(dict.TryAdd(4, x => {
                    return(monitor = 9);
                }));
                Assert.AreEqual(8, monitor);
                Assert.IsTrue(dict.TryAdd(5, 10, out monitor));
                Assert.AreEqual(0, monitor);
                Assert.IsFalse(dict.TryAdd(5, 9, out monitor));
                Assert.AreEqual(10, monitor);
                Assert.IsTrue(dict.TryAdd(6, x => 12, out monitor));
                Assert.AreEqual(0, monitor);
                Assert.IsFalse(dict.TryAdd(6, x => 9, out monitor));
                Assert.AreEqual(12, monitor);
                foreach (var kvp in dict)
                {
                    Assert.AreEqual(kvp.Value, kvp.Key * 2);
                }
            }