public ApplicationMetadata ParseApplicationMetadata()
        {
            var applicationMetadata = new ApplicationMetadata();

            // Resolve start data.
            string startApp;

            if (!GetValue(StartApp, out startApp))
            {
                Logger.Error("No --start-app parameter provided at the command line");
                throw new Exception("start-app parameter is required");
            }

            applicationMetadata.StartData = startApp;

            // Resolve app ID if provided.
            string appId;

            if (GetValue(StartAppId, out appId))
            {
                applicationMetadata.Id = appId;
            }

            // Resolve instance ID if provided.
            string instId;

            if (GetValue(StartAppInstId, out instId))
            {
                applicationMetadata.InstanceId = instId;
            }

            // Resolve app type if provided.
            string appType;

            if (GetValue(StartAppType, out appType))
            {
                applicationMetadata.AppType = (ApplicationType)Enum.Parse(typeof(ApplicationType), appType, true);
            }

            // Resolve environment, default to Production.
            applicationMetadata.Environment = ApplicationEnvironment.Production;

            string environment;

            if (GetValue(Env, out environment))
            {
                applicationMetadata.Environment = (ApplicationEnvironment)Enum.Parse(typeof(ApplicationEnvironment), environment, true);
            }

            string wdPortStr;
            int    wdPortInt;

            if (GetValue(WDPort, out wdPortStr) && int.TryParse(wdPortStr, out wdPortInt))
            {
                applicationMetadata.WDPort = wdPortInt;
            }

            // Look for standalone flag
            applicationMetadata.IsStandalone = HasFlag(Standalone);

            return(applicationMetadata);
        }
Exemplo n.º 2
0
        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;
                }
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        /// <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);
        }