Esempio n. 1
0
        public override void NextStep(ref EnvironmentMessage message)
        {
            if ((_oldMessage != null) && (_oldMessage.ID != message.ID))
            {
                _oldMessage = null;
            }
            else
            {
                _oldMessage = _newMessage;
            }
            _newMessage = message;
            if (message.Entity is AgentConfig)
            {
                agentConfig = (AgentConfig)message.Entity;
                _nextFigure = false;
            }
            else if (message.Entity is EnvironmentConfig)
            {
                environmentConfig  = (EnvironmentConfig)_newMessage.Entity;
                _newMessage.Entity = agentConfig;
                if (_oldMessage != null)
                {
                    if (_newMessage.Message == TypeMessege.NewAgent)
                    {
                        if ((_newMessage.Action == MsgAction.Approve) &&
                            (_oldMessage.Action == MsgAction.Invoke))
                        {
                            _newMessage.Action = MsgAction.Commit;
                        }
                        else if ((_newMessage.Action == MsgAction.Approve) &&
                                 (_oldMessage.Action == MsgAction.Commit))
                        {
                            _newMessage = null;
                            _oldMessage = null;
                        }
                    }
                }
            }
            else if ((message.Entity is SendPoint) || (message.Entity == null))
            {
                switch (_newMessage.Message)
                {
                case TypeMessege.GetPoint:
                    NextAction();
                    break;

                case TypeMessege.DeletePoint:
                    CancelPoint();
                    break;
                }
            }
            message = _newMessage;
        }
Esempio n. 2
0
        public EnvironmentMessage Clone()
        {
            Object obj = null;

            if (_entity == null)
            {
                _entity = new SendPoint(0, new Point());
            }
            else if (_entity is Point)
            {
                Point temp = (Point)_entity;
                obj = new Point(temp.X, temp.Y);
            }
            else if (_entity is SendPoint)
            {
                SendPoint temp = (SendPoint)_entity;
                obj = new SendPoint(temp.ID, new Point(temp.Point.X, temp.Point.Y));
            }
            else if (_entity is AgentConfig)
            {
                AgentConfig temp        = (AgentConfig)_entity;
                Purpose     tempPurpose = new Purpose(temp.Purpose.Importance, temp.Purpose.Worship,
                                                      new Point(((Point)(temp.Purpose.Entity)).X, ((Point)(temp.Purpose.Entity)).Y));
                SortedList <TypeMessege, int> tempSortedList = new SortedList <TypeMessege, int>();
                List <List <Point> >          listConfig     = new List <List <Point> >();
                if (temp.ListConfig != null)
                {
                    List <Point> tempConfig;
                    foreach (List <Point> config in temp.ListConfig)
                    {
                        tempConfig = new List <Point>();
                        foreach (Point point in tempConfig)
                        {
                            tempConfig.Add(point);
                        }
                        listConfig.Add(tempConfig);
                    }
                }
                if (temp.ResponceTime != null)
                {
                    foreach (var i in temp.ResponceTime)
                    {
                        tempSortedList.Add(i.Key, i.Value);
                    }
                }
                Point tempPoint = new Point(temp.StartPoint.X, temp.StartPoint.Y);
                obj = new AgentConfig(temp.Name, temp.Color, temp.SenseOfPurpose,
                                      tempPurpose, temp.Worship, temp.Temper,
                                      temp.LifeCircle, temp.Attempt, tempSortedList,
                                      tempPoint, temp.Length, listConfig);
            }
            else if (_entity is EnvironmentConfig)
            {
                EnvironmentConfig             temp           = (EnvironmentConfig)_entity;
                Point                         tempPoint      = new Point(temp.OffsetXY.X, temp.OffsetXY.Y);
                SortedList <TypeMessege, int> tempSortedList = new SortedList <TypeMessege, int>();
                if (tempSortedList != null)
                {
                    foreach (var i in temp.Response)
                    {
                        tempSortedList.Add(i.Key, i.Value);
                    }
                }
                obj = new EnvironmentConfig(temp.Height, temp.Width, tempPoint, tempSortedList);
            }
            return(new EnvironmentMessage(_id, _idOwner, _typeMessege, _action, obj));
        }