public void ExecuteAllMessage_Basic()
        {
            var q = new EQueue <MyMessage>();

            for (var i = 0; i < 10; i++)
            {
                q.Enqueue(new MyMessage(i + 1));
            }
            var stateResults = q.ExecuteAllMessages();

            DS.Assert.AreEqual(DS.List(MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded, MessageExecution.Succeeded), stateResults);

            Assert.AreEqual(00, q.Count);
            Assert.AreEqual(10, stateResults.Count);
            Assert.AreEqual(10, q.SucceededMessages.Count);
            Assert.AreEqual(00, q.FailedMessages.Count);
            Assert.AreEqual(00, q.FailedMessages.Count);

            for (var i = 0; i < 10; i++)
            {
                var m = q.SucceededMessages.Dequeue();
                Assert.AreEqual(MessageState.Processed, m.State);
                Assert.IsTrue(m.EndProcessed >= m.StartProcessed);
                Assert.IsTrue(m.Dequeued >= m.Queued);
            }
        }
        public void StartEventLoop(CancellationToken token = default)
        {
            if (isLooping)
            {
                return;
            }
            isLooping = true;
            _loopTokenSource?.Dispose();
            _loopTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token, _internalSource.Token);
            var loopToken = _loopTokenSource.Token;

            loopTask = Task.Run(() =>
            {
                while (isLooping)
                {
                    if (EWaiter.WaitForEvent(loopToken))
                    {
                        try
                        {
                            var returned = EQueue.StartEvent();
                            AppendAwaitCompletion(returned.CommandTask);
                        }
                        //TODO: DO SOMETHING WITH THIS!
                        catch { }
                    }
                }
            });
        }
Example #3
0
        public void Recycle(Disposer obj)
        {
            Type type = obj.GetType();
            EQueue <Disposer> queue;

            if (!this.dictionary.TryGetValue(type, out queue))
            {
                queue = new EQueue <Disposer>();
            }
            queue.Enqueue(obj);
        }
Example #4
0
        private static EQueue <IReference> GetReferencePool(Type refType)
        {
            EQueue <IReference> referencePool = null;

            if (!s_ReferencePool.TryGetValue(refType, out referencePool))
            {
                referencePool = new EQueue <IReference>();
                s_ReferencePool.Add(refType, referencePool);
            }

            return(referencePool);
        }
Example #5
0
        private static EQueue <IReference> GetReferencePool(string fullName)
        {
            EQueue <IReference> referencePool = null;

            if (!s_ReferencePool.TryGetValue(fullName, out referencePool))
            {
                referencePool = new EQueue <IReference>();
                s_ReferencePool.Add(fullName, referencePool);
            }

            return(referencePool);
        }
Example #6
0
        public Disposer Fetch(Type type)
        {
            EQueue <Disposer> queue;

            if (!this.dictionary.TryGetValue(type, out queue))
            {
                queue = new EQueue <Disposer>();
                this.dictionary.Add(type, queue);
            }
            Disposer obj;

            if (queue.Count > 0)
            {
                obj    = queue.Dequeue();
                obj.Id = IdGenerater.GenerateId();
                return(obj);
            }
            obj = (Disposer)Activator.CreateInstance(type);
            return(obj);
        }
Example #7
0
        /// <summary>
        /// 从引用池获取引用。
        /// </summary>
        /// <typeparam name="T">引用类型。</typeparam>
        public static T Fetch <T>() where T : class, IReference
        {
            T tmpInstance = default(T);

            lock (s_ReferencePool)
            {
                EQueue <IReference> referencePool = GetReferencePool(typeof(T));
                if (referencePool.Count > 0)
                {
                    tmpInstance = (T)referencePool.Dequeue();
                }
            }

            if (null == tmpInstance)
            {
                tmpInstance = Activator.CreateInstance <T>();
            }

            tmpInstance.OnInit();
            return(tmpInstance);
        }
Example #8
0
        /// <summary>
        /// 从引用池获取引用。
        /// </summary>
        /// <typeparam name="T">引用类型。</typeparam>
        public static T Fetch <T>() where T : class, IReference, new()
        {
            T tmpInstance = default(T);

            lock (s_ReferencePool)
            {
                EQueue <IReference> referencePool = GetReferencePool(typeof(T).FullName);
                if (referencePool.Count > 0)
                {
                    tmpInstance = (T)referencePool.Dequeue();
                }
            }

            if (null == tmpInstance)
            {
                tmpInstance = new T();
            }

            tmpInstance.IsFromPool = true;

            return(tmpInstance);
        }
        public void PersisteOneMessage()
        {
            var q = new EQueue <MyMessage>(new jsonDb.FileSystemStore());

            q.Enqueue(new MyMessage(0));
        }
Example #10
0
 public LaunchPad()
 {
     DepartQueue = new EQueue <Plane>();
     AcceptQueue = new EQueue <Plane>();
 }
Example #11
0
        public static void Main(string[] args)
        {
            int passwords = int.Parse(Console.ReadLine());

            string[] passwordsArray = new string[passwords];

            for (int i = 0; i < passwords; i++)
            {
                string readpassword = Console.ReadLine();
                passwordsArray[i] = readpassword;
            }

            for (int i = 0; i < passwords; i++)
            {
                char[]        password      = passwordsArray[i].ToCharArray();
                EQueue <char> passwordQueue = new EQueue <char>(password.Length);

                // add items to queue
                for (int j = 0; j < password.Length; j++)
                {
                    passwordQueue.Add(password[j]);
                }

                List <char> realpassword = new List <char>();

                int index     = 0;
                int charCount = 0;

                // loop through queue
                for (int j = 0; j < password.Length; j++)
                {
                    char queueItem = passwordQueue.Poll();
                    switch (password[j])
                    {
                    case '-':
                        // functie backspace
                        if (index > 0)
                        {
                            index--;
                            realpassword.RemoveAt(index);
                        }
                        break;

                    case '<':
                        // functie cursor naar links
                        if (index > 0)
                        {
                            index--;
                        }
                        break;

                    case '>':
                        // functie cursor naar rechts
                        if (index < charCount)
                        {
                            index++;
                        }
                        break;

                    default:
                        // functie voeg character toe

                        if (index == charCount)
                        {
                            realpassword.Add(queueItem);
                        }
                        else
                        {
                            realpassword.Insert(index, queueItem);
                        }
                        charCount++;
                        index++;
                        break;
                    }
                }

                Console.WriteLine(string.Join("", realpassword.ToArray()));
            }
        }