public WebApplication(
     IApplicationMetadata metadata,
     int startupTimeout,
     IApplicationPackage package,
     Dictionary <string, object> args,
     // ReSharper disable once ParameterTypeCanBeEnumerable.Local
     IParagonPlugin[] kernelPlugins,
     Func <ICefWebBrowser> newBrowser,
     Func <IApplicationWindowEx> newAppWindow,
     Func <IApplicationWindowManagerEx> newWindowManager)
 {
     Logger                  = ParagonLogManager.GetLogger();
     Metadata                = metadata;
     Package                 = package;
     Args                    = args;
     Plugins                 = new List <IParagonPlugin>(kernelPlugins);
     _createNewWindow        = newAppWindow;
     _createNewBrowser       = newBrowser;
     _createWindowManager    = newWindowManager;
     _eventPageLaunchTimeout = TimeSpan.FromSeconds(startupTimeout);
     _renderPlugins          = new RenderSidePluginData()
     {
         PackagePath = Package != null ? Package.PackageFilePath : string.Empty, Plugins = new List <ApplicationPlugin>()
     };
     SystemEvents.SessionEnding             += OnSessionEnding;
     ParagonRuntime.RenderProcessInitialize += OnRenderProcessInitialize;
 }
Exemplo n.º 2
0
        protected override void OnRenderThreadCreated(CefListValue extraInfo)
        {
            Logger.Info("Render thread created");
            if (extraInfo != null && extraInfo.Count > 0)
            {
                var plugins = extraInfo.GetList(0);
                IApplicationPackage package         = null;
                List <IPluginInfo>  renderPlugins   = new List <IPluginInfo>();
                List <IPluginInfo>  renderJsPlugins = new List <IPluginInfo>();
                if (extraInfo.Count > 1)
                {
                    var renderSidePluginData = extraInfo.GetString(1);
                    Logger.Info("Render-side plugin information : " + (renderSidePluginData ?? string.Empty));
                    try
                    {
                        if (!string.IsNullOrEmpty(renderSidePluginData))
                        {
                            RenderSidePluginData renderPluginInfo = JsonConvert.DeserializeObject <RenderSidePluginData>(renderSidePluginData);
                            package = (renderPlugins != null &&
                                       !string.IsNullOrEmpty(renderPluginInfo.PackagePath) &&
                                       renderPluginInfo.Plugins != null &&
                                       renderPluginInfo.Plugins.Count > 0) ? new ApplicationPackage(renderPluginInfo.PackagePath, p => p) : null;
                            Logger.Info(string.Format("Found {0} render-side plugins in package {1}",
                                                      (renderPlugins != null && renderPluginInfo.Plugins != null) ? renderPluginInfo.Plugins.Count : 0,
                                                      package != null ? package.PackageFilePath : string.Empty));
                            if (package != null)
                            {
                                foreach (var pluginInfo in renderPluginInfo.Plugins)
                                {
                                    if (pluginInfo != null && pluginInfo.Assembly.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        renderJsPlugins.Add(pluginInfo);
                                    }
                                    else
                                    {
                                        renderPlugins.Add(pluginInfo);
                                    }
                                }

                                if (renderJsPlugins.Count > 0)
                                {
                                    _jsExtensions = PackagedPluginAssemblyResolver.LoadJavaScriptPlugins(package, renderJsPlugins);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Error resolving render-side plugins.", ex);
                    }
                }

                if (plugins != null || (package != null && renderPlugins.Count > 0))
                {
                    Logger.Info("Initializing managed plugins");
                    try
                    {
                        if (package != null && renderPlugins != null && renderPlugins.Count > 0)
                        {
                            _router.OnPluginContextCreated += delegate(IPluginContext context)
                            {
                                _renderSidePlugins = PackagedPluginAssemblyResolver.LoadManagedPlugins(context.PluginManager, package, renderPlugins);
                            };
                        }
                        _router.InitializePlugins(plugins);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Error initializing managed plugins.", ex);
                    }
                }

                extraInfo.Clear();
            }

            base.OnRenderThreadCreated(extraInfo);
        }