Ejemplo n.º 1
0
        private void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            var c = root as Generic.ICell <T>;

            if (c != null)
            {
                switch (eventType)
                {
                case CellEvent.Calculate:
                    _target.OnNext(new KeyValuePair <string, T>(c.Mnemonic, c.Value));
                    break;

                case CellEvent.Delete:
                    _target.OnCompleted();
                    break;

                case CellEvent.Error:
                    try
                    {
                        _target.OnNext(new KeyValuePair <string, T>(c.Mnemonic, c.Value));
                    }
                    catch (Exception e)
                    {
                        _target.OnError(e);
                    }
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Invalidate:
            case CellEvent.Delete:
            case CellEvent.JoinSession:
            case CellEvent.Link:
            case CellEvent.Calculate:
                _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, ((ICell)sender), epoch));
                _retry = 0;
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, (ICell)sender, epoch));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                    if (root is ICell c && _retry++ < Cell.ErrorRetry)
                    {
                        Thread.Sleep(_retry * Cell.ErrorRetry * 100);
                        c.OnChange(CellEvent.Calculate, this, this, DateTime.Now, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        public void OnChange(CellEvent eventType, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                var lastsession = Session.Current;
                Session.Current = session;
                _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                Session.Current = lastsession;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 4
0
 public virtual void OnChange(CellEvent eventType, ICellEvent root, DateTime epoch, ISession session)
 {
     if (Change != null)
     {
         Change(eventType, root, epoch, session);
     }
 }
Ejemplo n.º 5
0
        public void OnChange(CellEvent eventType, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Invalidate:
            case CellEvent.Delete:
            case CellEvent.JoinSession:
            case CellEvent.Link:
            case CellEvent.Calculate:
                _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, ((ICell)sender), epoch));
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new Tuple <ISession, Generic.ICell <T>, CellEvent, ICell, DateTime>(session, _source, eventType, (ICell)sender, epoch));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// <paramref name="target"/>にバフを適用出来るか返す
        /// </summary>
        private bool CanApplyBuff(ICellEvent target)
        {
            // そもそもIReceiveBuffを継承していない場合はなにもしない
            if (!(target is IReceiveBuff))
            {
                return(false);
            }

            // 範囲内に存在するかチェック
            var impactRange = this.levelParameter.ImpactRange;
            var range       = new RectInt(
                this.Origin.x - impactRange,
                this.Origin.y - impactRange,
                impactRange * 2,
                impactRange * 2
                );

            for (var y = 0; y < target.Size; y++)
            {
                for (var x = 0; x < target.Size; x++)
                {
                    var position = target.Origin + new Vector2Int(x, y);
                    if (
                        range.xMin <= position.x && position.x <= range.xMax &&
                        range.yMin <= position.y && position.y <= range.yMax
                        )
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                _target.OnNext((ICell)root);
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext((ICell)root);
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 8
0
        public void Remove(ICellEvent cellEvent)
        {
            this.cellMapper.Remove(cellEvent);
            cellEvent.Remove();

            Broker.Global.Publish(RemovedCellEvent.Get(cellEvent));
        }
Ejemplo n.º 9
0
        public virtual void OnChange(CellEvent eventType, ICellEvent root, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                if (session != null && session.State == SessionState.Open)
                {
                    _pending++;
                }
                else
                {
                    RaiseChange(CellEvent.Invalidate, root, epoch, session);
                    if (Cell.Parellel)
                    {
                        Task.Run(() => PoolCalculate(DateTime.Now, session));
                    }
                    else
                    {
                        PoolCalculate(epoch, session);
                    }
                }
                break;

            case CellEvent.Invalidate:
                var lastState = (CellState)Interlocked.Exchange(ref _state, (int)CellState.Dirty);
                if (lastState == CellState.Calculating || lastState == CellState.Blocking)
                {
                    lastState = (CellState)Interlocked.Exchange(ref _state, (int)lastState);
                }
                else
                {
                    RaiseChange(eventType, root, epoch, session);
                }
                break;

            case CellEvent.JoinSession:
                session.Join(this);
                RaiseChange(eventType, root, epoch, session);
                break;

            case CellEvent.Error:
                bool taken = false;
                _spinLock.Enter(ref taken);
                if (taken)
                {
                    SetState(CellState.Error);
                    _spinLock.Exit();
                }
                else
                {
                    Thread.Sleep(100);
                    OnChange(eventType, root, epoch, session);
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 10
0
 public virtual void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
 {
     if (sender == Parent)
     {
         return;
     }
     RaiseChange(eventType, root, this, epoch, session);
 }
Ejemplo n.º 11
0
 private void RaiseChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
 {
     if (Change != null)
     {
         Change(eventType, root, this, epoch, session);
     }
     if (Parent != null)
     {
         Parent.OnChange(eventType, root, this, epoch, session);
     }
 }
Ejemplo n.º 12
0
        public void Remove(ICellEvent cellEvent)
        {
            Assert.IsNotNull(cellEvent);

            this.cellEvent.RemoveListOnly(cellEvent);

            for (var y = 0; y < cellEvent.Size; y++)
            {
                for (var x = 0; x < cellEvent.Size; x++)
                {
                    var p = cellEvent.Origin + new Vector2Int(x, y);
                    this.cellEvent.RemoveMapOnly(p);
                }
            }
        }
Ejemplo n.º 13
0
        public void Add(ICellEvent cellEvent, Vector2Int position)
        {
            Assert.IsNotNull(cellEvent);

            this.cellEvent.AddListOnly(cellEvent);

            Assert.IsTrue(this.cell.Map.ContainsKey(position), $"position = {position}にセルが無いのにイベントが登録されました");

            for (var y = 0; y < cellEvent.Size; y++)
            {
                for (var x = 0; x < cellEvent.Size; x++)
                {
                    var p = position + new Vector2Int(x, y);
                    this.cellEvent.AddMapOnly(p, cellEvent);
                }
            }
        }
Ejemplo n.º 14
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                _target.OnNext(_source.Value);
                _retry = 0;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(_source.Value);
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                    if (root is ICell c && _retry++ < Cell.ErrorRetry)
                    {
                        Thread.Sleep(_retry * Cell.ErrorRetry * 100);
                        c.OnChange(CellEvent.Calculate, this, this, DateTime.Now, session);
                    }
                }
                break;

            case CellEvent.Link:
                if (_source.Parent != null && _source.Parent is Model)
                {
                    var source = ((Model)_source.Parent)[_source.Mnemonic] as Generic.ICell <T>;
                    if (source != null)
                    {
                        _source = source;
                        OnChange(CellEvent.Calculate, sender, sender, epoch, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 15
0
        private void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                var lastsession = Session.Current;
                Session.Current = session;
                ICell  c = ((ICell)root).Parent;
                string n = ((ICell)root).Mnemonic;
                while (c != null)
                {
                    n = c.Mnemonic + "|" + n;
                    c = c.Parent;
                }
                _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, ICell> >(session, new KeyValuePair <string, ICell>(n, (ICell)sender)));
                Session.Current = lastsession;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    c = ((ICell)sender).Parent;
                    n = ((ICell)sender).Mnemonic;
                    while (c != null)
                    {
                        n = c.Mnemonic + "|" + n;
                        c = c.Parent;
                    }
                    _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, ICell> >(session, new KeyValuePair <string, ICell>(n, (ICell)sender)));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 16
0
        public void OnChange(CellEvent eventType, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                _target.OnNext(_source.Value);
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(_source.Value);
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                }
                break;

            case CellEvent.Link:
                if (_source.Parent != null && _source.Parent is Model)
                {
                    var source = ((Model)_source.Parent)[_source.Mnemonic] as Generic.ICell <T>;
                    if (source != null)
                    {
                        _source = source;
                        OnChange(CellEvent.Calculate, sender, epoch, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 17
0
        public void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            switch (eventType)
            {
            case CellEvent.Calculate:
                var lastsession = Session.Current;
                Session.Current = session;
                _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                Session.Current = lastsession;
                _retry          = 0;
                break;

            case CellEvent.Delete:
                _target.OnCompleted();
                break;

            case CellEvent.Error:
                try
                {
                    _target.OnNext(new KeyValuePair <ISession, KeyValuePair <string, T> >(session, new KeyValuePair <string, T>(_source.Mnemonic, _source.Value)));
                }
                catch (Exception e)
                {
                    _target.OnError(e);
                    if (root is ICell c && _retry++ < Cell.ErrorRetry)
                    {
                        Thread.Sleep(_retry * Cell.ErrorRetry * 100);
                        c.OnChange(CellEvent.Calculate, this, this, DateTime.Now, session);
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 18
0
 public void RegisterEvent(ICellEvent cellEvent)
 {
     this.cellEvent = cellEvent;
     this.cellEvent.Initialize(this);
 }
Ejemplo n.º 19
0
        public virtual void OnChange(CellEvent eventType, ICellEvent root, ICellEvent sender, DateTime epoch, ISession session)
        {
            if (_disposd && root != this && eventType != CellEvent.Delete)
            {
                sender.OnChange(CellEvent.Delete, this, this, epoch, session);
            }
            if (sender == Parent || root == this)
            {
                return;
            }
            switch (eventType)
            {
            case CellEvent.Calculate:
                if (session != null && session.State == SessionState.Open)
                {
                    _pending++;
                }
                else if (epoch > _epoch)
                {
                    _epoch = epoch;
                    OnChange(CellEvent.Invalidate, root, this, epoch, session);
                    if (Cell.Parellel)
                    {
                        Task.Run(() => PoolCalculate(epoch, session));
                    }
                    else
                    {
                        PoolCalculate(epoch, session);
                    }
                }
                break;

            case CellEvent.Delete:
                _link   = true;
                Change -= root.OnChange;
                break;

            case CellEvent.Invalidate:
                var lastState = (CellState)Interlocked.Exchange(ref _state, (int)CellState.Dirty);
                if (lastState == CellState.Calculating || lastState == CellState.Blocking)
                {
                    lastState = (CellState)Interlocked.Exchange(ref _state, (int)lastState);
                }
                else
                {
                    RaiseChange(eventType, root, this, epoch, session);
                }
                break;

            case CellEvent.Link:
                if (root == this)
                {
                    throw new CyclicDependencyException();
                }
                _link = true;
                _flip = true;
                if (_func != null)
                {
                    SetState(CellState.Dirty);
                }
                OnChange(CellEvent.Calculate, root, this, epoch, session);
                break;

            case CellEvent.JoinSession:
                session.Join(this);
                RaiseChange(eventType, root, this, epoch, session);
                break;

            case CellEvent.Error:
                bool taken = false;
                _spinLock.Enter(ref taken);
                while (!taken)
                {
                    Thread.Yield();
                    _spinLock.Enter(ref taken);
                }
                SetState(CellState.Error);
                _spinLock.Exit();
                break;
            }
        }
Ejemplo n.º 20
0
 public void ClearEvent()
 {
     this.cellEvent        = null;
     this.EventImage.color = Color.clear;
 }