/// <summary> /// Mapira na Message /// </summary> /// <param name="node"></param> /// <returns></returns> public static Message MapToMessage(IParseTree node) { log.Debug("Mapper:MapToMessage"); try { MessageId message_id = node.GetNodes()[0].GetNodes()[10].GetValue(); if (message_id != "None") { Message message = Message.Create(message_id); int i = 0; bool result_record_processing = false; foreach (IParseTree item in node.GetNodes()) { Record record = MapToRecord(item); if (record.Type == RecordId.ResultRecord) { result_record_processing = true; ((Results)message[i]).ResultComment.Add(new ResultCommentPair() { Result = (ResultRecord)record }); } else if (record.Type == RecordId.CommentRecord) { result_record_processing = true; ((Results)message[i]).ResultComment[((Results)message[i]).ResultComment.Count - 1].Comment = (CommentRecord)record; } else { if (result_record_processing == true) i++; message[i++] = record; result_record_processing = false; } } return message; } return null; } catch (Exception ex) { log.Error(ex.ToString()); throw; } }
/// <summary> /// Maprira na Record, ali je totalno zbrkano, sve sam zakompliciro, ali sad nekako radi pa bolje ne dirat /// </summary> /// <param name="item"></param> /// <returns></returns> public static Record MapToRecord(IParseTree item) { log.Debug("Mapper:MapToRecord"); try { RecordId recordId = item.GetValue()[0].ToString(); Record record = Record.Create(recordId); //ovo je sad hackiranje, razlicita je interpretacija value-a result recorda u spec i kako mi uredjaj salje if (record.GetType() == typeof(ResultRecord)) if (!item.GetNodes()[3].GetValue().Contains("^")) { List<IParseTree> node = new List<IParseTree>(); node.Add(new ComponentTree()); node[0].SetValue(item.GetNodes()[3].GetValue() + "^"); item.GetNodes()[3].SetNodes(node); List<IParseTree> sub_node = new List<IParseTree>(); sub_node.Add(new SubComponentTree()); sub_node[0].SetValue(item.GetNodes()[3].GetValue()); sub_node.Add(new SubComponentTree()); sub_node[1].SetValue(""); item.GetNodes()[3].GetNodes()[0].SetNodes(sub_node); item.GetNodes()[3].SetValue(item.GetNodes()[3].GetValue() + "^"); } //kraj hakiranja for (int i = 0; i < item.GetNodes().Count; i++) { if (item.GetNodes()[i].GetNodes().Count > 0) { if (item.GetNodes()[i].GetNodes().Count == 1) { Field field = GetRecordItem(record, i + 1); if (((List<Field>)field.GetValue()).Count > 0) for (int j = 0; j < item.GetNodes()[i].GetNodes()[0].GetNodes().Count; j++) SetSubItem((Cm)field, item.GetNodes()[i].GetNodes()[0].GetNodes()[j].GetValue(), j); else //ovo sam totalno zakompliciro, uopce se vise ne snalazim { CreateSubItems(record, (Cm)field, i + 1, item.GetNodes()[i].GetNodes().Count); for (int j = 0; j < item.GetNodes()[i].GetNodes().Count; j++) for (int z = 0; z < item.GetNodes()[i].GetNodes()[j].GetNodes().Count; z++) SetSubItem(((Cm)((Cm)field).Value[j]), item.GetNodes()[i].GetNodes()[j].GetNodes()[z].GetValue(), z); } } else { Field field = GetRecordItem(record, i + 1); CreateSubItems(record, (Cm)field, i + 1, item.GetNodes()[i].GetNodes().Count); for (int j = 0; j < item.GetNodes()[i].GetNodes().Count; j++) for (int z = 0; z < item.GetNodes()[i].GetNodes()[j].GetNodes().Count; z++) SetSubItem(((Cm)((Cm)field).Value[j]), item.GetNodes()[i].GetNodes()[j].GetNodes()[z].GetValue(), z); } } else { if (item.GetNodes()[i].GetValue() != "") SetRecordItem(record, item.GetNodes()[i].GetValue(), i + 1); } } return record; } catch (Exception ex) { log.Error(ex.ToString()); throw; } }
public void ProcessItems(IParseTree item) { log.Debug("Parser:ProcessItems"); try { if (item.GetNodes().Count > 0) if (item.GetNodes()[item.GetNodes().Count - 1].GetValue() == "") item.GetNodes().RemoveAt(item.GetNodes().Count - 1); } catch (Exception ex) { log.Error(ex.ToString()); throw; } }
/// <summary> /// Parsa poruku, rekord i puni IParseTree objekt /// </summary> /// <param name="root"></param> /// <param name="item"></param> /// <param name="delimiter"></param> /// <param name="lv"></param> public void Parse(IParseTree root, string item, string delimiter, int lv) { log.Debug("Parser:Parse"); try { root.SetValue(item); if (lv >= delimiter.Length) return; string[] items = item.Split(delimiter[lv]); lv++; foreach (string str in items) { if (items.Length > 1 || items[0].Contains(delimiter[lv])) { IParseTree node = this.CreateNode(lv); node.SetValue(str); root.GetNodes().Add(node); Parse(node, str, delimiter, lv); } } } catch (Exception ex) { log.Error(ex.ToString()); throw; } }