Beispiel #1
0
        public XmlCommandField Clone()
        {
            XmlCommandField field = new XmlCommandField(_parentFields);

            field.Name     = "" + this.Name;
            field.DataType = this.DataType;
            //field._dataSize = this.DataSize;
            field._dataString = "" + this._dataString;

            field.FieldType        = this.FieldType;
            field.DynamicFieldType = this.DynamicFieldType;
            field.AutoFieldType    = this.AutoFieldType;
            field.Offset           = this.Offset;

            field._parentFields = this._parentFields;

            if (FieldType == FieldTypes.Variable)
            {
                if (TargetBuffer == null || TargetBuffer.Length == 0)
                {
                    //do nothing..
                }
                else
                {
                    int dataSize = Buffer.ByteLength(TargetBuffer);
                    field.TargetBuffer = new Byte[dataSize];
                    Buffer.BlockCopy(TargetBuffer, 0, field.TargetBuffer, 0, dataSize);
                }
            }
            //field.TargetBuffer = this.TargetBuffer;

            return(field);
        }
Beispiel #2
0
 public XmlResponseCondition(XmlCommand command, String fieldName, String symbolText, String value)
 {
     _command   = command;
     Field      = _command.ResponseData.Field(fieldName);
     CondSymbol = GetSymbol(symbolText);
     Value      = value;
 }
Beispiel #3
0
 public XmlResponseCondition(XmlCommand command, String fieldName, CondSymbols symbol, String value)
 {
     _command   = command;
     Field      = _command.ResponseData.Field(fieldName);
     CondSymbol = symbol;
     Value      = value;
 }
        public XmlCommandHeader Clone()
        {
            XmlCommandHeader newHeader = new XmlCommandHeader();
            int count = 0;

            foreach (XmlCommandField field in FieldList.Values)
            {
                XmlCommandField newField = field.Clone();
                newHeader.FieldList.Add(field.Name, newField);
                newHeader.addItem(count++, field.DataSize, true);
                if (field.FieldType == FieldTypes.DataSize)
                {
                    newHeader._dataSizeField = newField;
                }
                else if (field.Name.ToLower().Equals("id"))
                {
                    newHeader._idField = newField;
                }
                else if (field.Name.ToLower().Equals("tag"))
                {
                    newHeader._tagField = newField;
                }
            }
            newHeader.setBuffSize();
            int offset = 0;

            foreach (XmlCommandField field in newHeader.FieldList.Values)
            {
                field.SetTargetBuffer(newHeader.buffer, offset);
                offset    += field.DataSize;
                field.Data = FieldList[field.Name].Data;
            }

            return(newHeader);
        }
 public int GetDataToBuffer(Array targetBuffer, int nowOffset)
 {
     foreach (IPacketItem item in FieldList.Values)
     {
         XmlCommandField field = item as XmlCommandField;
         nowOffset = field.GetDataToBuffer(targetBuffer, nowOffset);
     }
     return(nowOffset);
 }
Beispiel #6
0
        public void LoadXml(XmlNode root)
        {
            string cond      = XmlGetter.Attribute(root, "CondText");
            string fieldName = "";
            string symbol    = "";
            string value     = "";

            for (int i = 0; i < cond.Length; i++)
            {
                if (cond[i].Equals('=') || cond[i].Equals('<') || cond[i].Equals('>') || cond[i].Equals('!'))
                {
                    symbol += cond[i];
                }
                else if (symbol.Length == 0)
                {
                    fieldName += cond[i];
                }
                else
                {
                    Value += cond[i];
                }
            }
            Field = _command.ResponseData.Field(fieldName.Trim());
            switch (symbol.Trim())
            {
            case "==":
                CondSymbol = CondSymbols.EQ;
                break;

            case ">=":
                CondSymbol = CondSymbols.GE;
                break;

            case ">":
                CondSymbol = CondSymbols.GT;
                break;

            case "<=":
                CondSymbol = CondSymbols.LE;
                break;

            case "<":
                CondSymbol = CondSymbols.LT;
                break;

            case "!=":
                CondSymbol = CondSymbols.NE;
                break;
            }
            Value = value.Trim();
        }
Beispiel #7
0
        /// <summary>
        /// 시나리오에서 데이터를 가져와 필드에 값을 넣어주는 함수이다.
        /// </summary>
        /// <param name="xDoc"></param>
        /// <param name="rootNode"></param>
        internal void loadFields(XmlDocument xDoc, XmlNode rootNode)
        {
            foreach (String name in FieldList.Keys)
            {
                string value = XmlGetter.Attribute(rootNode, name);

                XmlCommandField field = FieldList[name];
                if (value.Length > 0)
                {
                    field.Data = value;                //값 설정.
                }

                /*
                 * if (field.FieldType == FieldTypes.LoopCount)
                 * {
                 *  _loopCountField = field;
                 *
                 * }
                 * else if (field.FieldType == FieldTypes.VariableSize)
                 * {
                 *  _
                 * }
                 */
            }

            if (TemplateFields != null)
            {
                string fieldsName = TemplateFields.Name;
                int    count      = 0;
                foreach (XmlNode node in rootNode.ChildNodes)
                {
                    if (node.Name.Equals(fieldsName))
                    {
                        count++;                               //이름이 같은 Tag만 가져와 count함..
                    }
                }
                NumberOfFields = count; //방의 크기를 조정함..

                int index = 0;
                foreach (XmlNode node in rootNode.ChildNodes) //값을 채워넣음..
                {
                    if (node.Name.Equals(fieldsName))
                    {
                        FieldsList.ValueList[index++].loadFields(xDoc, node);
                    }
                }
            }
        }
        public void LoadXml(XmlDocument xDoc, XmlNode rootNode, Boolean refLoad = false)
        {
            if (rootNode == null)
            {
                return;
            }
            _xDoc = xDoc; XmlControlHandler.GetDefaultXmlItemAttributes(rootNode, xDoc, this);


            XmlNodeList fields = XmlGetter.Children(rootNode, "Field");
            int         count  = 0;

            foreach (XmlNode field in fields)
            {
                XmlCommandField xField = new XmlCommandField(null);
                xField.LoadXml(xDoc, field, refLoad);

                FieldList.Add(xField.Name, xField);
                if (xField.FieldType == FieldTypes.DataSize)
                {
                    _dataSizeField = xField;
                }
                else if (xField.Name.ToLower().Equals("id"))
                {
                    _idField = xField;
                }
                else if (xField.Name.ToLower().Equals("tag"))
                {
                    _tagField = xField;
                }

                addItem(count++, xField.DataSize, true);
            }
            setBuffSize();
            int offset = 0;

            foreach (XmlCommandField field in FieldList.Values)
            {
                field.SetTargetBuffer(this.buffer, offset);
                field.Data = field.Data;
                offset    += field.DataSize;
            }

            /*
             * XmlCommandFields xmlFields = new XmlCommandFields(null);
             * xmlFields.LoadXml(xDoc, fields, refLoad);
             */
        }
Beispiel #9
0
        public XmlCommandFields Clone(String newName)
        {
            XmlCommandFields newFields = new XmlCommandFields(_parentFields, _structType);

            int count = 0;

            foreach (XmlCommandField field in FieldList.Values)
            {
                XmlCommandField newField = field.Clone();
                newFields.FieldList.Add(field.Name, newField);
                newFields.addItem(count++, field.DataSize, true);
                if (field.FieldType == FieldTypes.LoopCount)
                {
                    newFields._loopCountField = newField;
                }
                else if (field.FieldType == FieldTypes.Variable)
                {
                    newFields._variableField = newField;
                }
                else if (field.FieldType == FieldTypes.VariableSize)
                {
                    newFields._variableSizeField = newField;
                }
            }
            newFields.setBuffSize();
            int offset = 0;

            foreach (XmlCommandField field in newFields.FieldList.Values)
            {
                field.SetTargetBuffer(newFields.buffer, offset);
                offset    += field.DataSize;
                field.Data = FieldList[field.Name].Data;
            }

            foreach (XmlCommandFields fields in FieldsList.Values)
            {
                newFields.FieldsList.Add(fields.Name, fields.Clone(fields.Name));
            }
            newFields.Name               = newName;
            newFields._templateName      = _templateName;
            newFields._templateFields    = _templateFields;// (_templateFields != null) ? _templateFields.Clone(_templateFields.Name) : null;
            newFields._numberChangedMode = _numberChangedMode;
            //newFields.SizeDefineField = SizeDefineField;
            return(newFields);
        }
Beispiel #10
0
        public int GetDataToBuffer(Array targetBuffer, int nowOffset)
        {
            if (VariableSizeField != null && VariableField != null)
            {
                VariableSizeField.DataValue = Buffer.ByteLength(VariableField.TargetBuffer); //크기 지정..
            }

            foreach (XmlCommandField item in FieldList.Values)
            {
                XmlCommandField field = item as XmlCommandField;
                nowOffset = field.GetDataToBuffer(targetBuffer, nowOffset);
            }

            foreach (XmlCommandFields item in FieldsList.Values)
            {
                XmlCommandFields fields = item as XmlCommandFields;
                nowOffset = fields.GetDataToBuffer(targetBuffer, nowOffset);
            }
            return(nowOffset);
        }
Beispiel #11
0
        public void LoadXml(XmlDocument xDoc, XmlNode rootNode, Boolean refLoad = false)
        {
            if (rootNode == null)
            {
                return;
            }
            _xDoc = xDoc; XmlControlHandler.GetDefaultXmlItemAttributes(rootNode, xDoc, this);


            //int count = 0;
            //int index = 0;
            int count = 0;

            _pacektHandlingType = PacketHandlingTypes.Static;//default

            foreach (XmlNode fieldNode in rootNode.ChildNodes)
            {
                if (fieldNode.Name.Equals(Properties.Resources.Fields_Field_Tag))
                {
                    XmlCommandField field = new XmlCommandField(this);

                    field.LoadXml(xDoc, fieldNode);

                    addItem(count++, field.DataSize, field.FieldType == FieldTypes.Dynamic, field.DataType);
                    _fieldList.Add(field.Name, field);
                    if (field.FieldType == FieldTypes.LoopCount)
                    {
                        _loopCountField = field;
                        //field.DataValue = 0;
                        _pacektHandlingType = PacketHandlingTypes.Loop;
                    }
                    else if (field.FieldType == FieldTypes.VariableSize)
                    {
                        _variableSizeField  = field;
                        _pacektHandlingType = PacketHandlingTypes.Serial;
                    }
                    else if (field.FieldType == FieldTypes.Variable)
                    {
                        _variableField = field;
                        if (_structType == StructType.Command)
                        {
                            if (_variableSizeField == null)
                            {
                                throw new Exception("There's no FieldType[VariableSizeField] for this field[" + field.Name + "]");
                            }
                            else
                            {
                                _variableSizeField.DataValue = Buffer.ByteLength(field.TargetBuffer);
                            }
                        }
                    }
                }
                else if (fieldNode.Name.Equals(Properties.Resources.Fields_Loop_Tag))
                {
                    XmlCommandFields fields = new XmlCommandFields(_parentFields, _structType);

                    String name = XmlGetter.Attribute(fieldNode, Properties.Resources.Fields_Loop_Name_Attr);

                    fields.LoadXml(xDoc, fieldNode, refLoad);
                    TemplateFields      = fields;
                    fields.Name         = name;
                    fields.TemplateName = name;
                    //NumberOfFields = Convert.ToInt32(SizeDefineField.DataValue);//default로 지정된 크기를 만들어준다.

                    //_fieldsList.Add(name, fields);
                }
            }

            setBuffSize(); //size를 fix함..
            int offset = 0;

            for (int i = 0; i < _fieldList.Values.Count; i++)
            {
                _fieldList.ValueList[i].SetTargetBuffer(this.buffer, offset);
                if (_fieldList.ValueList[i].FieldType == FieldTypes.Dynamic)
                {
                    _fieldList.ValueList[i].Data = _fieldList.ValueList[i].Data;//실제 값을 넣어준다.
                }
                else if (_fieldList.ValueList[i].FieldType == FieldTypes.LoopCount)
                {
                    _fieldList.ValueList[i].Data = "0";
                }
                else
                {
                    _fieldList.ValueList[i].Data = _fieldList.ValueList[i].Data;//실제 값을 넣어준다.
                }
                offset += _fieldList.ValueList[i].DataSize;
            }
        }
Beispiel #12
0
        public bool GetCondition()
        {
            XmlCommandField clone = Field.Clone();

            clone.Data = Value;

            if (CondSymbol == CondSymbols.EQ)
            {
                if (Field.Data.Equals(clone.Data))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (CondSymbol == CondSymbols.GE)
            {
                if (Field.DataType == typeof(float))
                {
                    if ((float)Field.DataValue >= (float)clone.DataValue)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (Convert.ToInt64(Field.DataValue) >= Convert.ToInt64(clone.DataValue))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else if (CondSymbol == CondSymbols.GT)
            {
                if (Field.DataType == typeof(float))
                {
                    if ((float)Field.DataValue > (float)clone.DataValue)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (Convert.ToInt64(Field.DataValue) > Convert.ToInt64(clone.DataValue))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else if (CondSymbol == CondSymbols.LE)
            {
                if (Field.DataType == typeof(float))
                {
                    if ((float)Field.DataValue <= (float)clone.DataValue)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (Convert.ToInt64(Field.DataValue) <= Convert.ToInt64(clone.DataValue))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else if (CondSymbol == CondSymbols.LT)
            {
                if (Field.DataType == typeof(float))
                {
                    if ((float)Field.DataValue < (float)clone.DataValue)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (Convert.ToInt64(Field.DataValue) < Convert.ToInt64(clone.DataValue))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else// if (CondSymbol == CondSymbols.NE)
            {
                if (Field.DataType == typeof(float))
                {
                    if ((float)Field.DataValue != (float)clone.DataValue)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (Convert.ToInt64(Field.DataValue) != Convert.ToInt64(clone.DataValue))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }