private PackagePart GetPart(string path) { try { if (!string.IsNullOrEmpty(path) || _package != null) { return(_package.GetPart(path)); } Logger.Warn("Package part not found: " + path); } catch (Exception e) { Logger.Error("Failed to get package part. Path:{0}, Exception: {1}", path, e.ToString()); } return(null); }
protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request) { if (!string.IsNullOrEmpty(schemeName) && schemeName.Equals(SchemeName, StringComparison.InvariantCultureIgnoreCase)) { try { var absolutePath = new Uri(request.Url).AbsolutePath; if (!string.IsNullOrEmpty(absolutePath) && absolutePath.EndsWith(EventPage)) { var scripts = GetApplicationBackgroundScripts(); if (scripts.Length != 0) { var memoryStream = new MemoryStream(); var writer = new StreamWriter(memoryStream, Encoding.UTF8, 2048); { writer.Write(@"<!DOCTYPE html> <html lang=""en""> <head/> <body>"); foreach (var script in scripts) { writer.Write("<script src=\"{0}\"></script>\r\n", script); } writer.Write(@" </body> </html>"); writer.Flush(); } memoryStream.Seek(0, SeekOrigin.Begin); return(new StreamResourceHandler("text/html", memoryStream)); } } var resourcePart = _package.GetPart(absolutePath); if (resourcePart != null) { return(new StreamResourceHandler(resourcePart.ContentType, resourcePart.GetStream())); } } catch (Exception exception) { Logger.Error("Failed to create resource handler for [{0}] because: {1}", request.Url, exception); } } return(null); }
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); }
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; } } }