Exemplo n.º 1
0
        public static void Test123()
        {
            var ttt     = new AasForms.FormDescProperty("t", AasForms.FormMultiplicity.One, null, "xdscdsds");
            var descDoc = new FormDescListOfElement();

            descDoc.Add(ttt);

            using (var s = new StreamWriter("test2.json"))
            {
                JsonSerializerSettings settings = new JsonSerializerSettings
                {
                    SerializationBinder = new DisplayNameSerializationBinder(
                        new[] { typeof(FormDescListOfElement), typeof(FormDescProperty) }),
                    NullValueHandling     = NullValueHandling.Ignore,
                    ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                    TypeNameHandling      = TypeNameHandling.Auto,
                    Formatting            = Formatting.Indented
                };
                JsonSerializer serializer = JsonSerializer.Create(settings);
                using (JsonWriter writer = new JsonTextWriter(s))
                {
                    serializer.Serialize(writer, descDoc, typeof(FormDescProperty));
                }
            }

            var settings2 = AasxPluginOptionSerialization.GetDefaultJsonSettings(new[] { typeof(FormDescBase) });

            var test2  = new AasForms.FormDescSubmodel("t", null, "xdscdsds");
            var test22 = new AasForms.FormDescProperty("t", AasForms.FormMultiplicity.One, null, "xdscdsds");

            test2.Add(test22);

            Newtonsoft.Json.JsonConvert.SerializeObject(test2, settings2);
        }
 public FormDescProperty(FormDescProperty other)
     : base(other)
 {
     // this part == static, therefore only shallow copy
     this.allowedValueTypes      = other.allowedValueTypes;
     this.presetValue            = other.presetValue;
     this.comboBoxChoices        = other.comboBoxChoices;
     this.valueFromComboBoxIndex = other.valueFromComboBoxIndex;
 }
Exemplo n.º 3
0
        public FormInstanceProperty(
            FormInstanceListOfSame parentInstance, FormDescProperty parentDesc,
            AdminShell.SubmodelElement source = null, bool deepCopy = false)
        {
            // way back to description
            this.parentInstance = parentInstance;
            this.desc           = parentDesc;

            // initialize Referable
            var p = new AdminShell.Property();

            this.sme = p;
            InitReferable(parentDesc, source);

            // check, if a source is present
            this.sourceSme = source;
            var pSource = this.sourceSme as AdminShell.Property;

            if (pSource != null)
            {
                // take over
                p.valueType = pSource.valueType;
                p.value     = pSource.value;
            }
            else
            {
                // some more preferences
                if (parentDesc.allowedValueTypes != null && parentDesc.allowedValueTypes.Length >= 1)
                {
                    p.valueType = parentDesc.allowedValueTypes[0];
                }

                if (parentDesc.presetValue != null && parentDesc.presetValue.Length > 0)
                {
                    p.value = parentDesc.presetValue;
                    // immediately set touched in order to have this value saved
                    this.Touch();
                }
            }

            // create user control
            this.subControl             = new FormSubControlProperty();
            this.subControl.DataContext = this;
        }
Exemplo n.º 4
0
        private static void RecurseExportAsTemplate(
            AdminShell.SubmodelElementWrapperCollection smwc, FormDescListOfElement tels,
            AdminShell.AdministrationShellEnv env = null, AdminShell.ListOfConceptDescriptions cds = null)
        {
            // access
            if (smwc == null || tels == null)
            {
                return;
            }

            // over all elems
            foreach (var smw in smwc)
            {
                if (smw != null && smw.submodelElement != null)
                {
                    FormDescSubmodelElement tsme = null;
                    if (smw.submodelElement is AdminShell.Property p)
                    {
                        tsme = new FormDescProperty(
                            "" + p.idShort, FormMultiplicity.One, p.semanticId?.GetAsExactlyOneKey(),
                            "" + p.idShort, valueType: p.valueType);
                    }
                    if (smw.submodelElement is AdminShell.MultiLanguageProperty mlp)
                    {
                        tsme = new FormDescMultiLangProp(
                            "" + mlp.idShort, FormMultiplicity.One, mlp.semanticId?.GetAsExactlyOneKey(),
                            "" + mlp.idShort);
                    }
                    if (smw.submodelElement is AdminShell.File fl)
                    {
                        tsme = new FormDescFile(
                            "" + fl.idShort, FormMultiplicity.One, fl.semanticId?.GetAsExactlyOneKey(),
                            "" + fl.idShort);
                    }
                    if (smw.submodelElement is AdminShell.ReferenceElement rf)
                    {
                        tsme = new FormDescReferenceElement(
                            "" + rf.idShort, FormMultiplicity.One, rf.semanticId?.GetAsExactlyOneKey(),
                            "" + rf.idShort);
                    }
                    if (smw.submodelElement is AdminShell.SubmodelElementCollection smec)
                    {
                        tsme = new FormDescSubmodelElementCollection(
                            "" + smec.idShort, FormMultiplicity.One, smec.semanticId?.GetAsExactlyOneKey(),
                            "" + smec.idShort);
                    }

                    if (tsme != null)
                    {
                        // take over directly
                        tsme.PresetCategory = smw.submodelElement.category;

                        // Qualifers
                        var qs = smw.submodelElement.qualifiers;

                        var q = qs?.FindType("FormTitle");
                        if (q != null)
                        {
                            tsme.FormTitle = "" + q.value;
                        }

                        q = qs?.FindType("FormInfo");
                        if (q != null)
                        {
                            tsme.FormInfo = "" + q.value;
                        }

                        q = qs?.FindType("EditIdShort");
                        if (q != null)
                        {
                            tsme.FormEditIdShort = q.value.Trim().ToLower() == "true";
                        }

                        q = qs?.FindType("EditDescription");
                        if (q != null)
                        {
                            tsme.FormEditDescription = q.value.Trim().ToLower() == "true";
                        }

                        q = qs?.FindType("Multiplicity");
                        if (q != null)
                        {
                            foreach (var m in (FormMultiplicity[])Enum.GetValues(typeof(FormMultiplicity)))
                            {
                                if (("" + q.value) == Enum.GetName(typeof(FormMultiplicity), m))
                                {
                                    tsme.Multiplicity = m;
                                }
                            }
                        }

                        q = qs?.FindType("PresetValue");
                        if (q != null && tsme is FormDescProperty)
                        {
                            (tsme as FormDescProperty).presetValue = "" + q.value;
                        }

                        q = qs?.FindType("PresetMimeType");
                        if (q != null && tsme is FormDescFile)
                        {
                            (tsme as FormDescFile).presetMimeType = "" + q.value;
                        }

                        q = qs?.FindType("FormChoices");
                        if (q != null && q.value.HasContent() && tsme is FormDescProperty fdprop)
                        {
                            var choices = q.value.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                            if (choices != null && choices.Length > 0)
                            {
                                fdprop.comboBoxChoices = choices;
                            }
                        }

                        // adopt presetIdShort
                        if (tsme.Multiplicity == FormMultiplicity.ZeroToMany ||
                            tsme.Multiplicity == FormMultiplicity.OneToMany)
                        {
                            tsme.PresetIdShort += "{0:00}";
                        }

                        // Ignore this element
                        q = qs?.FindType("FormIgnore");
                        if (q != null)
                        {
                            continue;
                        }
                    }

                    if (tsme != null)
                    {
                        tels.Add(tsme);
                    }

                    // in any case, check for CD
                    if (env != null && cds != null && smw?.submodelElement?.semanticId?.Keys != null)
                    {
                        var masterCd = env.FindConceptDescription(smw?.submodelElement?.semanticId?.Keys);
                        if (masterCd != null && masterCd.identification != null)
                        {
                            // already in cds?
                            var copyCd = cds.Find(masterCd.identification);
                            if (copyCd == null)
                            {
                                // add clone
                                cds.Add(new AdminShell.ConceptDescription(masterCd));
                            }
                        }
                    }

                    // recurse
                    if (smw.submodelElement is AdminShell.SubmodelElementCollection)
                    {
                        RecurseExportAsTemplate(
                            (smw.submodelElement as AdminShell.SubmodelElementCollection).value,
                            (tsme as FormDescSubmodelElementCollection).value, env, cds);
                    }
                }
            }
        }