Example #1
0
 public ActionBase(bool isExclusive)
 {
     IsExclusive = isExclusive;
     Id          = NextId();
     ActionUnits = new List <ActionUnit>();
     Token       = new ActionToken(GetType(), Id, 0, CreateOperationResult());
 }
Example #2
0
        public void AddTimer(ActionToken token)
        {
            if (token == null)
            {
                throw new Exceptions.OperationException();
            }
            var dt = DateTime.Now;

            token.ExpireDateTime = dt + TimeSpan.FromMilliseconds(token.TimeoutMs);
            _values.Add(token);
        }
Example #3
0
        public virtual void NewToken(bool isNextId)
        {
            if (isNextId)
            {
                var newId = NextId();
                "{0}->{1}"._DLOG(Id, newId);
                Id = newId;
            }
            var oldTimeout = Token.TimeoutMs;

            Token           = new ActionToken(GetType(), Id, oldTimeout, CreateOperationResult());
            Token.TimeoutMs = oldTimeout;
            Token.Name      = Name;
            ActionUnits.Clear();
            CompletedCallback = null;
        }
Example #4
0
        private void TimerCallback(object state)
        {
            DateTime dt = DateTime.Now;

            for (int i = _values.Count - 1; i >= 0; i--)
            {
                ActionToken at = _values[i];
                if (at != null)
                {
                    if (!at.IsStateFinished)
                    {
                        if (at.CheckExpired(dt))
                        {
                            _sessionClient.TokenExpired(at);
                        }
                    }
                    else
                    {
                        _values.RemoveAt(i);
                    }
                }
            }
            for (int i = _timeIntervals.Count - 1; i >= 0; i--)
            {
                TimeInterval ti = _timeIntervals[i];
                if (ti != null)
                {
                    if (ti.CheckExpired(dt))
                    {
                        _sessionClient.HandleActionCase(ti);
                        _timeIntervals.RemoveAt(i);
                    }
                }
            }
            lock (mLockObject)
            {
                if (_timer != null)
                {
                    _timer.Change(TICK, Timeout.Infinite);
                }
            }
        }