public Array Dequeue(Type type, int retreiveCount = 0)
        {
            Array resultArr = default(Array);

            if (_queue.TryGetValue(type, out ConcurrentQueue <object> queue))
            {
                if (queue.Any())
                {
                    var count = queue.Count;

                    var configQueue = _config.Get(type);

                    var maxCount = retreiveCount > 0 ? retreiveCount : configQueue.MaxCount;

                    var len = retreiveCount < 0 ? count :
                              count >= maxCount ? maxCount : count;

                    var arrType = type.MakeArrayType();

                    resultArr = (Array)Activator.CreateInstance(arrType, len);

                    for (int i = 0; i < len; i++)
                    {
                        if (!queue.TryDequeue(out object res))
                        {
                            break;
                        }

                        resultArr.SetValue(res, i);
                    }
                }
            }

            return(resultArr);
        }
Esempio n. 2
0
        private void PostWorker(object typeObj, MethodInfo methodPost, int retreiveCount = 0)
        {
            var sender = _plugin.Sender;

            var type = (Type)typeObj;

            var arr = _localQueue.Dequeue(type, retreiveCount);

            if (arr == null || arr.Length == 0)
            {
                return;
            }

            var configQueue = _config.Get(type);

            var worker = configQueue.Factory.DynamicInvoke();

            if (!_cacheMethod.TryGetValue(type, out MethodInfo genericMethod))
            {
                genericMethod = methodPost.MakeGenericMethod(arr.GetType());

                _cacheMethod.Add(type, genericMethod);
            }

            genericMethod.Invoke(sender, new object[] { worker, arr, configQueue.TimeLimit });
        }
Esempio n. 3
0
        public int Send <TData>(TData data)
        {
            var triggerCount = _batchConfig.Get <TData>().TriggerCount;

            var queueCount = _queue.Enqueue(data);

            if (triggerCount > 0)
            {
                var res = triggerCount - queueCount;

                if (res <= 0)
                {
                    _queueEvent.AddEvent(data.GetType());
                }
            }

            return(queueCount);
        }