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 = AasxPluginWebBrowser.WebBrowserOptions.CreateDefault();

            // try load defaults options from assy directory
            try
            {
                var newOpt =
                    AasxPluginOptionsBase.LoadDefaultOptionsFromAssemblyDir <AasxPluginWebBrowser.WebBrowserOptions>(
                        this.GetPluginName(), Assembly.GetExecutingAssembly());
                if (newOpt != null)
                {
                    this.options = newOpt;
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exception when reading default options {1}");
            }
        }
Ejemplo n.º 2
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);
        }