/// <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; } }