public bool LaunchApp(string packageUri, string instanceId) { Logger.Debug("Launching application..."); string resolvedPackageUri; var package = ApplicationPackageResolver.Load(packageUri, (p) => p, out resolvedPackageUri); if (package == null) { throw new Exception("Could not resolve pacakge from " + packageUri); } var appId = package.Manifest.Id; var appType = package.Manifest.Type; Logger.Info(string.Format("Launching {0} application {1} ...", appType, appId)); if (instanceId == null) { instanceId = Guid.NewGuid().ToString(); } var environment = Application.Metadata.Environment; var exePath = Assembly.GetEntryAssembly().Location; var isStandalone = Application.Metadata.IsStandalone; var args = ParagonCommandLineParser.CreateCommandLine(environment, resolvedPackageUri, appType, appId, instanceId, isStandalone); var process = Process.Start(new ProcessStartInfo(exePath, args) { ErrorDialog = false }); return(process != null); }
public static void Main() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Create command line args parser. var cmdLine = new ParagonCommandLineParser(Environment.GetCommandLineArgs()); /* * Following statement is due to the Chromium bug: https://code.google.com/p/chromium/issues/detail?id=125614 * This statement can be removed once we know for sure that the issue has been fixed by Chrome. * For now, we are disabling any system setting/command line setting for the TZ variable. */ Environment.SetEnvironmentVariable("TZ", null); // Launch a debugger if a --debug flag was passed. if (cmdLine.HasFlag("debug")) { Debugger.Launch(); } // Extract app package. ApplicationMetadata appMetadata; IApplicationPackage appPackage; if (!ApplicationManager.ResolveMetadataAndPackage(cmdLine, out appMetadata, out appPackage)) { Environment.ExitCode = 1; return; } try { _appManager = ApplicationManager.GetInstance(); //initialize logger earlier in the start up sequence _appManager.InitializeLogger(Environment.ExpandEnvironmentVariables(Settings.Default.CacheDirectory), appPackage); // Bail if the app is a singleton and an instance is already running. Cmd line args from // this instance will be sent to the singleton isntance by the SingleInstance utility. if (_appManager.RedirectApplicationLaunchIfNeeded(appPackage, appMetadata.Environment)) { return; } // Initialize the app. App app; using (AutoStopwatch.TimeIt("Initializing Paragon.App")) { app = new App(); app.InitializeComponent(); app.Startup += delegate { _appManager.Initialize( (name, version, iconStream) => new ParagonSplashScreen(name, version, iconStream), (package, metadata, args) => { var bootstrapper = new Bootstrapper(); var appFactory = bootstrapper.Resolve <ApplicationFactory>(); return(appFactory.CreateApplication(metadata, package, args)); }, (args) => { var query = HttpUtility.ParseQueryString(args); return(query.Keys.Cast <string>().ToDictionary <string, string, object>(key => key, key => query[key])); }, Environment.ExpandEnvironmentVariables(Settings.Default.CacheDirectory), true, appPackage.Manifest.DisableSpellChecking ); _appManager.AllApplicationsClosed += delegate { _appManager.Shutdown("All applications closed"); _appManager.ShutdownLogger(); app.Shutdown(); }; _appManager.RunApplication(cmdLine, appPackage, appMetadata); }; } // Run the app (this is a blocking call). app.Run(); } catch (Exception ex) { MessageBox.Show(string.Format("Error launching application : {0}", ex.InnerException != null ? ex.InnerException.Message : ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Environment.ExitCode = 1; throw; } }