Example #1
0
        void ProcessThread()
        {
            Thread.CurrentThread.Name = "ProcessThread";

            while (!requestExit)
            {
                processTime.Refresh(25);

                device.Begin();

                if (safeMode)
                {
                    try
                    {
                        if (!crashed)
                        {
                            app.Process(processTime.Elapsed);
                            mainTarget.elapsed = processTime.Elapsed;
                            app.Render(mainTarget);
                        }
                    }
                    catch (Exception e)
                    {
                        crashed = true;

                        File file = FileSystem.GetFile("system/errorlog.txt", FileOpenMode.NoPackage | FileOpenMode.Write);
                        file.Seek(0, SeekPosition.End);

                        System.IO.StreamWriter writer = new System.IO.StreamWriter(file);
                        writer.WriteLine();
                        writer.WriteLine("----------------------------------------------------------------------");
                        writer.WriteLine(System.DateTime.Now.ToLocalTime().ToString());
                        writer.WriteLine("exception: " + e.Message);
                        writer.WriteLine("trace:");
                        writer.Write(e.StackTrace);
                        writer.WriteLine();
                        writer.Close();

                        file.Close();
                    }
                }
                else
                {
                    app.Process(processTime.Elapsed);
                    mainTarget.elapsed = processTime.Elapsed;
                    app.Render(mainTarget);
                }

                device.End();
            }

            app.Close();
        }
Example #2
0
        private void CloseIfRequested()
        {
            if (!ViewModel.UseAutoClose)
            {
                return;
            }

            var anyErrors = ViewModel.WorkingFolders.Any(m => m.NumConflicts > 0 || m.NumFailures > 0);

            if (anyErrors)
            {
                if (ViewModel.UseForceClose)
                {
                    _application.Close();
                }
            }
            else if (ViewModel.WorkingFolders.Any())
            {
                _application.Close();
            }
        }
 public async Task RequestInternetAccess()
 {
     if (!m_internet.IsConnected())
     {
         while (!m_internet.IsConnected())
         {
             bool isCanceled = !(await m_internet.RequestConnection());
             if (isCanceled)
             {
                 m_application.Close();
             }
         }
     }
 }
Example #4
0
 private void InitActions()
 {
     _switchActions.Add("/exit", () =>
     {
         _app.Close();
     });
     _switchActions.Add("/restart", () =>
     {
         _app.Restart();
     });
     _argumentedSwitches.Add("/module", async(name) =>
     {
         if (!string.IsNullOrEmpty(name))
         {
             await _app.TabManager.StartModule(name, true);
         }
     });
 }
Example #5
0
        public void Close()
        {
            m_shutdown = true;

            m_internalApplication.Close();
        }
Example #6
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;
                }
            }
        }
Example #7
0
 private static void OnExitClick(object sender, EventArgs eventArgs)
 {
     _application.Close();
 }