コード例 #1
0
ファイル: MainForm.cs プロジェクト: zhangjiayin/TradeSharp
        /// <summary>
        /// распарсить лог-файл
        /// </summary>
        private void BtnLoadClick(object sender, EventArgs e)
        {
            // прочитать словари
            var doc = new XmlDocument();

            doc.Load(Dictionary.DicPath);
            var dicMsg = FixTag.ReadTags(doc.DocumentElement.GetElementsByTagName(FixTag.PARENT_MSG)[0]);

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var messages = new List <FixMessage>();

            using (var fs = new StreamReader(openFileDialog.FileName, fileEncoding))
            {
                while (!fs.EndOfStream)
                {
                    var line = fs.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        break;
                    }
                    var msg = FixMessage.ParseMessage(line, dicMsg);
                    if (msg != null)
                    {
                        messages.Add(msg);
                    }
                }
            }

            gridLog.DataSource = messages;
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: zhangjiayin/TradeSharp
        private void BtnParseClick(object sender, EventArgs e)
        {
            // прочитать словари
            var doc = new XmlDocument();

            doc.Load(Dictionary.DicPath);
            var dicTag = FixTag.ReadTags(doc.DocumentElement.GetElementsByTagName(FixTag.PARENT_TAG)[0]);
            var dicMsg = FixTag.ReadTags(doc.DocumentElement.GetElementsByTagName(FixTag.PARENT_MSG)[0]);

            // разбить сообщение по парам тэг-значение
            var fields         = new List <FIXField>();
            var msg            = tbMsg.Text;
            var optSeparatChar = !string.IsNullOrEmpty(tbSeparator.Text) ? tbSeparator.Text[0] : (char)1;
            var pairs          = msg.Split(new[] { (char)0, optSeparatChar });

            var msgType = "";

            foreach (var pair in pairs)
            {
                var keyval = pair.Split('=');
                if (keyval.Length != 2)
                {
                    continue;
                }

                var field = new FIXField {
                    Tag = keyval[0], Value = keyval[1]
                };
                if (dicTag.ContainsKey(keyval[0]))
                {
                    var tag = dicTag[keyval[0]];
                    field.Title       = tag.Title;
                    field.Description = tag.Description;
                    field.URL         = tag.URL;
                }
                fields.Add(field);

                if (keyval[0] == "35")
                {
                    msgType = keyval[1];
                }
            }

            if (dicMsg.ContainsKey(msgType))
            {
                var msgInfo = dicMsg[msgType];
                var field   = new FIXField
                {
                    Tag         = "ТИП",
                    Title       = msgInfo.Title,
                    URL         = msgInfo.URL,
                    Description = msgInfo.Description,
                    Value       = msgType
                };
                fields.Add(field);
            }

            gridMessage.DataSource = fields;
        }