Exemple #1
0
        private static AdminShellV20.AdministrationShell CreateAdminShell(AdminShellV20.AdministrationShellEnv env)
        {
            var adminShell = new AdminShellV20.AdministrationShell()
            {
                identification = new AdminShellV20.Identification(
                    AdminShellV20.Identification.IRI,
                    AdminShellUtil.GenerateIdAccordingTemplate(Options.Curr.TemplateIdAas))
            };

            env.AdministrationShells.Add(adminShell);
            return(adminShell);
        }
Exemple #2
0
        public static AdminShellV20.Submodel CreateSubmodel(
            AdminShellV20.AdministrationShellEnv env,
            AdminShellV20.AdministrationShell adminShell, Iec61360Data data)
        {
            // We need this to ensure that we don't use the same AAS ID twice when importing multiple submodels (as
            // GenerateIdAccordingTemplate uses the timestamp as part of the ID).
            Thread.Sleep(1000);
            var submodel = new AdminShellV20.Submodel()
            {
                identification = new AdminShellV20.Identification(
                    AdminShell.Identification.IRI,
                    AdminShellUtil.GenerateIdAccordingTemplate(Options.Curr.TemplateIdSubmodelInstance)),
                idShort = data.IdShort,
                kind    = AdminShellV20.ModelingKind.CreateAsInstance(),
            };

            AddDescriptions(submodel, data);
            AddDataSpecification(env, submodel, data);

            adminShell.AddSubmodelRef(submodel.GetReference() as AdminShellV20.SubmodelRef);
            env.Submodels.Add(submodel);

            return(submodel);
        }
Exemple #3
0
        //
        // Identifiable
        //

        public void DisplayOrEditEntityIdentifiable(AnyUiStackPanel stack,
                                                    AdminShell.Identifiable identifiable,
                                                    string templateForIdString,
                                                    DispEditInjectAction injectToId = null,
                                                    bool checkForIri = true)
        {
            // access
            if (stack == null || identifiable == null)
            {
                return;
            }

            // members
            this.AddGroup(stack, "Identifiable:", levelColors.SubSection);

            this.AddHintBubble(stack, hintMode, new[] {
                new HintCheck(
                    () => { return(identifiable.identification == null); },
                    "Providing a worldwide unique identification is mandatory.",
                    breakIfTrue: true),
                new HintCheck(
                    () => { return(checkForIri &&
                                   identifiable.identification.idType != AdminShell.Identification.IRI); },
                    "Check if identification type is correct. Use of IRIs is usual here.",
                    severityLevel: HintCheck.Severity.Notice),
                new HintCheck(
                    () => { return(identifiable.identification.id.Trim() == ""); },
                    "Identification id shall not be empty. You could use the 'Generate' button in order to " +
                    "generate a worldwide unique id. " +
                    "The template of this id could be set by commandline arguments.")
            });
            if (this.SafeguardAccess(
                    stack, repo, identifiable.identification, "identification:", "Create data element!",
                    v =>
            {
                identifiable.identification = new AdminShell.Identification();
                this.AddDiaryEntry(identifiable, new DiaryEntryStructChange());
                return(new AnyUiLambdaActionRedrawEntity());
            }))
            {
                this.AddKeyValueRef(
                    stack, "idType", identifiable, ref identifiable.identification.idType, null, repo,
                    v =>
                {
                    var dr = new DiaryReference(identifiable);
                    identifiable.identification.idType = v as string;
                    this.AddDiaryEntry(identifiable, new DiaryEntryStructChange(), diaryReference: dr);
                    return(new AnyUiLambdaActionNone());
                },
                    comboBoxItems: AdminShell.Key.IdentifierTypeNames);

                this.AddKeyValueRef(
                    stack, "id", identifiable, ref identifiable.identification.id, null, repo,
                    v =>
                {
                    var dr = new DiaryReference(identifiable);
                    identifiable.identification.id = v as string;
                    this.AddDiaryEntry(identifiable, new DiaryEntryStructChange(), diaryReference: dr);
                    return(new AnyUiLambdaActionNone());
                },
                    auxButtonTitles: DispEditInjectAction.GetTitles(new[] { "Generate" }, injectToId),
                    auxButtonLambda: (i) =>
                {
                    if (i == 0)
                    {
                        var dr = new DiaryReference(identifiable);
                        identifiable.identification.idType = AdminShell.Identification.IRI;
                        identifiable.identification.id     = AdminShellUtil.GenerateIdAccordingTemplate(
                            templateForIdString);
                        this.AddDiaryEntry(identifiable, new DiaryEntryStructChange(), diaryReference: dr);
                        return(new AnyUiLambdaActionRedrawAllElements(nextFocus: identifiable));
                    }
                    if (i >= 1)
                    {
                        var la = injectToId?.auxLambda?.Invoke(i - 1);
                        return(la);
                    }
                    return(new AnyUiLambdaActionNone());
                });
            }

            this.AddHintBubble(stack, hintMode, new[] {
                new HintCheck(
                    () => { return(identifiable.administration == null); },
                    "Check if providing admistrative information on version/ revision would be useful. " +
                    "This allows for better version management.",
                    breakIfTrue: true,
                    severityLevel: HintCheck.Severity.Notice),
                new HintCheck(
                    () =>
                {
                    return(identifiable.administration.version.Trim() == "" ||
                           identifiable.administration.revision.Trim() == "");
                },
                    "Admistrative information fields should not be empty.",
                    severityLevel: HintCheck.Severity.Notice)
            });
            if (this.SafeguardAccess(
                    stack, repo, identifiable.administration, "administration:", "Create data element!",
                    v =>
            {
                identifiable.administration = new AdminShell.Administration();
                this.AddDiaryEntry(identifiable, new DiaryEntryStructChange());
                return(new AnyUiLambdaActionRedrawEntity());
            }))
            {
                this.AddKeyValueRef(
                    stack, "version", identifiable.administration, ref identifiable.administration.version,
                    null, repo,
                    v =>
                {
                    identifiable.administration.version = v as string;
                    this.AddDiaryEntry(identifiable, new DiaryEntryStructChange());
                    return(new AnyUiLambdaActionNone());
                });

                this.AddKeyValueRef(
                    stack, "revision", identifiable.administration, ref identifiable.administration.revision,
                    null, repo,
                    v =>
                {
                    identifiable.administration.revision = v as string;
                    this.AddDiaryEntry(identifiable, new DiaryEntryStructChange());
                    return(new AnyUiLambdaActionNone());
                });
            }
        }
        protected ContextResult CreateBodyCD(
            ImportCellMatchContextBase context,
            AdminShell.AdministrationShellEnv env)
        {
            // access
            if (context?.Sme == null || context?.CD == null || env == null || _options == null)
            {
                return(null);
            }

            // first test, if the CD already exists
            var test = env.FindConceptDescription(context.Sme.semanticId);

            if (test != null)
            {
                return new ContextResult()
                       {
                           Elem = test
                       }
            }
            ;

            // a semanticId is required to link the Sme and the CD together
            if (context.Sme.semanticId == null || context.Sme.semanticId.Count < 1)
            {
                // generate a new one for SME + CD
                // this modifies the SME!
                var id = new AdminShell.Identification(
                    AdminShell.Identification.IRI,
                    AdminShellUtil.GenerateIdAccordingTemplate(_options.TemplateIdConceptDescription));

                context.Sme.semanticId = new AdminShell.SemanticId(
                    new AdminShell.Key(AdminShell.Key.ConceptDescription, true, id.idType, id.id));
            }

            // create, add
            var cd = new AdminShell.ConceptDescription(context?.CD);

            env.ConceptDescriptions.Add(cd);
            var res = new ContextResult()
            {
                Elem = cd
            };

            // link CD to SME
            var sid = context.Sme.semanticId.GetAsExactlyOneKey();

            if (sid == null)
            {
                // should not happen, see above
                return(null);
            }
            cd.identification = new AdminShell.Identification(sid.idType, sid.value);

            // some further attributes
            if (!cd.idShort.HasContent())
            {
                cd.idShort = context.Sme.idShort;
            }

            // ok
            return(res);
        }