示例#1
0
        public State(string inName, EnStateType inStateType, Diagram inDiagram)
        {
            _Diagram = inDiagram;
            geometry = "";

            this._id               = SingleNextIDs.Instance.NextID(EnIDTypes.itState);
            this.name              = inName;
            this.stateType         = inStateType;
            this._events           = new List <Event>();
            this._evActions        = new List <ActionList>();
            this._immediateActions = new ActionList();

            _Diagram.AddState(this);
        }
示例#2
0
        public override bool DeserializeDerived(object obj, bool wrapped, EmraldModel lists, bool useGivenIDs)
        {
            dynamic dynObj = (dynamic)obj;

            if (wrapped)
            {
                if (dynObj.State == null)
                {
                    return(false);
                }

                dynObj = ((dynamic)obj).State;
            }

            if (!base.DeserializeDerived((object)dynObj, false, lists, useGivenIDs))
            {
                return(false);
            }

            lists.allStates.Add(this, false);

            this.stateType = (EnStateType)Enum.Parse(typeof(EnStateType), (string)dynObj.stateType, true);

            this._Diagram = lists.allDiagrams.FindByName((string)dynObj.diagramName);
            if (this._Diagram == null)
            {
                //Instead of throwing exception, create a new diagram to add state to?
                //this._Diagram = new Diagram(null);
                throw new Exception("State must have a valid diagram ");
            }

            this._Diagram.AddState(this);

            this.geometry = (string)dynObj.geometry;

            if ((dynObj.immediateActions == null) || (dynObj.events == null) || (dynObj.eventActions == null))
            {
                throw new Exception("Deserialize State, missing immediateActions, events, or eventActions.");
            }

            //Now done in LoadObjLinks()
            ////load the Immediate Actions
            //this._immediateActions.Clear();
            //foreach (dynamic actName in dynObj.immediateActions)
            //{
            //  Action curAct = lists.allActions.FindByName(actName);
            //  if (curAct == null)
            //  {
            //    throw new Exception("Deserialize State, failed to find immediateAction - " + actName);
            //  }

            //  _immediateActions.Add(curAct);
            //}

            ////load the Event Items
            //foreach (dynamic eventName in dynObj.events)
            //{
            //  Event curEv = lists.allEvents.FindByName(eventName);
            //  if (curEv == null)
            //  {
            //    throw new Exception("Deserialize State, failed to find event - " + eventName);
            //  }
            //  _events.Add(curEv);
            //}

            ////load the Event Actions
            //if (dynObj.eventActions != null)
            //{
            //  this._evActions.Clear();

            //  foreach (dynamic curToObj in dynObj.eventActions)
            //  {
            //    ActionList curEvActList = new ActionList();
            //    curEvActList.DeserializeJSON(curToObj, lists);
            //    this._evActions.Add(curEvActList);
            //  }
            //}

            processed = true;
            return(true);
        }