public static FieldDic GetFieldDic(string name) { FieldDic fieldDic = null; string key = (name + "").Trim().ToLower(); if (dic.ContainsKey(key)) { fieldDic = dic[key]; } return(fieldDic); }
private void parseFields(XmlNode node, Fix.Common.Model.Fix fix) { foreach (XmlNode xn in node.ChildNodes) { if ((xn.Name + "").ToLower() == "field") { FieldDic fd = new FieldDic(); parseFieldDic(fd, xn, fix); fix.Fields.Add(fd); } else { LogHelper.Warn(string.Format("{0} not field", xn.Name)); } } }
private void parseFieldDic(FieldDic fd, XmlNode node, Fix.Common.Model.Fix fix) { fd.Name = node.Attributes["name"].Value; fd.Number = int.Parse(node.Attributes["number"].Value); fd.Type = node.Attributes["type"].Value; LogHelper.Debug(string.Format("field:{0},{1},{2}", fd.Name, fd.Number, fd.Type)); foreach (XmlNode xn in node.ChildNodes) { if (xn.Name == "value") { Value v = new Value(); v.Enum = xn.Attributes["enum"].Value; v.Description = xn.Attributes["description"].Value; LogHelper.Debug(string.Format("\t\tvalue:{0},{1}", v.Enum, v.Description)); fd.Values.Add(v); } } }
/// <summary> /// 生成指定单一文件 /// </summary> /// <param name="o"></param> public void GenCode(object[] o, string language) { NVelocityHelper nVelocityHelper = new NVelocityHelper(FilePathHelper.TemplatesPath); Header header = o[0] as Header; Trailer trailer = o[0] as Trailer; Message message = o[0] as Message; Component component = o[0] as Component; FieldDic field = o[0] as FieldDic; string tableName = ""; string path = string.Format(@"{0}", TemplateParas.TemplateName); //var dic = new Dictionary<string, object>(); var dic = GetNVelocityVars(); if (header != null) { tableName = "header"; dic.Add("header", o[0]); } if (trailer != null) { tableName = "trailer"; dic.Add("trailer", o[0]); } if (message != null) { tableName = message.Name; dic.Add("messages", o); } if (component != null) { tableName = component.Name; dic.Add("components", o); } if (field != null) { tableName = field.Name; dic.Add("fields", o); } FixHelper.FieldDics = FieldDics; dic.Add("FixHelper", new FixHelper()); //dic.Add("codeGenHelper", new CodeGenHelper()); string str = nVelocityHelper.GenByTemplate(path, dic); string title = tableName + "." + (TemplateParas.CodeLanguage + "").ToLower(); if (!string.IsNullOrEmpty(TemplateParas.SaveFileName)) { title = TemplateParas.SaveFileName; title = nVelocityHelper.GenByStr(title, dic); } if (TemplateParas.IsShowGenCode) { CodeShow(title, str); } else { FileHelper.Write(TemplateParas.SaveFilePath + title, new[] { str }, SaveFileEncoding); } }