private void buttonLogin_Click(object sender, EventArgs e) { this.buttonLogin.Enabled = false; IfdConceptInRelationship ifdRoot = new IfdConceptInRelationship(); ifdRoot.guid = "1aUB00FUqHuO00025QrE$V"; TreeNode tnRoot = new TreeNode(); tnRoot.Tag = ifdRoot; tnRoot.Text = "Data Dictionary"; this.treeViewContainer.Nodes.Add(tnRoot); TreeNode tnSub = new TreeNode(); tnSub.Text = "Loading..."; tnRoot.Nodes.Add(tnSub); tnRoot.Expand(); // was trigger event notification to load //this.backgroundWorkerContexts.RunWorkerAsync(); //this.backgroundWorkerConcepts.RunWorkerAsync(tnRoot); this.buttonOK.Enabled = true; }
private void backgroundWorkerConcepts_DoWork(object sender, DoWorkEventArgs e) { IfdConceptInRelationship ifdConcept = null; TreeNode tn = (TreeNode)e.Argument; ifdConcept = (IfdConceptInRelationship)tn.Tag; IList <IfdConceptInRelationship> listItem = DataDictionary.GetConcepts(this.m_project, this.backgroundWorkerConcepts, this.textBoxUrl.Text, this.textBoxUsername.Text, this.textBoxPassword.Text, ifdConcept, true); IList <IfdConceptInRelationship> listHost = DataDictionary.GetConcepts(this.m_project, this.backgroundWorkerConcepts, this.textBoxUrl.Text, this.textBoxUsername.Text, this.textBoxPassword.Text, ifdConcept, false); List <IfdConceptInRelationship> listComb = new List <IfdConceptInRelationship>(); listComb.AddRange(listItem); listComb.AddRange(listHost); tn.Nodes[0].Tag = listComb; e.Result = tn; }
public bool RelatePropertyToPSet(string psetGuid, string propertyGuid, string relationContextGuid) { //GET /IfdConcept/{guid}/parents //Gets all the parents of a given concept. You need minimum PUBLIC access to use this method. bool propertyIsRelated = true; var requestParentCheck = new RestRequest($"/IfdConcept/{propertyGuid}/parents", Method.GET); requestParentCheck.AddQueryParameter("cache", "false"); requestParentCheck.AddHeader("Accept", "application/json"); requestParentCheck.AddCookie("peregrineapisessionid", Session.Guid); var responseParentCheck = restclient.Execute <IfdConceptInRelationshipFix>(requestParentCheck); try { IfdConceptInRelationship relation = new IfdConceptInRelationship(); bool contextIsIfcContext = false; relation = responseParentCheck?.Data?.IfdConceptInRelationship ?? null; if (relation != null) { if (relation.Contexts != null) { foreach (var context in relation.Contexts) { if (context.Guid != null) { if (context.Guid == relationContextGuid) { contextIsIfcContext = true; } } } } } //Dirty Hack, to have a workaround if ((relation?.Guid != psetGuid) || (relation == null))// || (!contextIsIfcContext)) //Open: Check, if the relation is on the given context, or on another context { //The Property is not related to it's PSet, we have to fix the relation //POST /IfdConcept/{guid}/parent //Adds a parent to the concept You need minimum IFD_EDITOR access to use this method. propertyIsRelated = false; var requestRelationFix = new RestRequest($"/IfdConcept/{propertyGuid}/parent", Method.POST); requestRelationFix.AddQueryParameter("cache", "false"); requestRelationFix.AddHeader("Accept", "application/json"); requestRelationFix.AddCookie("peregrineapisessionid", Session.Guid); requestRelationFix.AddParameter("parentGuid", psetGuid, ParameterType.GetOrPost); requestRelationFix.AddParameter("relationshipType", "COLLECTS", ParameterType.GetOrPost); requestRelationFix.AddParameter("contextGuid", relationContextGuid, ParameterType.GetOrPost); var responseRelationFix = restclient.Execute <IfdBase>(requestRelationFix); } } catch (Exception ex) { } return(propertyIsRelated); }
/// <summary> /// Gets child concepts /// </summary> /// <param name="docProject"></param> /// <param name="worker"></param> /// <param name="baseurl"></param> /// <param name="username"></param> /// <param name="password"></param> /// <param name="ifdParent"></param> /// <param name="direction">True for children, False for parents</param> /// <returns></returns> public static IList <IfdConceptInRelationship> GetConcepts(DocProject docProject, BackgroundWorker worker, string baseurl, string username, string password, IfdConceptInRelationship ifdParent, bool direction) { SortedList <string, IfdConceptInRelationship> list = new SortedList <string, IfdConceptInRelationship>(); string sessionid = Connect(docProject, worker, baseurl, username, password); // get children string nextpage = null; do { string url = baseurl + "api/4.0/IfdConcept/" + ifdParent.guid; if (direction) { url += "/children";//filter/SUBJECT"; // ifc-2X4 } else { url += "/parents"; } if (nextpage != null) { url += "?page=" + nextpage; } HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Accept = "application/json"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); nextpage = response.Headers.Get("Next-Page"); Stream stream = response.GetResponseStream(); ResponseConceptInRelationship responseSearch = null; try { DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ResponseConceptInRelationship)); responseSearch = (ResponseConceptInRelationship)ser.ReadObject(stream); if (responseSearch != null) { foreach (IfdConceptInRelationship ifdRel in responseSearch.IfdConceptInRelationship) { list.Add(ifdRel.ToString(), ifdRel); } } } catch { break; } }while (!String.IsNullOrEmpty(nextpage)); return(list.Values); }