Esempio n. 1
0
        /*
         * Static Main Testing Method
         */

#if VARTABLE_DEBUG
        public static void Main(string[] args)
        {
            VariableTable table = new VariableTable("TestSpec");

            ApplianceState state1 = new ApplianceState("TestState1", false);

            state1.Type = new PUCType(new IntegerSpace());
            table.RegisterObject("TestSpec.Group1.Group2.TestState1", state1);

            ApplianceState state2 = new ApplianceState("TestState2", false);

            state2.Type = new PUCType(new EnumeratedSpace(4));
            table.RegisterObject("TestSpec.Group1.TestState2", state2);

            ApplianceState state3 = new ApplianceState("Flag", false);

            state3.Type = new PUCType(new BooleanSpace());
            table.RegisterObject("TestSpec.Group1.ListGroup.Flag", state3);

            ApplianceState state4 = new ApplianceState("Date", false);

            state4.Type = new PUCType(new StringSpace());
            table.RegisterObject("TestSpec.Group1.Mailbox.Messages.Date", state4);

            ApplianceState state5 = new ApplianceState("TestState1", false);

            state5.Type = new PUCType(new StringSpace());
            table.RegisterObject("TestSpec.Group1.Group1.TestState1", state5);

            table.StoreValue("TestSpec.Group1.Mailbox[3].Messages[4].Date", "Mon, Jan 4 11:15am");
            table.StoreValue("TestSpec.Group1.ListGroup[2].Flag", true);
            table.StoreValue("TestSpec.Group1.Group2.TestState1", 2);

            bool flag = (bool)table.GetValue("TestSpec.Group1.ListGroup[2].Flag");
        }
Esempio n. 2
0
        protected ApplianceState storeValue(string fullVarName, object data)
        {
            string[]  names       = fullVarName.Split(NAME_SEPARATORS);
            Hashtable currentData = _dataTable;
            Hashtable currentVar  = _varTable;

            if (names[0] != _specName)
            {
                throw new FormatException("Variable name does not start with unique appliance name.");
            }

            for (int i = 1; i < names.Length - 1; i++)
            {
                currentData = (Hashtable)getNextDataObject(currentData, ref names, i, true);
                currentVar  = (Hashtable)getNextVarObject(currentVar, names, i);

                if (currentVar == null)
                {
                    throw new FormatException("Value to store does not have a corresponding variable object.");
                }
            }

            ApplianceState state = (ApplianceState)getNextVarObject(currentVar, names, names.Length - 1);

            object dataToStore = state.Type.ValueSpace.Validate(data);

            if (dataToStore == null)
            {
                throw new FormatException("Data is not valid value for this variable.");
            }

            storeInNextDataObject(currentData, names[names.Length - 1], dataToStore);

            return(state);
        }
Esempio n. 3
0
        public ValueDataWindow(ValueDataWindow valueWindow)
        {
            _state = valueWindow._state;

            valueWindow.Parent.AddChildWindow(this);
            this.Update();
        }
Esempio n. 4
0
        protected void registerVariable(string fullVarName, ApplianceState state)
        {
            string[]  names   = fullVarName.Split(NAME_SEPARATORS);
            Hashtable current = _varTable;

            if (names[0] != _specName)
            {
                throw new FormatException("Variable name does not start with unique appliance name.");
            }

            if (names[names.Length - 1] != state.Name)
            {
                throw new FormatException("Variable name does not end with same name as ApplianceState object");
            }

            for (int i = 1; i < names.Length - 1; i++)
            {
                if (current[names[i]] == null)
                {
                    current[names[i]] = new Hashtable();
                }

                current = (Hashtable)current[names[i]];
            }

            current[state.Name] = state;
            state.VariableTable = this;
        }
Esempio n. 5
0
        public override bool ResolveObject(VariableTable varTable)
        {
            if (!base.ResolveObject(varTable))
            {
                return(false);
            }

            if (_isRef)
            {
                ApplianceState stateVar = (ApplianceState)varTable[_stringValue];
                _valid = stateVar != null;

                if (_valid)
                {
                    _value = new ValueConstraint(stateVar);
                }
            }
            else
            {
                try
                {
                    _value = new PUCValue(State.Type.ValueSpace.Validate(_stringValue));
                }
                catch (Exception)
                {
                    _valid = false;
                    throw new PUC.Parsers.SpecParseException(this.LineNumber, "String value does not match the value space of state " + State.Name);
                }
            }

            return(_valid);
        }
Esempio n. 6
0
        /// <summary>
        /// This method helps in the cloning process by allowing each
        /// class in the hierarchy to clone their own member variables.
        /// The class being cloned will create a new instance of itself,
        /// and then call the cloneHelper in its super-class to get any
        /// member variables of its super classes to be copied.
        /// </summary>
        /// <param name="clone">the instance of the cloned object</param>
        protected void cloneHelper(ApplianceState clone)
        {
            base.cloneHelper(clone);

            // this may not always be appropriate...but should be given
            // when I expect the cloning to be taking place
            clone.SetNetworkHandler();

            // these events should not have any handlers yet
            System.Diagnostics.Debug.Assert(TypeChangedEvent == null);
            System.Diagnostics.Debug.Assert(ValueChangedEvent == null);

            // this shouldn't contain anything yet
            // assuming that it doesn't, we don't need to copy it
            System.Diagnostics.Debug.Assert(_reverseDeps.Count == 0);

            // these items shouldn't be defined yet
            System.Diagnostics.Debug.Assert(_windowNames == null);
            System.Diagnostics.Debug.Assert(_windowRef == null);
            System.Diagnostics.Debug.Assert(_windowParent == null);

            // shallow copy these items
            clone._readonly           = _readonly;
            clone._constraintVariable = _constraintVariable;
            clone._defined            = _defined;
            clone._varTable           = _varTable;
            clone._type = _type;
            clone._internalController = _internalController;
        }
Esempio n. 7
0
        /*
         * Constructor
         */

        public ValueDataWindow(ApplianceState state)
        {
            _state = state;

            state.Parent.AddChildWindow(this);
            this.Update();
        }
Esempio n. 8
0
        /*
         * Member Methods
         */

        public void RegisterConstraints(ApplianceState state)
        {
            if (_enable != null)
            {
                new TypeConstraintListener(state, _enable);
            }

            RegisterConstraints((ApplianceObject)state);
        }
Esempio n. 9
0
        public void CreateExtraStates(Appliance appliance, VariableTable varTable)
        {
            _unionState      = new ApplianceState(appliance, UNION_STATE, _readonly);
            _unionState.Type = new PUCType(new StringSpace());
            GroupNode newG = new ObjectGroupNode(_unionState);

            newG.Parent = this;
            this.Children.Add(newG);
            varTable.RegisterObject(_unionState.FullName, _unionState);
        }
Esempio n. 10
0
        /*
         * Member Methods
         */

        public override object Clone()
        {
            // create the clone object
            ApplianceState state = new ApplianceState();

            // call the cloneHelper
            cloneHelper(state);

            // return the clone
            return(state);
        }
Esempio n. 11
0
        public void RegisterConstraints(ApplianceState state)
        {
            _valueSpace.RegisterConstraints(state);

            if (_valueLabels != null)
            {
                IEnumerator labeldict = _valueLabels.Values.GetEnumerator();
                while (labeldict.MoveNext())
                {
                    ((LabelDictionary)labeldict.Current).RegisterConstraints(state);
                }
            }
        }
Esempio n. 12
0
        public virtual bool ResolveObject(VariableTable varTable)
        {
            ApplianceState stateVar = (ApplianceState)varTable[_stateName];

            _valid = stateVar != null;

            if (_valid)
            {
                _state = new ValueDataWindow(stateVar);
            }

            return(_valid);
        }
Esempio n. 13
0
        protected void sendNetworkChangeRequest(ApplianceState state, object value)
        {
            try
            {
                PUCData data =
                    (PUCData)_windowParent.AssemblePUCData(new ValueData(this.DataWindow, value.ToString()));

                _appliance.GetConnection().Send(new PUC.Communication.StateChangeRequest(data));
            }
            catch (Exception)
            {
            }
        }
Esempio n. 14
0
        public StateValueDependency(ApplianceState state, ApplianceState refState)
            : base(state)
        {
            _stringValue = refState.FullName;
            _isRef       = true;
            _valid       = false;

            if (!state.Type.ValueSpace.IsSameSpace(refState.Type.ValueSpace))
            {
                throw new PUC.Parsers.SpecParseException(0, "Value space of state " + state.FullName + " does not match space of state " + refState.FullName);
            }

            _value = new ValueConstraint(refState);

            _valid = true;
        }
Esempio n. 15
0
        public StateValueDependency(ApplianceState state, string value)
            : base(state)
        {
            _stringValue = value;
            _isRef       = false;

            try
            {
                _valid = false;
                _value = new PUCValue(State.Type.ValueSpace.Validate(_stringValue));
            }
            catch (Exception)
            {
                throw new PUC.Parsers.SpecParseException(0, "Value does not match value space of state " + State.Name);
            }

            _valid = true;
        }
Esempio n. 16
0
        /*
         * Constructors
         */

        public LessThanDependency(ApplianceState state, string value)
            : base(state, value)
        {
        }
Esempio n. 17
0
        /*
         * Constructors
         */

        public WholeSetDependency(ApplianceState state)
            : base(state)
        {
        }
Esempio n. 18
0
        public void CreateExtraStates(VariableTable varTable, IBranchDataWindow window)
        {
            // Add Length State
            _listLengthState = new ApplianceState(_appliance, LIST_LENGTH_STATE, true);

            PUC.Types.IntegerSpace intSpace;
            if (_itemCount != null)
            {
                intSpace = new PUC.Types.IntegerSpace(_itemCount, _itemCount);
                if (_itemCount is IConstraint)
                {
                    new TypeConstraintListener(_listLengthState, (IConstraint)_itemCount);
                }
            }
            else if (_minimum == null && _maximum == null)
            {
                intSpace = new PUC.Types.IntegerSpace(new IntNumber(0), new IntNumber(Int32.MaxValue));
            }
            else if (_minimum != null && _maximum != null)
            {
                intSpace = new PUC.Types.IntegerSpace(_minimum, _maximum);

                if (_minimum is IConstraint)
                {
                    new TypeConstraintListener(_listLengthState, (IConstraint)_minimum);
                }
                if (_maximum is IConstraint)
                {
                    new TypeConstraintListener(_listLengthState, (IConstraint)_maximum);
                }
            }
            else if (_minimum != null)
            {
                intSpace = new IntegerSpace(_minimum, new IntNumber(Int32.MaxValue));

                if (_minimum is IConstraint)
                {
                    new TypeConstraintListener(_listLengthState, (IConstraint)_minimum);
                }
            }
            else
            {
                intSpace = new IntegerSpace(new IntNumber(0), _maximum);

                if (_maximum is IConstraint)
                {
                    new TypeConstraintListener(_listLengthState, (IConstraint)_maximum);
                }
            }

            _listLengthState.Type = new PUCType(intSpace);

            GroupNode newG = new ObjectGroupNode(_listLengthState);

            newG.Parent = this;
            this.Children.Add(newG);
            varTable.RegisterObject(_listLengthState.MakeFullName(this.FullPath), _listLengthState);
            window.AddChildWindow(_listLengthState);
            newG.Parent = null;             // remove from group so it doesn't get in the way later
            this.Children.Remove(newG);

            // Add Selection States
            _listSelectionState      = new ApplianceState(_appliance, LIST_SELECTION_STATE, _selectionReadOnly);
            _listSelectionState.Type = new PUCType(new IntegerSpace(new IntNumber(0), new NumberConstraint(_listSelectionState, _listLengthState)));

            if (_selectionType == SelectionType.One)
            {
                // one selection
                newG        = new ObjectGroupNode(_listSelectionState);
                newG.Parent = this;
                this.Children.Add(newG);
                _listSelectionState.FullName = _listSelectionState.MakeFullName(this.FullPath);
                _listSelectionState.SetNetworkHandler();
                window.AddChildWindow(_listSelectionState);
                newG.Parent = null;                 // remove from group so it doesn't get in the way later
                this.Children.Remove(newG);
            }
            else
            {
                // multiple selections
                BranchGroupNode selGroup = new BranchGroupNode();

                _listSelectionLengthState      = new ApplianceState(_appliance, LIST_LENGTH_STATE, false);
                _listSelectionLengthState.Type = new PUCType(new IntegerSpace(new IntNumber(0), new NumberConstraint(_listSelectionState, _listLengthState)));

                this.Children.Add(selGroup);
                selGroup.Name = LIST_SELECTION_STATE;
                newG          = new ObjectGroupNode(_listSelectionLengthState);
                newG.Parent   = selGroup;
                selGroup.Children.Add(newG);
                newG        = new ObjectGroupNode(_listSelectionState);
                newG.Parent = selGroup;
                selGroup.Children.Add(newG);

                varTable.RegisterObject(_listSelectionLengthState.MakeFullName(selGroup.FullPath), _listSelectionLengthState);
                _listSelectionState.FullName = _listSelectionState.MakeFullName(selGroup.FullPath);
                window.AddChildWindow(_listSelectionLengthState);
                window.AddChildWindow(_listSelectionState);

                this.Children.Remove(selGroup);
            }

            varTable.RegisterObject(_listSelectionState.FullName, _listSelectionState);
        }
Esempio n. 19
0
        /*
         * Constructors
         */

        public UndefinedDependency(ApplianceState state)
            : base(state)
        {
        }
Esempio n. 20
0
 public StateDependency(ApplianceState state)
 {
     _state     = new ValueDataWindow(state);
     _stateName = state.FullName;
     _valid     = true;
 }
Esempio n. 21
0
        /*
         * Constructors
         */

        public EqualsDependency(ApplianceState state, string value)
            : base(state, value)
        {
        }
Esempio n. 22
0
        /*
         * Member Methods
         */

        public void ScheduleStateUpdate(ApplianceState state)
        {
            _statesToUpdate[state] = true;
        }
Esempio n. 23
0
 public EqualsDependency(ApplianceState state1, ApplianceState state2)
     : base(state1, state2)
 {
 }
Esempio n. 24
0
 public GreaterThanDependency(ApplianceState state1, ApplianceState state2)
     : base(state1, state2)
 {
 }
Esempio n. 25
0
 public LessThanDependency(ApplianceState state1, ApplianceState state2)
     : base(state1, state2)
 {
 }