Esempio n. 1
0
        public ArrayRenderer GetArrayRenderer(string template, object[] args)
        {
            if (_renderers.TryGetValue(template, out var renderer))
            {
                return((ArrayRenderer)renderer);
            }

            var arguments     = BuildArguments(template);
            var argumentTypes = new LocalList <Type>(args.Length);

            foreach (var arg in args)
            {
                argumentTypes.Add(arg.GetType());
            }

            var messageRenderer = new DefaultStringFormatter(template);

            renderer = new ArrayRenderer(arguments, messageRenderer, argumentTypes, _converters);

            using (Lock.Enter(_lock))
            {
                _renderers[template] = renderer;
            }

            return((ArrayRenderer)renderer);
        }
 public IEnumerator <double> GetEnumerator()
 {
     using (Lock.Enter())
     {
         return((Queue?.ToArray().AsEnumerable() ?? Enumerable.Empty <double>()).GetEnumerator());
     }
 }
Esempio n. 3
0
 public ImmutableArray <T> Clear()
 {
     using (Lock.Enter())
     {
         DistinctSet.Clear();
         return(DistinctInOrderArrayStorage = ImmutableArray <T> .Empty);
     }
 }
Esempio n. 4
0
 public Task EnqueueAsync(TItem item)
 {
     using (Lock.Enter())
     {
         ItemsQueue.Enqueue(item);
         return(LockedInsertUpdateAsync());
     }
 }
Esempio n. 5
0
        public void LockEnter()
        {
            var lockStruct = Lock.Enter(_lock);

            Assert.True(Monitor.IsEntered(_lock));

            lockStruct.Dispose();
            Assert.False(Monitor.IsEntered(_lock));
        }
Esempio n. 6
0
 private int?SetThrottleLevelLimiter(int?throttleLevel = null)
 {
     using (Lock.Enter())
     {
         ThrottleLevelLimiter = throttleLevel <= 0 ? null : throttleLevel;
         LockedUpdateEnqueueAccess();
         return(ThrottleLevelLimiter);
     }
 }
Esempio n. 7
0
        public void LockUsing()
        {
            using (Lock.Enter(_lock))
            {
                Assert.True(Monitor.IsEntered(_lock));
            }

            Assert.False(Monitor.IsEntered(_lock));
        }
Esempio n. 8
0
        public void AddGroup <TActor>(IActorGroup <TActor> actorGroup) where TActor : Actor
        {
            var typeId = Typeof <TActor> .Id;

            using (Lock.Enter(_groups))
            {
                _groups.Add(typeId, actorGroup);
            }
        }
Esempio n. 9
0
        public void AddFilter <TComponent>(IActorFilter <TComponent> actorFilter) where TComponent : IComponent
        {
            var filterId = Typeof <IActorFilter <TComponent> > .Id;

            using (Lock.Enter(_filters))
            {
                _filters.Add(filterId, actorFilter);
            }
        }
Esempio n. 10
0
 public ImmutableArray <T> Remove(T item)
 {
     using (Lock.Enter())
     {
         return(DistinctSet.Remove(item)
                         ? DistinctInOrderArrayStorage = DistinctInOrderArrayStorage.Remove(item)
                         : DistinctInOrderArrayStorage
                );
     }
 }
Esempio n. 11
0
        public void Write(LogContext context, JsonObject message)
        {
            using (Lock.Enter(_lock))
            {
                context.WriteMessage(message, _output);

                _output.WriteLine();
                _output.Flush();
            }
        }
 public ISequencerExceptionRegister TryReThrowException()
 {
     using (Lock.Enter())
     {
         if (TryGetExceptionLocked() == null)
         {
             return(this);
         }
         throw AggregateException;
     }
 }
Esempio n. 13
0
 public static void RegisterPerfCounterFactory(IPerfCounterFactoryUC factory)
 {
     if (factory == null)
     {
         throw new ArgumentNullException(nameof(factory));
     }
     using (Lock.Enter())
     {
         Factories[factory.PerfCounterType] = factory;
     }
 }
Esempio n. 14
0
 public ConcurrencyLevelEntry TryEnter()
 {
     using (Lock.Enter())
     {
         if (ConcurrencyLevelValue >= MaxConcurrencyLevel)
         {
             return(ConcurrencyLevelEntry.NoEntry);
         }
         ++ConcurrencyLevelValue;
         return(new ConcurrencyLevelEntry(ActionOnExit));
     }
 }
Esempio n. 15
0
        public Task RegisterAsync(Action asyncCallback)
        {
            if (asyncCallback == null)
            {
                throw new ArgumentNullException(nameof(asyncCallback));
            }
            CallBackRequest request = new CallBackRequest(asyncCallback, TickGeneratorRequest.Add);

            if (Status == TickGeneratorStatus.Disposed)
            {
                return(request.TrySetDisposed().Task);
            }
            if (Status == TickGeneratorStatus.Disposing)
            {
                return(request.TrySetCanceled().Task);
            }

            using (Lock.Enter())
            {
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TickGeneratorSequencer.RegisterStatus, Status);
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TickGeneratorSequencer.RegisterActiveProcessing, ActiveProcessing);
                if (Status == TickGeneratorStatus.Disposed)
                {
                    return(request.TrySetDisposed().Task);
                }
                if (Status == TickGeneratorStatus.Disposing)
                {
                    return(request.TrySetCanceled().Task);
                }
                Requests.Enqueue(request);
                if (ActiveProcessing)
                {
                    return(request.Task);
                }
            }

            if (Processing(processActions: false) == ProcessingResult.Processed)
            {
                return(request.Task);
            }

            using (Lock.Enter())
            {
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TickGeneratorSequencer.RegisterEnd, Status);
                if (Status == TickGeneratorStatus.Disposed)
                {
                    return(request.TrySetDisposed().Task);
                }
                TryUpdateTimer(activate: true);
                return(request.Task);
            }
        }
Esempio n. 16
0
        public void Enrich(LogLevel level, Type sender, JsonObject message)
        {
            if (!_senders.TryGetValue(sender, out var value))
            {
                value = new JsonVerbose(ReflectionUtils.GetName(sender));
                using (Lock.Enter(_lock))
                {
                    _senders[sender] = value;
                }
            }

            message.Add(Name, value);
        }
Esempio n. 17
0
 public Task EnqueuedItemsAsync()
 {
     using (Lock.Enter())
     {
         if (ItemsQueue.Count > 0)
         {
             return(Task.CompletedTask);
         }
         var tcs = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
         DequeueAccess.Enqueue(tcs);
         return(tcs.Task);
     }
 }
Esempio n. 18
0
 public override string ToString()
 {
     using (Lock.Enter())
     {
         return
             ($"[ConcurrentQueueNotifier]" +
              $"[{nameof(ThrottleLevel)}:{ThrottleLevelLimiter?.ToString() ?? "none"}]" +
              $"[AwaitingEnqueues:{EnqueueAccess.Count}]" +
              $"[AwaitingDequeues:{DequeueAccess.Count}]" +
              $"[ItemsCount:{ItemsQueue.Count}]"
             );
     }
 }
 /// <summary>
 /// Use only with TryDequeue with same priority!
 /// </summary>
 public AsyncEnqueuedCompletionUC EnqueuedItemsAsync(TPrioritySelectorEnum prioritySelector)
 {
     using (Lock.Enter())
     {
         if (HasItems(prioritySelector))
         {
             return(AsyncEnqueuedCompletionUC.Completed);                                           //AsyncEnqueuedCompletionUC.AlreadyAsyncEnqueued;
         }
         TaskCompletionSource <object> asyncEnqueued = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
         NotifyPriority[prioritySelector].Enqueue(asyncEnqueued);
         return(new AsyncEnqueuedCompletionUC(asyncEnqueued.Task));
     }
 }
 /// <summary>
 /// Use only with TryDequeue without overridden priority!
 /// Awaitable returns completed as long as there are any items for any priority!
 /// </summary>
 public AsyncEnqueuedCompletionUC EnqueuedItemsAsync()
 {
     using (Lock.Enter())
     {
         if (HasItems())
         {
             return(AsyncEnqueuedCompletionUC.Completed);
         }
         TaskCompletionSource <object> asyncEnqueued = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);
         NotifyAnyPriority.Enqueue(asyncEnqueued);
         return(new AsyncEnqueuedCompletionUC(asyncEnqueued.Task));
     }
 }
Esempio n. 21
0
        public static IPerfCounterUC CreatePerfCounter(this PerfCounterTypeUC perfCounterType, string processName = null, int?pid = null)
        {
            IPerfCounterFactoryUC factory;

            using (Lock.Enter())
            {
                if (!Factories.TryGetValue(perfCounterType, out factory) || factory == null)
                {
                    throw new ArgumentException($"{nameof(PerfCounterTypeUC)}.{perfCounterType} not registered!");
                }
            }

            return(factory.NewPerfCounterUC(processName, pid));
        }
        public ISequencerExceptionRegister RegisterException(Exception exception)
        {
            if (exception == null)
            {
                return(this);
            }

            using (Lock.Enter())
            {
                Exceptions.Enqueue(exception);
                AggregateException = new AggregateException(Exceptions);
            }
            TokenSource.Cancel(false);
            return(this);
        }
Esempio n. 23
0
        public bool TryDequeu(out TItem item)
        {
            using (Lock.Enter())
            {
                if (ItemsQueue.Count <= 0)
                {
                    item = default(TItem);
                    return(false);
                }

                item = ItemsQueue.Dequeue();
                LockedUpdateEnqueueAccess();
                return(true);
            }
        }
        public void Dispose()
        {
            using (Lock.Enter())
            {
                StopWatch?.Stop();
                PerfCounter?.Dispose();
                Queue?.Clear();
                Unique?.Clear();

                StopWatch   = null;
                PerfCounter = null;
                Queue       = null;
                Unique      = null;
            }
        }
Esempio n. 25
0
        public AsyncTimerProcessorResult <TArg> RegisterAsync <TArg>(TimeSpan delay)
        {
            TimerProcessorCallBackRequest request = TimerProcessorCallBackRequest.Add <TArg>(RealTimeSource.GetUtcNow(), delay);

            if (Status == TimerProcessorStatus.Disposed)
            {
                return(request.TrySetDisposed().GetAsyncResult <TArg>());
            }
            if (Status == TimerProcessorStatus.Disposing)
            {
                return(request.TrySetCanceled().GetAsyncResult <TArg>());
            }

            using (Lock.Enter())
            {
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TimerProcessorSequencer.RegisterStatus, Status);
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TimerProcessorSequencer.RegisterActiveProcessing, ActiveProcessing);
                if (Status == TimerProcessorStatus.Disposed)
                {
                    return(request.TrySetDisposed().GetAsyncResult <TArg>());
                }
                if (Status == TimerProcessorStatus.Disposing)
                {
                    return(request.TrySetCanceled().GetAsyncResult <TArg>());
                }
                Requests.Enqueue(request);
                if (ActiveProcessing)
                {
                    return(request.GetAsyncResult <TArg>());
                }
            }

            if (Processing(processActions: false) == ProcessingResult.Processed)
            {
                return(request.GetAsyncResult <TArg>());
            }

            using (Lock.Enter())
            {
                NullSafeSequencer.PointArg(SeqPointTypeUC.Notify, TimerProcessorSequencer.RegisterEnd, Status);
                if (Status == TimerProcessorStatus.Disposed)
                {
                    return(request.TrySetDisposed().GetAsyncResult <TArg>());
                }
                TryUpdateTimer(activate: true);
                return(request.GetAsyncResult <TArg>());
            }
        }
Esempio n. 26
0
        public void Write(LogContext context, JsonObject message)
        {
            using (Lock.Enter(_lock))
            {
                var output = GetOutput(context.Level);

                Console.ForegroundColor = GetColor(context.Level);

                context.WriteMessage(message, output);

                output.WriteLine();
                output.Flush();

                Console.ResetColor();
            }
        }
Esempio n. 27
0
        public static Type GetForCommand(Type commandType)
        {
            if (ResolvedTypes.TryGetValue(commandType, out var exists))
            {
                return(exists);
            }

            var pipelineType = Command.MakeGenericType(commandType);

            using (Lock.Enter(ResolvedTypes))
            {
                ResolvedTypes[commandType] = pipelineType;
            }

            return(pipelineType);
        }
Esempio n. 28
0
        public static Type GetForNotification(Type notificationType)
        {
            if (ResolvedTypes.TryGetValue(notificationType, out var exists))
            {
                return(exists);
            }

            var pipelineType = Notification.MakeGenericType(notificationType);

            using (Lock.Enter(ResolvedTypes))
            {
                ResolvedTypes[notificationType] = pipelineType;
            }

            return(pipelineType);
        }
Esempio n. 29
0
        public IJsonConverter Get(Type type)
        {
            if (_converters.TryGetValue(type, out var exists))
            {
                return(exists);
            }

            var converter = Build(type);

            using (Lock.Enter(_lock))
            {
                _converters[type] = converter;
            }

            return(converter);
        }
Esempio n. 30
0
        public static Type GetForQuery(Type queryType)
        {
            if (ResolvedTypes.TryGetValue(queryType, out var exists))
            {
                return(exists);
            }

            var resultType   = ReflectionUtils.GetGenericInterfaceParameters(queryType, QueryType)[0];
            var pipelineType = Query.MakeGenericType(queryType, resultType);

            using (Lock.Enter(ResolvedTypes))
            {
                ResolvedTypes[queryType] = pipelineType;
            }

            return(pipelineType);
        }