Exemple #1
0
 static VDI2770v11()
 {
     Static = new VDI2770v11();
     Static.ReadLibrary(
         Assembly.GetExecutingAssembly(), "AasxPredefinedConcepts.Resources." + "VDI2770v11.json");
     Static.RetrieveEntriesByReflection(typeof(VDI2770v11), useFieldNames: true);
 }
Exemple #2
0
        public static ListOfDocumentEntity ParseSubmodelForV11(
            AdminShellPackageEnv thePackage,
            AdminShell.Submodel subModel, AasxPredefinedConcepts.VDI2770v11 defs11,
            string defaultLang,
            int selectedDocClass, AasxLanguageHelper.LangEnum selectedLanguage)
        {
            // set a new list
            var its = new ListOfDocumentEntity();

            if (thePackage == null || subModel == null || defs11 == null)
            {
                return(its);
            }

            // look for Documents
            if (subModel.submodelElements != null)
            {
                foreach (var smcDoc in
                         subModel.submodelElements.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                             defs11.CD_Document?.GetReference(), AdminShellV20.Key.MatchMode.Relaxed))
                {
                    // access
                    if (smcDoc == null || smcDoc.value == null)
                    {
                        continue;
                    }

                    // look immediately for DocumentVersion, as only with this there is a valid List item
                    foreach (var smcVer in
                             smcDoc.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                                 defs11.CD_DocumentVersion?.GetReference(), AdminShellV20.Key.MatchMode.Relaxed))
                    {
                        // access
                        if (smcVer == null || smcVer.value == null)
                        {
                            continue;
                        }

                        //
                        // try to lookup info in smcDoc and smcVer
                        //

                        // take the 1st title
                        var title = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defs11.CD_Title?.GetReference(), AdminShellV20.Key.MatchMode.Relaxed)?.value;

                        // could be also a multi-language title
                        foreach (var mlp in
                                 smcVer.value.FindAllSemanticIdAs <AdminShell.MultiLanguageProperty>(
                                     defs11.CD_Title?.GetReference(), AdminShellV20.Key.MatchMode.Relaxed))
                        {
                            if (mlp.value != null)
                            {
                                title = mlp.value.GetDefaultStr(defaultLang);
                            }
                        }

                        // have multiple opportunities for orga
                        var orga = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defs11.CD_OrganizationOfficialName?.GetReference(),
                            AdminShellV20.Key.MatchMode.Relaxed)?.value;
                        if (orga.Trim().Length < 1)
                        {
                            orga = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defs11.CD_OrganizationName?.GetReference(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value;
                        }

                        // try find language
                        // collect country codes
                        var countryCodesStr  = new List <string>();
                        var countryCodesEnum = new List <AasxLanguageHelper.LangEnum>();
                        foreach (var cclp in
                                 smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(defs11.CD_Language?.GetReference(),
                                                                                        AdminShellV20.Key.MatchMode.Relaxed))
                        {
                            // language code
                            var candidate = "" + cclp.value;
                            if (candidate.Length < 1)
                            {
                                continue;
                            }

                            // convert to country codes and add
                            var le = AasxLanguageHelper.FindLangEnumFromLangCode(candidate);
                            if (le != AasxLanguageHelper.LangEnum.Any)
                            {
                                countryCodesEnum.Add(le);
                                countryCodesStr.Add(AasxLanguageHelper.GetCountryCodeFromEnum(le));
                            }
                        }

                        var okLanguage =
                            (selectedLanguage == AasxLanguageHelper.LangEnum.Any ||
                             countryCodesEnum == null ||
                             // make only exception, if no language not all (not only the preferred
                             // of LanguageSelectionToISO639String) are in the property
                             countryCodesStr.Count < 1 ||
                             countryCodesEnum.Contains(selectedLanguage));

                        // try find a 2770 classification
                        var okDocClass = false;
                        foreach (var smcClass in
                                 smcDoc.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                                     defs11.CD_DocumentClassification?.GetReference(), AdminShellV20.Key.MatchMode.Relaxed))
                        {
                            // access
                            if (smcClass?.value == null)
                            {
                                continue;
                            }

                            // shall be a 2770 classification
                            var classSys = "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defs11.CD_ClassificationSystem?.GetReference(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value;
                            if (classSys.ToLower().Trim() != DefinitionsVDI2770.Vdi2770Sys.ToLower())
                            {
                                continue;
                            }

                            // class infos
                            var classId = "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defs11.CD_ClassId?.GetReference(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value;

                            // evaluate, if in selection
                            okDocClass = okDocClass ||
                                         (classId.Trim().Length < 1 ||
                                          classId.Trim()
                                          .StartsWith(
                                              DefinitionsVDI2770.GetDocClass(
                                                  (DefinitionsVDI2770.Vdi2770DocClass)selectedDocClass)));
                        }

                        // success for selections?
                        if (!(selectedDocClass < 1 || okDocClass) || !okLanguage)
                        {
                            continue;
                        }

                        // further info
                        var further = "";
                        foreach (var fi in
                                 smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(
                                     defs11.CD_DocumentVersionId?.GetReference()))
                        {
                            further += "\u00b7 version: " + fi.value;
                        }
                        foreach (var fi in
                                 smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(
                                     defs11.CD_DocumentIdValue?.GetReference()))
                        {
                            further += "\u00b7 id: " + fi.value;
                        }
                        foreach (var fi in
                                 smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(defs11.CD_SetDate?.GetReference(),
                                                                                        AdminShellV20.Key.MatchMode.Relaxed))
                        {
                            further += "\u00b7 date: " + fi.value;
                        }
                        if (further.Length > 0)
                        {
                            further = further.Substring(2);
                        }

                        // construct entity
                        var ent = new DocumentEntity(title, orga, further, countryCodesStr.ToArray());
                        ent.ReferableHash = String.Format(
                            "{0:X14} {1:X14}", thePackage.GetHashCode(), smcDoc.GetHashCode());

                        // for updating data, set the source elements of this document entity
                        ent.SourceElementsDocument        = smcDoc.value;
                        ent.SourceElementsDocumentVersion = smcVer.value;

                        // file informations
                        var fl = smcVer.value.FindFirstSemanticIdAs <AdminShell.File>(
                            defs11.CD_DigitalFile?.GetReference(), AdminShellV20.Key.MatchMode.Relaxed);
                        if (fl != null)
                        {
                            ent.DigitalFile = new DocumentEntity.FileInfo(fl);
                        }

                        fl = smcVer.value.FindFirstSemanticIdAs <AdminShell.File>(
                            defs11.CD_PreviewFile?.GetReference(), AdminShellV20.Key.MatchMode.Relaxed);
                        if (fl != null)
                        {
                            ent.PreviewFile = new DocumentEntity.FileInfo(fl);
                        }

                        // relations
                        SearchForRelations(smcVer.value, DocumentEntity.DocRelationType.DocumentedEntity,
                                           defs11.CD_DocumentedEntity?.GetReference(), ent);
                        SearchForRelations(smcVer.value, DocumentEntity.DocRelationType.RefersTo,
                                           defs11.CD_RefersTo?.GetReference(), ent);
                        SearchForRelations(smcVer.value, DocumentEntity.DocRelationType.BasedOn,
                                           defs11.CD_BasedOn?.GetReference(), ent);
                        SearchForRelations(smcVer.value, DocumentEntity.DocRelationType.TranslationOf,
                                           defs11.CD_TranslationOf?.GetReference(), ent);

                        // add
                        ent.SmVersion = DocumentEntity.SubmodelVersion.V11;
                        its.Add(ent);
                    }
                }
            }

            // ok
            return(its);
        }