private void toolStripButtonTranslationInsert_Click(object sender, EventArgs e) { using (FormSelectLocale form = new FormSelectLocale()) { DialogResult res = form.ShowDialog(this); if (res == DialogResult.OK && form.SelectedLocale != null) { DocLocalization docLocal = new DocLocalization(); docLocal.Locale = form.SelectedLocale.Name; this.m_target.Localization.Add(docLocal); ListViewItem lvi = new ListViewItem(); lvi.Tag = docLocal; lvi.Text = docLocal.Locale; lvi.SubItems.Add(""); lvi.SubItems.Add(""); this.listViewLocale.Items.Add(lvi); this.listViewLocale.SelectedItems.Clear(); lvi.Selected = true; } } }
public void Load() { // prepare map Dictionary<string, DocObject> map = new Dictionary<string, DocObject>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { map.Add(docEntity.Name, docEntity); } foreach (DocType docType in docSchema.Types) { map.Add(docType.Name, docType); } foreach (DocPropertySet docPropertySet in docSchema.PropertySets) { map.Add(docPropertySet.Name, docPropertySet); } foreach (DocQuantitySet docQuantitySet in docSchema.QuantitySets) { map.Add(docQuantitySet.Name, docQuantitySet); } foreach(DocPropertyEnumeration docPropertyEnumeration in docSchema.PropertyEnums) { map.Add(docPropertyEnumeration.Name, docPropertyEnumeration); } } } // use tabs for simplicity using (System.IO.StreamReader reader = new System.IO.StreamReader(this.m_filename)) { string headerline = reader.ReadLine(); string[] headercols = headerline.Split(new char[]{'\t'}, StringSplitOptions.RemoveEmptyEntries); string blankline = reader.ReadLine(); // expect blank line // first column is name that identifies definition string[] locales = new string[headercols.Length]; string[] fields = new string[headercols.Length]; for(int icol = 0; icol < headercols.Length; icol++) { string col = headercols[icol]; int popen = col.IndexOf('('); int pclos = col.IndexOf(')'); if(popen > 0 && pclos > popen) { locales[icol] = col.Substring(popen + 1, pclos - popen - 1); fields[icol] = col.Substring(0, popen); } } // now rows while (!reader.EndOfStream) { string rowdata = reader.ReadLine(); string[] rowcells = rowdata.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (rowcells.Length > 1) { DocObject docObj = null; string[] fullID = rowcells[0].Split('.'); string identifier = fullID[0]; if (map.TryGetValue(identifier, out docObj)) { if(fullID.Length == 2) { string subType = fullID[1]; if(docObj is DocEntity) { DocEntity entity = (DocEntity)docObj; foreach (DocAttribute attr in entity.Attributes) { if(attr.Name == subType) { docObj = attr; break; } } } if(docObj is DocEnumeration) { DocEnumeration type = (DocEnumeration)docObj; foreach(DocConstant constnt in type.Constants) { docObj = type; break; } } if(docObj is DocPropertyEnumeration) { DocPropertyEnumeration propEnum = (DocPropertyEnumeration)docObj; foreach(DocPropertyConstant propConst in propEnum.Constants) { docObj = propEnum; break; } } if(docObj is DocPropertySet) { DocPropertySet propSet = (DocPropertySet)docObj; foreach(DocProperty docProp in propSet.Properties) { docObj = propSet; break; } } if(docObj is DocQuantitySet) { DocQuantitySet quantSet = (DocQuantitySet)docObj; foreach(DocQuantity docQuant in quantSet.Quantities) { docObj = quantSet; break; } } } for(int i = 1; i < rowcells.Length && i < headercols.Length; i++) { if (locales[i] != null) { // find existing DocLocalization docLocalization = null; foreach (DocLocalization docLocal in docObj.Localization) { if (docLocal.Locale.Equals(locales[i])) { docLocalization = docLocal; break; } } // create new if (docLocalization == null) { docLocalization = new DocLocalization(); docLocalization.Locale = locales[i]; docObj.Localization.Add(docLocalization); } string value = rowcells[i]; if (value != null && value.StartsWith("\"") && value.EndsWith("\"")) { // strip quotes value = value.Substring(1, value.Length - 2); } // update info switch (fields[i]) { case "Name": docLocalization.Name = value; break; case "Description": docLocalization.Documentation = value; break; } } } } } } } }
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); } }
/// <summary> /// Extracts description of referenced data, using properties, quantities, and attributes. /// </summary> /// <param name="mapEntity"></param> /// <param name="docView">Optional model view, for retrieving more specific descriptions such as for ports</param> /// <returns></returns> public string GetDescription(Dictionary <string, DocObject> mapEntity, DocModelView docView) { string desc = null; CvtValuePath valpath = this; if (valpath != null && valpath.Property != null && valpath.Property.Name.Equals("IsDefinedBy") && valpath.InnerPath != null && valpath.InnerPath.Type.Name.Equals("IfcRelDefinesByProperties") && valpath.Identifier != null) { DocObject docPset = null; mapEntity.TryGetValue(valpath.Identifier, out docPset); if (docPset is DocPropertySet) { DocProperty docProp = ((DocPropertySet)docPset).GetProperty(valpath.InnerPath.InnerPath.Identifier); if (docProp != null) { desc = docProp.Documentation;// localize?? if (String.IsNullOrEmpty(docProp.Documentation)) { this.ToString(); } } } else if (docPset is DocQuantitySet) { DocQuantity docProp = ((DocQuantitySet)docPset).GetQuantity(valpath.InnerPath.InnerPath.Identifier); if (docProp != null) { desc = docProp.Documentation;// localize?? if (String.IsNullOrEmpty(docProp.Documentation)) { this.ToString(); } } } } else if (valpath != null && valpath.Property != null && valpath.Property.Name.Equals("HasAssignments") && valpath.InnerPath != null && valpath.InnerPath.Type.Name.Equals("IfcRelAssignsToControl") && valpath.InnerPath.InnerPath != null && valpath.InnerPath.InnerPath.Type.Name.Equals("IfcPerformanceHistory")) { DocObject docPset = null; if (mapEntity.TryGetValue(valpath.InnerPath.InnerPath.Identifier, out docPset)) { DocProperty docProp = ((DocPropertySet)docPset).GetProperty(valpath.InnerPath.InnerPath.InnerPath.InnerPath.Identifier); if (docProp != null) { desc = docProp.Documentation;// localize?? if (docProp.Documentation == null) { DocLocalization docLoc = docProp.GetLocalization(null); if (docLoc != null) { desc = docLoc.Documentation; } } } } this.ToString(); } else if (valpath != null && valpath.Property != null && valpath.Property.Name.Equals("HasPropertySets") && valpath.InnerPath != null && valpath.InnerPath.Type.Name.Equals("IfcPropertySet")) { DocObject docPset = null; mapEntity.TryGetValue(valpath.Identifier, out docPset); if (docPset is DocPropertySet) { DocProperty docProp = ((DocPropertySet)docPset).GetProperty(valpath.InnerPath.Identifier); if (docProp != null) { desc = docProp.Documentation;// localize?? if (String.IsNullOrEmpty(docProp.Documentation)) { this.ToString(); } } } } else if (valpath != null && valpath.Property != null && valpath.Property.Name.Equals("Material") && valpath.InnerPath != null && valpath.InnerPath.Type.Name.Equals("IfcMaterial") && valpath.InnerPath.InnerPath != null && valpath.InnerPath.InnerPath.Type.Name.Equals("IfcMaterialProperties")) { DocObject docPset = null; mapEntity.TryGetValue(valpath.InnerPath.Identifier, out docPset); if (docPset is DocPropertySet) { DocProperty docProp = ((DocPropertySet)docPset).GetProperty(valpath.InnerPath.InnerPath.Identifier); if (docProp != null) { desc = docProp.Documentation; } } } else if (valpath != null && valpath.Property != null && valpath.Property.Name.Equals("HasProperties") && valpath.InnerPath != null && valpath.InnerPath.Type.Name.Equals("IfcMaterialProperties")) { DocObject docPset = null; mapEntity.TryGetValue(valpath.Identifier, out docPset); if (docPset is DocPropertySet) { DocProperty docProp = ((DocPropertySet)docPset).GetProperty(valpath.InnerPath.Identifier); if (docProp != null) { desc = docProp.Documentation; } } } else if (valpath != null && valpath.Property != null && valpath.Property.Name.Equals("IsNestedBy") && valpath.InnerPath != null && valpath.InnerPath.InnerPath != null && valpath.InnerPath.InnerPath != null) { CvtValuePath pathInner = valpath.InnerPath.InnerPath; if (pathInner.Type != null && pathInner.Type.Name.Equals("IfcDistributionPort")) { string portname = valpath.InnerPath.Identifier; if (pathInner.Property != null && pathInner.Property.Name.Equals("IsDefinedBy")) { // lookup description of property at port DocObject docPset = null; mapEntity.TryGetValue(pathInner.Identifier, out docPset); if (docPset is DocPropertySet) { DocProperty docProp = ((DocPropertySet)docPset).GetProperty(pathInner.InnerPath.InnerPath.Identifier); if (docProp != null) { desc = portname + ": " + docProp.Documentation; } } } else { desc = portname; // lookup description of port Guid guidPortNesting = new Guid("bafc93b7-d0e2-42d8-84cf-5da20ee1480a"); if (docView != null) { foreach (DocConceptRoot docRoot in docView.ConceptRoots) { if (docRoot.ApplicableEntity == valpath.Type) { foreach (DocTemplateUsage docConcept in docRoot.Concepts) { if (docConcept.Definition != null && docConcept.Definition.Uuid == guidPortNesting) { foreach (DocTemplateItem docItem in docConcept.Items) { if (docItem.Name != null && docItem.Name.Equals(portname)) { desc = docItem.Documentation; break; } } } } } } } } } } if (desc == null) { while (valpath != null && valpath.InnerPath != null && valpath.InnerPath.Property != null) { valpath = valpath.InnerPath; } if (valpath != null && valpath.Property != null) { desc = valpath.Property.Documentation; } else if (valpath != null) { desc = "The IFC class identifier indicating the subtype of object."; } } // clear out any notes int block = desc.IndexOf("<blockquote"); if (block != -1) { desc = desc.Substring(0, block); } return(desc); }
public static DocProject LoadFile(string filePath) { List <object> instances = new List <object>(); string ext = System.IO.Path.GetExtension(filePath).ToLower(); string schema = ""; DocProject project = null; switch (ext) { case ".ifcdoc": using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { Dictionary <long, object> dictionaryInstances = null; StepSerializer formatDoc = new StepSerializer(typeof(DocProject), SchemaDOC.Types); project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances); instances.AddRange(dictionaryInstances.Values); schema = formatDoc.Schema; } break; case ".ifcdocxml": using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { Dictionary <string, object> dictionaryInstances = null; XmlSerializer formatDoc = new XmlSerializer(typeof(DocProject)); project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances); instances.AddRange(dictionaryInstances.Values); } break; default: MessageBox.Show("Unsupported file type " + ext, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; #if MDB case ".mdb": using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances)) { format.Load(); } break; #endif } if (project == null) { return(null); } double schemaVersion = 0; if (!string.IsNullOrEmpty(schema)) { string[] fields = schema.Split("_".ToCharArray()); int i = 0; if (fields.Length > 1) { if (int.TryParse(fields[1], out i)) { schemaVersion = i; } if (fields.Length > 2 && int.TryParse(fields[2], out i)) { schemaVersion += i / 10.0; } } } List <SEntity> listDelete = new List <SEntity>(); List <DocTemplateDefinition> listTemplate = new List <DocTemplateDefinition>(); foreach (object o in instances) { if (o is DocSchema) { DocSchema docSchema = (DocSchema)o; // renumber page references foreach (DocPageTarget docTarget in docSchema.PageTargets) { if (docTarget.Definition != null) // fix it up -- NULL bug from older .ifcdoc files { int page = docSchema.GetDefinitionPageNumber(docTarget); int item = docSchema.GetPageTargetItemNumber(docTarget); docTarget.Name = page + "," + item + " " + docTarget.Definition.Name; foreach (DocPageSource docSource in docTarget.Sources) { docSource.Name = docTarget.Name; } } } } else if (o is DocExchangeDefinition) { // files before V4.9 had Description field; no longer needed so use regular Documentation field again. DocExchangeDefinition docexchange = (DocExchangeDefinition)o; if (docexchange._Description != null) { docexchange.Documentation = docexchange._Description; docexchange._Description = null; } } else if (o is DocTemplateDefinition) { // files before V5.0 had Description field; no longer needed so use regular Documentation field again. DocTemplateDefinition doctemplate = (DocTemplateDefinition)o; if (doctemplate._Description != null) { doctemplate.Documentation = doctemplate._Description; doctemplate._Description = null; } listTemplate.Add((DocTemplateDefinition)o); } else if (o is DocConceptRoot) { // V12.0: ensure template is defined DocConceptRoot docConcRoot = (DocConceptRoot)o; if (docConcRoot.ApplicableTemplate == null && docConcRoot.ApplicableEntity != null) { docConcRoot.ApplicableTemplate = new DocTemplateDefinition(); docConcRoot.ApplicableTemplate.Type = docConcRoot.ApplicableEntity.Name; } } else if (o is DocTemplateUsage) { // V12.0: ensure template is defined DocTemplateUsage docUsage = (DocTemplateUsage)o; if (docUsage.Definition == null) { docUsage.Definition = new DocTemplateDefinition(); } } else if (o is DocLocalization) { DocLocalization localization = o as DocLocalization; if (!string.IsNullOrEmpty(localization.Name)) { localization.Name = localization.Name.Trim(); } } // ensure all objects have valid guid DocObject docObject = o as DocObject; if (docObject != null) { if (docObject.Uuid == Guid.Empty) { docObject.Uuid = Guid.NewGuid(); } if (!string.IsNullOrEmpty(docObject.Documentation)) { docObject.Documentation = docObject.Documentation.Trim(); } if (schemaVersion < 12.1) { DocChangeSet docChangeSet = docObject as DocChangeSet; if (docChangeSet != null) { docChangeSet.ChangesEntities.RemoveAll(x => !isUnchanged(x)); } else { if (schemaVersion < 12) { DocEntity entity = docObject as DocEntity; if (entity != null) { entity.ClearDefaultMember(); } } } } } } if (project == null) { return(null); } if (schemaVersion > 0 && schemaVersion < 12.1) { Dictionary <string, DocPropertyEnumeration> encounteredPropertyEnumerations = new Dictionary <string, DocPropertyEnumeration>(); foreach (DocSchema docSchema in project.Sections.SelectMany(x => x.Schemas)) { extractListingsV12_1(project, docSchema, encounteredPropertyEnumerations); } } foreach (DocModelView docModelView in project.ModelViews) { // sort alphabetically (V11.3+) docModelView.SortConceptRoots(); } // upgrade to Publications (V9.6) if (project.Annotations.Count == 4) { project.Publications.Clear(); DocAnnotation docCover = project.Annotations[0]; DocAnnotation docContents = project.Annotations[1]; DocAnnotation docForeword = project.Annotations[2]; DocAnnotation docIntro = project.Annotations[3]; DocPublication docPub = new DocPublication(); docPub.Name = "Default"; docPub.Documentation = docCover.Documentation; docPub.Owner = docCover.Owner; docPub.Author = docCover.Author; docPub.Code = docCover.Code; docPub.Copyright = docCover.Copyright; docPub.Status = docCover.Status; docPub.Version = docCover.Version; docPub.Annotations.Add(docForeword); docPub.Annotations.Add(docIntro); project.Publications.Add(docPub); docCover.Delete(); docContents.Delete(); project.Annotations.Clear(); } project.SortProject(); return(project); }
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]; } }
public void Load() { // prepare map Dictionary <string, DocObject> map = new Dictionary <string, DocObject>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocEntity docEntity in docSchema.Entities) { map.Add(docEntity.Name, docEntity); } foreach (DocType docType in docSchema.Types) { map.Add(docType.Name, docType); } foreach (DocPropertySet docPropertySet in docSchema.PropertySets) { map.Add(docPropertySet.Name, docPropertySet); } foreach (DocQuantitySet docQuantitySet in docSchema.QuantitySets) { map.Add(docQuantitySet.Name, docQuantitySet); } foreach (DocPropertyEnumeration docPropertyEnumeration in docSchema.PropertyEnums) { map.Add(docPropertyEnumeration.Name, docPropertyEnumeration); } } } // use tabs for simplicity using (System.IO.StreamReader reader = new System.IO.StreamReader(this.m_filename)) { string headerline = reader.ReadLine(); string[] headercols = headerline.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); string blankline = reader.ReadLine(); // expect blank line // first column is name that identifies definition string[] locales = new string[headercols.Length]; string[] fields = new string[headercols.Length]; for (int icol = 0; icol < headercols.Length; icol++) { string col = headercols[icol]; int popen = col.IndexOf('('); int pclos = col.IndexOf(')'); if (popen > 0 && pclos > popen) { locales[icol] = col.Substring(popen + 1, pclos - popen - 1); fields[icol] = col.Substring(0, popen); } } // now rows while (!reader.EndOfStream) { string rowdata = reader.ReadLine(); string[] rowcells = rowdata.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (rowcells.Length > 1) { DocObject docObj = null; string[] fullID = rowcells[0].Split('.'); string identifier = fullID[0]; if (map.TryGetValue(identifier, out docObj)) { if (fullID.Length == 2) { string subType = fullID[1]; if (docObj is DocEntity) { DocEntity entity = (DocEntity)docObj; foreach (DocAttribute attr in entity.Attributes) { if (attr.Name == subType) { docObj = attr; break; } } } if (docObj is DocEnumeration) { DocEnumeration type = (DocEnumeration)docObj; foreach (DocConstant constnt in type.Constants) { docObj = type; break; } } if (docObj is DocPropertyEnumeration) { DocPropertyEnumeration propEnum = (DocPropertyEnumeration)docObj; foreach (DocPropertyConstant propConst in propEnum.Constants) { docObj = propEnum; break; } } if (docObj is DocPropertySet) { DocPropertySet propSet = (DocPropertySet)docObj; foreach (DocProperty docProp in propSet.Properties) { docObj = propSet; break; } } if (docObj is DocQuantitySet) { DocQuantitySet quantSet = (DocQuantitySet)docObj; foreach (DocQuantity docQuant in quantSet.Quantities) { docObj = quantSet; break; } } } for (int i = 1; i < rowcells.Length && i < headercols.Length; i++) { if (locales[i] != null) { // find existing DocLocalization docLocalization = null; foreach (DocLocalization docLocal in docObj.Localization) { if (docLocal.Locale.Equals(locales[i])) { docLocalization = docLocal; break; } } // create new if (docLocalization == null) { docLocalization = new DocLocalization(); docLocalization.Locale = locales[i]; docObj.Localization.Add(docLocalization); } string value = rowcells[i]; if (value != null && value.StartsWith("\"") && value.EndsWith("\"")) { // strip quotes value = value.Substring(1, value.Length - 2); } // update info switch (fields[i]) { case "Name": docLocalization.Name = value; break; case "Description": docLocalization.Documentation = value; break; } } } } } } } }
public static void Download(DocProject project, BackgroundWorker worker, string baseurl, string username, string password, DocModelView[] docViews) { string sessionid = Connect(project, worker, baseurl, username, password); if (sessionid == null) { return; } //foreach (DocModelView docView in docViews) string page = null; do { //string url = baseurl + "api/4.0/IfdContext/" + SGuid.Format(docView.Uuid); string url = baseurl + "api/4.0/IfdConcept/filter/SUBJECT"; // ifc-2X4 //string url = baseurl + "api/4.0/IfdConcept/search/filter/language/1ASQw0qJqHuO00025QrE$V/*";//type/SUBJECT/*"; if (page != null) { url += "?page=" + page; } HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Accept = "application/json"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); page = response.Headers.Get("Next-Page"); System.Diagnostics.Debug.WriteLine(page); ResponseSearch responseSearch = null; try { DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ResponseSearch)); responseSearch = (ResponseSearch)ser.ReadObject(stream); if (responseSearch != null) { responseSearch.ToString(); foreach (IfdConcept ifdConcept in responseSearch.IfdConcept) { DocModelView docView = new DocModelView(); if (ifdConcept.shortNames != null) { foreach (IfdName ifdName in ifdConcept.shortNames) { DocLocalization docLoc = new DocLocalization(); docLoc.Locale = ifdName.language.languageCode; docLoc.Name = ifdName.name; docView.Localization.Add(docLoc); if (ifdName.language.languageCode == "en") { docView.Name = ifdName.name; } } } else if (ifdConcept.fullNames != null) { ifdConcept.ToString(); } docView.Uuid = SGuid.Parse(ifdConcept.guid); docView.Version = ifdConcept.versionId; docView.Copyright = ifdConcept.versionDate; docView.Status = ifdConcept.status; //docView.Owner = ifdConcept.owner; //docView.Documentation = ifdConcept.comments project.ModelViews.Add(docView); ifdConcept.ToString(); } //foreach (IfdDescription ifcDesc in ifdContext.definitions) { // create/update concept root //... } } } catch (Exception xx) { xx.ToString(); } }while (!String.IsNullOrEmpty(page)); }
/// <summary> /// Helper function to populate attributes /// </summary> /// <param name="mvd"></param> /// <param name="doc"></param> private static void ImportMvdObject(Element mvd, DocObject doc) { doc.Name = mvd.Name; doc.Uuid = mvd.Uuid; doc.Version = mvd.Version; doc.Owner = mvd.Owner; doc.Status = mvd.Status; doc.Copyright = mvd.Copyright; doc.Code = mvd.Code; doc.Author = mvd.Author; if (mvd.Definitions != null) { foreach (Definition def in mvd.Definitions) { if (def != null) { // base definition if (def.Body != null) { doc.Documentation = def.Body.Content; } if (def.Links != null) { foreach (Link link in def.Links) { DocLocalization loc = new DocLocalization(); doc.Localization.Add(loc); loc.Name = link.Title; loc.Documentation = link.Content; loc.Category = (DocCategoryEnum)Enum.Parse(typeof(DocCategoryEnum), link.Category.ToString()); loc.Locale = link.Lang; loc.URL = link.Href; } } } } } }
private void toolStripMenuItemEditPaste_Click(object sender, EventArgs e) { if (this.treeView.Focused) { DocObject docSelect = this.treeView.SelectedNode.Tag as DocObject; if (docSelect is DocSection && this.m_clipboard is DocSchema && this.m_clipboardNode.Parent.Tag is DocSection) { DocSchema docSchema = (DocSchema)this.m_clipboard; DocSection docSectionNew = (DocSection)docSelect; DocSection docSectionOld = (DocSection)this.m_clipboardNode.Parent.Tag; docSectionOld.Schemas.Remove(docSchema); docSectionNew.Schemas.Add(docSchema); this.m_clipboardNode.Remove(); TreeNode tnSchema = this.LoadNode(this.treeView.SelectedNode, docSchema, docSchema.Name, true); this.treeView.SelectedNode = tnSchema; LoadNodeSchema(tnSchema, docSchema); } else if (docSelect is DocSchema && this.m_clipboard is DocPropertySet) { DocSchema schemaNew = (DocSchema)docSelect; DocPropertySet psetOld = (DocPropertySet)this.m_clipboard; if (this.m_clipboardCut) { if (this.m_clipboardNode.Parent.Parent.Tag is DocSchema) { DocSchema schemaOld = (DocSchema)this.m_clipboardNode.Parent.Parent.Tag; schemaOld.PropertySets.Remove(psetOld); schemaNew.PropertySets.Add(psetOld); this.m_clipboardNode.Remove(); this.m_clipboardNode = null; this.m_clipboard = null; this.m_clipboardCut = false; this.treeView.SelectedNode = this.LoadNode(this.treeView.SelectedNode.Nodes[4], psetOld, psetOld.Name, false); } } else { // TODO... } } else if (docSelect is DocPropertySet && this.m_clipboard is DocProperty) { DocPropertySet psetNew = (DocPropertySet)docSelect; DocProperty propOld = (DocProperty)this.m_clipboard; if (this.m_clipboardCut) { if (this.m_clipboardNode.Parent.Tag is DocPropertySet) { DocPropertySet psetOld = (DocPropertySet)this.m_clipboardNode.Parent.Tag; psetOld.Properties.Remove(propOld); psetNew.Properties.Add(propOld); this.m_clipboardNode.Remove(); this.m_clipboardNode = null; this.m_clipboard = null; this.m_clipboardCut = false; this.treeView.SelectedNode = this.LoadNode(this.treeView.SelectedNode, propOld, propOld.Name, false); } } else { DocProperty propNew = new DocProperty(); propNew.Name = propOld.Name; propNew.Documentation = propOld.Documentation; propNew.PropertyType = propOld.PropertyType; propNew.PrimaryDataType = propOld.PrimaryDataType; propNew.SecondaryDataType = propOld.SecondaryDataType; foreach(DocLocalization localOld in propOld.Localization) { DocLocalization localNew = new DocLocalization(); localNew.Name = localOld.Name; localNew.Documentation = localOld.Documentation; localNew.Category = localOld.Category; localNew.Locale = localOld.Locale; localNew.URL = localOld.URL; propNew.Localization.Add(localNew); } this.treeView.SelectedNode = this.LoadNode(this.treeView.SelectedNode, propNew, propNew.Name, false); } } else if (docSelect is DocConceptRoot && this.m_clipboard is DocTemplateUsage) { DocConceptRoot docRoot = (DocConceptRoot)docSelect; DocTemplateUsage docSource = (DocTemplateUsage)this.m_clipboard; DocTemplateUsage docTarget = new DocTemplateUsage(); docRoot.Concepts.Add(docTarget); CopyTemplateUsage(docSource, docTarget); this.treeView.SelectedNode = LoadNode(this.treeView.SelectedNode, docTarget, docTarget.Name, false); } else if (docSelect is DocModelView && this.m_clipboard is DocExchangeDefinition) { DocModelView docView = (DocModelView)docSelect; DocExchangeDefinition docSource = (DocExchangeDefinition)this.m_clipboard; DocExchangeDefinition docTarget = new DocExchangeDefinition(); docView.Exchanges.Add(docTarget); docTarget.Name = docSource.Name; docTarget.Documentation = docSource.Documentation; docTarget.Author = docSource.Author; docTarget.Copyright = docSource.Copyright; docTarget.Owner = docSource.Owner; docTarget.Icon = docSource.Icon; // copy entity requirements if in same view if (docView.Exchanges.Contains(docSource)) { foreach (DocConceptRoot docRoot in docView.ConceptRoots) { foreach (DocTemplateUsage docConcept in docRoot.Concepts) { List<DocExchangeItem> listNew = new List<DocExchangeItem>(); foreach (DocExchangeItem docSourceER in docConcept.Exchanges) { if (docSourceER.Exchange == docSource) { DocExchangeItem docTargetER = new DocExchangeItem(); docTargetER.Exchange = docTarget; docTargetER.Applicability = docSourceER.Applicability; docTargetER.Requirement = docSourceER.Requirement; listNew.Add(docTargetER); } } foreach (DocExchangeItem docTargetER in listNew) { docConcept.Exchanges.Add(docTargetER); } } } } this.treeView.SelectedNode = LoadNode(this.treeView.SelectedNode, docTarget, docTarget.Name, false); } } else { this.textBoxHTML.Paste(); } }
public static void Download(DocProject project, System.ComponentModel.BackgroundWorker worker, string baseurl, string username, string password) { if (project.Sections[4].Schemas.Count == 0) { project.Sections[4].Schemas.Add(new DocSchema()); } string url = baseurl + "api/4.0/session/login?email=" + HttpUtility.UrlEncode(username) + "&password="******"POST"; request.ContentLength = 0; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "application/json"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); System.IO.Stream stream = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(stream); string body = reader.ReadToEnd(); string cookie = response.Headers.Get("Set-Cookie"); string[] parts = cookie.Split(new char[] { ';', ',' }); // bug? comma separates session ID string match = "peregrineapisessionid="; string sessionid = null; foreach (string part in parts) { if (part.StartsWith(match)) { sessionid = part.Substring(match.Length); break; } } /*-Get all users: * var client = new RestClient("http://test.bsdd.buildingsmart.org/api/4.0/IfdUser/"); * var request = new RestRequest(Method.GET); * request.AddHeader("cookie", "peregrineapisessionid=thesessionid"); * request.AddHeader("accept", "application/json"); * request.AddHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8"); * IRestResponse response = client.Execute(request);*/ /*- Get all languages: * var client = new RestClient("http://test.bsdd.buildingsmart.org/api/4.0/IfdLanguage/"); * var request = new RestRequest(Method.GET); * request.AddHeader("cookie", "peregrineapisessionid={{sessionId}}"); * request.AddHeader("accept", "application/json"); * request.AddHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8"); * IRestResponse response = client.Execute(request);*/ request = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdLanguage/"); request.Method = "GET"; request.ContentLength = 0; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); request.Accept = "application/json"; response = (HttpWebResponse)request.GetResponse(); stream = response.GetResponseStream(); reader = new System.IO.StreamReader(stream); body = reader.ReadToEnd(); body.ToString(); request = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdConcept/search/filter/language/1ASQw0qJqHuO00025QrE$V/type/NEST/Pset_*"); request.Method = "GET"; request.ContentLength = 0; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); request.Accept = "application/json"; response = (HttpWebResponse)request.GetResponse(); stream = response.GetResponseStream(); reader = new System.IO.StreamReader(stream); body = reader.ReadToEnd(); System.IO.Stream ms = new System.IO.MemoryStream(); System.IO.StreamWriter writer = new System.IO.StreamWriter(ms); writer.Write(body); writer.Flush(); ms.Position = 0; //System.IO.MemoryStream mstream = new System.IO.MemoryStream() ResponseSearch ifdRoot; try { DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); //settings.UseSimpleDictionaryFormat = true; System.Runtime.Serialization.Json.DataContractJsonSerializer ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(ResponseSearch)); ifdRoot = (ResponseSearch)ser.ReadObject(ms); } catch { return; } // PERF: consider API on server that would return all information at once (currently 150+ round trips) for (int iConc = 0; iConc < ifdRoot.IfdConcept.Length; iConc++) { IfdConcept concept = ifdRoot.IfdConcept[iConc]; worker.ReportProgress((int)(100.0 * (double)iConc / (double)ifdRoot.IfdConcept.Length)); // api/4.0/IfdPSet/{guid}/ifcVersion/{ifcVersion}/XML #if true //figure out version info // language code starting at 5th character then lowercase -- e.g. "IFC-2X4" -> "2x4" string ifcversion = "2x4"; // "IFC4";// "ifc-2X4"; //???? what should this be ???? -- code "ifc-2X4" appears in headers; "IFC-2x4" appears in UI; "IFC4" is official schema name request = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdPSet/" + concept.guid + "/ifcVersion/" + ifcversion + "/XML"); request.Method = "GET"; request.ContentLength = 0; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); request.Accept = "application/xml"; #endif #if false // worked April 1, but no longer works as of 2017-06-13 (http body returns "null" -- as in 4 character string) -- issue with test server -- CoBuilder merge wiped out content?? request = (HttpWebRequest)HttpWebRequest.Create(baseurl + "api/4.0/IfdConcept/" + concept.guid + "/children"); request.Method = "GET"; request.ContentLength = 0; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); request.Accept = "application/json"; //request.Accept = "application/xml"; #endif try { response = (HttpWebResponse)request.GetResponse(); stream = response.GetResponseStream(); reader = new System.IO.StreamReader(stream); body = reader.ReadToEnd(); if (body != null && body != "null") // !!!! { ms = new MemoryStream(); writer = new StreamWriter(ms, Encoding.Unicode); writer.Write(body); writer.Flush(); ms.Position = 0; try { using (FormatXML format = new FormatXML(ms, typeof(PropertySetDef), null, null)) { format.Load(); PropertySetDef psd = (PropertySetDef)format.Instance; Program.ImportPsd(psd, project); } } catch { System.Diagnostics.Debug.WriteLine("Error downloading property set: " + concept.guid.ToString()); } #if false ResponsePset ifdResponse; DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); //settings.UseSimpleDictionaryFormat = true; System.Runtime.Serialization.Json.DataContractJsonSerializer ser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(ResponsePset)); try { System.IO.Stream xs = new System.IO.MemoryStream(); System.IO.StreamWriter xwriter = new System.IO.StreamWriter(xs); xwriter.Write(body); xwriter.Flush(); xs.Position = 0; ifdResponse = (ResponsePset)ser.ReadObject(xs); ifdResponse.ToString(); DocPropertySet docPset = new DocPropertySet(); docPset.Uuid = new Guid();// concept.guid; foreach (IfdName ifdName in concept.fullNames) { // if english if (ifdName.languageFamily == "IFC") { docPset.Name = ifdName.name; } else { DocLocalization docLoc = new DocLocalization(); docLoc.Locale = ifdName.language.languageCode; docLoc.Name = ifdName.name; docPset.Localization.Add(docLoc); } } docPset.Documentation = concept.definitions.description; project.Sections[4].Schemas[0].PropertySets.Add(docPset); foreach (IfdConceptInRelationship ifdProp in ifdResponse.IfdConceptInRelationship) { //ifdProp.fullNames[0]. DocProperty docProp = new DocProperty(); if (ifdProp.definitions != null) { docProp.Documentation = ifdProp.definitions.description; } docPset.Properties.Add(docProp); foreach (IfdName ifdName in ifdProp.fullNames) { // if english if (ifdName.languageFamily == "IFC") { //docProp.Name = ifdName.name; string[] nameparts = ifdName.name.Split('.'); if (nameparts.Length == 2) { docPset.Name = nameparts[0]; docProp.Name = nameparts[1]; } } else { DocLocalization docLoc = new DocLocalization(); docLoc.Locale = ifdName.language.languageCode; docLoc.Name = ifdName.name; docProp.Localization.Add(docLoc); } } } } #endif } } catch { //... return; } } }