public OptionVariable ToOptionVariable(Dictionary <string, string> SbsVarDict)
        {
            var optnVar = new OptionVariable(this.NameCode, this.NameText);

            if (this.ValueEmpty == true)
            {
                optnVar.ValueEmpty = true;
            }
            if (this.ValueText != null)
            {
                optnVar.ValueText = this.ValueText;
            }
            if (this.ValueBytes != null)
            {
                optnVar.ValueBytes = this.ValueBytes;
            }

            // a subsitution variable name is spcfd. Retrieve the value from the
            // substitution value dictionary. Apply the value as the value of this variable.
            if (this.ValueSubstitute != null)
            {
                if (SbsVarDict.ContainsKey(this.ValueSubstitute))
                {
                    optnVar.ValueText = SbsVarDict[this.ValueSubstitute];
                }
            }

            return(optnVar);
        }
Exemple #2
0
        /// <summary>
        /// construct an OptionVariable starting at the next byte in the input array.
        /// </summary>
        /// <param name="ByteArray"></param>
        /// <returns></returns>
        public static OptionVariable Construct(InputByteArray InputArray)
        {
            OptionVariable optnVar = null;

            if (InputArray.IsEof() == false)
            {
                var b1 = InputArray.PeekNextByte();
                var ev = b1.ToEnvironVarCode();
                if (ev != null)
                {
                    var varCode = ev.Value;
                    if ((varCode == EnvironVarCode.VAR) || (varCode == EnvironVarCode.USERVAR))
                    {
                        byte[] valueBytes = null;
                        bool   gotValue   = false;

                        // advance past the VAR or USERVAR code.
                        InputArray.GetNextByte();

                        // isolate the name text which follows the VAR or USERVAR code.
                        // ( return the stop code. But do not consume it. )
                        var rv = InputArray.GetBytesUntilCode(
                            new byte[] { 0xff, 0x00, 0x01, 0x02, 0x03 });
                        var nameBytes    = rv.Item1;
                        var endAccumCode = rv.Item2.ToEnvironVarCode();

                        // the name text ends with VALUE marker. The text that follows is the text value
                        // of the variable.
                        if ((endAccumCode != null) && (endAccumCode.Value == EnvironVarCode.VALUE))
                        {
                            gotValue = true;

                            // advance past the VALUE var code.
                            InputArray.GetNextByte();

                            // get the value bytes until end of value code.
                            var rv2 = InputArray.GetBytesUntilCode(
                                new byte[] { 0xff, 0x00, 0x01, 0x02, 0x03 });
                            valueBytes = rv2.Item1;
                        }

                        optnVar = new OptionVariable(varCode, nameBytes, valueBytes);
                        if (gotValue == true)
                        {
                            optnVar.ValueEmpty = true;
                        }
                    }
                }
            }

            return(optnVar);
        }