Example #1
0
 internal StepValue(StepToken token, Object val){
     this._token = token;
     this._value = val;
     if(this._value == null)
         this._valueType = null;
     else
         this._valueType = val.GetType();
 }
Example #2
0
 internal StepValue(StepToken token, Object val)
 {
     this._token = token;
     this._value = val;
     if (this._value == null)
     {
         this._valueType = null;
     }
     else
     {
         this._valueType = val.GetType();
     }
 }
Example #3
0
        private StepToken LogMessage(string message)
        {
            var result = new StepToken();

            try
            {
                _logManager.LogInfo(message);
            }
            catch (Exception e)
            {
                result.SetException(e);
                _logManager.LogError(e, "LogMessage.LogMessage");
            }
            return(result);
        }
Example #4
0
        private StepTokenType GetTypeForCloseToken(StepToken token)
        {
            switch (token)
            {
            case StepToken.EndSTEP:
                return(StepTokenType.STEP);

            case StepToken.EndSection:
                return(StepTokenType.Section);

            case StepToken.EndEntity:
                return(StepTokenType.Entity);

            case StepToken.EndArray:
                return(StepTokenType.Array);

            default:
                throw CreateStepReaderException("Not a valid close JsonToken: {0}", token);
            }
        }
Example #5
0
        private StepTokenType GetTypeForCloseToken(StepToken token)
        {
            switch (token)
            {
            case StepToken.EndSTEP:
                return(StepTokenType.STEP);

            case StepToken.EndSection:
                return(StepTokenType.Section);

            case StepToken.EndEntity:
                return(StepTokenType.Entity);

            case StepToken.EndArray:
                return(StepTokenType.Array);

            default:
                throw new StepWriterException("No type for token: " + token);
            }
        }
Example #6
0
 /// <summary>
 /// Writes the specified end token to the stream
 /// </summary>
 /// <param name="token">The end token to write.</param>
 protected void WriteEnd(StepToken token)
 {
 	logger.Debug(String.Format("WriteEnd( {0} ); //_currentState : {1}; _top : {2};", token, _currentState, _top));
     switch (token)
     {
         case StepToken.EndSTEP:
             _writer.Write("END-ISO-10303-21;");
             break;
         case StepToken.EndSection:
             _writer.Write("ENDSEC");
             WriteEndLine();
             break;
         case StepToken.EndLine:
             _writer.Write(";\r\n");
             break;
         case StepToken.EndEntity:
             _writer.Write(")");
             break;
         case StepToken.EndArray:
             _writer.Write(")");
             break;
         case StepToken.None://HACK using None as the end token for LineIdentifier
             break;
         default:
             throw new StepWriterException("Invalid StepToken: " + token);
     }
 }
Example #7
0
        private void AutoCompleteClose(StepToken tokenBeingClosed)
        {
            // write closing symbol and calculate new state

            int levelsToComplete = 0;

            for (int i = 0; i < _top; i++)
            {
                int currentLevel = _top - i;

                if (_stack[currentLevel] == GetTypeForCloseToken(tokenBeingClosed))
                {
                    levelsToComplete = i + 1;
                    break;
                }
            }

            if (levelsToComplete == 0)
                throw new StepWriterException("No token to close.");

            for (int i = 0; i < levelsToComplete; i++)
            {
                StepToken token = GetCloseTokenForType(Pop());

                WriteEnd(token);
            }

            StepTokenType currentLevelType = Peek();

            switch (currentLevelType)
            {
                case StepTokenType.STEP:
                    _currentState = State.STEP;
                    break;
                case StepTokenType.Section:
                    _currentState = State.Section;
                    break;
                case StepTokenType.Entity:
                    _currentState = State.Entity;
                    break;
                case StepTokenType.Array:
                    _currentState = State.Array;
                    break;
                case StepTokenType.LineIdentifier:
                    _currentState = State.LineIdentifier;
                    break;
                case StepTokenType.None:
                    _currentState = State.Start;
                    break;
                default:
                    throw new StepWriterException("Unknown StepType: " + currentLevelType);
            }
        }
Example #8
0
 private StepTokenType GetTypeForCloseToken(StepToken token)
 {
     switch (token)
     {
         case StepToken.EndSTEP:
             return StepTokenType.STEP;
         case StepToken.EndSection:
             return StepTokenType.Section;
         case StepToken.EndEntity:
             return StepTokenType.Entity;
         case StepToken.EndArray:
             return StepTokenType.Array;
         default:
             throw new StepWriterException("No type for token: " + token);
     }
 }
Example #9
0
        private void AutoCompleteClose(StepToken tokenBeingClosed)
        {
            // write closing symbol and calculate new state

            int levelsToComplete = 0;

            for (int i = 0; i < _top; i++)
            {
                int currentLevel = _top - i;

                if (_stack[currentLevel] == GetTypeForCloseToken(tokenBeingClosed))
                {
                    levelsToComplete = i + 1;
                    break;
                }
            }

            if (levelsToComplete == 0)
            {
                throw new StepWriterException("No token to close.");
            }

            for (int i = 0; i < levelsToComplete; i++)
            {
                StepToken token = GetCloseTokenForType(Pop());

                WriteEnd(token);
            }

            StepTokenType currentLevelType = Peek();

            switch (currentLevelType)
            {
            case StepTokenType.STEP:
                _currentState = State.STEP;
                break;

            case StepTokenType.Section:
                _currentState = State.Section;
                break;

            case StepTokenType.Entity:
                _currentState = State.Entity;
                break;

            case StepTokenType.Array:
                _currentState = State.Array;
                break;

            case StepTokenType.LineIdentifier:
                _currentState = State.LineIdentifier;
                break;

            case StepTokenType.None:
                _currentState = State.Start;
                break;

            default:
                throw new StepWriterException("Unknown StepType: " + currentLevelType);
            }
        }
Example #10
0
 private void WriteToken(StepToken token, StringBuilder builder)
 {
     WriteText(token.ToString(this), builder);
 }
Example #11
0
        private void ValidateEnd(StepToken endToken)
        {
            StepTokenType currentObject = Pop();

            if (GetTypeForCloseToken(endToken) != currentObject)
                throw CreateStepReaderException("ExpressToken {0} is not valid for closing ExpressType {1}.", endToken, currentObject);
        }
Example #12
0
 /// <summary>
 /// Changes the <see cref="State"/> to Closed.
 /// </summary>
 public virtual void Close()
 {
 	_reader.Close();
     _currentState = State.Closed;
     _token = StepToken.None;
     _value = null;
     _valueType = null;
     
 }
Example #13
0
 /// <summary>
 /// Sets the current token.
 /// </summary>
 /// <param name="newToken">The new token.</param>
 protected void SetToken(StepToken newToken)
 {
     SetToken(newToken, null);
 }
Example #14
0
 public StepMultiplierToken(StepToken parent, decimal multiplier)
 {
     this.parent     = parent ?? throw new ArgumentNullException(nameof(parent));
     this.Multiplier = multiplier;
 }
Example #15
0
 internal static bool IsStartToken(StepToken token)
 {
     switch (token)
     {
         case StepToken.StartSection:
         case StepToken.StartEntity:
         case StepToken.StartArray:
         case StepToken.LineIdentifier:
         case StepToken.EntityName:
             return true;
         case StepToken.None:
         case StepToken.Comment:
         case StepToken.Integer:
         case StepToken.Float:
         case StepToken.String:
         case StepToken.Boolean:
         case StepToken.Null:
         case StepToken.Undefined:
         case StepToken.EndEntity:
         case StepToken.EndArray:
         case StepToken.Date:
         case StepToken.EndSection:
             return false;
         default:
             throw new ArgumentOutOfRangeException("token", token, "Unexpected JsonToken value.");
     }
 }
Example #16
0
        /// <summary>
        /// Sets the current token and value.
        /// </summary>
        /// <param name="newToken">The new token.</param>
        /// <param name="value">The value.</param>
        protected virtual void SetToken(StepToken newToken, object value)
        {
            _token = newToken;
            
            switch (newToken)
            {
                case StepToken.StartSTEP:
                    _currentState = State.ExpressStart;
                    Push(StepTokenType.STEP);
                    break;
                case StepToken.StartSection:
                    _currentState = State.SectionStart;
                    Push(StepTokenType.Section);
                    break;
                case StepToken.StartEntity:
                    _currentState = State.EntityStart;
                    Push(StepTokenType.Entity);
                    break;
                case StepToken.StartArray:
                    _currentState = State.ArrayStart;
                    Push(StepTokenType.Array);
                    break;
                case StepToken.EndSTEP:
                    ValidateEnd(StepToken.EndSTEP);
                    _currentState = State.Complete;
                    break;
                case StepToken.EndSection:
                    ValidateEnd(StepToken.EndSection);
                    _currentState = State.Express; //FIXME should this be State.PostValue
                    break;
                case StepToken.EndEntity:
                    ValidateEnd(StepToken.EndEntity);
                    _currentState = State.PostValue;
                    break;
                case StepToken.EndArray:
                    ValidateEnd(StepToken.EndArray);
                    _currentState = State.PostValue;
                    break;
                case StepToken.EntityName:
                    _currentState = State.EntityName;
                    break;
                case StepToken.Undefined:
                case StepToken.Integer:
                case StepToken.Float:
                case StepToken.Boolean:
                case StepToken.Null:
                case StepToken.Date:
                case StepToken.String:
                case StepToken.Enumeration:
                case StepToken.Overridden:
                    _currentState = State.PostValue;
                    break;
            }

            //ExpressTokenType current = Peek();
            //if (current == ExpressTokenType.Entity && _currentState == State.PostValue)
            //    Pop();

            if (value != null)
            {
                _value = value;
                _valueType = value.GetType();
            }
            else
            {
                _value = null;
                _valueType = null;
            }
        }
Example #17
0
 /// <summary>
 /// Sets the current token.
 /// </summary>
 /// <param name="newToken">The new token.</param>
 protected void SetToken(StepToken newToken)
 {
     SetToken(newToken, null);
 }
Example #18
0
        /// <summary>
        /// Attempts to complete the token being written
        /// </summary>
        /// <param name="tokenBeingWritten"></param>
        internal void AutoComplete(StepToken tokenBeingWritten)
        {
        	logger.Debug(String.Format("AutoComplete( {0} ); //tokenBeingWritten : {1}; _currentState : {2}, _top : {3};", 
        	                           tokenBeingWritten,
        	                           (int)tokenBeingWritten,
        	                           _currentState, _top));
        	
            int token;
            switch (tokenBeingWritten)
            {
                default:
                    token = (int)tokenBeingWritten;
                    break;
                case StepToken.Integer:
                case StepToken.Float:
                case StepToken.String:
                case StepToken.Boolean:
                case StepToken.Enumeration:
                case StepToken.Overridden:
                case StepToken.Null:
                case StepToken.Undefined:
                case StepToken.Date:
                    // a value is being written
                    token = 7;
                    break;
            }
            
            
            
            // gets new state based on the current state and what is being written
            State newState = stateArray[token][(int)_currentState];

            /*logger.Debug(String.Format(CultureInfo.InvariantCulture,
                                       "From a Current State, {0}, and attempting to write a token of {1} has resulted in a state of {2}",
                                       _currentState.ToString(), tokenBeingWritten.ToString(), newState.ToString()));
            */
            if (newState == State.Error)
                throw new StepWriterException(String.Format(CultureInfo.InvariantCulture,
                                                            "Token {0} in state {1} would result in an invalid Step object.",
                                                            tokenBeingWritten.ToString(),
                                                            _currentState.ToString()));

            if ((_currentState == State.Entity || _currentState == State.Array) && tokenBeingWritten != StepToken.Comment)
            {
                WriteValueDelimiter();
            }

            WriteState writeState = WriteState;

            _currentState = newState;
        }
Example #19
0
        /// <summary>
        /// Sets the current token and value.
        /// </summary>
        /// <param name="newToken">The new token.</param>
        /// <param name="value">The value.</param>
        protected virtual void SetToken(StepToken newToken, object value)
        {
            _token = newToken;

            switch (newToken)
            {
            case StepToken.StartSTEP:
                _currentState = State.ExpressStart;
                Push(StepTokenType.STEP);
                break;

            case StepToken.StartSection:
                _currentState = State.SectionStart;
                Push(StepTokenType.Section);
                break;

            case StepToken.StartEntity:
                _currentState = State.EntityStart;
                Push(StepTokenType.Entity);
                break;

            case StepToken.StartArray:
                _currentState = State.ArrayStart;
                Push(StepTokenType.Array);
                break;

            case StepToken.EndSTEP:
                ValidateEnd(StepToken.EndSTEP);
                _currentState = State.Complete;
                break;

            case StepToken.EndSection:
                ValidateEnd(StepToken.EndSection);
                _currentState = State.Express;     //FIXME should this be State.PostValue
                break;

            case StepToken.EndEntity:
                ValidateEnd(StepToken.EndEntity);
                _currentState = State.PostValue;
                break;

            case StepToken.EndArray:
                ValidateEnd(StepToken.EndArray);
                _currentState = State.PostValue;
                break;

            case StepToken.EntityName:
                _currentState = State.EntityName;
                break;

            case StepToken.Undefined:
            case StepToken.Integer:
            case StepToken.Float:
            case StepToken.Boolean:
            case StepToken.Null:
            case StepToken.Date:
            case StepToken.String:
            case StepToken.Enumeration:
            case StepToken.Overridden:
                _currentState = State.PostValue;
                break;
            }

            //ExpressTokenType current = Peek();
            //if (current == ExpressTokenType.Entity && _currentState == State.PostValue)
            //    Pop();

            if (value != null)
            {
                _value     = value;
                _valueType = value.GetType();
            }
            else
            {
                _value     = null;
                _valueType = null;
            }
        }
		public void AssertStepValue(StepToken expectedToken, Type expectedValueType, object expectedValue, StepValue actual){
			Assert.IsNotNull(actual);
			Assert.AreEqual(expectedToken, actual.Token);
			Assert.AreEqual(expectedValueType, actual.ValueType);
			Assert.AreEqual(expectedValue, actual.Value);
		}
Example #21
0
 private StepTokenType GetTypeForCloseToken(StepToken token)
 {
     switch (token)
     {
         case StepToken.EndSTEP:
             return StepTokenType.STEP;
         case StepToken.EndSection:
             return StepTokenType.Section;
         case StepToken.EndEntity:
             return StepTokenType.Entity;
         case StepToken.EndArray:
             return StepTokenType.Array;
         default:
             throw CreateStepReaderException("Not a valid close JsonToken: {0}", token);
     }
 }