Esempio n. 1
0
        private void cbMessages_SelectedIndexChanged(object sender, EventArgs e)
        {
            SbeMessage message = SbeLoader.LoadMessageByName(cbMessages.Text);

            if (message != null)
            {
                tree.BeginUpdate();
                lblDescription.Text = "Description: " + message.Description;
                lblId.Text          = "ID: " + message.Id;
                _Message.Clear();
                _Message.Add(message);
                if (checkBox1.Checked)
                {
                    CreateHeader();
                }
                tree.Roots = _Message;
                tree.ExpandAll();
                tree.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                colValue.Width = 100;
                tree.EndUpdate();
            }
            else
            {
                lblDescription.Text = "Description:";
                lblId.Text          = "ID:";
                tree.Clear();
            }
        }
Esempio n. 2
0
        public static SbeField GetField(Assembly assembly, SbeField field, String MessageName, object MessageBody)
        {
            if (SbeLoader._Enums.Find(x => x.Name == field.Type) != null)
            {
                #region Enumeration
                GetEnumerationField(assembly, field, MessageBody, MessageName);
                #endregion
            }
            else if (SbeLoader._SimpleTypes.Find(x => x.Name == field.Type) != null)
            {
                #region Simple Type
                if (field.Presence.Contains("constant"))
                {
                    return(field);
                }

                //SimpleType
                SbeType simple = SbeLoader._SimpleTypes.Find(x => x.Name == field.Type);
                if (simple.PrimitiveType.ToLower().Equals("char"))
                {
                    FieldInfo l      = ReflectionHelper.GetFieldByName(assembly, MessageName, field.Name + "Length");
                    int       length = (int)l.GetValue(MessageBody);

                    var        fieldByte = new byte[length];
                    MethodInfo mi        = ReflectionHelper.GetMethodByName(assembly, MessageName, "Get" + field.Name, "byte[]");
                    mi.Invoke(MessageBody, new object[] { fieldByte, 0 }).ToString();

                    FieldInfo fi  = ReflectionHelper.GetFieldByName(assembly, MessageName, field.Name + "CharacterEncoding");
                    string    enc = fi.GetValue(MessageBody).ToString();
                    field.Value = Encoding.GetEncoding(enc).GetString(fieldByte, 0, length);
                }
                else
                {
                    PropertyInfo pi = ReflectionHelper.GetPropertyByName(assembly, MessageName, field.Name);
                    field.Value = Convert.ChangeType(pi.GetValue(MessageBody), pi.PropertyType).ToString();
                }
                #endregion
            }
            else if (SbeLoader._CompositeTypes.Find(x => x.Name == field.Type) != null)
            {
                #region Composite
                if (field.Type.ToLower().Equals("groupsizeencoding"))
                {
                    #region groupsizeencoding
                    //var fuelFiguresGroup = car.FuelFigures;
                    //while (fuelFiguresGroup.HasNext)
                    //{
                    //var fuelFigures = fuelFiguresGroup.Next();
                    //sb.Append("\ncar.fuelFigures.speed=").Append(fuelFigures.Speed);
                    //sb.Append("\ncar.fuelFigures.mpg=").Append(fuelFigures.Mpg);
                    //}
                    PropertyInfo no     = ReflectionHelper.GetPropertyByName(assembly, MessageName, field.Name);
                    var          repeat = no.GetValue(MessageBody);

                    PropertyInfo hasNext   = ReflectionHelper.GetPropertyByName(assembly, field.Name, "HasNext");
                    bool         nextValue = (bool)hasNext.GetValue(repeat);

                    SbeMessage _Original      = SbeLoader.LoadMessageByName(MessageName);
                    SbeField   _OriginalField = _Original.Fields.Find(x => x.Name == field.Name).Clone();
                    field.Fields.Clear();

                    MethodInfo next = ReflectionHelper.GetNestedMethodByName(assembly, MessageName, field.Name + "Group", "next");

                    int size = 0;
                    while (nextValue)
                    {
                        size++;
                        next.Invoke(repeat, null);
                        foreach (SbeField child in _OriginalField.Fields)
                        {
                            if (!child.Presence.Contains("constant"))
                            {
                                if (SbeLoader._Enums.Find(x => x.Name == child.Type) != null)
                                {
                                    Type _enumType = ReflectionHelper.GetType(assembly, child.Type);
                                    if (_enumType.IsEnum)
                                    {
                                        SbeEnum _enum = SbeLoader._Enums.Find(x => x.Name == child.Type);

                                        PropertyInfo pi = ReflectionHelper.GetPropertyByName(assembly, field.Name + "Group", child.Name);
                                        child.ValueRef = Convert.ChangeType(pi.GetValue(repeat), pi.PropertyType).ToString();

                                        SbeEnumValidValue valid = _enum.ValidValues.Find(x => x.Name == child.ValueRef);
                                        if (valid != null)
                                        {
                                            child.Value = valid.Value;
                                        }
                                    }
                                }
                                else
                                {
                                    PropertyInfo pi = ReflectionHelper.GetNestedPropertyByName(assembly, MessageName, field.Name + "Group", child.Name);
                                    child.Value = pi.GetValue(repeat).ToString();
                                }
                            }
                            field.Fields.Add(child.Clone());
                        }

                        nextValue = (bool)hasNext.GetValue(repeat);
                    }
                    field.Value = size.ToString();
                    #endregion
                }
                else
                {
                    PropertyInfo pi = ReflectionHelper.GetPropertyByName(assembly, MessageName, field.Type);
                    if (pi != null)
                    {
                        object parent = pi.GetValue(MessageBody);

                        foreach (SbeField child in field.Fields)
                        {
                            if (child.Presence.Contains("constant"))
                            {
                                continue;
                            }

                            PropertyInfo pi2 = ReflectionHelper.GetPropertyByName(assembly, field.Type, child.Name);
                            child.Value = pi2.GetValue(parent).ToString();
                        }
                    }
                    else
                    {
                        // length = car.GetManufacturer(buffer, 0, buffer.Length);
                        //sb.Append("\ncar.manufacturer=").Append(Encoding.GetEncoding(Car.ManufacturerCharacterEncoding).GetString(buffer, 0, length));
                        // length = car.GetModel(buffer, 0, buffer.Length);
                        //sb.Append("\ncar.model=").Append(Encoding.GetEncoding(Car.ModelCharacterEncoding).GetString(buffer, 0, length));

                        FieldInfo  fi     = ReflectionHelper.GetFieldByName(assembly, MessageName, field.Name + "CharacterEncoding");
                        var        buffer = new byte[128];
                        MethodInfo mi     = ReflectionHelper.GetMethodByName(assembly, MessageName, "Get" + field.Name, "byte[]");

                        int len = (int)(mi.Invoke(MessageBody, new object[] { buffer, 0, buffer.Length }));
                        field.Value = Encoding.GetEncoding(fi.GetValue(MessageBody).ToString()).GetString(buffer, 0, len);
                    }
                }
                #endregion
            }

            return(field);
        }
Esempio n. 3
0
        public static void SetField(Assembly assembly, SbeField field, String MessageName, object MessageBody)
        {
            if (SbeLoader._Enums.Find(x => x.Name == field.Type) != null)
            {
                #region Enumeration
                SetEnumerationField(assembly, field, MessageBody, MessageName);
                #endregion
            }
            else if (SbeLoader._SimpleTypes.Find(x => x.Name == field.Type) != null)
            {
                #region Simple Type
                if (field.Presence.Contains("constant") || String.IsNullOrEmpty(field.Value))
                {
                    return;
                }

                //SimpleType
                SbeType simple = SbeLoader._SimpleTypes.Find(x => x.Name == field.Type);
                if (simple.PrimitiveType.ToLower().Equals("char"))
                {
                    FieldInfo  fi        = ReflectionHelper.GetFieldByName(assembly, MessageName, field.Name + "CharacterEncoding");
                    byte[]     fieldByte = System.Text.Encoding.GetEncoding(fi.GetValue(MessageBody).ToString()).GetBytes(field.Value);
                    MethodInfo mi        = ReflectionHelper.GetMethodByName(assembly, MessageName, "Set" + field.Name, "byte[]");
                    mi.Invoke(MessageBody, new object[] { fieldByte, 0 });
                }
                else
                {
                    PropertyInfo pi = ReflectionHelper.GetPropertyByName(assembly, MessageName, field.Name);
                    pi.SetValue(MessageBody, Convert.ChangeType(field.Value, pi.PropertyType));
                }
                #endregion
            }
            else if (SbeLoader._CompositeTypes.Find(x => x.Name == field.Type) != null)
            {
                #region Composite
                if (field.Type.ToLower().Equals("groupsizeencoding"))
                {
                    #region groupsizeencoding
                    //var sides = cross.NoSidesCount(2);
                    //sides.Next();
                    //sides.Side = Side.BUY;
                    //sides.Account = 111;
                    //sides.ClOrdID = 12345;
                    //sides.Next();
                    //sides.Side = Side.SELL;
                    //sides.Account = 222;
                    //sides.ClOrdID = 67890;
                    MethodInfo mi          = ReflectionHelper.GetMethodByName(assembly, MessageName, field.Name + "Count");
                    var        repeatGroup = mi.Invoke(MessageBody, new object[] { int.Parse(field.Value) });

                    MethodInfo next = ReflectionHelper.GetNestedMethodByName(assembly, MessageName, field.Name + "Group", "next");

                    SbeMessage _Original      = SbeLoader.LoadMessageByName(MessageName);
                    SbeField   _OriginalField = _Original.Fields.Find(x => x.Name == field.Name).Clone();

                    foreach (SbeField child in field.Fields)
                    {
                        if (child.Name == _OriginalField.Fields[0].Name)
                        {
                            next.Invoke(repeatGroup, null);
                        }

                        if (!String.IsNullOrEmpty(child.Value))
                        {
                            if (SbeLoader._Enums.Find(x => x.Name == child.Type) != null)
                            {
                                if (child.Presence.Contains("constant") || String.IsNullOrEmpty(child.Value))
                                {
                                    continue;
                                }

                                Type _enumType = ReflectionHelper.GetType(assembly, child.Type);
                                if (_enumType.IsEnum)
                                {
                                    SbeEnum           _enum = SbeLoader._Enums.Find(x => x.Name == child.Type);
                                    SbeEnumValidValue valid = _enum.ValidValues.Find(x => x.Value == child.Value);

                                    PropertyInfo pi = ReflectionHelper.GetNestedPropertyByName(assembly, MessageName, field.Name + "Group", child.Name);
                                    pi.SetValue(repeatGroup, Enum.Parse(_enumType, valid.Name));
                                }
                            }
                            else
                            {
                                PropertyInfo pi = ReflectionHelper.GetNestedPropertyByName(assembly, MessageName, field.Name + "Group", child.Name);
                                pi.SetValue(repeatGroup, Convert.ChangeType(child.Value, pi.PropertyType));
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    PropertyInfo pi = ReflectionHelper.GetPropertyByName(assembly, MessageName, field.Type);
                    if (pi != null)
                    {
                        object parent = pi.GetValue(MessageBody);

                        foreach (SbeField child in field.Fields)
                        {
                            if (child.Presence.Contains("constant") || String.IsNullOrEmpty(child.Value))
                            {
                                continue;
                            }

                            PropertyInfo pi2 = ReflectionHelper.GetPropertyByName(assembly, field.Type, child.Name);
                            pi2.SetValue(parent, Convert.ChangeType(child.Value, pi2.PropertyType));
                        }
                    }
                    else
                    {
                        // Manufacturer = Encoding.GetEncoding(Car.ManufacturerCharacterEncoding).GetBytes("Honda");
                        // car.SetManufacturer(Manufacturer, srcOffset, Manufacturer.Length);
                        FieldInfo fi        = ReflectionHelper.GetFieldByName(assembly, MessageName, field.Name + "CharacterEncoding");
                        byte[]    fieldByte = System.Text.Encoding.GetEncoding(fi.GetValue(MessageBody).ToString())
                                              .GetBytes(field.Value);
                        MethodInfo mi = ReflectionHelper.GetMethodByName(assembly, MessageName, "Set" + field.Name, "byte[]");
                        mi.Invoke(MessageBody, new object[] { fieldByte, 0, fieldByte.Length });
                        //mi.Invoke(MessageBody, new object[] { fieldByte, 0 });
                    }
                }
                #endregion
            }
        }
Esempio n. 4
0
        private void tree_CellEditFinishing(object sender, BrightIdeasSoftware.CellEditEventArgs e)
        {
            if (e.Cancel)
            {
                return;
            }

            SbeField field = (SbeField)e.RowObject;

            if (e.Control is ComboBox)
            {
                if (e.Column.Text == "PrimitiveType")
                {
                    field.PrimitiveType = e.Control.Text.Trim();
                    switch (field.PrimitiveType)
                    {
                    case "uint8":
                    case "int8":
                        field.Length = 1;
                        break;

                    case "uint16":
                    case "int16":
                        field.Length = 2;
                        break;

                    case "uint32":
                    case "int32":
                        field.Length = 4;
                        break;

                    case "uint64":
                    case "int64":
                        field.Length = 8;
                        break;

                    case "char":
                        field.Length = 10;
                        break;
                    }
                }
                else if (e.Column.Text == "Value")
                {
                    if (e.Control.Text.Contains("|"))
                    {
                        field.Value = e.Control.Text.Split('|')[0].Trim();
                    }
                    else
                    {
                        field.Value = e.Control.Text.Trim();
                    }
                }
            }
            else if (e.Control is TextBox)
            {
                if (e.Column.Text == "Value")
                {
                    field.Value = e.Control.Text.Trim();
                }
                else if (e.Column.Text == "Length")
                {
                    field.Length = int.Parse(e.Control.Text.Trim());
                }
            }

            if (field.Type.ToLower().Equals("groupsizeencoding"))
            {
                try
                {
                    int        repeating           = int.Parse(field.Value);
                    int        repeatingGroupAtual = field.Fields.FindAll(x => x.Name == field.Fields[0].Name).Count;
                    SbeMessage _Original           = null;
                    if (checkBox1.Checked)
                    {
                        _Original = SbeLoader.LoadMessageByName(_Message[1].Name);
                    }
                    else
                    {
                        _Original = SbeLoader.LoadMessageByName(_Message[0].Name);
                    }

                    SbeField _OriginalField = _Original.Fields.Find(x => x.Name == field.Name).Clone();

                    if (repeating > repeatingGroupAtual)
                    {
                        while (repeating > repeatingGroupAtual)
                        {
                            SbeField _FieldOriginal = _OriginalField.Clone();
                            field.Fields.AddRange(_FieldOriginal.Fields);
                            repeatingGroupAtual = field.Fields.FindAll(x => x.Name == field.Fields[0].Name).Count;
                        }
                    }
                    else if (repeating < repeatingGroupAtual)
                    {
                        while (repeating < repeatingGroupAtual)
                        {
                            foreach (SbeField _ChildField in _OriginalField.Fields)
                            {
                                SbeField toRemove = field.Fields.FindLast(x => x.Name == _ChildField.Name);
                                field.Fields.Remove(toRemove);
                            }

                            repeatingGroupAtual = field.Fields.FindAll(x => x.Name == field.Fields[0].Name).Count;
                        }
                    }
                    tree.Roots = _Message;
                    tree.ExpandAll();
                }
                catch
                {
                }
            }

            tree.RefreshItem(e.ListViewItem);
            e.Cancel = true;
        }