public static IfdName CreateName(string baseurl, string sessionid, string langid, string name) { try { string url = baseurl + "api/4.0/IfdName?languageGuid=" + langid + "&name=" + name + "&nameType=FULLNAME"; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = 0; request.Accept = "application/json"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(IfdName)); IfdName ifdRoot = (IfdName)ser.ReadObject(stream); return(ifdRoot); } catch (Exception xx) { System.Diagnostics.Debug.WriteLine(xx.Message); } return(null); }
/// <summary> /// /// </summary> /// <param name="baseurl">URL of server</param> /// <param name="sessionid">identifies server session</param> /// <param name="docObject">object to be published</param> /// <param name="identifier">identifier to use for IFC name</param> /// <param name="name">identifier to use for English name</param> /// <param name="type">identifier to use for IFC property type encoding, which is stored within description of IFC language</param> /// <param name="conctype">type of concept</param> /// <returns>guid of new concept</returns> public static IfdBase CreateConcept(string baseurl, string sessionid, DocObject docObject, string identifier, string name, string type, IfdConceptTypeEnum conctype) { System.Diagnostics.Debug.WriteLine(DateTime.Now + " " + conctype.ToString() + " " + identifier + " START"); List <IfdName> listNames = new List <IfdName>(); List <IfdBase> listDescs = new List <IfdBase>(); // create name for IFC IfdName ifdNameIFC = CreateName(baseurl, sessionid, LanguageID, identifier); if (ifdNameIFC == null) { return(null); } listNames.Add(ifdNameIFC); // create type identifier if indicated if (!String.IsNullOrEmpty(type)) { string desc = HttpUtility.UrlEncode(type); IfdBase ifdDescID = CreateDescription(baseurl, sessionid, LanguageID, desc); if (ifdDescID == null) { return(null); } listDescs.Add(ifdDescID); } // localization bool hasEnglishName = false; bool hasEnglishDesc = false; foreach (DocLocalization docLoc in docObject.Localization) { // look up language id string langid = GetLanguageId(docLoc.Locale); if (langid != null) { if (!String.IsNullOrEmpty(docLoc.Name)) { string locname = HttpUtility.UrlEncode(docLoc.Name); IfdName ifdName = CreateName(baseurl, sessionid, langid, locname); if (ifdName == null) { return(null); } listNames.Add(ifdName); if (langid == LanguageEN) { hasEnglishName = true; } } if (!String.IsNullOrEmpty(docLoc.Documentation)) { string locdesc = HttpUtility.UrlEncode(docLoc.Documentation); IfdBase ifdDesc = CreateDescription(baseurl, sessionid, langid, locdesc); if (ifdDesc == null) { return(null); } listDescs.Add(ifdDesc); if (langid == LanguageEN) { hasEnglishDesc = true; } } } } if (!hasEnglishName && !String.IsNullOrEmpty(name)) { // add default english name IfdName ifdNameEN = CreateName(baseurl, sessionid, LanguageEN, name); if (ifdNameEN == null) { return(null); } listNames.Add(ifdNameEN); } if (!hasEnglishDesc && !String.IsNullOrEmpty(docObject.Documentation)) { string desc = HttpUtility.UrlEncode(docObject.Documentation); IfdBase ifdDescEN = CreateDescription(baseurl, sessionid, LanguageEN, desc); if (ifdDescEN == null) { return(null); } listDescs.Add(ifdDescEN); } // create concept StringBuilder sb = new StringBuilder(); sb.Append(baseurl); sb.Append("api/4.0/IfdConcept?fullNameGuids="); for (int i = 0; i < listNames.Count; i++) { if (i != 0) { sb.Append(","); } sb.Append(listNames[i].guid); } sb.Append("&conceptType="); sb.Append(conctype.ToString()); if (listDescs.Count > 0) { sb.Append("&definitionGuids="); for (int i = 0; i < listDescs.Count; i++) { if (i != 0) { sb.Append(","); } sb.Append(listDescs[i].guid); } } string url = sb.ToString(); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = 0; request.Accept = "application/json"; request.Headers.Add("cookie", "peregrineapisessionid=" + sessionid); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(IfdBase)); IfdBase ifdRoot = (IfdBase)ser.ReadObject(stream); // record the ID on the doc object docObject.RegisterDictionary(baseurl, ifdRoot.guid); System.Diagnostics.Debug.WriteLine(DateTime.Now + " " + conctype.ToString() + " " + identifier + " FINISH"); return(ifdRoot); }