Esempio n. 1
0
        public static IfdBase CreateDescription(string baseurl, string sessionid, string langid, string desc)
        {
            try
            {
                string         url     = baseurl + "api/4.0/IfdDescription?languageGuid=" + langid + "&description=" + desc + "&descriptionType=DEFINITION";
                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);
                return(ifdRoot);
            }
            catch (Exception xx)
            {
                System.Diagnostics.Debug.WriteLine(xx.Message);
            }

            return(null);
        }
Esempio n. 2
0
        public static void UploadTemplateUsage(DocProject docProject, string baseurl, string sessionid, string parentid, DocTemplateUsage docConc)
        {
            // MVD Concept entry is a relationship in BSDD; contexts are exchanges
            foreach (DocTemplateItem docItem in docConc.Items)
            {
                if (docItem.Concepts.Count == 0)
                {
                    string code = docItem.GetParameterValue("Reference");
                    if (String.IsNullOrEmpty(code))
                    {
                        code = docItem.Name;
                    }
                    code = HttpUtility.UrlEncode(code);

                    string name = docItem.GetParameterValue("Name");
                    if (code != null && name != null)
                    {
                        // if no sub-concepts, then its a property
                        IfdBase ifdItem = CreateConcept(baseurl, sessionid, docItem, code, name, null, IfdConceptTypeEnum.PROPERTY);
                        CreateRelationship(baseurl, sessionid, parentid, ifdItem.guid, IfdRelationshipTypeEnum.ASSIGNS_PROPERTIES);

                        string paramval = docItem.GetParameterValue("Value");
                        if (!String.IsNullOrEmpty(paramval))
                        {
                            DocDefinition docDef = docProject.GetDefinition(paramval);
                            if (docDef != null)
                            {
                                // get the measure type
                                IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE);
                                if (ifdType == null)
                                {
                                    // create concept
                                    ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE);
                                }
                                CreateRelationship(baseurl, sessionid, ifdItem.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES);
                            }
                        }
                    }
                }
                else
                {
                    // otherwise its a nest
                    if (docItem.Name != null)
                    {
                        IfdBase ifdItem = CreateConcept(baseurl, sessionid, docItem, docItem.Name, docItem.Name, null, IfdConceptTypeEnum.NEST);
                        CreateRelationship(baseurl, sessionid, parentid, ifdItem.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS);

                        // recurse -- e.g. properties within property sets
                        foreach (DocTemplateUsage docInner in docItem.Concepts)
                        {
                            UploadTemplateUsage(docProject, baseurl, sessionid, ifdItem.guid, docInner);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        public static void Upload(DocProject docProject, BackgroundWorker worker, string baseurl, string username, string password, string parentid, DocModelView[] docViews)
        {
            string sessionid = Connect(docProject, worker, baseurl, username, password);

#if false
            if (docViews != null && docViews.Length > 0)
            {
                foreach (DocModelView docView in docViews)//docProject.ModelViews)
                {
                    // hack: only bridge view for now
                    if (docView.Name.Contains("Bridge"))
                    {
                        string codename = docView.Name;
                        if (!String.IsNullOrEmpty(docView.Code))
                        {
                            codename = docView.Code;
                        }

                        IfdBase ifdView = CreateConcept(baseurl, sessionid, docView, codename, docView.Name, IfdConceptTypeEnum.BAG);
                        //CreateRelationship(baseurl, sessionid, parentid, ifdView.guid, "COLLECTS"); // no top-level item for now

                        foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                        {
                            if (docRoot.Name != null)
                            {
                                System.Diagnostics.Debug.WriteLine(docRoot.ToString());

                                IfdBase ifdRoot = CreateConcept(baseurl, sessionid, docRoot, docRoot.ApplicableEntity.Name, docRoot.Name, IfdConceptTypeEnum.SUBJECT);
                                CreateRelationship(baseurl, sessionid, ifdView.guid, ifdRoot.guid, IfdRelationshipTypeEnum.COLLECTS);

                                foreach (DocTemplateUsage docConc in docRoot.Concepts)
                                {
                                    UploadTemplateUsage(docProject, baseurl, sessionid, ifdRoot.guid, docConc);
                                }
                            }
                        }
                    }
                }
            }
            else
#endif
            {
                // build list of types referenced by property sets
                Dictionary <string, IfdBase> mapEntities = new Dictionary <string, IfdBase>();


                // core schema
                foreach (DocSection docSection in docProject.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        // only export objects that have associated property sets
                        foreach (DocPropertySet docPset in docSchema.PropertySets)
                        {
                            IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, docPset.PropertySetType.ToString(), IfdConceptTypeEnum.BAG);
                            foreach (DocProperty docProp in docPset.Properties)
                            {
                                IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.PropertyType.ToString(), IfdConceptTypeEnum.PROPERTY);
                                if (ifdProp != null)
                                {
                                    CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS);

                                    string paramval = docProp.PrimaryDataType;
                                    if (!String.IsNullOrEmpty(paramval))
                                    {
                                        DocDefinition docDef = docProject.GetDefinition(paramval);
                                        if (docDef != null)
                                        {
                                            // get the measure type
                                            IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE);
                                            if (ifdType == null)
                                            {
                                                // create concept
                                                ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE);

                                                // for enums, get enumerated type
                                                if (docProp.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE)
                                                {
                                                    DocSchema docPropSchema            = null;
                                                    DocPropertyEnumeration docPropEnum = docProject.FindPropertyEnumeration(docProp.SecondaryDataType, out docPropSchema);
                                                    if (docPropEnum != null)
                                                    {
                                                        foreach (DocPropertyConstant docPropConst in docPropEnum.Constants)
                                                        {
                                                            IfdBase ifdConst = CreateConcept(baseurl, sessionid, docPropConst, docPropConst.Name, docPropConst.Name, null, IfdConceptTypeEnum.VALUE);
                                                            CreateRelationship(baseurl, sessionid, ifdType.guid, ifdConst.guid, IfdRelationshipTypeEnum.ASSIGNS_VALUES);
                                                        }
                                                    }
                                                }
                                            }
                                            CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText
                                        }
                                    }
                                }
                            }

                            // now link the property set to applicable type
                            DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject);
                            if (docEntities != null && docEntities.Length > 0)
                            {
                                // only the first one matters
                                DocEntity docEnt = docEntities[0];
                                IfdBase   ifdEnt = null;
                                if (!mapEntities.TryGetValue(docEnt.Name, out ifdEnt))
                                {
                                    ifdEnt = CreateConcept(baseurl, sessionid, docEnt, docEnt.Name, docEnt.Name, null, IfdConceptTypeEnum.SUBJECT);
                                    mapEntities.Add(docEnt.Name, ifdEnt);

                                    // subtypes (predefined type)
                                    foreach (DocAttribute docAttr in docEnt.Attributes)
                                    {
                                        if (docAttr.Name.Equals("PredefinedType"))
                                        {
                                            DocEnumeration docEnum = docProject.GetDefinition(docAttr.DefinedType) as DocEnumeration;
                                            if (docEnum != null)
                                            {
                                                foreach (DocConstant docConst in docEnum.Constants)
                                                {
                                                    IfdBase ifdConst = CreateConcept(baseurl, sessionid, docConst, docConst.Name, docConst.Name, null, IfdConceptTypeEnum.SUBJECT);
                                                    CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdConst.guid, IfdRelationshipTypeEnum.SPECIALIZES);
                                                }
                                            }
                                        }
                                    }
                                }
                                CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS); //!!! Fails with Forbidden!!! why???
                                // http://test.bsdd.buildingsmart.org/api/4.0/IfdRelationship/validrelations/SUBJECT/BAG indicates
                                // <ifdRelationshipTypeEnums>
                                //   <IfdRelationshipType xmlns="http://peregrine.catenda.no/objects">ASSIGNS_COLLECTIONS</IfdRelationshipType>
                                // </ifdRelationshipTypeEnums>
                            }
                        }

                        foreach (DocQuantitySet docPset in docSchema.QuantitySets)
                        {
                            IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, "QTO_OCCURRENCEDRIVEN", IfdConceptTypeEnum.BAG);
                            foreach (DocQuantity docProp in docPset.Quantities)
                            {
                                IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.QuantityType.ToString(), IfdConceptTypeEnum.PROPERTY);
                                if (ifdProp != null)
                                {
                                    CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS);

                                    string propclass = "IfcQuantityCount";
                                    switch (docProp.QuantityType)
                                    {
                                    case DocQuantityTemplateTypeEnum.Q_AREA:
                                        propclass = "IfcQuantityArea";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_COUNT:
                                        propclass = "IfcQuantityCount";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_LENGTH:
                                        propclass = "IfcQuantityLength";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_TIME:
                                        propclass = "IfcQuantityTime";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_VOLUME:
                                        propclass = "IfcQuantityVolume";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_WEIGHT:
                                        propclass = "IfcQuantityWeight";
                                        break;
                                    }

                                    string paramval = propclass;
                                    if (!String.IsNullOrEmpty(paramval))
                                    {
                                        DocDefinition docDef = docProject.GetDefinition(paramval);
                                        if (docDef != null)
                                        {
                                            // get the measure type
                                            IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE);
                                            if (ifdType == null)
                                            {
                                                // create concept
                                                ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE);
                                            }
                                            CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText
                                        }
                                    }
                                }
                            }

                            // now link the property set to applicable type
                            DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject);
                            if (docEntities != null && docEntities.Length > 0)
                            {
                                // only the first one matters
                                DocEntity docEnt = docEntities[0];
                                IfdBase   ifdEnt = null;
                                if (mapEntities.TryGetValue(docEnt.Name, out ifdEnt))
                                {
                                    CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS);
                                }
                            }
                        }
                    }
                }
            }
        }