public override List <ObjectObserver> GetObserversForAdd(ObjectBuilder builder)
        {
            List <ObjectObserver> observers = null;

            _lock.Enter();
            try
            {
                foreach (var observer in Observers)
                {
                    if (!observer.CanAdd(builder))
                    {
                        continue;
                    }
                    if (observers == null)
                    {
                        observers = new List <ObjectObserver>();
                    }
                    observers.Add(observer);
                }
                return(observers);
            }
            finally
            {
                _lock.Exit();
            }
        }
        protected internal override void Add(ObjectBuilder builder)
        {
            _lock.Enter();
            try
            {
                if (_builders.Count == 0)
                {
                    _builders.Add(builder);
                    return;
                }

                var newRanking = builder.ObjectDescription.Ranking;
                if (newRanking < _builders[0].ObjectDescription.Ranking)
                {
                    _builders.Insert(0, builder);
                    return;
                }

                var targetPosition = 0;
                for (int i = _builders.Count - 1; i >= 0; i--)
                {
                    var existing = _builders[i];
                    if (newRanking >= existing.ObjectDescription.Ranking)
                    {
                        targetPosition = i + 1;
                        break;
                    }
                }
                _builders.Insert(targetPosition, builder);
            }
            finally
            {
                _lock.Exit();
            }
        }
 /// <summary>
 /// Adds the specified component to the container.
 /// </summary>
 /// <param name="component">The component.</param>
 public void Add(object component)
 {
     Requires.NotNull(component, "component");
     _lock.Enter();
     try
     {
         _type2Components.Add(component.GetType(), component);
     }
     finally
     {
         _lock.Exit();
     }
 }
Ejemplo n.º 4
0
 // The builder.BuilderType looks like List<>/IList<> or some other types.
 public void Add(IObjectMapperBuilder builder)
 {
     Requires.NotNull(builder, "builder");
     _lock.Enter();
     try
     {
         _type2Builders.Add(builder.BuilderType, builder);
     }
     finally
     {
         _lock.Exit();
     }
 }
        public Type GetOrCreateParameterMergerType(int paramLength)
        {
            //if (paramLength > 8)
            //    throw new ArgumentOutOfRangeException("Can not build injectors for constructor with more than 8 parameters right now. This function is coming soon...");

            if (paramLength == 0)
            {
                throw new InvalidOperationException();
            }

            var result = GetDefaultParameterMergerType(paramLength);

            if (result != null)
            {
                return(result);
            }

            _mergerLock.Enter();
            try
            {
                if (_length2Merger.TryGetValue(paramLength, out result))
                {
                    return(result);
                }

                result = _provider.CreateParameterMergerType(paramLength);
                _length2Merger.Add(paramLength, result);
                return(result);
            }
            finally
            {
                _mergerLock.Exit();
            }
        }
Ejemplo n.º 6
0
        internal void BuildNodeList(int level, DispatcherNode[] nodeList, string[] keyParts)
        {
            // find/create subnode
            nodeList[_Level] = this;
            DispatcherNode subNode;

            _ChildIndexLock.Enter();
            try
            {
                if (!_ChildIndex.TryGetValue(keyParts[_Level], out subNode))
                {
                    subNode = new DispatcherNode(_Dispatcher, _Level + 1, this);
                    _ChildIndex.Add(keyParts[_Level], subNode);
                }
            }
            finally
            {
                _ChildIndexLock.Leave();
            }
            nodeList[_Level + 1] = subNode;
            if (level > (_Level + 1))
            {
                subNode.BuildNodeList(level, nodeList, keyParts);
            }
        }
Ejemplo n.º 7
0
 public void Write(long storeOffset, byte[] data)
 {
     using (_writeOffsetLock.Enter(storeOffset))
     {
         using (var offsetWriteStream = _provider.AcquireWriteStream())
         {
             offsetWriteStream.Seek(storeOffset, SeekOrigin.Begin);
             offsetWriteStream.Write(data, 0, data.Length);
             if (_lastFlushOffset > storeOffset)
             {
                 _lastFlushOffset = storeOffset - 1;
             }
         }
     }
 }
Ejemplo n.º 8
0
        protected int AddObjectBuilderCore(T builder)
        {
            MyLock.Enter();
            try
            {
                if (MyBuilders.Count == 0)
                {
                    MyBuilders.Add(builder);
                    return(0);
                }

                var newRanking = builder.ObjectDescription.Ranking;
                if (newRanking < MyBuilders[0].ObjectDescription.Ranking)
                {
                    MyBuilders.Insert(0, builder);
                    return(0);
                }

                var targetPosition = 0;
                for (int i = MyBuilders.Count - 1; i >= 0; i--)
                {
                    var existing = MyBuilders[i];
                    if (newRanking >= existing.ObjectDescription.Ranking)
                    {
                        targetPosition = i + 1;
                        break;
                    }
                }
                MyBuilders.Insert(targetPosition, builder);
                return(targetPosition);
            }
            finally
            {
                MyLock.Exit();
            }
        }
        public Type GetOrCreateInjectorType(InjectorEmitBody emitBody)
        {
            EmitInjectorKey key;
            var             methodEmitBodySet = emitBody.MethodEmitBodySet;

            if (methodEmitBodySet != null)
            {
                var injectedMethods = new MethodInfo[methodEmitBodySet.Length];
                for (int i = 0; i < methodEmitBodySet.Length; i++)
                {
                    var methodEmitBody = methodEmitBodySet[i];
                    injectedMethods[i] = methodEmitBody.InjectedMethod;
                }
                key = new EmitConstructorAndMemberInjectorKey(emitBody.ConstructorEmitBody.InjectedConstructor, injectedMethods);
            }
            else
            {
                key = new EmitInjectorKey(emitBody.ConstructorEmitBody.InjectedConstructor);
            }

            _injectorLock.Enter();
            try
            {
                Type injectorType;
                if (_key2Injector.TryGetValue(key, out injectorType))
                {
                    return(injectorType);
                }

                injectorType = _provider.CreateInjectorType(emitBody, GetUniqueDynamicTypeName());
                _key2Injector.Add(key, injectorType);
                return(injectorType);
            }
            finally
            {
                _injectorLock.Exit();
            }
        }
Ejemplo n.º 10
0
 protected override void EnterWithoutChaining(ILock theLock, ref bool lockTaken)
 {
     theLock.Enter();
     lockTaken = true;
 }
 protected override void EnterWithoutChaining(ILock theLock, ref bool lockTaken)
 {
     theLock.Enter();
     lockTaken = true;
 }