Ejemplo n.º 1
0
        public void InitPlugin(string[] args)
        {
            // start ..
            Log.Info("InitPlugin() called with args = {0}", (args == null) ? "" : string.Join(", ", args));

            // .. with built-in options
            options = AasxPluginGenericForms.GenericFormOptions.CreateDefault();

            // try load defaults options from assy directory
            try
            {
                // need special settings
                var settings = AasxPluginOptionSerialization.GetDefaultJsonSettings(
                    new[] { typeof(AasxPluginGenericForms.GenericFormOptions), typeof(AasForms.FormDescBase) });

                // base options
                var newOpt =
                    AasxPluginOptionsBase.LoadDefaultOptionsFromAssemblyDir <AasxPluginGenericForms.GenericFormOptions>(
                        this.GetPluginName(), Assembly.GetExecutingAssembly(), settings);
                if (newOpt != null)
                {
                    this.options = newOpt;
                }

                // try find additional options
                this.options.TryLoadAdditionalOptionsFromAssemblyDir <AasxPluginGenericForms.GenericFormOptions>(
                    this.GetPluginName(), Assembly.GetExecutingAssembly(), settings, this.Log);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception when reading default options {1}");
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            try
            {
                // for speed reasons, have the most often used at top!
                if (action == "call-check-visual-extension")
                {
                    // arguments
                    if (args.Length < 1)
                    {
                        return(null);
                    }

                    // looking only for Submodels
                    var sm = args[0] as AdminShell.Submodel;
                    if (sm == null)
                    {
                        return(null);
                    }

                    // check for a record in options, that matches Submodel
                    var found = this.options?.MatchRecordsForSemanticId(sm.semanticId);
                    if (found == null)
                    {
                        return(null);
                    }

                    // success prepare record
                    var cve = new AasxPluginResultVisualExtension(found.FormTag, found.FormTitle);

                    // ok
                    return(cve);
                }

                // rest follows

                if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
                {
                    var settings =
                        AasxPluginOptionSerialization.GetDefaultJsonSettings(
                            new[] {
                        typeof(AasxPluginGenericForms.GenericFormOptions),
                        typeof(AasForms.FormDescBase)
                    });
                    var newOpt =
                        Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginGenericForms.GenericFormOptions>(
                            (args[0] as string), settings);
                    if (newOpt != null)
                    {
                        this.options = newOpt;
                    }
                }

                if (action == "get-json-options")
                {
                    var settings = AasxPluginOptionSerialization.GetDefaultJsonSettings(
                        new[] {
                        typeof(AasxPluginGenericForms.GenericFormOptions),
                        typeof(AasForms.FormDescBase)
                    });
                    var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                        this.options, typeof(AasxPluginGenericForms.GenericFormOptions), settings);
                    return(new AasxPluginResultBaseObject("OK", json));
                }

                if (action == "get-licenses")
                {
                    var lic = new AasxPluginResultLicense();
                    lic.shortLicense = "";

                    lic.isStandardLicense = true;
                    lic.longLicense       = AasxPluginHelper.LoadLicenseTxtFromAssemblyDir(
                        "LICENSE.txt", Assembly.GetExecutingAssembly());

                    return(lic);
                }

                if (action == "get-events" && this.eventStack != null)
                {
                    // try access
                    return(this.eventStack.PopEvent());
                }

                if (action == "event-return" && args != null &&
                    args.Length >= 1 && args[0] is AasxPluginEventReturnBase &&
                    this.formsControl != null)
                {
                    this.formsControl.HandleEventReturn(args[0] as AasxPluginEventReturnBase);
                }

                if (action == "get-check-visual-extension")
                {
                    var cve = new AasxPluginResultBaseObject();
                    cve.strType = "True";
                    cve.obj     = true;
                    return(cve);
                }

                if (action == "fill-panel-visual-extension")
                {
                    // arguments
                    if (args == null || args.Length < 3)
                    {
                        return(null);
                    }

                    // call
                    this.formsControl = AasxPluginGenericForms.GenericFormsControl.FillWithWpfControls(
                        Log, args[0], args[1], this.options, this.eventStack, args[2]);

                    // give object back
                    var res = new AasxPluginResultBaseObject();
                    res.obj = this.formsControl;
                    return(res);
                }

                if (action == "get-list-new-submodel")
                {
                    // prepare list
                    var list = new List <string>();

                    // check
                    if (options != null && options.Records != null)
                    {
                        foreach (var rec in options.Records)
                        {
                            if (rec.FormTitle != null)
                            {
                                list.Add("" + rec.FormTitle);
                            }
                        }
                    }

                    // make result
                    var res = new AasxPluginResultBaseObject();
                    res.strType = "OK";
                    res.obj     = list;
                    return(res);
                }

                if (action == "generate-submodel" && args != null && args.Length >= 1 && args[0] is string)
                {
                    // get arguments
                    var smName = args[0] as string;
                    if (smName == null)
                    {
                        return(null);
                    }

                    // identify record
                    AasxPluginGenericForms.GenericFormsOptionsRecord foundRec = null;
                    if (options != null && options.Records != null)
                    {
                        foreach (var rec in options.Records)
                        {
                            if (rec.FormTitle != null && rec.FormTitle == smName)
                            {
                                foundRec = rec;
                            }
                        }
                    }
                    if (foundRec == null || foundRec.FormSubmodel == null)
                    {
                        return(null);
                    }

                    // generate
                    var sm = foundRec.FormSubmodel.GenerateDefault();

                    // make result
                    var res = new AasxPluginResultGenerateSubmodel();
                    res.sm  = sm;
                    res.cds = foundRec.ConceptDescriptions;
                    return(res);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "");
            }

            // default
            return(null);
        }