private void WriteList(System.IO.StreamWriter writer, SortedList <string, DocObject> sortlist) { foreach (string key in sortlist.Keys) { DocObject docEntity = sortlist[key]; WriteItem(writer, docEntity, 0, docEntity.Name); if (docEntity is DocEntity) { DocEntity docEnt = (DocEntity)docEntity; foreach (DocAttribute docAttr in docEnt.Attributes) { WriteItem(writer, docAttr, 1, docEntity.Name); } } else if (docEntity is DocEnumeration) { DocEnumeration docEnum = (DocEnumeration)docEntity; foreach (DocConstant docConst in docEnum.Constants) { WriteItem(writer, docConst, 1, docEntity.Name); } } else if (docEntity is DocPropertySet) { DocPropertySet docPset = (DocPropertySet)docEntity; foreach (DocProperty docProp in docPset.Properties) { WriteItem(writer, docProp, 1, docEntity.Name); } } else if (docEntity is DocPropertyEnumeration) { DocPropertyEnumeration docPE = (DocPropertyEnumeration)docEntity; foreach (DocPropertyConstant docPC in docPE.Constants) { WriteItem(writer, docPC, 1, docEntity.Name); } } else if (docEntity is DocQuantitySet) { DocQuantitySet docQset = (DocQuantitySet)docEntity; foreach (DocQuantity docQuan in docQset.Quantities) { WriteItem(writer, docQuan, 1, docEntity.Name); } } } }
public static PropertySetDef ExportPsd(DocPropertySet docPset, Dictionary<string, DocPropertyEnumeration> mapEnum) { string[] apptypes = new string[0]; if (docPset.ApplicableType != null) { apptypes = docPset.ApplicableType.Split(','); } // convert to psd schema PropertySetDef psd = new PropertySetDef(); psd.Versions = new List<IfcVersion>(); psd.Versions.Add(new IfcVersion()); psd.Versions[0].version = "IFC4"; psd.Name = docPset.Name; psd.Definition = docPset.Documentation; psd.TemplateType = docPset.PropertySetType; psd.ApplicableTypeValue = docPset.ApplicableType; psd.ApplicableClasses = new List<ClassName>(); foreach (string app in apptypes) { ClassName cln = new ClassName(); cln.Value = app; psd.ApplicableClasses.Add(cln); } psd.IfdGuid = docPset.Uuid.ToString("N"); psd.PsetDefinitionAliases = new List<PsetDefinitionAlias>(); foreach (DocLocalization docLocal in docPset.Localization) { PsetDefinitionAlias alias = new PsetDefinitionAlias(); psd.PsetDefinitionAliases.Add(alias); alias.lang = docLocal.Locale; alias.Value = docLocal.Documentation; } psd.PropertyDefs = new List<PropertyDef>(); foreach (DocProperty docProp in docPset.Properties) { PropertyDef prop = new PropertyDef(); psd.PropertyDefs.Add(prop); ExportPsdProperty(docProp, prop, mapEnum); } return psd; }
public void Load() { // prepare map Dictionary <string, DocPropertySet> map = new Dictionary <string, DocPropertySet>(); foreach (DocSection docSection in this.m_project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocPropertySet docEntity in docSchema.PropertySets) { map.Add(docEntity.Name, docEntity); } } } // use commas for simplicity using (System.IO.StreamReader reader = new System.IO.StreamReader(this.m_filename)) { string headerline = reader.ReadLine(); // blank // now rows while (!reader.EndOfStream) { string rowdata = reader.ReadLine(); string[] rowcells = rowdata.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (rowcells.Length > 1) { DocPropertySet docObj = null; string ifdguid = rowcells[0]; string ifdname = rowcells[1]; Guid guid = SGuid.Parse(ifdguid); string[] nameparts = ifdname.Split('.'); string psetname = nameparts[0].Trim(); string propname = null; if (nameparts.Length == 2) { propname = nameparts[1]; } if (map.TryGetValue(psetname, out docObj)) { if (propname != null) { foreach (DocProperty docprop in docObj.Properties) { if (propname.Equals(docprop.Name)) { // found it docprop.Uuid = guid; break; } } } else { docObj.Uuid = guid; } } else { System.Diagnostics.Debug.WriteLine("IFD (not found): " + psetname); } } } } }
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 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 WriteList(System.IO.StreamWriter writer, SortedList <string, DocObject> sortlist) { foreach (string key in sortlist.Keys) { DocObject docEntity = sortlist[key]; WriteItem(writer, docEntity, 0, docEntity.Name); if (docEntity is DocEntity) { if ((this.m_scope & DocDefinitionScopeEnum.EntityAttribute) != 0) { DocEntity docEnt = (DocEntity)docEntity; foreach (DocAttribute docAttr in docEnt.Attributes) { WriteItem(writer, docAttr, 1, docEntity.Name); } } } else if (docEntity is DocEnumeration) { if ((this.m_scope & DocDefinitionScopeEnum.TypeConstant) != 0) { DocEnumeration docEnum = (DocEnumeration)docEntity; foreach (DocConstant docConst in docEnum.Constants) { WriteItem(writer, docConst, 1, docEntity.Name); } } } else if (docEntity is DocPropertySet) { if ((this.m_scope & DocDefinitionScopeEnum.PsetProperty) != 0) { DocPropertySet docPset = (DocPropertySet)docEntity; DocEntity docApp = null; DocEntity[] docApplicable = docPset.GetApplicableTypeDefinitions(this.m_project); if (docApplicable != null && docApplicable.Length > 0 && docApplicable[0] != null) { docApp = this.m_project.GetDefinition(docApplicable[0].BaseDefinition) as DocEntity; } foreach (DocProperty docProp in docPset.Properties) { // filter out leaf properties defined at common pset (e.g. Reference, Status) DocProperty docSuper = this.m_project.FindProperty(docProp.Name, docApp); if (docSuper == docProp || docSuper == null) { WriteItem(writer, docProp, 1, docEntity.Name); } } } } else if (docEntity is DocPropertyEnumeration) { if ((this.m_scope & DocDefinitionScopeEnum.PEnumConstant) != 0) { DocPropertyEnumeration docPE = (DocPropertyEnumeration)docEntity; foreach (DocPropertyConstant docPC in docPE.Constants) { WriteItem(writer, docPC, 1, docEntity.Name); } } } else if (docEntity is DocQuantitySet) { if ((this.m_scope & DocDefinitionScopeEnum.QsetQuantity) != 0) { DocQuantitySet docQset = (DocQuantitySet)docEntity; foreach (DocQuantity docQuan in docQset.Quantities) { WriteItem(writer, docQuan, 1, docEntity.Name); } } } } }
private void toolStripMenuItemInsertPropertyset_Click(object sender, EventArgs e) { TreeNode tn = this.treeView.SelectedNode; if (tn.Parent.Tag is DocSchema) { tn = tn.Parent; } DocSchema docSchema = (DocSchema)tn.Tag; DocPropertySet docPset = new DocPropertySet(); docSchema.PropertySets.Add(docPset); this.treeView.SelectedNode = this.LoadNode(tn.Nodes[4], docPset, docPset.Name, true); this.toolStripMenuItemEditRename_Click(sender, e); }
private void BuildConceptForPropertySets(DocConceptRoot docRoot, DocTemplateDefinition docTemplatePset, DocPropertySet[] psets) { DocTemplateUsage docConcept = null; // get any existing concept for psets foreach (DocTemplateUsage docExistConcept in docRoot.Concepts) { if (docExistConcept.Definition == docTemplatePset) { docConcept = docExistConcept; break; } } if (psets.Length > 0) { if (docConcept == null) { docConcept = new DocTemplateUsage(); docConcept.Definition = docTemplatePset; docRoot.Concepts.Add(docConcept); LoadNode(this.treeView.SelectedNode, docConcept, docConcept.ToString(), false); } // remove old listings for (int iExist = docConcept.Items.Count - 1; iExist >= 0; iExist--) { docConcept.Items[iExist].Delete(); docConcept.Items.RemoveAt(iExist); } foreach (DocPropertySet docPset in psets) { //if (docPset.PropertySetType == "PSET_OCCURRENCEDRIVEN" || // docPset.PropertySetType == "PSET_TYPEDRIVENOVERRIDE") { // add new, in order DocTemplateItem docItemPset = new DocTemplateItem(); docItemPset.RuleParameters = "Name=" + docPset.Name + ";"; docConcept.Items.Add(docItemPset); //... predefined type //... properties... int order = 0; foreach (DocProperty docProp in docPset.Properties) { DocTemplateDefinition docInnerTemplate = null; string suffix = String.Empty; switch (docProp.PropertyType) { case DocPropertyTemplateTypeEnum.P_SINGLEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("6655f6d0-29a8-47b8-8f3d-c9fce9c9a620")); break; case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("3d67a2d2-761d-44d9-a09e-b7fbb1fa5632")); break; case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("c148a099-c351-43a8-9266-5f3de0b45a95")); suffix = "Reference=" + docProp.SecondaryDataType.Substring(0, docProp.SecondaryDataType.IndexOf(':')); break; case DocPropertyTemplateTypeEnum.P_LISTVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("8e10b688-9179-4e3a-8db2-6abcaafe952d")); break; case DocPropertyTemplateTypeEnum.P_TABLEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("35c947b0-6abc-4b13-8ec7-696ef2041721")); suffix = "Reference=" + docProp.SecondaryDataType; break; case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("e20bc116-889b-46cc-b193-31b3e2376a8e")); suffix = "Reference=" + docProp.SecondaryDataType; break; } if (docInnerTemplate != null) { order++; DocTemplateUsage docInnerConcept = docItemPset.RegisterParameterConcept("Properties", docInnerTemplate); DocTemplateItem docInnerItem = new DocTemplateItem(); docInnerItem.RuleParameters = "Order=" + order + ";Name=" + docProp.Name + ";Value=" + docProp.PrimaryDataType + ";" + suffix; docInnerConcept.Items.Add(docInnerItem); } } } } } }
private void BuildConceptForPropertySets(DocConceptRoot docRoot, DocTemplateDefinition docTemplatePset, DocPropertySet[] psets) { DocTemplateUsage docConcept = null; // get any existing concept for psets foreach (DocTemplateUsage docExistConcept in docRoot.Concepts) { if (docExistConcept.Definition == docTemplatePset) { docConcept = docExistConcept; break; } } if (psets.Length > 0) { if (docConcept == null) { docConcept = new DocTemplateUsage(); docConcept.Definition = docTemplatePset; docRoot.Concepts.Add(docConcept); LoadNode(this.treeView.SelectedNode, docConcept, docConcept.Name, false); } // remove old listings for (int iExist = docConcept.Items.Count - 1; iExist >= 0; iExist--) { docConcept.Items[iExist].Delete(); docConcept.Items.RemoveAt(iExist); } foreach (DocPropertySet docPset in psets) { //if (docPset.PropertySetType == "PSET_OCCURRENCEDRIVEN" || // docPset.PropertySetType == "PSET_TYPEDRIVENOVERRIDE") { // add new, in order DocTemplateItem docItemPset = new DocTemplateItem(); docItemPset.RuleParameters = "Name=" + docPset.Name + ";"; docConcept.Items.Add(docItemPset); //... predefined type //... properties... foreach (DocProperty docProp in docPset.Properties) { DocTemplateDefinition docInnerTemplate = null; switch (docProp.PropertyType) { case DocPropertyTemplateTypeEnum.P_SINGLEVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("6655f6d0-29a8-47b8-8f3d-c9fce9c9a620")); break; case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("3d67a2d2-761d-44d9-a09e-b7fbb1fa5632")); break; case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE: docInnerTemplate = this.m_project.GetTemplate(new Guid("c148a099-c351-43a8-9266-5f3de0b45a95")); break; } if (docInnerTemplate != null) { DocTemplateUsage docInnerConcept = docItemPset.RegisterParameterConcept("Properties", docInnerTemplate); DocTemplateItem docInnerItem = new DocTemplateItem(); docInnerItem.RuleParameters = "Name=" + docProp.Name + ";Value=" + docProp.PrimaryDataType + ";"; docInnerConcept.Items.Add(docInnerItem); } } } } } }
private void toolStripButtonTemplateInsert_Click(object sender, EventArgs e) { if (this.dataGridViewConceptRules.SelectedRows.Count == 0) { return; } this.m_editcon = true; DocPropertySet existingPropertySet = null; bool isPsetDefined = false; bool isPropertyDefined = false; if (this.m_conceptleaf != null) { if (this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyList || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyBounded || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyEnumerated || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyReference || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertySingle || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyTable) { foreach (DocSection docSection in this.Project.Sections) { foreach (DocSchema docSchema in docSection.Schemas) { foreach (DocPropertySet docPset in docSchema.PropertySets) { if (docPset.Name == this.ConceptItem.Name) { isPsetDefined = true; existingPropertySet = docPset; } // search properties foreach (DocProperty docProp in docPset.Properties) { for (int i = 0; i < this.dataGridViewConceptRules.SelectedRows.Count; i++) { if (dataGridViewConceptRules.SelectedRows[i].Tag is DocTemplateItem) { DocTemplateItem propertyItem = (DocTemplateItem)dataGridViewConceptRules.SelectedRows[i].Tag; if (docProp.Name == propertyItem.GetParameterValue("PropertyName")) { isPropertyDefined = true; } } } } } } } } else { //this.m_conceptroot.ApplicableItems.RemoveAt(index); } if (!isPsetDefined) { FormSelectSchema schemaSelect = new FormSelectSchema(this.Project); schemaSelect.ShowDialog(); DocPropertySet pset = new DocPropertySet(); DocTemplateItem psetItem = (DocTemplateItem)this.ConceptItem; pset.Name = psetItem.GetParameterValue("PsetName"); if (!isPropertyDefined) { for (int i = 0; i < this.dataGridViewConceptRules.SelectedRows.Count; i++) { DocProperty property = new DocProperty(); if (dataGridViewConceptRules.SelectedRows[i].Tag is DocTemplateItem) { DocTemplateItem propertyItem = (DocTemplateItem)dataGridViewConceptRules.SelectedRows[i].Tag; property.Name = propertyItem.GetParameterValue("PropertyName"); //if (propertyItem.GetParameterValue("Value") != null) //{ property.PrimaryDataType = propertyItem.GetParameterValue("Value"); //} pset.Properties.Add(property); } } } schemaSelect.Selection.PropertySets.Add(pset); } else { if (!isPropertyDefined) { for (int i = 0; i < this.dataGridViewConceptRules.SelectedRows.Count; i++) { DocProperty property = new DocProperty(); if (dataGridViewConceptRules.SelectedRows[i].Tag is DocTemplateItem) { DocTemplateItem propertyItem = (DocTemplateItem)dataGridViewConceptRules.SelectedRows[i].Tag; property.Name = propertyItem.GetParameterValue("PropertyName"); //if (propertyItem.GetParameterValue("Value") != null) //{ property.PrimaryDataType = propertyItem.GetParameterValue("Value"); //} existingPropertySet.Properties.Add(property); } } } } if (this.ParentForm.Owner is FormEdit) { FormEdit ownerForm = (FormEdit)this.ParentForm.Owner; //ownerForm.i } this.m_editcon = false; } }
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; } } }