Exemple #1
0
        public void It_should_corect_work_when_internal_state_reused()
        {
            results.Clear();

            using (var timer = new MultiTimer <int>(MultiTimerCalback, 256))
            {
                int id1 = timer.Add(300, Environment.TickCount + 300);
                int id2 = timer.Add(300, Environment.TickCount + 300);
                int id3 = timer.Add(300, Environment.TickCount + 300);

                timer.Add(300, Environment.TickCount + 300);
                timer.Add(300, Environment.TickCount + 300);
                timer.Add(300, Environment.TickCount + 300);

                timer.Remove(id1);
                timer.Remove(id2);
                timer.Remove(id3);

                timer.Add(600, Environment.TickCount + 600);
                timer.Add(600, Environment.TickCount + 600);
                timer.Add(600, Environment.TickCount + 600);

                Validate(6);
            }
        }
Exemple #2
0
        public void It_should_stop_timer_by_param()
        {
            results.Clear();

            using (var timer = new MultiTimer <long>(MultiTimerCalback, 256, true))
            {
                long[] param = new long[6];

                int id1 = timer.Add(700, param[0] = Environment.TickCount + 700);
                int id2 = timer.Add(500, param[1] = Environment.TickCount + 500);
                int id3 = timer.Add(200, param[2] = Environment.TickCount + 200);
                int id4 = timer.Add(600, param[3] = Environment.TickCount + 600);
                int id5 = timer.Add(300, param[4] = Environment.TickCount + 300);
                int id6 = timer.Add(100, param[5] = Environment.TickCount + 100);

                timer.Remove(param[0]);
                timer.Remove(param[2]);
                timer.Remove(param[4]);

                Validate(3);

                Assert.AreEqual((int)param[5], results[0].Expected);
                Assert.AreEqual((int)param[1], results[1].Expected);
                Assert.AreEqual((int)param[3], results[2].Expected);
            }
        }
Exemple #3
0
        private void FileChanged(int accountId)
        {
            bool removed;

            lock (ignoreWatcher)
                removed = ignoreWatcher.Remove(accountId);

            if (removed == false)
            {
                timer.RemoveByParam(accountId);
                timer.Add(accountId);
            }
        }
Exemple #4
0
        public void It_should_call_remove_by_id_if_T_is_int()
        {
            results.Clear();

            using (var timer = new MultiTimer <int>(MultiTimerCalback, 256, true))
            {
                int id = timer.Add(100, 12345);

                timer.RemoveByParam(12345);

                Thread.Sleep(200);
                Assert.AreEqual(0, results.Count);
            }
        }
        private void ContactAddedHandlerInternal(Bindings bindings, Binding binding, SipMessageReader request)
        {
            timer.Add(binding.Expires * 1000, bindings.Aor);

            if (binding.ConnectionAddresses.Transport == Transports.Tcp || binding.ConnectionAddresses.Transport == Transports.Tls)
            {
                bindingsByConnectionId.Replace(binding.ConnectionAddresses.ConnectionId, bindings.Aor);
            }

            if (bindings.IsNew)
            {
                AorAdded(bindings.Aor);
            }

            ContactAdded(bindings.Aor, binding, request);
        }
		public void It_should_callback_after_due_time_for_same_delay()
		{
			results.Clear();

			using (var timer = new MultiTimer<int>(MultiTimerCalback, 256))
			{
				timer.Add(300, Environment.TickCount + 300);
				timer.Add(300, Environment.TickCount + 300);
				timer.Add(300, Environment.TickCount + 300);
				timer.Add(300, Environment.TickCount + 300);
				timer.Add(300, Environment.TickCount + 300);
				timer.Add(300, Environment.TickCount + 300);

				Validate(6);
			}
		}
		public void It_should_callback_after_due_time()
		{
			results.Clear();

			using (var timer = new MultiTimer<int>(MultiTimerCalback, 256))
			{
				timer.Add(700, Environment.TickCount + 700);
				timer.Add(500, Environment.TickCount + 500);
				timer.Add(200, Environment.TickCount + 200);
				timer.Add(600, Environment.TickCount + 600);
				timer.Add(300, Environment.TickCount + 300);
				timer.Add(100, Environment.TickCount + 100);

				Validate(6);
			}
		}
Exemple #8
0
        public void It_should_callback_after_due_time_for_same_delay()
        {
            results.Clear();

            using (var timer = new MultiTimer <int>(MultiTimerCalback, 256))
            {
                timer.Add(300, Environment.TickCount + 300);
                timer.Add(300, Environment.TickCount + 300);
                timer.Add(300, Environment.TickCount + 300);
                timer.Add(300, Environment.TickCount + 300);
                timer.Add(300, Environment.TickCount + 300);
                timer.Add(300, Environment.TickCount + 300);

                Validate(6);
            }
        }
Exemple #9
0
        public void It_should_callback_after_due_time()
        {
            results.Clear();

            using (var timer = new MultiTimer <int>(MultiTimerCalback, 256))
            {
                timer.Add(700, Environment.TickCount + 700);
                timer.Add(500, Environment.TickCount + 500);
                timer.Add(200, Environment.TickCount + 200);
                timer.Add(600, Environment.TickCount + 600);
                timer.Add(300, Environment.TickCount + 300);
                timer.Add(100, Environment.TickCount + 100);

                Validate(6);
            }
        }
Exemple #10
0
		public void It_should_stop_timer_by_id()
		{
			results.Clear();

			using (var timer = new MultiTimer<int>(MultiTimerCalback, 256))
			{
				int id1 = timer.Add(700, Environment.TickCount + 700);
				int id2 = timer.Add(500, Environment.TickCount + 500);
				int id3 = timer.Add(200, Environment.TickCount + 200);
				int id4 = timer.Add(600, Environment.TickCount + 600);
				int id5 = timer.Add(300, Environment.TickCount + 300);
				int id6 = timer.Add(100, Environment.TickCount + 100);

				timer.Remove(id1);
				timer.Remove(id3);
				timer.Remove(id5);

				Validate(3);
			}
		}
Exemple #11
0
        public void It_should_stop_timer_by_id()
        {
            results.Clear();

            using (var timer = new MultiTimer <int>(MultiTimerCalback, 256))
            {
                int id1 = timer.Add(700, Environment.TickCount + 700);
                int id2 = timer.Add(500, Environment.TickCount + 500);
                int id3 = timer.Add(200, Environment.TickCount + 200);
                int id4 = timer.Add(600, Environment.TickCount + 600);
                int id5 = timer.Add(300, Environment.TickCount + 300);
                int id6 = timer.Add(100, Environment.TickCount + 100);

                timer.Remove(id1);
                timer.Remove(id3);
                timer.Remove(id5);

                Validate(3);
            }
        }
Exemple #12
0
		public void It_should_stop_timer_by_param()
		{
			results.Clear();

			using (var timer = new MultiTimer<long>(MultiTimerCalback, 256, true))
			{
				long[] param = new long[6];

				int id1 = timer.Add(700, param[0] = Environment.TickCount + 700);
				int id2 = timer.Add(500, param[1] = Environment.TickCount + 500);
				int id3 = timer.Add(200, param[2] = Environment.TickCount + 200);
				int id4 = timer.Add(600, param[3] = Environment.TickCount + 600);
				int id5 = timer.Add(300, param[4] = Environment.TickCount + 300);
				int id6 = timer.Add(100, param[5] = Environment.TickCount + 100);

				timer.Remove(param[0]);
				timer.Remove(param[2]);
				timer.Remove(param[4]);

				Validate(3);

				Assert.AreEqual((int)param[5], results[0].Expected);
				Assert.AreEqual((int)param[1], results[1].Expected);
				Assert.AreEqual((int)param[3], results[2].Expected);
			}
		}
Exemple #13
0
		public void It_should_corect_work_when_internal_state_reused()
		{
			results.Clear();

			using (var timer = new MultiTimer<int>(MultiTimerCalback, 256))
			{
				int id1 = timer.Add(300, Environment.TickCount + 300);
				int id2 = timer.Add(300, Environment.TickCount + 300);
				int id3 = timer.Add(300, Environment.TickCount + 300);

				timer.Add(300, Environment.TickCount + 300);
				timer.Add(300, Environment.TickCount + 300);
				timer.Add(300, Environment.TickCount + 300);

				timer.Remove(id1);
				timer.Remove(id2);
				timer.Remove(id3);

				timer.Add(600, Environment.TickCount + 600);
				timer.Add(600, Environment.TickCount + 600);
				timer.Add(600, Environment.TickCount + 600);

				Validate(6);
			}
		}
Exemple #14
0
		public void It_should_call_remove_by_id_if_T_is_int()
		{
			results.Clear();

			using (var timer = new MultiTimer<int>(MultiTimerCalback, 256, true))
			{
				int id = timer.Add(100, 12345);

				timer.RemoveByParam(12345);

				Thread.Sleep(200);
				Assert.AreEqual(0, results.Count);
			}
		}
Exemple #15
0
        private void DoWork(int transactionKId, int action)
        {
            if ((action & Transaction.Action.StartTimerA1) > 0)
            {
                timerA.Add(T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerA2) > 0)
            {
                timerA.Add(2 * T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerA3) > 0)
            {
                timerA.Add(4 * T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerA4) > 0)
            {
                timerA.Add(8 * T1, transactionKId);
            }

            if ((action & Transaction.Action.StartTimerG1) > 0)
            {
                timerG.Add(T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerG2) > 0)
            {
                timerG.Add(2 * T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerG3) > 0)
            {
                timerG.Add(4 * T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerG4) > 0)
            {
                timerG.Add(8 * T1, transactionKId);
            }

            if ((action & Transaction.Action.StartTimerE1) > 0)
            {
                timerE.Add(T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerE2) > 0)
            {
                timerE.Add(2 * T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerE3) > 0)
            {
                timerE.Add(4 * T1, transactionKId);
            }
            if ((action & Transaction.Action.StartTimerE4) > 0)
            {
                timerE.Add(8 * T1, transactionKId);
            }

            if ((action & Transaction.Action.StartTimerB) > 0)
            {
                timerB.Add(transactionKId);
            }

            if ((action & Transaction.Action.StartTimerD) > 0)
            {
                timerD.Add(transactionKId);
            }

            if ((action & Transaction.Action.StartTimerF) > 0)
            {
                timerF.Add(transactionKId);
            }

            if ((action & Transaction.Action.StartTimerH) > 0)
            {
                timerH.Add(transactionKId);
            }

            if ((action & Transaction.Action.StartTimerI) > 0)
            {
                timerI.Add(transactionKId);
            }

            if ((action & Transaction.Action.StartTimerJ) > 0)
            {
                timerJ.Add(transactionKId);
            }

            if ((action & Transaction.Action.StartTimerK) > 0)
            {
                timerK.Add(transactionKId);
            }
        }
Exemple #16
0
        public int ProcessConnection(Connection connection)
        {
            Session session = null;

            int sessionId = GetSessionId(connection.HttpReader);

            if (sessionId == Session.InvalidId)
            {
                if (connection.HttpReader.Method == Methods.Get)
                {
                    session = new Session(GenerateSessionId(connection.HttpReader));
                    session.StoreAddresses(connection);

                    lock (session)
                    {
                        sessions.Add(session.Id, session);
                        SendJsonMessage(session);
                    }
                }
                else
                {
                    SendResponse(connection, StatusCodes.NotAcceptable);
                }
            }
            else if (sessions.TryGetValue(sessionId, out session))
            {
                if (connection.HttpReader.Method == Methods.Get)
                {
                    lock (session)
                    {
                        if (session.IsConnected)
                        {
                            SendEmptyMessage(session);
                        }

                        session.StoreAddresses(connection);

                        var e = session.GetOutgoingMessage();

                        if (e != null)
                        {
                            SendSipEventArgs(e, session);
                        }
                        else
                        {
                            session.TimerId = timer.Add(session.Id);
                        }
                    }
                }
                else if (connection.HttpReader.Method == Methods.Post)
                {
                    SendResponse(connection, StatusCodes.OK);
                }
                else
                {
                    session = null;
                    SendResponse(connection, StatusCodes.NotAcceptable);
                }
            }
            else
            {
                SendResponse(connection, StatusCodes.Gone);
            }

            return((session != null) ? session.Id : Session.InvalidId);
        }