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; }
public bool RedirectApplicationLaunchIfNeeded(IApplicationPackage package, ApplicationEnvironment environment) { bool shouldRedirect = false; var manifest = package.Manifest; if (manifest.SingleInstance || !string.IsNullOrEmpty(manifest.ProcessGroup)) { var mutexName = string.Format("{0}:{1}:{2}", (string.IsNullOrEmpty(manifest.ProcessGroup) ? manifest.Id : manifest.ProcessGroup), environment, System.Environment.UserName); string channelName = mutexName + ":LaunchRedirectorService"; bool createdNew = false; var mutex = new Mutex(true, mutexName, out createdNew); shouldRedirect = !createdNew; if (shouldRedirect) { RedirectAplicationLaunch(channelName); mutex.Close(); } else { _mutex = mutex; if (!_pendingSingleInstanceAppLaunches.Contains(manifest.Id)) { _pendingSingleInstanceAppLaunches.Add(manifest.Id); } StartApplicationLaunchRedirectionService(channelName); } } return(shouldRedirect); }
private IApplication CreateWebApplication(IApplicationMetadata metadata, IApplicationPackage package, Dictionary <string, object> args) { return(new WebApplication( metadata, package.Manifest.App.StartupTimeout, package, args, _kernelPlugins(), _createBrowser, _createWindow, _createWindowManager)); }
public IApplicationPackage GetApplicationPackage() { string resolvedUri; if (_package == null) { var package = ApplicationPackageResolver.Load(StartData, PackageSignatureVerifier, out resolvedUri); if (package == null) { throw new Exception("Invalid start data"); } _package = package; Id = package.Manifest.Id; } return(_package); }
public IApplication CreateApplication(IApplicationMetadata metadata, IApplicationPackage package, Dictionary <string, object> args) { metadata.Id = package.Manifest.Id; metadata.AppType = package.Manifest.Type; switch (package.Manifest.Type) { case ApplicationType.Hosted: return(CreateWebApplication(metadata, package, args)); case ApplicationType.Packaged: return(CreateWebApplication(metadata, package, args)); default: throw new Exception("Unknown application type"); } }
public static Dictionary <string, string> LoadJavaScriptPlugins(IApplicationPackage package, List <IPluginInfo> plugins) { if (package == null) { throw new ArgumentException("package"); } var addedPlugins = new Dictionary <string, string>(); if (plugins != null) { foreach (var appPlugin in plugins) { if (appPlugin.Assembly.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase)) { try { var pp = package.GetPart(Path.Combine(appPlugin.Path, appPlugin.Assembly)); if (pp != null) { using (var ps = pp.GetStream()) { var pv = new StreamReader(ps).ReadToEnd(); if (!string.IsNullOrEmpty(pv)) { Logger.Info("Resolved render-side JavaScript plugin : " + appPlugin.Name); addedPlugins[appPlugin.Assembly] = pv; } else { Logger.Warn("Render-side JavaScript plugin {0} is empty! ", appPlugin.Name); } } } } catch (Exception ex) { Logger.Error("Could not create application plugin : " + appPlugin.Name, ex); } } } } return(addedPlugins); }
public static bool ResolveMetadataAndPackage(ParagonCommandLineParser cmdLine, out ApplicationMetadata appMetadata, out IApplicationPackage appPackage) { appMetadata = null; appPackage = null; try { using (AutoStopwatch.TimeIt("Parsing application metadata")) { appMetadata = cmdLine.ParseApplicationMetadata(); Logger.Info("The current environment is {0}", appMetadata != null ? appMetadata.Environment : ApplicationEnvironment.Production); } } catch (Exception ex) { MessageBox.Show(string.Format("Error parsing command line : {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { using (AutoStopwatch.TimeIt("Gettting application package")) { appPackage = appMetadata.GetApplicationPackage(); Logger.Info("The current application package is {0}", appPackage == null || appPackage.Signature == null ? "unsigned" : string.Format("digitally signed by {0} on {1}", appPackage.Signature.Signer.Subject, appPackage.Signature.SigningTime)); return(appPackage != null); } } catch (SecurityException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(string.Format("Error parsing manifest file : {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } return(false); }
protected virtual void RunApplicationInternal(ParagonCommandLineParser cmdLine, IApplicationPackage package, ApplicationMetadata metadata) { IParagonSplashScreen splash = null; IApplication application = null; Window splashWindow = null; var manifest = package.Manifest; #if ENFORCE_PACKAGE_SECURITY var isSigned = package.Signature != null; #endif try { ParagonLogManager.AddApplicationTraceListener(manifest.Id); // Load custom WPF theme for the application var stylePart = !string.IsNullOrEmpty(manifest.CustomTheme) ? package.GetPart(manifest.CustomTheme) : null; var styleStream = stylePart != null?stylePart.GetStream() : null; if (styleStream != null) { var theme = XamlReader.Load(styleStream) as ResourceDictionary; if (theme != null) { #if ENFORCE_PACKAGE_SECURITY if (isSigned) #endif Application.Current.Resources.MergedDictionaries.Add(theme); } } // Create and show the splash screen if needed if (cmdLine != null && !cmdLine.HasFlag("no-splash") && _createSplashScreen != null) { #if ENFORCE_PACKAGE_SECURITY splash = _createSplashScreen(isSigned ? manifest.Name : manifest.Name + " (Unsigned)", manifest.Version, package.GetIcon()); #else splash = _createSplashScreen(manifest.Name, manifest.Version, package.GetIcon()); #endif splashWindow = (Window)splash; metadata.UpdateLaunchStatus = s => { if (splash != null && splashWindow != null && splashWindow.IsVisible) { splash.ShowText(s); } }; #if ENFORCE_PACKAGE_SECURITY if (!isSigned) { splashWindow.Style = Application.Current.Resources["AlarmSplashScreenStyle"] as Style; } #endif splashWindow.Show(); } // Extract the application arguments from the command line Dictionary <string, object> args = null; if (cmdLine != null && _appArgumentParser != null) { string appArgs, appUrl; if (cmdLine.GetValue("args", out appArgs)) { args = _appArgumentParser(appArgs); } else if (cmdLine.GetValue("url", out appUrl)) { Uri uri; if (Uri.TryCreate(appUrl, UriKind.Absolute, out uri)) { if (!string.IsNullOrEmpty(uri.Query)) { args = _appArgumentParser(uri.Query.Substring(1)); } } } } //Create and register application application = _createApplication(package, metadata, args); Register(application); // Launch the application var stopWatch = AutoStopwatch.TimeIt("Launching"); application.Launched += delegate { if (splashWindow != null) { splashWindow.Dispatcher.BeginInvoke(new Action(() => { if (splashWindow != null) { splashWindow.Close(); } })); } this.RemoveSingleInstanceLaunchMarker(metadata.Id); stopWatch.Dispose(); }; application.Launch(); string protocolUri = null; if (cmdLine != null) { cmdLine.GetValue("url", out protocolUri); if (!string.IsNullOrEmpty(protocolUri)) { application.OnProtocolInvoke(protocolUri); } } } catch (Exception ex) { Logger.Info("Error starting paragon application : {0}", ex); MessageBox.Show("Unable to start:\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); if (splashWindow != null) { splashWindow.Close(); } if (application != null) { RemoveSingleInstanceLaunchMarker(metadata.Id); application.Close(); application = null; } } }
/// <summary> /// Launch the first application in the host process /// </summary> /// <param name="package"></param> /// <param name="metadata"></param> public void RunApplication(ParagonCommandLineParser cmdLine, IApplicationPackage package, ApplicationMetadata metadata) { if (IsInitialized) { throw new Exception("Application manger is already initialized"); } var manifest = package.Manifest; // Initialize the following from the first application manifest ProcessGroup = manifest.ProcessGroup ?? string.Empty; CacheFolder = Path.Combine(_paragonFolder, string.IsNullOrEmpty(manifest.ProcessGroup) ? manifest.Id : manifest.ProcessGroup); Environment = metadata.Environment; DisableSpellChecking = manifest.DisableSpellChecking; // set browser language from manifest - default is en-US // "automatic" will set browser language to os culture info if (!string.IsNullOrEmpty(manifest.BrowserLanguage)) { if (string.Equals(manifest.BrowserLanguage, "Automatic", StringComparison.InvariantCultureIgnoreCase)) { BrowserLanguage = CultureInfo.CurrentCulture.Name; } else { //verify specified culture CultureInfo cultureInfo = null; try { cultureInfo = new CultureInfo(manifest.BrowserLanguage); } catch (Exception) { Logger.Error("Manifest browser language is not valid. Using default browser language en-US"); } BrowserLanguage = (cultureInfo != null) ? (cultureInfo.Name) : (BrowserLanguage); } Logger.Info(string.Format("Browser language being used is {0}", BrowserLanguage)); } string auth_server_whitelist = null; string auth_delegate_whitelist = null; if (cmdLine != null) { cmdLine.GetValue("auth-server-whitelist", out auth_server_whitelist); Logger.Info(string.Format("auth-server-whitelist [{0}]", auth_server_whitelist)); cmdLine.GetValue("auth-delegate-whitelist", out auth_delegate_whitelist); Logger.Info(string.Format("auth-delegate-whitelist [{0}]", auth_delegate_whitelist)); } // Initialize CEF using (AutoStopwatch.TimeIt("CEF initialization")) { ParagonRuntime.Initialize( CacheFolder, null, BrowserLanguage, auth_server_whitelist, auth_delegate_whitelist, DisableSpellChecking, Environment == ApplicationEnvironment.Development); } RunApplicationInternal(cmdLine, package, metadata); }
public void InitializeLogger(string paragonFolder, IApplicationPackage appPackage) { var cachePath = Path.Combine(paragonFolder, string.IsNullOrEmpty(appPackage.Manifest.ProcessGroup) ? appPackage.Manifest.Id : appPackage.Manifest.ProcessGroup); ParagonLogManager.ConfigureLogging(cachePath, LogContext.Browser, Settings.Default.MaxRolledLogFiles); }
public PackagedApplicationSchemeHandlerFactory(IApplicationPackage package) { _package = package; Register(); }
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); }
public static List <IParagonPlugin> LoadManagedPlugins(IPluginManager pluginManager, IApplicationPackage package, List <IPluginInfo> plugins) { if (pluginManager == null) { throw new ArgumentException("pluginManager"); } if (package == null) { throw new ArgumentException("package"); } var addedPlugins = new List <IParagonPlugin>(); if (plugins != null) { foreach (var appPlugin in plugins) { if (!appPlugin.Assembly.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase)) { try { using (var resolver = new PackagedPluginAssemblyResolver(package, appPlugin.Path)) { Logger.Info("Loading managed plugin " + appPlugin.Name); if (appPlugin.UnmanagedDlls != null) { Logger.Info("Loading the unmanaged DLLs for plugin " + appPlugin.Name); resolver.LoadUnmanagedDLLs(appPlugin.UnmanagedDlls); } var assembly = Assembly.Load(appPlugin.Assembly); var plugin = pluginManager.AddApplicationPlugin(appPlugin.Name, assembly); if (plugin == null) { Logger.Info("Could not load plugin " + appPlugin.Name); continue; } Logger.Info("Loaded managed plugin " + appPlugin.Name); if (plugin is IParagonPlugin) { addedPlugins.Add((IParagonPlugin)plugin); } } } catch (Exception ex) { Logger.Error("Could not create application plugin : " + appPlugin.Name, ex); } } } } return(addedPlugins); }
public PackagedPluginAssemblyResolver(IApplicationPackage package, string pluginPath) { _path = pluginPath; _package = package; AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve; }