private void SaveNode(TreeNode tn) { ChangeInfo info = (ChangeInfo)tn.Tag; if (tn.Checked) { if (info.Original == null) { // add new item if (info.Change is DocLocalization) { DocLocalization localChange = (DocLocalization)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocObject docObj = (DocObject)parentinfo.Original; docObj.RegisterLocalization(localChange.Locale, localChange.Name, localChange.Documentation); } else if (info.Change is DocAttribute) { DocAttribute localAttr = (DocAttribute)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocEntity docEntity = (DocEntity)parentinfo.Original; DocAttribute docAttr = (DocAttribute)localAttr.Clone(); docEntity.Attributes.Add(docAttr); } else if (info.Change is DocWhereRule) { DocWhereRule localAttr = (DocWhereRule)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocEntity docEntity = (DocEntity)parentinfo.Original; DocWhereRule docAttr = (DocWhereRule)localAttr.Clone(); docEntity.WhereRules.Add(docAttr); } else if (info.Change is DocFunction) { DocFunction localAttr = (DocFunction)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocSchema docSchema = (DocSchema)parentinfo.Original; DocFunction docAttr = (DocFunction)localAttr.Clone(); docSchema.Functions.Add(docAttr); } else if (info.Change is DocConstant) { this.ToString(); } else if (info.Change is DocProperty) { this.ToString(); DocProperty localProp = (DocProperty)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocPropertySet docPset = (DocPropertySet)parentinfo.Original; DocProperty docProperty = (DocProperty)localProp.Clone(); docPset.Properties.Add(docProperty); } else if (info.Change is DocPropertyConstant) { this.ToString(); DocPropertyConstant localProp = (DocPropertyConstant)info.Change; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocPropertyEnumeration docPset = (DocPropertyEnumeration)parentinfo.Original; DocPropertyEnumeration docEnumChange = (DocPropertyEnumeration)parentinfo.Change; int index = docEnumChange.Constants.IndexOf(localProp); DocPropertyConstant docProperty = (DocPropertyConstant)localProp.Clone(); docPset.Constants.Insert(index, docProperty); } else { this.ToString(); } } else if (info.Change == null) { // removal of definition if (info.Original is DocAttribute) { DocAttribute docAttr = (DocAttribute)info.Original; ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag; DocEntity docEntity = (DocEntity)parentinfo.Original; docEntity.Attributes.Remove(docAttr); docAttr.Delete(); } else { this.ToString(); } } else { // change of documentation info.Original.Name = info.Change.Name; info.Original.Documentation = info.Change.Documentation; if (info.Original is DocWhereRule) { DocWhereRule whereOriginal = (DocWhereRule)info.Original; DocWhereRule whereChange = (DocWhereRule)info.Change; whereOriginal.Expression = whereChange.Expression; } else if (info.Original is DocFunction) { DocFunction whereOriginal = (DocFunction)info.Original; DocFunction whereChange = (DocFunction)info.Change; whereOriginal.Expression = whereChange.Expression; } } } foreach (TreeNode tnSub in tn.Nodes) { SaveNode(tnSub); } }
public FormMerge(Dictionary <Guid, DocObject> mapOriginal, DocProject docChange) : this() { this.m_mapOriginal = mapOriginal; // add nodes for everything, then delete ones that haven't changed or don't have any children // iterate and find changes in documentation foreach (DocPropertyEnumeration docChangePset in docChange.PropertyEnumerations) { DocObject docOriginalPset = null; if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset)) { TreeNode tnPset = null; if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation)) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } foreach (DocPropertyConstant docChangeProp in docChangePset.Constants) { DocObject docOriginalProp = ((DocPropertyEnumeration)docOriginalPset).GetConstant(docChangeProp.Name); if (docOriginalProp != null) { TreeNode tnProperty = null; if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // localization foreach (DocLocalization docChangeLocal in docChangeProp.Localization) { DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale); if (docOriginalLocal != null) { if (!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } else { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // new localization this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } } else { if (tnPset == null) { tnPset = this.AddNode(null, new ChangeInfo(docOriginalPset.Name, docOriginalPset, docChangePset)); } // NEW: this.AddNode(tnPset, new ChangeInfo(docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp)); } } } else { // NEW: this.AddNode(null, new ChangeInfo(docChangePset.Name, null, docChangePset)); } } foreach (DocSection docChangeSection in docChange.Sections) { DocObject docOriginalSection = null; if (mapOriginal.TryGetValue(docChangeSection.Uuid, out docOriginalSection)) { foreach (DocSchema docChangeSchema in docChangeSection.Schemas) { DocObject docOriginalSchema; if (mapOriginal.TryGetValue(docChangeSchema.Uuid, out docOriginalSchema)) { // compare schemas TreeNode tnSchema = this.AddNode(null, new ChangeInfo(docOriginalSchema.Name, docOriginalSchema, docChangeSchema)); foreach (DocType docChangeType in docChangeSchema.Types) { DocObject docOriginalType = null; if (mapOriginal.TryGetValue(docChangeType.Uuid, out docOriginalType)) { TreeNode tnType = null; if (!String.Equals(docOriginalType.Documentation, docChangeType.Documentation)) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType)); } if (docChangeType is DocEnumeration) { DocEnumeration docChangeEnum = (DocEnumeration)docChangeType; foreach (DocConstant docChangeConst in docChangeEnum.Constants) { DocObject docOriginalConst = null; if (mapOriginal.TryGetValue(docChangeConst.Uuid, out docOriginalConst)) { if (!String.Equals(docOriginalConst.Documentation, docChangeConst.Documentation)) { if (tnType == null) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType)); } this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, docOriginalConst, docChangeConst)); } } else { if (tnType == null) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType)); } // NEW: this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, null, docChangeConst)); } } } } } foreach (DocEntity docChangeEntity in docChangeSchema.Entities) { DocObject docOriginalObj = null; if (mapOriginal.TryGetValue(docChangeEntity.Uuid, out docOriginalObj)) { DocEntity docOriginalEntity = (DocEntity)docOriginalObj; TreeNode tnEntity = null; if (!String.Equals(docOriginalEntity.Documentation, docChangeEntity.Documentation)) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // add attributes foreach (DocAttribute docChangeAttr in docChangeEntity.Attributes) { DocObject docOriginalAttr = null; if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr)) { if (!String.Equals(docOriginalAttr.Name, docChangeAttr.Name) || !String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation)) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr)); } } else { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // new attribute this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeAttr.Name, null, docChangeAttr)); } } // remove attributes foreach (DocAttribute docOriginalAttr in docOriginalEntity.Attributes) { bool bFound = false; foreach (DocAttribute docChangeAttr in docChangeEntity.Attributes) { if (docOriginalAttr.Uuid.Equals(docChangeAttr.Uuid)) { bFound = true; break; } } if (!bFound) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // delete attribute this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, null)); } } foreach (DocWhereRule docChangeWhere in docChangeEntity.WhereRules) { DocObject docOriginalWhere = null; if (mapOriginal.TryGetValue(docChangeWhere.Uuid, out docOriginalWhere)) { DocWhereRule docOriginalWhereRule = (DocWhereRule)docOriginalWhere; if (!String.Equals(docOriginalWhere.Name, docChangeWhere.Name) || !String.Equals(docOriginalWhere.Documentation, docChangeWhere.Documentation) || !String.Equals(docOriginalWhereRule.Expression, docChangeWhere.Expression)) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalWhere.Name, docOriginalWhere, docChangeWhere)); } } else { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } // new where rule this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeWhere.Name, null, docChangeWhere)); } } foreach (DocUniqueRule docChangeAttr in docChangeEntity.UniqueRules) { DocObject docOriginalAttr = null; if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr)) { if (!String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation)) { if (tnEntity == null) { tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity)); } this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr)); } } } } } foreach (DocFunction docChangeFunction in docChangeSchema.Functions) { DocObject docOriginalFunc = null; if (mapOriginal.TryGetValue(docChangeFunction.Uuid, out docOriginalFunc)) { TreeNode tnType = null; DocFunction docOriginalFunction = (DocFunction)docOriginalFunc; if (!String.Equals(docOriginalFunction.Name, docChangeFunction.Name) || !String.Equals(docOriginalFunction.Documentation, docChangeFunction.Documentation) || !String.Equals(docOriginalFunction.Expression, docChangeFunction.Expression)) { tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalFunction.Name, docOriginalFunction, docChangeFunction)); } } else { // new attribute this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docChangeFunction.Name, null, docChangeFunction)); } } foreach (DocPropertySet docChangePset in docChangeSchema.PropertySets) { DocObject docOriginalPset = null; if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset)) { TreeNode tnPset = null; if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation)) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } foreach (DocProperty docChangeProp in docChangePset.Properties) { DocObject docOriginalProp = ((DocPropertySet)docOriginalPset).GetProperty(docChangeProp.Name); if (docOriginalProp != null) { TreeNode tnProperty = null; if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // localization foreach (DocLocalization docChangeLocal in docChangeProp.Localization) { DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale); if (docOriginalLocal != null) { if (!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation)) { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } else { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } if (tnProperty == null) { tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } // new localization this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal)); } } } else { if (tnPset == null) { tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } // NEW: this.AddNode(tnPset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp)); } } } else { // NEW: this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset)); } } foreach (DocQuantitySet docChangePset in docChangeSchema.QuantitySets) { DocObject docOriginalPset = null; if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset)) { TreeNode tnQset = null; if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation)) { tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } foreach (DocQuantity docChangeProp in docChangePset.Quantities) { DocObject docOriginalProp = ((DocQuantitySet)docOriginalPset).GetQuantity(docChangeProp.Name); if (docOriginalProp != null) { if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation)) { if (tnQset == null) { tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } this.AddNode(tnQset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp)); } } else { if (tnQset == null) { tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset)); } // NEW: this.AddNode(tnQset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp)); } } } else { // NEW: this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset)); } } } } } } if (this.treeView.Nodes.Count > 0) { this.treeView.SelectedNode = this.treeView.Nodes[0]; } }
private void toolStripMenuItemInsertFunction_Click(object sender, EventArgs e) { TreeNode tnParent = this.treeView.SelectedNode; DocSchema docSchema = (DocSchema)tnParent.Tag; DocFunction docType = new DocFunction(); docSchema.Functions.Add(docType); this.treeView.SelectedNode = this.LoadNode(tnParent.Nodes[3], docType, null, true); toolStripMenuItemEditRename_Click(this, e); }
/// <summary> /// Loads all content from a folder hierarchy (overlaying anything already existing) /// </summary> /// <param name="project"></param> /// <param name="path"></param> public static void LoadFolder(DocProject project, string path) { // get all files within folder hierarchy string pathSchema = path + @"\schemas"; IEnumerable <string> en = System.IO.Directory.EnumerateFiles(pathSchema, "*.cs", System.IO.SearchOption.AllDirectories); List <string> list = new List <string>(); foreach (string s in en) { list.Add(s); } string[] files = list.ToArray(); Dictionary <string, string> options = new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }; Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider(options); System.CodeDom.Compiler.CompilerParameters parms = new System.CodeDom.Compiler.CompilerParameters(); parms.GenerateInMemory = true; parms.GenerateExecutable = false; parms.ReferencedAssemblies.Add("System.dll"); parms.ReferencedAssemblies.Add("System.Core.dll"); parms.ReferencedAssemblies.Add("System.ComponentModel.dll"); parms.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll"); parms.ReferencedAssemblies.Add("System.Data.dll"); parms.ReferencedAssemblies.Add("System.Runtime.Serialization.dll"); parms.ReferencedAssemblies.Add("System.Xml.dll"); System.CodeDom.Compiler.CompilerResults results = prov.CompileAssemblyFromFile(parms, files); System.Reflection.Assembly assem = results.CompiledAssembly; LoadAssembly(project, assem); // EXPRESS rules (eventually in C#, though .exp file snippets for now) en = System.IO.Directory.EnumerateFiles(pathSchema, "*.exp", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string name = Path.GetFileNameWithoutExtension(file); string expr = null; using (StreamReader readExpr = new StreamReader(file, Encoding.UTF8)) { if (name.Contains('-')) { // where rule expr = readExpr.ReadToEnd(); } else { // function: skip first and last lines readExpr.ReadLine(); StringBuilder sbExpr = new StringBuilder(); while (!readExpr.EndOfStream) { string line = readExpr.ReadLine(); if (!readExpr.EndOfStream) { sbExpr.AppendLine(line); } } expr = sbExpr.ToString(); } } if (name.Contains('-')) { // where rule string[] parts = name.Split('-'); if (parts.Length == 2) { DocWhereRule docWhere = new DocWhereRule(); docWhere.Name = parts[1]; docWhere.Expression = expr; DocDefinition docDef = project.GetDefinition(parts[0]); if (docDef is DocEntity) { DocEntity docEnt = (DocEntity)docDef; docEnt.WhereRules.Add(docWhere); } else if (docDef is DocDefined) { DocDefined docEnt = (DocDefined)docDef; docEnt.WhereRules.Add(docWhere); } else if (docDef == null) { //... global rule... } } } else { // function string schema = Path.GetDirectoryName(file); schema = Path.GetDirectoryName(schema); schema = Path.GetFileName(schema); DocSchema docSchema = project.GetSchema(schema); if (docSchema != null) { DocFunction docFunction = new DocFunction(); docSchema.Functions.Add(docFunction); docFunction.Name = name; docFunction.Expression = expr; } } } // now, hook up html documentation en = System.IO.Directory.EnumerateFiles(pathSchema, "*.htm", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string name = Path.GetFileNameWithoutExtension(file); DocObject docObj = null; if (name == "schema") { string schema = Path.GetDirectoryName(file); schema = Path.GetFileName(schema); docObj = project.GetSchema(schema); } else if (name.Contains('-')) { // where rule string[] parts = name.Split('-'); if (parts.Length == 2) { DocDefinition docDef = project.GetDefinition(parts[0]); if (docDef is DocEntity) { DocEntity docEnt = (DocEntity)docDef; foreach (DocWhereRule docWhereRule in docEnt.WhereRules) { if (docWhereRule.Name.Equals(parts[1])) { docObj = docWhereRule; break; } } } else if (docDef is DocDefined) { DocDefined docEnt = (DocDefined)docDef; foreach (DocWhereRule docWhereRule in docEnt.WhereRules) { if (docWhereRule.Name.Equals(parts[1])) { docObj = docWhereRule; break; } } } } } else { docObj = project.GetDefinition(name); if (docObj == null) { docObj = project.GetFunction(name); } } if (docObj != null) { using (StreamReader readHtml = new StreamReader(file, Encoding.UTF8)) { docObj.Documentation = readHtml.ReadToEnd(); } } } // load schema diagrams en = System.IO.Directory.EnumerateFiles(pathSchema, "*.svg", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string schema = Path.GetDirectoryName(file); schema = Path.GetFileName(schema); DocSchema docSchema = project.GetSchema(schema); if (docSchema != null) { using (IfcDoc.Schema.SVG.SchemaSVG schemaSVG = new IfcDoc.Schema.SVG.SchemaSVG(file, docSchema, project, DiagramFormat.UML)) { schemaSVG.Load(); } } } // psets, qsets //... // exchanges en = System.IO.Directory.EnumerateFiles(path, "*.mvdxml", System.IO.SearchOption.AllDirectories); foreach (string file in en) { IfcDoc.Schema.MVD.SchemaMVD.Load(project, file); } // examples string pathExamples = path + @"\examples"; if (Directory.Exists(pathExamples)) { en = System.IO.Directory.EnumerateFiles(pathExamples, "*.htm", SearchOption.TopDirectoryOnly); foreach (string file in en) { DocExample docExample = new DocExample(); docExample.Name = Path.GetFileNameWithoutExtension(file); project.Examples.Add(docExample); using (StreamReader reader = new StreamReader(file)) { docExample.Documentation = reader.ReadToEnd(); } string dirpath = file.Substring(0, file.Length - 4); if (Directory.Exists(dirpath)) { IEnumerable <string> suben = System.IO.Directory.EnumerateFiles(dirpath, "*.ifc", SearchOption.TopDirectoryOnly); foreach (string ex in suben) { DocExample docEx = new DocExample(); docEx.Name = Path.GetFileNameWithoutExtension(ex); docExample.Examples.Add(docEx); // read the content of the file using (FileStream fs = new FileStream(ex, FileMode.Open, FileAccess.Read)) { docEx.File = new byte[fs.Length]; fs.Read(docEx.File, 0, docEx.File.Length); } // read documentation string exdoc = ex.Substring(0, ex.Length - 4) + ".htm"; if (File.Exists(exdoc)) { using (StreamReader reader = new StreamReader(exdoc)) { docEx.Documentation = reader.ReadToEnd(); } } } } } } // localization en = System.IO.Directory.EnumerateFiles(path, "*.txt", System.IO.SearchOption.AllDirectories); foreach (string file in en) { using (FormatCSV format = new FormatCSV(file)) { try { format.Instance = project; format.Load(); } catch { } } } }
/// <summary> /// Loads all content from a folder hierarchy (overlaying anything already existing) /// </summary> /// <param name="project"></param> /// <param name="path"></param> public static void Load(DocProject project, string path) { // get all files within folder hierarchy string pathSchema = path + @"\schemas"; IEnumerable <string> en = System.IO.Directory.EnumerateFiles(pathSchema, "*.cs", System.IO.SearchOption.AllDirectories); List <string> list = new List <string>(); foreach (string s in en) { list.Add(s); } string[] files = list.ToArray(); Dictionary <string, string> options = new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }; Microsoft.CSharp.CSharpCodeProvider prov = new Microsoft.CSharp.CSharpCodeProvider(options); System.CodeDom.Compiler.CompilerParameters parms = new System.CodeDom.Compiler.CompilerParameters(); parms.GenerateInMemory = true; parms.GenerateExecutable = false; parms.ReferencedAssemblies.Add("System.dll"); parms.ReferencedAssemblies.Add("System.Core.dll"); parms.ReferencedAssemblies.Add("System.ComponentModel.dll"); parms.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll"); parms.ReferencedAssemblies.Add("System.Data.dll"); parms.ReferencedAssemblies.Add("System.Runtime.Serialization.dll"); parms.ReferencedAssemblies.Add("System.Xml.dll"); System.CodeDom.Compiler.CompilerResults results = prov.CompileAssemblyFromFile(parms, files); System.Reflection.Assembly assem = results.CompiledAssembly; // look through classes of assembly foreach (Type t in assem.GetTypes()) { string[] namespaceparts = t.Namespace.Split('.'); string schema = namespaceparts[namespaceparts.Length - 1]; DocSection docSection = null; if (t.Namespace.EndsWith("Resource")) { docSection = project.Sections[7]; } else if (t.Namespace.EndsWith("Domain")) { docSection = project.Sections[6]; } else if (t.Namespace.Contains("Shared")) { docSection = project.Sections[5]; } else { docSection = project.Sections[4]; // kernel, extensions } // find schema DocSchema docSchema = null; foreach (DocSchema docEachSchema in docSection.Schemas) { if (docEachSchema.Name.Equals(schema)) { docSchema = docEachSchema; break; } } if (docSchema == null) { docSchema = new DocSchema(); docSchema.Name = schema; docSection.Schemas.Add(docSchema); docSection.SortSchemas(); } DocDefinition docDef = null; if (t.IsEnum) { DocEnumeration docEnum = new DocEnumeration(); docSchema.Types.Add(docEnum); docDef = docEnum; System.Reflection.FieldInfo[] fields = t.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); foreach (System.Reflection.FieldInfo field in fields) { DocConstant docConst = new DocConstant(); docEnum.Constants.Add(docConst); docConst.Name = field.Name; DescriptionAttribute[] attrs = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attrs.Length == 1) { docConst.Documentation = attrs[0].Description; } } } else if (t.IsValueType) { DocDefined docDefined = new DocDefined(); docSchema.Types.Add(docDefined); docDef = docDefined; PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); docDefined.DefinedType = fields[0].PropertyType.Name; } else if (t.IsInterface) { DocSelect docSelect = new DocSelect(); docSchema.Types.Add(docSelect); docDef = docSelect; } else if (t.IsClass) { DocEntity docEntity = new DocEntity(); docSchema.Entities.Add(docEntity); docDef = docEntity; if (t.BaseType != typeof(object)) { docEntity.BaseDefinition = t.BaseType.Name; } if (!t.IsAbstract) { docEntity.EntityFlags = 0x20; } Dictionary <int, DocAttribute> attrsDirect = new Dictionary <int, DocAttribute>(); List <DocAttribute> attrsInverse = new List <DocAttribute>(); PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | BindingFlags.DeclaredOnly); foreach (PropertyInfo field in fields) { DocAttribute docAttr = new DocAttribute(); docAttr.Name = field.Name.Substring(1); Type typeField = field.PropertyType; if (typeField.IsGenericType) { Type typeGeneric = typeField.GetGenericTypeDefinition(); typeField = typeField.GetGenericArguments()[0]; if (typeGeneric == typeof(Nullable <>)) { docAttr.IsOptional = true; } else if (typeGeneric == typeof(ISet <>)) { docAttr.AggregationType = (int)DocAggregationEnum.SET; } else if (typeGeneric == typeof(IList <>)) { docAttr.AggregationType = (int)DocAggregationEnum.LIST; } } docAttr.DefinedType = typeField.Name; MinLengthAttribute mla = (MinLengthAttribute)field.GetCustomAttribute(typeof(MinLengthAttribute)); if (mla != null) { docAttr.AggregationLower = mla.Length.ToString(); } MaxLengthAttribute mxa = (MaxLengthAttribute)field.GetCustomAttribute(typeof(MaxLengthAttribute)); if (mxa != null) { docAttr.AggregationUpper = mxa.Length.ToString(); } PropertyInfo propinfo = t.GetProperty(docAttr.Name); if (propinfo != null) { DescriptionAttribute da = (DescriptionAttribute)propinfo.GetCustomAttribute(typeof(DescriptionAttribute)); if (da != null) { docAttr.Documentation = da.Description; } } DataMemberAttribute dma = (DataMemberAttribute)field.GetCustomAttribute(typeof(DataMemberAttribute)); if (dma != null) { attrsDirect.Add(dma.Order, docAttr); RequiredAttribute rqa = (RequiredAttribute)field.GetCustomAttribute(typeof(RequiredAttribute)); if (rqa == null) { docAttr.IsOptional = true; } CustomValidationAttribute cva = (CustomValidationAttribute)field.GetCustomAttribute(typeof(CustomValidationAttribute)); if (cva != null) { docAttr.IsUnique = true; } } else { InversePropertyAttribute ipa = (InversePropertyAttribute)field.GetCustomAttribute(typeof(InversePropertyAttribute)); if (ipa != null) { docAttr.Inverse = ipa.Property; attrsInverse.Add(docAttr); } } // xml XmlIgnoreAttribute xia = (XmlIgnoreAttribute)field.GetCustomAttribute(typeof(XmlIgnoreAttribute)); if (xia != null) { docAttr.XsdFormat = DocXsdFormatEnum.Hidden; } else { XmlElementAttribute xea = (XmlElementAttribute)field.GetCustomAttribute(typeof(XmlElementAttribute)); if (xea != null) { if (!String.IsNullOrEmpty(xea.ElementName)) { docAttr.XsdFormat = DocXsdFormatEnum.Element; } else { docAttr.XsdFormat = DocXsdFormatEnum.Attribute; } } } } foreach (DocAttribute docAttr in attrsDirect.Values) { docEntity.Attributes.Add(docAttr); } foreach (DocAttribute docAttr in attrsInverse) { docEntity.Attributes.Add(docAttr); } // get derived attributes based on properties PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); foreach (PropertyInfo prop in props) { // if no backing field, then derived FieldInfo field = t.GetField("_" + prop.Name, BindingFlags.NonPublic | BindingFlags.Instance); if (field == null) { DocAttribute docDerived = new DocAttribute(); docDerived.Name = prop.Name; docEntity.Attributes.Add(docDerived); } } } if (docDef != null) { docDef.Name = t.Name; docDef.Uuid = t.GUID; } docSchema.SortTypes(); docSchema.SortEntities(); } // pass 2: hook up selects foreach (Type t in assem.GetTypes()) { Type[] typeInterfaces = t.GetInterfaces(); if (typeInterfaces.Length > 0) { foreach (Type typeI in typeInterfaces) { DocSelect docSelect = project.GetDefinition(typeI.Name) as DocSelect; if (docSelect != null) { DocSelectItem docItem = new DocSelectItem(); docItem.Name = t.Name; docSelect.Selects.Add(docItem); } } } } // EXPRESS rules (eventually in C#, though .exp file snippets for now) en = System.IO.Directory.EnumerateFiles(pathSchema, "*.exp", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string name = Path.GetFileNameWithoutExtension(file); string expr = null; using (StreamReader readExpr = new StreamReader(file, Encoding.UTF8)) { expr = readExpr.ReadToEnd(); } if (name.Contains('-')) { // where rule string[] parts = name.Split('-'); if (parts.Length == 2) { DocWhereRule docWhere = new DocWhereRule(); docWhere.Name = parts[1]; docWhere.Expression = expr; DocDefinition docDef = project.GetDefinition(parts[0]); if (docDef is DocEntity) { DocEntity docEnt = (DocEntity)docDef; docEnt.WhereRules.Add(docWhere); } else if (docDef is DocDefined) { DocDefined docEnt = (DocDefined)docDef; docEnt.WhereRules.Add(docWhere); } else if (docDef == null) { //... global rule... } } } else { // function string schema = Path.GetDirectoryName(file); schema = Path.GetDirectoryName(schema); schema = Path.GetFileName(schema); DocSchema docSchema = project.GetSchema(schema); if (docSchema != null) { DocFunction docFunction = new DocFunction(); docSchema.Functions.Add(docFunction); docFunction.Name = name; docFunction.Expression = expr; } } } // now, hook up html documentation en = System.IO.Directory.EnumerateFiles(pathSchema, "*.htm", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string name = Path.GetFileNameWithoutExtension(file); DocObject docObj = null; if (name == "schema") { string schema = Path.GetDirectoryName(file); schema = Path.GetFileName(schema); docObj = project.GetSchema(schema); } else if (name.Contains('-')) { // where rule string[] parts = name.Split('-'); if (parts.Length == 2) { DocDefinition docDef = project.GetDefinition(parts[0]); if (docDef is DocEntity) { DocEntity docEnt = (DocEntity)docDef; foreach (DocWhereRule docWhereRule in docEnt.WhereRules) { if (docWhereRule.Name.Equals(parts[1])) { docObj = docWhereRule; break; } } } else if (docDef is DocDefined) { DocDefined docEnt = (DocDefined)docDef; foreach (DocWhereRule docWhereRule in docEnt.WhereRules) { if (docWhereRule.Name.Equals(parts[1])) { docObj = docWhereRule; break; } } } } } else { docObj = project.GetDefinition(name); if (docObj == null) { docObj = project.GetFunction(name); } } if (docObj != null) { using (StreamReader readHtml = new StreamReader(file, Encoding.UTF8)) { docObj.Documentation = readHtml.ReadToEnd(); } } } // load schema diagrams en = System.IO.Directory.EnumerateFiles(pathSchema, "*.svg", System.IO.SearchOption.AllDirectories); foreach (string file in en) { string schema = Path.GetDirectoryName(file); schema = Path.GetFileName(schema); DocSchema docSchema = project.GetSchema(schema); if (docSchema != null) { using (IfcDoc.Schema.SVG.SchemaSVG schemaSVG = new IfcDoc.Schema.SVG.SchemaSVG(file, docSchema, project)) { schemaSVG.Load(); } } } // psets, qsets //... // exchanges en = System.IO.Directory.EnumerateFiles(path, "*.mvdxml", System.IO.SearchOption.AllDirectories); foreach (string file in en) { IfcDoc.Schema.MVD.SchemaMVD.Load(project, file); } // examples string pathExamples = path + @"\examples"; if (Directory.Exists(pathExamples)) { en = System.IO.Directory.EnumerateFiles(pathExamples, "*.htm", SearchOption.TopDirectoryOnly); foreach (string file in en) { DocExample docExample = new DocExample(); docExample.Name = Path.GetFileNameWithoutExtension(file); project.Examples.Add(docExample); using (StreamReader reader = new StreamReader(file)) { docExample.Documentation = reader.ReadToEnd(); } string dirpath = file.Substring(0, file.Length - 4); if (Directory.Exists(dirpath)) { IEnumerable <string> suben = System.IO.Directory.EnumerateFiles(dirpath, "*.ifc", SearchOption.TopDirectoryOnly); foreach (string ex in suben) { DocExample docEx = new DocExample(); docEx.Name = Path.GetFileNameWithoutExtension(ex); docExample.Examples.Add(docEx); // read the content of the file using (FileStream fs = new FileStream(ex, FileMode.Open, FileAccess.Read)) { docEx.File = new byte[fs.Length]; fs.Read(docEx.File, 0, docEx.File.Length); } // read documentation string exdoc = ex.Substring(0, ex.Length - 4) + ".htm"; if (File.Exists(exdoc)) { using (StreamReader reader = new StreamReader(exdoc)) { docEx.Documentation = reader.ReadToEnd(); } } } } } } // localization en = System.IO.Directory.EnumerateFiles(path, "*.txt", System.IO.SearchOption.AllDirectories); foreach (string file in en) { using (FormatCSV format = new FormatCSV(file)) { try { format.Instance = project; format.Load(); } catch { } } } }