public Converter(string sourceFolderXml, string targetFolderYaml, string targetFolderJson, string targetFolderResx, bool checkBSDD = false) { CheckBSDD = checkBSDD; _bsdd = new Bsdd(); string propertySetVersionList = string.Empty; string propertySetTemplateList = string.Empty; string propertyTypeList = string.Empty; string propertyUnitList = string.Empty; foreach (string sourceFile in Directory.EnumerateFiles(sourceFolderXml, "PSet*.xml").OrderBy(x => x).ToList())//.Where(x=>x.Contains("Pset_ConstructionResource"))) { numberOfPsets++; PropertySetDef pSet = PropertySetDef.LoadFromFile(sourceFile); log.Info("--------------------------------------------------"); log.Info($"Checking PSet {pSet.Name}"); log.Info($"Opened PSet-File {sourceFile.Replace(sourceFolderXml + @"\", string.Empty)}"); if (!propertySetVersionList.Contains(pSet.IfcVersion.version)) { propertySetVersionList += pSet.IfcVersion.version + ","; } if (!propertySetTemplateList.Contains(pSet.templatetype.ToString())) { propertySetTemplateList += pSet.templatetype.ToString() + ","; } PropertySet propertySet = new PropertySet() { name = pSet.Name, dictionaryReference = new DictionaryReference() { ifdGuid = "", legacyGuid = "" }, ifcVersion = new IfcVersion() { version = ConvertToSematicVersion(pSet.IfcVersion.version).ToString(), schema = pSet.IfcVersion.schema }, definition = pSet.Definition }; propertySet.applicableIfcClasses = new List <ApplicableIfcClass>(); foreach (var applicableClass in pSet.ApplicableClasses) { propertySet.applicableIfcClasses.Add(new ApplicableIfcClass() { name = applicableClass, type = pSet.ApplicableTypeValue }); } //Insert missing standard localizations as dummys propertySet.localizations = new List <Localization>(); foreach (string standardLanguage in StandardLanguages.OrderBy(x => x)) { if (propertySet.localizations.Where(x => x.language == standardLanguage).FirstOrDefault() == null) { propertySet.localizations.Add(new Localization() { language = standardLanguage, name = string.Empty, definition = string.Empty }); } } if (CheckBSDD) { if (propertySet.dictionaryReference.legacyGuid.Length == 0) { Console.ForegroundColor = ConsoleColor.Red; log.Info($" ERROR: The GUID is missing in PSet!"); Console.ResetColor(); } } IfdConceptList ifdConceptList = _bsdd.SearchNests(pSet.Name); if (ifdConceptList == null) { log.Info($" Could not find the PSet in bSDD"); } else { numberOfPsetsWithbSDDGuid++; IfdConcept bsddPSet = ifdConceptList.IfdConcept.FirstOrDefault(); log.Info($" Loaded Property from bSDD (1 out of {ifdConceptList.IfdConcept.Count})"); log.Info($" Loaded PSet from bSDD"); log.Info($" Guid: {bsddPSet.Guid}"); log.Info($" Status: {bsddPSet.Status}"); log.Info($" VersionDate: {bsddPSet.VersionDate}"); log.Info($" Web: http://bsdd.buildingsmart.org/#concept/browse/{bsddPSet.Guid}"); if (ifdConceptList.IfdConcept.Count == 1) { log.Info($" The GUID of the PSet in the file was changed {propertySet.dictionaryReference.legacyGuid} => {bsddPSet.Guid}"); propertySet.dictionaryReference.ifdGuid = bsddPSet.Guid; } } propertySet.dictionaryReference.dictionaryWebUri = $"http://bsdd.buildingsmart.org/#concept/browse/{propertySet.dictionaryReference.ifdGuid}"; propertySet.dictionaryReference.dictionaryApiUri = $"http://bsdd.buildingsmart.org/api/4.0/IfdConcept/{propertySet.dictionaryReference.ifdGuid}"; log.Info($" Now checking the properties within the PSet"); propertySet.properties = LoadProperties(pSet, pSet.PropertyDefs); propertySet = Utils.PrepareTexts(propertySet); string targetFileYaml = sourceFile.Replace("xml", "YAML").Replace(sourceFolderXml, targetFolderYaml); string targetFileJson = sourceFile.Replace("xml", "json").Replace(sourceFolderXml, targetFolderJson); string targetFileResx = sourceFile.Replace("xml", "resx").Replace(sourceFolderXml, targetFolderResx); var ScalarStyleSingleQuoted = new YamlMemberAttribute() { ScalarStyle = ScalarStyle.SingleQuoted }; var yamlSerializer = new SerializerBuilder() //.WithNamingConvention(new CamelCaseNamingConvention()) .WithAttributeOverride <PropertySet>(nc => nc.name, ScalarStyleSingleQuoted) .WithAttributeOverride <PropertySet>(nc => nc.definition, ScalarStyleSingleQuoted) .WithAttributeOverride <Localization>(nc => nc.name, ScalarStyleSingleQuoted) .WithAttributeOverride <Localization>(nc => nc.definition, ScalarStyleSingleQuoted) .Build(); string yamlContent = yamlSerializer.Serialize(propertySet); File.WriteAllText(targetFileYaml, yamlContent, Encoding.UTF8); log.Info("The PSet was saved as YAML file"); JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings(); jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore; string jsonContent = JsonConvert.SerializeObject(propertySet, Formatting.Indented, jsonSerializerSettings); File.WriteAllText(targetFileJson, jsonContent, Encoding.UTF8); log.Info("The PSet was saved as JSON file"); var yamlDeserializer = new DeserializerBuilder() .Build(); try { propertySet = yamlDeserializer.Deserialize <PropertySet>(new StringReader(File.ReadAllText(targetFileYaml))); log.Info("The YAML file is valid"); } catch (Exception ex) { Console.Write(" ERROR!"); log.Info(ex.Message); } ResxWriter resx = new ResxWriter(targetFileResx); resx.Write(propertySet, StandardLanguages); log.Info("The PSet was saved as RESX file"); } log.Info($"Number of PSets: {numberOfPsets}"); log.Info($" with not resolved bSDD Guid: {numberOfPsetsWithbSDDGuid}"); log.Info($"Number of Properties: {numberOfProperties}"); log.Info($" with not resolved bSDD Guid: {numberOfPropertiesWithbSDDGuid}"); }
private List <Property> LoadProperties(PropertySetDef pset, List <PropertyDef> PropertyDefs) { List <Property> properties = new List <Property>(); foreach (PropertyDef psetProperty in PropertyDefs) { numberOfProperties++; log.Info(" ................."); int itemNumber = 0; foreach (var item in psetProperty.Items) { string ty = item.ToString(); if (item.ToString().Contains("PropertyType")) { break; } itemNumber++; } PropertyType psetValueType = (PropertyType)psetProperty.Items[itemNumber]; PropertyTypeTypePropertyBoundedValue psetBoundedValue = null; PropertyTypeTypeComplexProperty psetComplexProperty = null; PropertyTypeTypePropertyEnumeratedValue psetEnumeratedValue = null; PropertyTypeTypePropertyListValue psetListValue = null; PropertyTypeTypePropertyReferenceValue psetReferenceValue = null; PropertyTypeTypePropertySingleValue psetSingleValue = null; PropertyTypeTypePropertyTableValue psetTableValue = null; string valueTypeAsString = psetValueType.Item.ToString().Replace("PSet2YamlConverter.", ""); Property property = new Property() { name = psetProperty.Items[0].ToString(), dictionaryReference = new DictionaryReference() { dictionaryIdentifier = "http://bsdd.buildingsmart.org", dictionaryNamespace = "PSet", ifdGuid = "", legacyGuid = psetProperty.ifdguid, legacyGuidAsIfcGlobalId = Utils.GuidConverterToIfcGuid(psetProperty.ifdguid) }, definition = psetProperty.Items[2].ToString() }; log.Info($" Name: {property.name}"); if (CheckBSDD) { if (property.dictionaryReference.legacyGuidAsIfcGlobalId.Length == 0) { Console.ForegroundColor = ConsoleColor.Red; log.Info($" ERROR: The GUID for {property.name} is missing in PSet!"); Console.ResetColor(); } } if (CheckGuidWithBsdd(property.dictionaryReference.legacyGuidAsIfcGlobalId) == false) { Console.ForegroundColor = ConsoleColor.Red; log.Info($" ERROR: The GUID {property.dictionaryReference.legacyGuidAsIfcGlobalId} for {property.name} is not resolved by http://bsdd.buildingsmart.org"); Console.ResetColor(); IfdConceptList ifdConceptList = _bsdd.SearchProperties(pset.Name + "." + property.name); if (ifdConceptList == null) { log.Info($" Could not find the Property in bSDD"); } else { numberOfPropertiesWithbSDDGuid++; IfdConcept bsddProperty = ifdConceptList.IfdConcept.FirstOrDefault(); log.Info($" Loaded Property from bSDD (1 out of {ifdConceptList.IfdConcept.Count})"); log.Info($" Guid: {bsddProperty.Guid}"); log.Info($" Status: {bsddProperty.Status}"); log.Info($" VersionDate: {bsddProperty.VersionDate}"); log.Info($" Web: http://bsdd.buildingsmart.org/#concept/browse/{bsddProperty.Guid}"); foreach (var item in bsddProperty.FullNames) { int l = item.Language.LanguageCode.Length; string tab = new string(' ', 10 - l); log.Info($" Name {item.Language.LanguageCode}:{tab}{item.Name}"); } if (ifdConceptList.IfdConcept.Count == 1) { log.Info($" The GUID in the PSet file was changed {property.dictionaryReference.legacyGuid} => {bsddProperty.Guid}"); property.dictionaryReference.ifdGuid = bsddProperty.Guid; } } } else { Console.ForegroundColor = ConsoleColor.Green; log.Info($" OK: The GUID {property.dictionaryReference.legacyGuidAsIfcGlobalId} for {property.name} is properly resolved by http://bsdd.buildingsmart.org"); property.dictionaryReference.ifdGuid = property.dictionaryReference.legacyGuidAsIfcGlobalId; Console.ResetColor(); } property.dictionaryReference.dictionaryWebUri = $"http://bsdd.buildingsmart.org/#concept/browse/{property.dictionaryReference.ifdGuid}"; property.dictionaryReference.dictionaryApiUri = $"http://bsdd.buildingsmart.org/api/4.0/IfdConcept/{property.dictionaryReference.ifdGuid}"; property.localizations = new List <Localization>(); PropertyDefNameAliases nameAliases; if (psetProperty.Items.Length >= 4) { nameAliases = (PropertyDefNameAliases)psetProperty.Items[3]; PropertyDefDefinitionAliases definitionAliases = new PropertyDefDefinitionAliases(); if (psetProperty.Items.Length >= 5) { definitionAliases = (PropertyDefDefinitionAliases)psetProperty.Items[4]; } foreach (var alias in nameAliases.NameAlias) { property.localizations.Add(new Localization() { language = alias.lang, name = alias.Value ?? string.Empty, definition = definitionAliases.DefinitionAlias.Where(x => x.lang == alias.lang)?.FirstOrDefault()?.Value ?? string.Empty }); } } //Insert missing standard localizations as dummys foreach (string standardLanguage in StandardLanguages.OrderBy(x => x)) { if (property.localizations.Where(x => x.language == standardLanguage).FirstOrDefault() == null) { property.localizations.Add(new Localization() { language = standardLanguage, name = string.Empty, definition = string.Empty }); } } IfcDataType resultParseIfcDataType; ReferenceClass resultParseReferenceClass; switch (valueTypeAsString) { case "PropertyTypeTypePropertyBoundedValue": psetBoundedValue = (PropertyTypeTypePropertyBoundedValue)psetValueType.Item; property.typePropertyBoundedValue = new TypePropertyBoundedValue(); property.typePropertyBoundedValue.typeName = nameof(TypePropertyBoundedValue); Enum.TryParse(psetSingleValue?.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyBoundedValue.dataType = resultParseIfcDataType; property.typePropertyBoundedValue.unitType = psetBoundedValue.UnitType.ToString() ?? string.Empty; property.typePropertyBoundedValue.LowerBoundValue = psetBoundedValue.ValueRangeDef.LowerBoundValue.value?.ToString() ?? string.Empty; property.typePropertyBoundedValue.UpperBoundValue = psetBoundedValue.ValueRangeDef.UpperBoundValue.value?.ToString() ?? string.Empty; break; case "PropertyTypeTypeComplexProperty": psetComplexProperty = (PropertyTypeTypeComplexProperty)psetValueType.Item; property.typeComplexProperty = new TypeComplexProperty(); property.typeComplexProperty.name = psetComplexProperty.name ?? string.Empty; property.typeComplexProperty.subProperties = LoadProperties(pset, psetComplexProperty.PropertyDef); //Recursiv loading break; case "PropertyTypeTypePropertyEnumeratedValue": psetEnumeratedValue = (PropertyTypeTypePropertyEnumeratedValue)psetValueType.Item; property.typePropertyEnumeratedValue = new TypePropertyEnumeratedValue(); property.typePropertyEnumeratedValue.listName = psetEnumeratedValue.EnumList.name; property.typePropertyEnumeratedValue.enumerationValues = new List <EnumerationValue>(); foreach (var enumValue in psetEnumeratedValue.EnumList.EnumItem) { EnumerationValue enumerationValue = new EnumerationValue() { ifdGuid = string.Empty,// Utils.GuidConverterToIfcGuid(Guid.NewGuid().ToString()), name = Utils.CleanUp(enumValue), definition = string.Empty, localizations = new List <Localization>() }; foreach (string standardLanguage in StandardLanguages.OrderBy(x => x)) { enumerationValue.localizations.Add(new Localization() { language = standardLanguage, name = Utils.FirstUpperRestLower(enumValue.ToString()), definition = string.Empty }); } property.typePropertyEnumeratedValue.enumerationValues.Add(enumerationValue); } break; case "PropertyTypeTypePropertyListValue": psetListValue = (PropertyTypeTypePropertyListValue)psetValueType.Item; property.typePropertyListValue = new TypePropertyListValue(); Enum.TryParse(psetListValue?.ListValue.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyListValue.dataType = resultParseIfcDataType; property.typePropertyListValue.unitType = psetListValue?.ListValue.UnitType?.type.ToString() ?? string.Empty; property.typePropertyListValue.measureType = ""; if (psetListValue.ListValue.Values.ValueItem.Count > 0) { property.typePropertyListValue.listValues = new List <string>(); foreach (string valueItem in psetListValue.ListValue.Values.ValueItem) { property.typePropertyListValue.listValues.Add(valueItem); } } break; case "PropertyTypeTypePropertyReferenceValue": psetReferenceValue = (PropertyTypeTypePropertyReferenceValue)psetValueType.Item; property.typePropertyReferenceValue = new TypePropertyReferenceValue(); Enum.TryParse(psetReferenceValue.reftype.ToString() ?? string.Empty, out resultParseReferenceClass); property.typePropertyReferenceValue.refType = resultParseReferenceClass; if (property.typePropertyReferenceValue.refType.ToString().StartsWith("Ifc")) { property.typePropertyReferenceValue.guid = string.Empty; property.typePropertyReferenceValue.url = "http://buildingsmart-tech.org"; property.typePropertyReferenceValue.libraryName = "Industry Foundation Classes by buildingSMART International"; property.typePropertyReferenceValue.sectionref = "Core Schema"; } else { property.typePropertyReferenceValue.guid = string.Empty; property.typePropertyReferenceValue.url = string.Empty; property.typePropertyReferenceValue.libraryName = string.Empty; property.typePropertyReferenceValue.sectionref = string.Empty; } break; case "PropertyTypeTypePropertySingleValue": psetSingleValue = (PropertyTypeTypePropertySingleValue)psetValueType.Item; property.typePropertySingleValue = new TypePropertySingleValue(); Enum.TryParse(psetSingleValue?.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertySingleValue.dataType = resultParseIfcDataType; property.typePropertySingleValue.unitType = psetSingleValue?.UnitType?.type.ToString() ?? string.Empty; property.typePropertySingleValue.measureType = ""; break; case "PropertyTypeTypePropertyTableValue": psetTableValue = (PropertyTypeTypePropertyTableValue)psetValueType.Item; property.typePropertyTableValue = new TypePropertyTableValue(); property.typePropertyTableValue.Expression = psetTableValue.Expression; property.typePropertyTableValue.DefiningValue = new TableDefValues(); Enum.TryParse(psetTableValue?.DefiningValue?.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyTableValue.DefiningValue.dataType = resultParseIfcDataType; property.typePropertyTableValue.DefiningValue.unitType = psetTableValue?.DefiningValue.UnitType?.type.ToString() ?? string.Empty; property.typePropertyTableValue.DefiningValue.measureType = ""; property.typePropertyTableValue.DefinedValue = new TableDefValues(); Enum.TryParse(psetTableValue?.DefinedValue.DataType?.type.ToString() ?? string.Empty, out resultParseIfcDataType); property.typePropertyTableValue.DefinedValue.dataType = resultParseIfcDataType; property.typePropertyTableValue.DefinedValue.unitType = psetTableValue?.DefiningValue.UnitType?.type.ToString() ?? string.Empty; property.typePropertyTableValue.DefinedValue.measureType = ""; break; } ; property.status = new PublicationStatus() { versionNumber = 4, dateOfVersion = new DateTime(2018, 1, 1), revisionNumber = 2, dateOfRevision = new DateTime(2018, 1, 1), status = PublicationStatus.Status.Active.ToString(), dateOfCreation = new DateTime(2018, 1, 1), dateOfActivation = new DateTime(2018, 1, 1), dateOfLastChange = new DateTime(2018, 1, 1), languageOfCreator = "en-EN" }; properties.Add(property); } return(properties); }
public Converter(string sourceFolderXml, string targetFolderYaml, string targetFolderJson, bool checkBSDD = false) { Console.OutputEncoding = System.Text.Encoding.UTF8; CheckBSDD = checkBSDD; _bsdd = new Bsdd(); string propertySetVersionList = string.Empty; string propertySetTemplateList = string.Empty; string propertyTypeList = string.Empty; string propertyUnitList = string.Empty; foreach (string sourceFile in Directory.EnumerateFiles(sourceFolderXml, "PSet*.xml").OrderBy(x => x).ToList())//.Where(x=>x.Contains("Pset_ConstructionResource"))) { PropertySetDef pSet = PropertySetDef.LoadFromFile(sourceFile); Console.WriteLine("--------------------------------------------------"); Console.WriteLine($"Checking PSet {pSet.Name}"); Console.WriteLine($"Opened PSet-File {sourceFile.Replace(sourceFolderXml + @"\", string.Empty)}"); IfdConceptList ifdConceptList = _bsdd.SearchNests(pSet.Name); if (ifdConceptList == null) { Console.WriteLine($"Could not find the PSet in bSDD"); } else { IfdConcept bsddPSet = ifdConceptList.IfdConcept.FirstOrDefault(); Console.WriteLine($"Loaded PSet from bSDD"); Console.WriteLine($"Guid: {bsddPSet.Guid}"); Console.WriteLine($"Status: {bsddPSet.Status}"); Console.WriteLine($"VersionDate: {bsddPSet.VersionDate}"); } if (!propertySetVersionList.Contains(pSet.IfcVersion.version)) { propertySetVersionList += pSet.IfcVersion.version + ","; } if (!propertySetTemplateList.Contains(pSet.templatetype.ToString())) { propertySetTemplateList += pSet.templatetype.ToString() + ","; } PropertySet propertySet = new PropertySet() { name = pSet.Name, ifdGuid = "", legacyGuid = "", ifcVersion = new IfcVersion() { version = ConvertToSematicVersion(pSet.IfcVersion.version).ToString(), schema = pSet.IfcVersion.schema }, definition = pSet.Definition }; propertySet.applicableIfcClasses = new List <ApplicableIfcClass>(); foreach (var applicableClass in pSet.ApplicableClasses) { propertySet.applicableIfcClasses.Add(new ApplicableIfcClass() { name = applicableClass, type = pSet.ApplicableTypeValue }); } //Insert missing standard localizations as dummys propertySet.localizations = new List <Localization>(); foreach (string standardLanguage in StandardLanguages.OrderBy(x => x)) { if (propertySet.localizations.Where(x => x.language == standardLanguage).FirstOrDefault() == null) { propertySet.localizations.Add(new Localization() { language = standardLanguage, name = string.Empty, definition = string.Empty }); } } Console.WriteLine($"Now checking the properties within the PSet"); propertySet.properties = LoadProperties(pSet, pSet.PropertyDefs); propertySet = Utils.PrepareTexts(propertySet); string targetFileYaml = sourceFile.Replace("xml", "YAML").Replace(sourceFolderXml, targetFolderYaml); string targetFileJson = sourceFile.Replace("xml", "json").Replace(sourceFolderXml, targetFolderJson); //Console.WriteLine($" Writing {targetFileYaml.Replace(targetFolderYaml + @"\", string.Empty)}"); //Console.WriteLine($" Writing {targetFileJson.Replace(targetFolderJson + @"\", string.Empty)}"); var ScalarStyleSingleQuoted = new YamlMemberAttribute() { ScalarStyle = ScalarStyle.SingleQuoted }; var yamlSerializer = new SerializerBuilder() //.WithNamingConvention(new CamelCaseNamingConvention()) .WithAttributeOverride <PropertySet>(nc => nc.name, ScalarStyleSingleQuoted) .WithAttributeOverride <PropertySet>(nc => nc.definition, ScalarStyleSingleQuoted) .WithAttributeOverride <Localization>(nc => nc.name, ScalarStyleSingleQuoted) .WithAttributeOverride <Localization>(nc => nc.definition, ScalarStyleSingleQuoted) .Build(); string yamlContent = yamlSerializer.Serialize(propertySet); File.WriteAllText(targetFileYaml, yamlContent, Encoding.UTF8); Console.WriteLine("The PSet was saved as YAML file"); JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings(); jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); jsonSerializerSettings.NullValueHandling = NullValueHandling.Ignore; string jsonContent = JsonConvert.SerializeObject(propertySet, Formatting.Indented, jsonSerializerSettings); File.WriteAllText(targetFileJson, jsonContent, Encoding.UTF8); Console.WriteLine("The PSet was saved as JSON file"); var yamlDeserializer = new DeserializerBuilder() .Build(); try { propertySet = yamlDeserializer.Deserialize <PropertySet>(new StringReader(File.ReadAllText(targetFileYaml))); Console.WriteLine("The YAML file is valid"); } catch (Exception ex) { Console.Write(" ERROR!"); Console.WriteLine(ex.Message); } } Console.WriteLine($"Used Versions in PSets: {propertySetVersionList}"); Console.WriteLine($"Used Templates in PSets: {propertySetTemplateList}"); Console.WriteLine($"Used PropertyTypes: {propertyTypeList}"); Console.WriteLine($"Used Units: {propertyUnitList}"); }
static void Main(string[] args) { Console.WriteLine("bsDD.NET started"); Console.WriteLine("bsDD.NET is s simple example to connect to buildingSMART Data Dictionary via C#"); Console.WriteLine("For further information look at http://bsdd.buildingsmart.org/docs/"); Console.WriteLine("Now, please enter your bsDD Credentials"); Console.Write("eMail:"); string email = Console.ReadLine(); Console.Write("Password:"******"Put here your bsDD-eMail"; //password = "******"; //Debug if ((email.Length > 1) && (password.Length > 1)) //TODO Check Exceptions on empty or invalid credentials { bsdd _bsdd = new bsdd(email, password); Console.WriteLine("Connected to bsDD: " + _bsdd.BaseUrl); Console.WriteLine("Session: " + _bsdd.Session.Guid); Console.WriteLine("User: "******" (" + _bsdd.Session.User.PreferredOrganization + ")"); Console.WriteLine("Group: " + _bsdd.Session.User.MemberOf.Name); Console.WriteLine("Role: " + _bsdd.Session.User.Role); Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++++++"); string mode; do { Console.WriteLine("What do you want to do?"); Console.WriteLine("Press sn to search for names"); Console.WriteLine("Press co to search for concepts"); Console.WriteLine("Press ex to exit"); mode = Console.ReadLine(); switch (mode) { case "sn": Console.WriteLine("Now, you can search in the dictionary"); Console.Write("Please enter a search phrase for a name: "); string searchnamestring = Console.ReadLine(); IfdNameList Names = _bsdd.SearchNames(searchnamestring); if (Names == null) { Console.WriteLine("no result could be found in this search, please try another name"); } else { Console.WriteLine(Names.IfdName.Count.ToString() + " result(s) found"); Console.WriteLine("++++++++"); foreach (IfdName name in Names.IfdName) { Console.WriteLine("IfdName.Guid: " + name.Guid); Console.WriteLine("IfdName.Language: " + name.Language.LanguageCode + " ()" + name.Language.NameInSelf); Console.WriteLine("IfdName.LanguageFamily: " + name.LanguageFamily); Console.WriteLine("IfdName.NameType: " + name.NameType); Console.WriteLine("++++++++"); } } break; case "co": Console.WriteLine("Now, you can search in the dictionary"); Console.Write("Please enter a search phrase for a concept: "); string searchconceptstring = Console.ReadLine(); IfdConceptList Concepts = _bsdd.SearchConcepts(searchconceptstring); if (Concepts == null) { Console.WriteLine("no result could be found in this search, please try another name"); } else { Console.WriteLine(Concepts.IfdConcept.Count.ToString() + " result(s) found"); foreach (IfdConcept concept in Concepts.IfdConcept.OrderByDescending(x => x.VersionDate)) { WriteToColoredConsole("IfdConcept.Guid: " + concept.Guid, ConsoleColor.Blue, ConsoleColor.White); WriteToColoredConsole("IfdConcept.ConceptType: " + concept.ConceptType); WriteToColoredConsole("IfdConcept.Status: " + concept.Status); WriteToColoredConsole("IfdConcept.VersionId: " + concept.VersionId); CultureInfo ci = new CultureInfo("de-DE"); WriteToColoredConsole("IfdConcept.VersionDate: " + concept.VersionDate.ToString(ci)); if (concept.FullNames != null) { foreach (IfdName fullname in concept.FullNames.OrderBy(x => x.Language.LanguageCode)) { WriteToColoredConsole("LanguageCode: " + fullname.Language.LanguageCode, ConsoleColor.Yellow, ConsoleColor.Black); WriteToColoredConsole("IfdConcept.FullNames: " + fullname.Guid + " / " + fullname.Name, ConsoleColor.DarkGray, ConsoleColor.Black); if (concept.ShortNames != null) { foreach (IfdName shortname in concept.ShortNames) { if (shortname.Language.Guid == fullname.Language.Guid) { WriteToColoredConsole("IfdConcept.ShortNames: " + shortname.Guid + " / " + shortname.Name); } } } if (concept.Definitions != null) { foreach (IfdDescription description in concept.Definitions) { if (description.Language.Guid == fullname.Language.Guid) { WriteToColoredConsole("IfdConcept.Definitions: " + description.Guid + " / " + " / " + Regex.Replace(description.Description, @"\r\n?|\n", " ")); } } } } } } } break; case "ex": Console.Write("Finished, Prese Enter to exit:"); break; default: Console.WriteLine("This Mode is not valid, please try again."); break; } } while (mode != "ex"); Console.ReadLine(); Console.ResetColor(); } }
public int Workspace(string folderYaml, string bsddUrl, string bsddUser, string bsddPassword, string languageCode) { log.Info($"Upload the texts to concepts in the buildingSMART Data Dictionary (bSDD) from this source: {folderYaml}"); if (folderYaml != null) { if (!Directory.Exists(folderYaml)) { log.Error($"ERROR - The Directory {folderYaml} does not exist. Exiting!"); return(1); } } Bsdd bsdd = new Bsdd(bsddUrl, bsddUser, bsddPassword); log.Info($"Successfully logged in, into bSDD at {bsddUrl}"); var yamlFileNames = Directory.EnumerateFiles(folderYaml, "PSet*.YAML");//.Where(x => x.Contains("Pset_StairCommon")); //A dirty trick to get all PSets done within one hour (the build time of Appveyor is limited to one hour) //Travers randomly the list of the PSet in ascending or descending order Random rand = new Random(); if (rand.Next(0, 2) == 0) { yamlFileNames = yamlFileNames.OrderBy(x => x); } else { yamlFileNames = yamlFileNames.OrderByDescending(x => x); } int ctPSets = 0; int ctProperties = 0; int ctPropertiesWithMissingTranslation = 0; int ctPropertiesWithMissingGuid = 0; foreach (string yamlFileName in yamlFileNames) { ctPSets++; log.Info($"--------------------------------------------------------------------------------------------------------"); log.Info($"--------------------------------------------------------------------------------------------------------"); log.Info($"Loading PSet {ctPSets}/{yamlFileNames.Count()}"); var yamlDeserializer = new DeserializerBuilder().Build(); PropertySet PSet; try { PSet = yamlDeserializer.Deserialize <PropertySet>(new StringReader(File.ReadAllText(yamlFileName))); log.Info($"Opened the YAML file {yamlFileName}"); log.Info($"--------------------------------------------------------------------------------------------------------"); log.Info($"--------------------------------------------------------------------------------------------------------"); log.Info($"Now checking the PSet {PSet.name} in the bSDD at {PSet.dictionaryReference.ifdGuid}"); IfdConcept pSetConcept = bsdd.GetConcept(PSet.dictionaryReference.ifdGuid); if (pSetConcept != null) { log.Info($"Ok, the PSet lives here: {bsddUrl}/#concept/browse/{pSetConcept.Guid}"); log.Info($"Status: {pSetConcept.Status}"); //Localisations of the PSet foreach (var localization in PSet.localizations .Where(x => x.language.ToLower() == languageCode.ToLower()) .Where(x => x.name.Length > 0)) { log.Info($"Publishing PSet {PSet.name} for language {localization.language}"); var existingFullName = pSetConcept.FullNames.Where(x => x.Language.LanguageCode.ToLower() == localization.language.ToLower()).FirstOrDefault(); //Dirty fix for https://github.com/buildingSMART/bSDD/issues/11 localization.name = localization.name.Replace(" ", " "); if (existingFullName == null) { log.Info($" Insert Name for concept => {localization.name}"); var answer = bsdd.InsertConceptName(pSetConcept.Guid, localization.language, localization.name); log.Info($" Succesfully inserted => {answer.Guid}"); } else { log.Info($" Existing Translation for name {existingFullName.Language.LanguageCode}"); log.Info($" NameType : {existingFullName.NameType}"); if (existingFullName.Name != localization.name) { log.Warn($" Update: {existingFullName.Name}=>{localization.name}"); var answer = bsdd.UpdateConceptName(pSetConcept.Guid, existingFullName.Guid, localization.language, localization.name); log.Warn($" Succesfully update => {answer.Guid}"); } else { log.Info($" No Update needed, the names are identical: {existingFullName.Guid}"); } } var existingDefinition = pSetConcept.Definitions.Where(x => x.Language.LanguageCode.ToLower() == localization.language.ToLower()).FirstOrDefault(); //Dirty fix for https://github.com/buildingSMART/bSDD/issues/11 localization.definition = localization.definition.Replace(" ", " "); if (existingDefinition == null) { log.Warn($" Insert description for concept : '{localization.definition}'"); var answer = bsdd.InsertConceptDefinition(pSetConcept.Guid, localization.language, localization.definition); log.Warn($" Succesfully inserted => {answer.Guid}"); } else { log.Info($" Existing Translation for description {existingDefinition.Language.LanguageCode}"); log.Info($" DescriptionType : {existingDefinition.DescriptionType}"); if (existingDefinition.Description != localization.definition) { log.Warn($" Update: {existingDefinition.Description}=>{localization.definition}"); var answer = bsdd.UpdateConceptDefinition(pSetConcept.Guid, existingDefinition.Guid, localization.language, localization.definition); log.Warn($" Succesfully update => {answer.Guid}"); } else { log.Info($" No Update needed, the definitions are identical: {existingDefinition.Guid}"); } } } //Now traversing the properties of the PSet foreach (var property in PSet.properties) { log.Info($"--------------------------------------------------------------------------------------------------------"); ctProperties++; log.Info($"Loading property #{ctProperties}"); IfdConcept propertyConcept = bsdd.GetConcept(property.dictionaryReference.ifdGuid); if (propertyConcept != null) { log.Info($"Ok, the property '{property.name}' lives here: {bsddUrl}/#concept/browse/{propertyConcept.Guid}"); log.Info($"Status: {propertyConcept.Status}"); //Check, if the property is correctly related to its PSet //If not, fix the relation bool isRelated = bsdd.RelatePropertyToPSet(psetGuid: pSetConcept.Guid, propertyGuid: propertyConcept.Guid, relationContextGuid: GuidOfIfc4Context); if (isRelated) { log.Info($"The property is correctly related to its PSet"); } else { log.Warn($"The relation of the property to its PSet was now inserted with the relationshipType='COLLECTS'."); } //Localizations of the Property var propertyLocalizations = property.localizations .Where(x => x.language.ToLower() == languageCode.ToLower()) .Where(x => x.name.Length > 0); if (propertyLocalizations.Count() == 0) { ctPropertiesWithMissingTranslation++; log.Error($"ERROR: Translation missing for {PSet.name}.{property.name} into {languageCode}"); } else { foreach (var localization in propertyLocalizations) { log.Info($"Publishing the Property for language {localization.language}"); { //managing the names of the property //Dirty fix for https://github.com/buildingSMART/bSDD/issues/11 localization.name = localization.name.Replace(" ", " "); var existingNames = propertyConcept.FullNames.Where(x => x.Language.LanguageCode.ToLower() == localization.language.ToLower()).ToList(); if (existingNames.Count == 0) { log.Warn($" No name exists for the language {localization.language}"); log.Warn($" Insert this name as the first name : '{localization.name}'"); if (localization.name.Length > 0) { var answer = bsdd.InsertConceptName(propertyConcept.Guid, localization.language, localization.name); log.Warn($" Succesfully inserted first name with GUID {answer.Guid} for the concept {propertyConcept.Guid}"); } else { ctPropertiesWithMissingTranslation++; log.Error($" ERROR: Translation of name missing for {PSet.name}.{property.name} into {languageCode}"); } } else { log.Info($" There exists {existingNames.Count()} name(s) for the concept {propertyConcept.Guid} in the language {localization.language}"); //INTERNAL REMARK: In the context of IFC should only exist one name per concept and language, // even when the data model of IFD allows more than one name // So, we check, if the name allready exists, and if not, // then we insert the new name and delete all existing name for this language and concept //TECHNICAL REMARK: Since at leat one name mus exist, we have to insert first the new name, if is does not // allready exist, and then delete all other names for this concept and language string guidOfExistingName = null; string guidOfNewName = null; if (existingNames.Select(x => x.Name).ToList().Contains(localization.name)) { guidOfExistingName = existingNames.Where(x => x.Name == localization.name).FirstOrDefault().Guid; log.Info($" The name already exists with the GUID {guidOfExistingName} : '{localization.name}'"); log.Info($" No insertion needed"); } else { log.Warn($" The name does not exist, inserting it now : '{localization.name}'"); var answer = bsdd.InsertConceptName(propertyConcept.Guid, localization.language, localization.name); guidOfNewName = answer.Guid; log.Warn($" Succesfully inserted with the GUID {guidOfNewName}"); } foreach (var name in existingNames.Where(x => x.Guid != guidOfExistingName).Where(y => y.Guid != guidOfNewName)) { log.Warn($" Deleting old name with GUID {name.Guid} : '{name.Name}'"); var answer = bsdd.DeleteConceptName(propertyConcept.Guid, name.Guid); } } } { //Managing the definitions of the property //Dirty fix for https://github.com/buildingSMART/bSDD/issues/11 localization.definition = localization.definition.Replace(" ", " "); var existingDefinitions = propertyConcept.Definitions.Where(x => x.Language.LanguageCode.ToLower() == localization.language.ToLower()).ToList(); if (existingDefinitions.Count() == 0) { log.Warn($" No description exists for the language {localization.language}"); log.Warn($" Insert this description as the first description : '{localization.definition}'"); if (localization.definition.Length > 0) { var answer = bsdd.InsertConceptDefinition(propertyConcept.Guid, localization.language, localization.definition); log.Warn($" Succesfully inserted first description with GUID {answer.Guid} for the concept {propertyConcept.Guid}"); } else { ctPropertiesWithMissingTranslation++; log.Error($" ERROR: Translation of definition missing for {PSet.name}.{property.name} into {languageCode}"); } } else { log.Info($" There exists {existingDefinitions.Count()} description(s) for the concept {propertyConcept.Guid} in the language {localization.language}"); string guidOfExistingDefinition = null; string guidOfNewDefinition = null; if (existingDefinitions.Select(x => x.Description).ToList().Contains(localization.definition)) { guidOfExistingDefinition = existingDefinitions.Where(x => x.Description == localization.definition).FirstOrDefault().Guid; log.Info($" The description already exists with the GUID {guidOfExistingDefinition} : '{localization.definition}'"); log.Info($" No insertion needed"); } else { log.Warn($" The description does not exist, inserting it now : '{localization.definition}'"); var answer = bsdd.InsertConceptDefinition(propertyConcept.Guid, localization.language, localization.definition); guidOfNewDefinition = answer.Guid; log.Warn($" Succesfully inserted with the GUID {guidOfNewDefinition}"); } foreach (var definition in existingDefinitions.Where(x => x.Guid != guidOfExistingDefinition).Where(y => y.Guid != guidOfNewDefinition)) { log.Warn($" Deleting old description with GUID {definition.Guid} : '{definition.Description}'"); var answer = bsdd.DeleteConceptDescription(propertyConcept.Guid, definition.Guid); } } } } } if (propertyConcept.Status != IfdStatusEnum.APPROVED) { bsdd.UpdateConceptStatus(propertyConcept.Guid, IfdStatusEnum.APPROVED); log.Warn($" Succesfully updated the status of the Property concept {propertyConcept.Guid} to APPROVED"); } } else { ctPropertiesWithMissingGuid++; log.Error($"ERROR: The property '{property.name}' cannot be found in the bSDD!"); if (property.dictionaryReference.ifdGuid.Length == 0) { log.Error($"ERROR: The property '{PSet.name}.{property.name}' has no ifdGuid in the YAML file."); log.Warn($"Please search the GUID for the property in the bSDD and insert it into the YAML file."); log.Warn($"Then store the file to GitHub(e.g.with a pull request)"); log.Warn($"ERROR: Now I am making a search for you on the bSDD for possible concepts with the term '{property.name}'"); IfdConceptList possibleConcepts = bsdd.SearchConcepts(property.name); if (possibleConcepts == null) { log.Warn($" no terms found"); } else { log.Warn($" {possibleConcepts.IfdConcept.Count()} terms found, showing the first 15"); foreach (var possibleConcept in possibleConcepts.IfdConcept.Where(x => x.Definitions != null).OrderBy(x => x.Status.ToString()).Take(15)) { log.Warn($" Found: {possibleConcept.Status} : {possibleConcept.ConceptType} - {possibleConcept.Guid} : {possibleConcept.Definitions.FirstOrDefault().Description}"); } log.Warn($"{possibleConcepts.IfdConcept.Count()} Concepts found - You could pick up one of these for your property..."); } } } } log.Info($"--------------------------------------------------------------------------------------------------------"); if (pSetConcept.Status != IfdStatusEnum.APPROVED) { bsdd.UpdateConceptStatus(pSetConcept.Guid, IfdStatusEnum.APPROVED); log.Warn($" Succesfully updated the status of the PSet concept {pSetConcept.Guid} to APPROVED"); } } } catch (Exception ex) { log.Error(ex.Message); return(1); } } log.Warn($"Published {ctPSets} PSets with {ctProperties} Properties."); log.Warn($"{ctPropertiesWithMissingTranslation} translations missing."); log.Warn($"{ctPropertiesWithMissingGuid} guid missing."); return(ctPropertiesWithMissingTranslation + ctPropertiesWithMissingGuid); }