private void ParseAttributeFile(string file) { ShxAttributeNode root = null; List <ShxAttributeNode> nodes = null; ParseAttribute(file, out root, out nodes, String.Empty); string key = System.IO.Path.GetFileNameWithoutExtension(file).ToUpper(); if (AttributeListMap.ContainsKey(key) == false) { AttributeListMap.Add(key, nodes); AttributeList.Add(nodes); } if (AttributeRootMap.ContainsKey(key) == false) { AttributeRootMap.Add(key, root); } }
/// <summary> /// Make Attribute File for Import /// </summary> /// <param name="model">Model Info</param> /// <param name="path">Model Path</param> /// <param name="attribute_file">Attribute File</param> /// <param name="viz_file">VIZ File</param> /// <returns>결과 - True / False</returns> public bool MakeAttributeFile(Dictionary <string, ShxAttributeModelNode> model, string path, out string attribute_file, out string viz_file) { // 빠른 검색을 위한 데이터 새로 생성 WriteOutput("빠른 검색을 위한 CACHE 데이터 생성...", OutputLogTypes.INFORMATION); Dictionary <string, ShxAttributeNode> att = new Dictionary <string, ShxAttributeNode>(); // 전체 로딩된 속성을 MAP으로 생성 for (int i = 0; i < AttributeList.Count; i++) { foreach (ShxAttributeNode item in AttributeList[i]) { //WriteOutput(string.Format("CACHE : {0} - {1}", item, item.NodePath), Color.Lime); att.Add(item.NodePath, item); } } StringBuilder sb = new StringBuilder(); int found = 0; if (AttributeList.Count != 0) { // 전체 노드를 대상으로 검색 foreach (KeyValuePair <string, ShxAttributeModelNode> item in model) { //WriteOutput(string.Format("노드 : {0}", item.NodePath), Color.Lime); // 노드 경로로 비교 : item.Key (NodePath) if (att.ContainsKey(item.Key) == true) { ShxAttributeNode fAtt = att[item.Key]; List <string> exclude = new List <string>(); foreach (KeyValuePair <string, string> kv in fAtt.Property) { if (IsAllowAttribute(kv.Key) == false) { exclude.Add(kv.Key); //WriteOutput(string.Format("출력 불가 속성 : {0}", kv.Key), Color.Red); continue; } //WriteOutput(string.Format("속성 추가 : {0}", kv.Key), Color.Lime); sb.AppendLine(string.Format("{0}<<,>>{1}<<,>>{2}", item.Value.ID, kv.Key, kv.Value)); found++; } //WriteOutput(string.Format("출력 불가 속성 : {0}", string.Join(",", exclude.ToArray())), Color.Red); } else { //WriteOutput(string.Format("[결과] 미포함 노드 : {0}", item.Key), OutputLogTypes.WARNING); } } } // 찾은 결과가 없는 경우 // 모델 노드 이름에 해당하는 속성 파일 기준으로 체크 if (found == 0) { WriteOutput("모델/속성 파일 매핑 안됨", OutputLogTypes.ERROR); // KEY : NODE PATH // VAlUE : NODE Value Object (ID, NAME, NODEPATH) foreach (KeyValuePair <string, ShxAttributeModelNode> item in model) { // MODEL string nodepath = item.Key; string node = item.Value.Name.ToUpper(); if (String.IsNullOrEmpty(AttributePath) == true && AttributeRootMap.ContainsKey(node) == true) { WriteOutput(string.Format("상대경로 속성파일 발견 : {0}", AttributeRootMap[node].AttributeFileName), OutputLogTypes.WARNING); ShxAttributeNode root = null; List <ShxAttributeNode> nodes = null; WriteOutput(string.Format("상대경로 속성파일 분석 : {0}", AttributeRootMap[node].AttributeFileName), OutputLogTypes.WARNING); ParseAttribute(AttributeRootMap[node].AttributeFileName, out root, out nodes, nodepath); WriteOutput(string.Format("상대경로 속성파일 분석 결과 - 노드 : {0:N0} EA", nodes.Count), OutputLogTypes.WARNING); Dictionary <string, ShxAttributeNode> relativeAtt = new Dictionary <string, ShxAttributeNode>(); WriteOutput(string.Format("상대경로 속성파일 CACHE 생성 - 속성 : {0:N0} EA", root.GetPropertyCount()), OutputLogTypes.INFORMATION); // 전체 로딩된 속성을 MAP으로 생성 foreach (ShxAttributeNode attNode in nodes) { //WriteOutput(string.Format("CACHE : {0} - {1}", item, item.NodePath), Color.Lime); relativeAtt.Add(attNode.NodePath, attNode); } // 전체 모델 재검색 int subfound = 0; foreach (KeyValuePair <string, ShxAttributeModelNode> modelNode in model) { string relativeNodepath = modelNode.Key; string relativeNode = modelNode.Value.Name.ToUpper(); if (relativeAtt.ContainsKey(relativeNodepath) == true) { ShxAttributeNode rAtt = relativeAtt[relativeNodepath]; foreach (KeyValuePair <string, string> rKV in rAtt.Property) { if (IsAllowAttribute(rKV.Key) == true) { sb.AppendLine(string.Format("{0}<<,>>{1}<<,>>{2}", modelNode.Value.ID, rKV.Key, rKV.Value)); found++; subfound++; } } } } WriteOutput(string.Format("상대경로 기반 속성 연계 결과 - 속성 : {0:N0} EA", subfound), OutputLogTypes.INFORMATION); } else if (String.IsNullOrEmpty(AttributePath) == false) { string attfile = string.Format("{0}\\{1}.att", AttributePath, node); if (System.IO.File.Exists(attfile) == false) { continue; } WriteOutput(string.Format("상대경로 속성파일 발견 : {0}.att", node), OutputLogTypes.WARNING); ShxAttributeNode root = null; List <ShxAttributeNode> nodes = null; WriteOutput(string.Format("상대경로 속성파일 분석 : {0}.att", node), OutputLogTypes.WARNING); ParseAttribute(attfile, out root, out nodes, nodepath); WriteOutput(string.Format("상대경로 속성파일 분석 결과 - 노드 : {0:N0} EA", nodes.Count), OutputLogTypes.WARNING); Dictionary <string, ShxAttributeNode> relativeAtt = new Dictionary <string, ShxAttributeNode>(); WriteOutput(string.Format("상대경로 속성파일 CACHE 생성 - 속성 : {0:N0} EA", root.GetPropertyCount()), OutputLogTypes.INFORMATION); // 전체 로딩된 속성을 MAP으로 생성 foreach (ShxAttributeNode attNode in nodes) { //WriteOutput(string.Format("CACHE : {0} - {1}", item, item.NodePath), Color.Lime); relativeAtt.Add(attNode.NodePath, attNode); } // 전체 모델 재검색 int subfound = 0; foreach (KeyValuePair <string, ShxAttributeModelNode> modelNode in model) { string relativeNodepath = modelNode.Key; string relativeNode = modelNode.Value.Name.ToUpper(); if (relativeAtt.ContainsKey(relativeNodepath) == true) { ShxAttributeNode rAtt = relativeAtt[relativeNodepath]; foreach (KeyValuePair <string, string> rKV in rAtt.Property) { if (IsAllowAttribute(rKV.Key) == true) { sb.AppendLine(string.Format("{0}<<,>>{1}<<,>>{2}", modelNode.Value.ID, rKV.Key, rKV.Value)); found++; subfound++; } } } } WriteOutput(string.Format("상대경로 기반 속성 연계 결과 - 속성 : {0:N0} EA", subfound), OutputLogTypes.INFORMATION); } } } attribute_file = string.Format("{0}\\{1}.sha", System.IO.Path.GetDirectoryName(path), System.IO.Path.GetFileNameWithoutExtension(path)); viz_file = string.Format("{0}\\{1}_ATTRIBUTE.viz", System.IO.Path.GetDirectoryName(path), System.IO.Path.GetFileNameWithoutExtension(path)); if (found != 0) { WriteOutput(string.Format("속성 파일 생성 : {0}", attribute_file), OutputLogTypes.INFORMATION); System.IO.StreamWriter sw = new System.IO.StreamWriter(attribute_file, false); sw.WriteLine(sb.ToString()); sw.Close(); return(true); } else { return(false); } }