public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt = Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginExportTable.ExportTableOptions>(
                    (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The OpenXML SDK is under MIT license." + Environment.NewLine +
                                   "The ClosedXML library is under MIT license." + Environment.NewLine +
                                   "The ExcelNumberFormat number parser is licensed under the MIT license." + Environment.NewLine +
                                   "The FastMember reflection access is licensed under Apache License 2.0 (Apache - 2.0).";

                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 == "export-submodel" && args != null && args.Length >= 3 &&
                args[0] is IFlyoutProvider && args[1] is AdminShell.AdministrationShellEnv &&
                args[2] is AdminShell.Submodel)
            {
                // flyout provider
                var fop = args[0] as IFlyoutProvider;

                // which Submodel
                var env = args[1] as AdminShell.AdministrationShellEnv;
                var sm  = args[2] as AdminShell.Submodel;
                if (env == null || sm == null)
                {
                    return(null);
                }

                // the Submodel elements need to have parents
                sm.SetAllParents();

                // prepare list of items to be exported
                var list = new ExportTableAasEntitiesList();
                ExportTable_EnumerateSubmodel(list, env, broadSearch: false, depth: 1, sm: sm, sme: null);

                // handle the export dialogue
                var uc = new ExportTableFlyout();
                uc.Presets = this.options.Presets;
                fop?.StartFlyoverModal(uc);
                if (uc.Result == null)
                {
                    return(null);
                }
                var job = uc.Result;

                // get the output file
                var dlg = new Microsoft.Win32.SaveFileDialog();
                // ReSharper disable EmptyGeneralCatchClause
                try
                {
                    dlg.InitialDirectory = System.IO.Path.GetDirectoryName(
                        System.AppDomain.CurrentDomain.BaseDirectory);
                }
                catch { }
                // ReSharper enable EmptyGeneralCatchClause
                dlg.Title = "Select text file to be exported";

                if (job.Format == (int)ExportTableRecord.FormatEnum.TSF)
                {
                    dlg.FileName   = "new.txt";
                    dlg.DefaultExt = "*.txt";
                    dlg.Filter     =
                        "Tab separated file (*.txt)|*.txt|Tab separated file (*.tsf)|*.tsf|All files (*.*)|*.*";
                }
                if (job.Format == (int)ExportTableRecord.FormatEnum.LaTex)
                {
                    dlg.FileName   = "new.tex";
                    dlg.DefaultExt = "*.tex";
                    dlg.Filter     = "LaTex file (*.tex)|*.tex|All files (*.*)|*.*";
                }
                if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
                {
                    dlg.FileName   = "new.xlsx";
                    dlg.DefaultExt = "*.xlsx";
                    dlg.Filter     = "Microsoft Excel (*.xlsx)|*.xlsx|All files (*.*)|*.*";
                }
                if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
                {
                    dlg.FileName   = "new.docx";
                    dlg.DefaultExt = "*.docx";
                    dlg.Filter     = "Microsoft Word (*.docx)|*.docx|All files (*.*)|*.*";
                }

                fop?.StartFlyover(new EmptyFlyout());
                var res = dlg.ShowDialog(fop?.GetWin32Window());

                try
                {
                    if (res == true)
                    {
                        Log.Info("Exporting table: {0}", dlg.FileName);
                        var success = false;
                        try
                        {
                            if (job.Format == (int)ExportTableRecord.FormatEnum.TSF)
                            {
                                success = job.ExportTabSeparated(dlg.FileName, list);
                            }
                            if (job.Format == (int)ExportTableRecord.FormatEnum.LaTex)
                            {
                                success = job.ExportLaTex(dlg.FileName, list);
                            }
                            if (job.Format == (int)ExportTableRecord.FormatEnum.Excel)
                            {
                                success = job.ExportExcel(dlg.FileName, list);
                            }
                            if (job.Format == (int)ExportTableRecord.FormatEnum.Word)
                            {
                                success = job.ExportWord(dlg.FileName, list);
                            }
                        }
                        catch
                        {
                            success = false;
                        }

                        if (!success)
                        {
                            fop?.MessageBoxFlyoutShow(
                                "Some error occured while exporting the table. Please refer to the log messages.",
                                "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "When exporting table, an error occurred");
                }

                fop?.CloseFlyover();
            }

            // default
            return(null);
        }
Beispiel #2
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            // 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 = false;
                // ReSharper disable once UnusedVariable
                foreach (var rec in _options.LookupAllIndexKey <DocumentShelfOptionsRecord>(
                             sm.semanticId?.GetAsExactlyOneKey()))
                {
                    found = true;
                }
                if (!found)
                {
                    return(null);
                }

                // success prepare record
                var cve = new AasxPluginResultVisualExtension("DOC", "Document Shelf");

                // ok
                return(cve);
            }

            // rest follows

            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt =
                    Newtonsoft.Json.JsonConvert.DeserializeObject <DocumentShelfOptions>(
                        (args[0] as string));
                if (newOpt != null)
                {
                    _options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    _options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The CountryFlag library (NuGet) is licensed under the MIT license (MIT).";

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

                return(lic);
            }

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

            if (action == "event-return" && args != null &&
                args.Length >= 1 && args[0] is AasxPluginEventReturnBase &&
                _shelfControl != null)
            {
                _shelfControl.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
                _shelfControl = ShelfControl.FillWithWpfControls(
                    _log, args[0], args[1], _options, _eventStack, args[2]);

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

            if (action == "get-list-new-submodel")
            {
                // prepare list
                var list = new List <string>();
                list.Add("Document (recommended version)");
                list.Add("Document (development version V1.1)");

                // make result
                var res = new AasxPluginResultBaseObject();
                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);
                }

                // generate (by hand)
                var sm = new AdminShell.Submodel();
                if (smName.Contains("V1.1"))
                {
                    sm.semanticId = new AdminShell.SemanticId(
                        AasxPredefinedConcepts.VDI2770v11.Static.SM_ManufacturerDocumentation.GetSemanticKey());
                    sm.idShort = "ManufacturerDocumentation";
                }
                else
                {
                    sm.semanticId = new AdminShell.SemanticId(DocuShelfSemanticConfig.Singleton.SemIdDocumentation);
                    sm.idShort    = "Documentation";
                }

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

            // default
            return(null);
        }
Beispiel #3
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt = Newtonsoft.Json.JsonConvert.DeserializeObject <AdvancedTextEditOptions>(
                    (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The AvalonEdit component, is licensed under the MIT license (MIT).";

                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 == "get-textedit-control" && args != null && args.Length >= 1 && args[0] is string)
            {
                // args
                var initialContent = args[0] as string;

                // build visual
                this.theEditControl      = new UserControlAdvancedTextEditor();
                this.theEditControl.Text = initialContent;

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

            if (action == "set-content" && args != null && args.Length >= 2 &&
                args[0] is string && args[1] is string &&
                this.theEditControl != null)
            {
                // args
                var mimeType = args[0] as string;
                var content  = args[1] as string;

                // apply
                this.theEditControl.MimeType = mimeType;
                this.theEditControl.Text     = content;
            }

            if (action == "get-content" && this.theEditControl != null)
            {
                // give object back
                var res = new AasxPluginResultBaseObject();
                res.obj = this.theEditControl.Text;
                return(res);
            }

            // default
            return(null);
        }
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense =
                    "This application uses the OPC Foundation .NET Standard stack. See: OPC REDISTRIBUTABLES "
                    + "Agreement of Use." + Environment.NewLine +
                    "The OPC UA Example Code of OPC UA Standard is licensed under the MIT license (MIT).";

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

                return(lic);
            }

            if (action == "server-stop")
            {
                this.stop = true;
            }

            if (action == "server-start")
            {
                // init
                this.stop = false;
                logger.Info("Starting OPC UA AASX Server. Based on the OPC Foundation UA Net Standard stack.");
                logger.Info("Copyright (c) 2018-2021 Festo AG & Co. KG " +
                            "<https://www.festo.com/net/de_de/Forms/web/contact_international>, author: Michael Hoffmeister.");
                logger.Info("Portions copyright (c) by OPC Foundation, Inc. and licensed under the Reciprocal "
                            + "Community License (RCL).");
                logger.Info("See https://opcfoundation.org/license/rcl.html.");

                // access AASX
                if (args == null || args.Length < 1)
                {
                    logger.Info("No AASX package environment passed to plug-in. Stopping...");
                    System.Threading.Thread.Sleep(5000);
                    return(null);
                }

                var package = args[0] as AdminShellPackageEnv;
                if (package == null)
                {
                    logger.Info("No AASX package environment passed to plug-in. Stopping...");
                    System.Threading.Thread.Sleep(5000);
                    return(null);
                }
                logger.Info("AASX package env has filename {0}", package.Filename);

                // configure UA here a little bit
                ApplicationInstance.MessageDlg = new ApplicationMessageDlg(logger);

                // arguments
                var externalOptions = new List <string>();
                if (options?.Args != null)
                {
                    foreach (var o1 in options.Args)
                    {
                        externalOptions.Add(o1);
                    }
                }

                if (args.Length >= 2 && args[1] is string[])
                {
                    var pluginArgs = args[1] as string[];
                    if (pluginArgs != null && pluginArgs.Length > 0)
                    {
                        foreach (var o2 in pluginArgs)
                        {
                            externalOptions.Add(o2);
                        }
                    }
                }

                // debug
                var lstr = $"Taking over {externalOptions.Count} arguments: ";
                foreach (var ls in externalOptions)
                {
                    lstr += ls + " ";
                }
                logger.Info("{0}", lstr);

                // parse
                var internalOptions = new AasOpcUaServer.AasxUaServerOptions();
                internalOptions.ParseArgs(externalOptions.ToArray());

                // run the server
                try
                {
                    this.server = new UaServerWrapper(_autoAccept: true, _stopTimeout: 0, _aasxEnv: package,
                                                      logger: logger, _serverOptions: internalOptions);
                    this.server.Run();
                }
                catch (Exception ex)
                {
                    logger.Info("Exception whenn running server: {0}", ex.Message);
                }

                // do as long as user wants
                int i = 0;
                while (true)
                {
                    if (this.stop)
                    {
                        logger.Info("Stopping ...");
                        if (this.server != null)
                        {
                            this.server.Stop();
                        }
                        break;
                    }

                    // MICHA TODO : Temporary disabled
                    // seems not to work anymore
                    ////if (this.server != null && this.server.IsNotRunningAnymore())
                    ////    break;

                    // new option
                    if (true == this.server?.FinallyStopped)
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(50);
                    if (i % 200 == 0)
                    {
                        logger.Info("Heartbeat {0} x 50ms ..", i);
                    }
                    i++;
                }
                logger.Info("Stopped.");
            }

            var res = new AasxPluginResultBase();

            return(res);
        }
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            // 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 = false;
                if (this.options != null && this.options.Records != null)
                {
                    foreach (var rec in this.options.Records)
                    {
                        if (rec.AllowSubmodelSemanticId != null)
                        {
                            foreach (var x in rec.AllowSubmodelSemanticId)
                            {
                                if (sm.semanticId != null && sm.semanticId.Matches(x))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!found)
                {
                    return(null);
                }

                // success prepare record
                var cve = new AasxPluginResultVisualExtension("MTP", "Module Type Package - View");

                // ok
                return(cve);
            }

            // rest follows

            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt = JsonConvert.DeserializeObject <AasxPluginMtpViewer.MtpViewerOptions>(args[0] as string);
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = JsonConvert.SerializeObject(this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The AutomationML.Engine is licensed under the MIT license (MIT) (see below).";

                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 == "get-check-visual-extension")
            {
                var cve = new AasxPluginResultBaseObject();
                cve.strType = "True";
                cve.obj     = true;
                return(cve);
            }

            if (action == "fill-panel-visual-extension" && this.viewerControl != null)
            {
                // arguments
                if (args?.Length < 3)
                {
                    return(null);
                }

                // call
                var resobj = AasxPluginMtpViewer.WpfMtpControlWrapper.FillWithWpfControls(args?[0], args?[1],
                                                                                          this.options, this.eventStack, args?[2]);

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

            // default
            return(null);
        }
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense =
                    "This application uses the OPC Foundation .NET Standard stack. See: OPC REDISTRIBUTABLES "
                    + "Agreement of Use." + Environment.NewLine +
                    "The OPC UA Example Code of OPC UA Standard is licensed under the MIT license (MIT).";

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

                return(lic);
            }

            if (action == "create-client")
            {
                // OPC Copyright
                MessageBox.Show(
                    "Copyright (c) 2018-2019 PHOENIX CONTACT GmbH & Co. KG <*****@*****.**>, " +
                    "author: Andreas Orzelski\n\n" +
                    "Portions copyright (c) by OPC Foundation, Inc. and licensed under the Reciprocal Community " +
                    "License (RCL)\n" + "see https://opcfoundation.org/license/rcl.html",
                    "Plugin Notice"
                    );

                // check for arguments
                if (args == null || args.Length != 5 || !(args[0] is string && args[1] is bool && args[2] is int &&
                                                          args[3] is string && args[4] is string))
                {
                    Log.Info("create-client() call with wrong arguments. Expected: (string _endpointURL, "
                             + "bool _autoAccept, int _stopTimeout, string _userName, string _password)");
                    return(null);
                }

                // re-establish arguments
                var _endpointURL = args[0] as string;
                var _autoAccept  = (bool)args[1];
                var _stopTimeout = (int)args[2];
                var _userName    = args[3] as string;
                var _password    = args[4] as string;

                // make client
                var client = new SampleClient.UASampleClient(_endpointURL, _autoAccept, _stopTimeout,
                                                             _userName, _password);
                client.ConsoleSampleClient().Wait();

                // return as plain object
                var res = new AasxPluginResultBaseObject();
                res.strType = "UASampleClient";
                res.obj     = client;
                return(res);
            }

            if (action == "read-sme-value")
            {
                // check for arguments
                if (args == null || args.Length != 3 || !(args[0] is SampleClient.UASampleClient &&
                                                          args[1] is string && args[2] is int))
                {
                    Log.Info("read-sme-value() call with wrong arguments. Expected: (UASampleClient client, "
                             + "string nodeName, int index)");
                    return(null);
                }

                // re-establish arguments
                var client    = args[0] as SampleClient.UASampleClient;
                var nodeName  = args[1] as string;
                var Namespace = (int)args[2];

                // make the call
                var value = client?.ReadSubmodelElementValue(nodeName, Namespace);

                // return as plain object
                var res = new AasxPluginResultBaseObject();
                res.strType = "value object";
                res.obj     = value;
                return(res);
            }

            return(null);
        }
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            // 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 || _options == null)
                {
                    return(null);
                }

                // check for a record in options, that matches Submodel
                var found = false;
                // ReSharper disable UnusedVariable
                foreach (var x in _options.MatchingRecords(sm.semanticId))
                {
                    found = true;
                    break;
                }
                if (!found)
                {
                    return(null);
                }
                // ReSharper enable UnusedVariable

                // success prepare record
                var cve = new AasxPluginResultVisualExtension("BOM", "Bill of Material - Graph display");

                // ok
                return(cve);
            }

            // rest follows

            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt =
                    Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginBomStructure.BomStructureOptions>(
                        (args[0] as string));
                if (newOpt != null)
                {
                    this._options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this._options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense =
                    "The Microsoft Microsoft Automatic Graph Layout, MSAGL, is licensed under the MIT license (MIT).";

                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 == "get-check-visual-extension")
            {
                var cve = new AasxPluginResultBaseObject();
                cve.strType = "True";
                cve.obj     = true;
                return(cve);
            }

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

                // call
                this._bomControl.SetEventStack(this._eventStack);
                var resobj = this._bomControl.FillWithWpfControls(_options, args[0], args[1], args[2]);

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

            // default
            return(null);
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt = Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginWebBrowser.WebBrowserOptions>(
                    (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The browser functionality is licensed under the cefSharp license (see below).";

                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 == "get-browser-grid" && args != null && args.Length >= 1 && args[0] is string)
            {
                // args
                var url = args[0] as string;

                // build visual
                this.browserGrid = new Grid();

                this.browserGrid.RowDefinitions.Add(
                    new RowDefinition()
                {
                    Height = new GridLength(1.0, GridUnitType.Star)
                });
                this.browserGrid.ColumnDefinitions.Add(
                    new ColumnDefinition()
                {
                    Width = new GridLength(1.0, GridUnitType.Star)
                });

                this.theBrowser         = new CefSharp.Wpf.ChromiumWebBrowser();
                this.theBrowser.Address = url;
                this.theBrowser.InvalidateVisual();

                this.browserGrid.Children.Add(this.theBrowser);
                Grid.SetRow(this.theBrowser, 0);
                Grid.SetColumn(this.theBrowser, 0);

                // TODO (MIHO, 2020-08-02): when dragging the divider between elements tree and browser window,
                // distortions can be seen (diagonal shifting of pixels). Interestingly, this problem was not
                // appearant, when the browser was integrated within the main application and is new for the
                // plugin approach. Would be great if somebody would find a solution.

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

            if (action == "go-to-address" && args != null && args.Length >= 1 && args[0] is string)
            {
                // args
                var url = args[0] as string;
                Log.Info("AasxPluginWebBrowser go to {0}", url);

                // check, if possible
                if (this.browserGrid != null && this.theBrowser != null)
                {
                    // try execute
                    this.theBrowser.Address = url;
                    this.theBrowser.InvalidateVisual();
                    this.browserGrid.InvalidateVisual();

                    // indicate OK
                    return(new AasxPluginResultBaseObject("OK", true));
                }
            }

            if (action == "gset-zoom-level" && args != null && args.Length >= 1 && args[0] is double)
            {
                // args
                var zoom = (double)args[0];

                // check, if possible
                if (this.browserGrid != null && this.theBrowser != null)
                {
                    // try execute
                    this.theBrowser.ZoomLevel = zoom;

                    // indicate OK
                    return(new AasxPluginResultBaseObject("OK", true));
                }
            }

            // default
            return(null);
        }
Beispiel #10
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            // 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 = false;
                if (this.options.AllowSubmodelSemanticIds != null)
                {
                    foreach (var x in this.options.AllowSubmodelSemanticIds)
                    {
                        if (sm.semanticId != null && sm.semanticId.Matches(x))
                        {
                            found = true;
                            break;
                        }
                    }
                }
                if (!found)
                {
                    return(null);
                }

                // success prepare record
                var cve = new AasxPluginResultVisualExtension("DOC", "Document Shelf");

                // ok
                return(cve);
            }

            // rest follows

            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt =
                    Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginDocumentShelf.DocumentShelfOptions>(
                        (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The CountryFlag library (NuGet) is licensed under the MIT license (MIT).";

                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 == "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
                var resobj = AasxPluginDocumentShelf.ShelfControl.FillWithWpfControls(
                    Log, args[0], args[1], this.options, this.eventStack, args[2]);

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

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

                // make result
                var res = new AasxPluginResultBaseObject();
                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);
                }

                // generate (by hand)
                var sm = new AdminShell.Submodel();
                sm.semanticId = new AdminShell.SemanticId(options.SemIdDocumentation);
                sm.idShort    = "Documentation";

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

            // default
            return(null);
        }
Beispiel #11
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            // 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 = false;
                if (this.options != null && this.options.Records != null)
                {
                    foreach (var rec in this.options.Records)
                    {
                        if (rec.AllowSubmodelSemanticId != null)
                        {
                            foreach (var x in rec.AllowSubmodelSemanticId)
                            {
                                if (sm.semanticId != null && sm.semanticId.Matches(x))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!found)
                {
                    return(null);
                }

                // success prepare record
                var cve = new AasxPluginResultVisualExtension("TED", "Technical Data Viewer");

                // ok
                return(cve);
            }

            // rest follows

            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt =
                    Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginTechnicalData.TechnicalDataOptions>(
                        (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense =
                    "The application uses one class provided under The Code Project Open License (CPOL).";

                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 == "get-check-visual-extension")
            {
                var cve = new AasxPluginResultBaseObject();
                cve.strType = "True";
                cve.obj     = true;
                return(cve);
            }

            if (action == "fill-panel-visual-extension" && args != null && args.Length >= 3)
            {
                // access
                var package = args[0] as AdminShellPackageEnv;
                var sm      = args[1] as AdminShell.Submodel;
                var master  = args[2] as DockPanel;
                if (package == null || sm == null || master == null)
                {
                    return(null);
                }

                // the Submodel elements need to have parents
                sm.SetAllParents();

                // create TOP control
                this.viewControl = new AasxPluginTechnicalData.TechnicalDataViewControl();
                this.viewControl.Start(package, sm, options, eventStack);
                master.Children.Add(this.viewControl);

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

            // default
            return(null);
        }
Beispiel #12
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            // 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 = false;
                if (this.options != null && this.options.Records != null)
                {
                    foreach (var rec in this.options.Records)
                    {
                        if (rec.AllowSubmodelSemanticId != null)
                        {
                            foreach (var x in rec.AllowSubmodelSemanticId)
                            {
                                if (sm.semanticId != null && sm.semanticId.Matches(x))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!found)
                {
                    return(null);
                }

                // success prepare record
                var cve = new AasxPluginResultVisualExtension("PLOT", "Plotting of data");

                // ok
                return(cve);
            }

            if (action == "push-aas-event")
            {
                // arguments
                if (args.Length < 1 || !(args[0] is AasEventMsgEnvelope ev))
                {
                    return(null);
                }

                _viewControl?.PushEvent(ev);
            }

            // rest follows

            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt =
                    Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginPlotting.PlottingOptions>(
                        (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense =
                    "The application uses the ScottPlot NuGet package, which is under the MIT license.";

                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 == "get-check-visual-extension")
            {
                var cve = new AasxPluginResultBaseObject();
                cve.strType = "True";
                cve.obj     = true;
                return(cve);
            }

            if (action == "clear-panel-visual-extension")
            {
                // simple delete reference to view control
                // this shall also stop event notifications!
                if (_viewControl != null)
                {
                    _viewControl.Stop();
                }
                _viewControl = null;
            }

            if (action == "fill-panel-visual-extension" && args != null && args.Length >= 3)
            {
                // access
                var package = args[0] as AdminShellPackageEnv;
                var sm      = args[1] as AdminShell.Submodel;
                var master  = args[2] as DockPanel;
                if (package == null || sm == null || master == null)
                {
                    return(null);
                }

                // the Submodel elements need to have parents
                sm.SetAllParents();

                // create TOP control
                _viewControl = new AasxPluginPlotting.PlottingViewControl();
                _viewControl.Start(package, sm, options, eventStack, Log);
                master.Children.Add(_viewControl);

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

            // default
            return(null);
        }
Beispiel #13
0
        public AasxPluginResultBase ActivateAction(string action, params object[] args)
        {
            if (action == "set-json-options" && args != null && args.Length >= 1 && args[0] is string)
            {
                var newOpt = Newtonsoft.Json.JsonConvert.DeserializeObject <AasxPluginExportTable.ExportTableOptions>(
                    (args[0] as string));
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }

            if (action == "get-json-options")
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(
                    this.options, Newtonsoft.Json.Formatting.Indented);
                return(new AasxPluginResultBaseObject("OK", json));
            }

            if (action == "get-licenses")
            {
                var lic = new AasxPluginResultLicense();
                lic.shortLicense = "The OpenXML SDK is under MIT license." + Environment.NewLine +
                                   "The ClosedXML library is under MIT license." + Environment.NewLine +
                                   "The ExcelNumberFormat number parser is licensed under the MIT license." + Environment.NewLine +
                                   "The FastMember reflection access is licensed under Apache License 2.0 (Apache - 2.0).";

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

                return(lic);
            }

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

            if ((action == "export-submodel" || action == "import-submodel") &&
                args != null && args.Length >= 3 &&
                args[0] is IFlyoutProvider && args[1] is AdminShell.AdministrationShellEnv &&
                args[2] is AdminShell.Submodel)
            {
                // flyout provider
                var fop = args[0] as IFlyoutProvider;

                // which Submodel
                var env = args[1] as AdminShell.AdministrationShellEnv;
                var sm  = args[2] as AdminShell.Submodel;
                if (env == null || sm == null)
                {
                    return(null);
                }

                // the Submodel elements need to have parents
                sm.SetAllParents();

                // handle the export dialogue
                var uc = new ExportTableFlyout((action == "export-submodel")
                    ? "Export SubmodelElements as Table"
                    : "Import SubmodelElements from Table");
                uc.Presets = this.options.Presets;
                fop?.StartFlyoverModal(uc);
                fop?.CloseFlyover();
                if (uc.Result == null)
                {
                    if (uc.CloseForHelp)
                    {
                        // give over to event stack
                        var evt = new AasxPluginResultEventDisplayContentFile();
                        evt.fn = "https://github.com/admin-shell-io/aasx-package-explorer/tree/" +
                                 "MIHO/AddPluginForKnownSubmodels/src/AasxPluginExportTable/help";
                        evt.mimeType = System.Net.Mime.MediaTypeNames.Text.Html;
                        _eventStack?.PushEvent(evt);
                    }

                    return(null);
                }

                if (action == "export-submodel")
                {
                    Export(uc.Result, fop, sm, env);
                }

                if (action == "import-submodel")
                {
                    Import(uc.Result, fop, sm, env);
                }
            }

            if (action == "export-uml" &&
                args != null && args.Length >= 3 &&
                args[0] is IFlyoutProvider && args[1] is AdminShell.AdministrationShellEnv &&
                args[2] is AdminShell.Submodel)
            {
                var fn = (args.Length >= 4) ? args[3] as string : null;

                // flyout provider (will be required in the future)
                var fop = args[0] as IFlyoutProvider;

                // which Submodel
                var env = args[1] as AdminShell.AdministrationShellEnv;
                var sm  = args[2] as AdminShell.Submodel;
                if (env == null || sm == null)
                {
                    return(null);
                }

                // the Submodel elements need to have parents
                sm.SetAllParents();

                // prep options
                var exop = options.UmlExport;
                if (exop == null)
                {
                    exop = new ExportUmlOptions();
                }

                // dialogue for user options
                var uc = new ExportUmlFlyout();
                uc.Result = exop;
                fop?.StartFlyoverModal(uc);
                fop?.CloseFlyover();
                if (uc.Result == null)
                {
                    return(null);
                }

                // ask for filename
                var dlg = new Microsoft.Win32.SaveFileDialog();
                try
                {
                    dlg.InitialDirectory = System.IO.Path.GetDirectoryName(
                        System.AppDomain.CurrentDomain.BaseDirectory);
                }
                catch (Exception ex)
                {
                    AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                }
                dlg.Title = "Select file for UML export ..";

                if (uc.Result.Format == ExportUmlOptions.ExportFormat.PlantUml)
                {
                    dlg.FileName   = "new.uml";
                    dlg.DefaultExt = "*.uml";
                    dlg.Filter     =
                        "PlantUML text file (*.uml)|*.uml|All files (*.*)|*.*";
                }
                else
                {
                    dlg.FileName   = "new.xml";
                    dlg.DefaultExt = "*.xml";
                    dlg.Filter     =
                        "XMI file (*.xml)|*.xml|All files (*.*)|*.*";
                }

                fop?.StartFlyover(new EmptyFlyout());
                var fnres = dlg.ShowDialog(fop?.GetWin32Window());
                fop?.CloseFlyover();
                if (fnres != true)
                {
                    return(null);
                }
                fn = dlg.FileName;

                // use functionality
                ExportUml.ExportUmlToFile(env, sm, uc.Result, fn);
                Log.Info($"Export UML data to file: {fn}");

                // copy?
                if (uc.Result.CopyToPasteBuffer)
                {
                    try
                    {
                        var lines = File.ReadAllText(fn);
                        Clipboard.SetData(DataFormats.Text, lines);
                        Log.Info("Export UML data copied to paste buffer.");
                    }
                    catch (Exception ex)
                    {
                        AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                    }
                }
            }

            // default
            return(null);
        }