示例#1
0
        public static void Main(string[] args)
        {
            // Make sure to use nothing except from this Assembly (event not derived from another assembly)
            // until the splash screen is shown
            // otherwise other assemblies will be loaded before the splash screen is visible

            var startupArguments = new StartupArguments(FindApplicationName(), args);

            // Do not use LoggingService here (see comment in Run(string[]))
            if (UseExceptionBox(args))
            {
                try
                {
                    Run(startupArguments);
                }
                catch (Exception ex)
                {
                    try
                    {
                        HandleMainException(startupArguments, ex);
                    }
                    catch (Exception loadError)
                    {
                        // HandleMainException can throw error when log4net is not found
                        MessageBox.Show(loadError.ToString(), "Critical error (Logging service defect?)");
                    }
                }
            }
            else
            {
                Run(startupArguments);
            }
        }
示例#2
0
 public StartupArguments(StartupArguments from)
 {
     ApplicationName   = from.ApplicationName;
     RequestedFileList = from.RequestedFileList;
     ParameterList     = from.ParameterList;
     StartupArgs       = from.StartupArgs;
 }
示例#3
0
 private static void HandleMainException(StartupArguments args, Exception ex)
 {
     Current.Log.Fatal(ex);
     try
     {
         new ExceptionBox(ex, "Unhandled exception terminated " + args.ApplicationName, true).ShowDialog();
     }
     catch
     {
         MessageBox.Show(ex.ToString(), "Critical error (cannot use ExceptionBox)");
     }
 }
示例#4
0
        private static void Run(StartupArguments startupArguments)
        {
            // DO NOT USE LoggingService HERE!
            // LoggingService requires ICSharpCode.Core.dll and log4net.dll
            // When a method containing a call to LoggingService is JITted, the
            // libraries are loaded.
            // We want to show the SplashScreen while those libraries are loading, so
            // don't call Current.Log.

#if DEBUG
            Control.CheckForIllegalCrossThreadCalls = true;
#endif
            bool noLogo = false;

            Application.SetCompatibleTextRenderingDefault(false);

            foreach (string parameter in startupArguments.ParameterList)
            {
                if ("nologo".Equals(parameter, StringComparison.OrdinalIgnoreCase))
                {
                    noLogo = true;
                }

                // do not show logo if Altaxo is started as COM server
                if ("embedding".Equals(parameter, StringComparison.OrdinalIgnoreCase))
                {
                    noLogo = true;
                }
            }

            if (!CheckEnvironment(startupArguments)) // check the framework version
            {
                return;
            }

            if (!noLogo)
            {
                SplashScreenForm.ShowSplashScreen(startupArguments.ApplicationName); // show splash screen
            }

            try
            {
                RunApplication(startupArguments); // now run the application
            }
            finally
            {
                if (SplashScreenForm.SplashScreen != null)
                {
                    SplashScreenForm.SplashScreen.Dispose();
                }
            }
        }
示例#5
0
        /// <summary>
        /// Checks if we do have a compatible dotnet framework version for running this app.
        /// </summary>
        /// <returns></returns>
        private static bool CheckEnvironment(StartupArguments args)
        {
            // Safety check: our setup already checks that .NET 4 is installed, but we manually check the .NET version in case the app is
            // used on another machine than it was installed on (e.g. "on USB stick")
            if (!Altaxo.Main.Services.NetFrameworkVersionDetermination.IsVersion471Installed())
            {
                MessageBox.Show(string.Format("This version of {0} requires .NET 4.7.1 You are using: {1}", args.ApplicationName, Environment.Version));
                return(false);
            }
            // Work around a WPF issue when %WINDIR% is set to an incorrect path
            string windir = Environment.GetFolderPath(Environment.SpecialFolder.Windows, Environment.SpecialFolderOption.DoNotVerify);

            if (Environment.GetEnvironmentVariable("WINDIR") != windir)
            {
                Environment.SetEnvironmentVariable("WINDIR", windir);
            }
            return(true);
        }
示例#6
0
        private static void RunApplication(StartupArguments startupArguments)
        {
#if DEBUG
            // The output encoding differs based on whether the app is a console app (debug mode)
            // or Windows app (release mode). Because this flag also affects the default encoding
            // when reading from other processes' standard output, we explicitly set the encoding to get
            // consistent behaviour in debug and release builds.

            // Console apps use the system's OEM codepage, windows apps the ANSI codepage.
            // We'll always use the Windows (ANSI) codepage.
            try
            {
                Console.OutputEncoding = System.Text.Encoding.Default;
            }
            catch (IOException)
            {
                // can happen if the application doesn't have a console appended
            }
#endif

            Current.Log.Info(string.Format("Starting {0}...", startupArguments.ApplicationName));
            Altaxo.Main.Services.IAutoUpdateInstallationService updateInstaller = null;
            try
            {
                var startupSettings = new StartupSettings(startupArguments.ApplicationName, startupArguments.StartupArgs, startupArguments.RequestedFileList, startupArguments.ParameterList);

#if DEBUG
                startupSettings.UseExceptionBoxForErrorHandler = UseExceptionBox(startupArguments.StartupArgs);
#endif

                Assembly thisAssembly = typeof(StartupMain).Assembly;
                startupSettings.ApplicationRootPath = Path.Combine(Path.GetDirectoryName(thisAssembly.Location), "..");
                startupSettings.AllowUserAddIns     = true;

                string configDirectory = System.Configuration.ConfigurationManager.AppSettings["settingsPath"];
                if (string.IsNullOrEmpty(configDirectory))
                {
                    string relativeConfigDirectory = System.Configuration.ConfigurationManager.AppSettings["relativeSettingsPath"];
                    if (string.IsNullOrEmpty(relativeConfigDirectory))
                    {
                        startupSettings.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), startupArguments.ApplicationName);
                    }
                    else
                    {
                        startupSettings.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), startupArguments.ApplicationName, relativeConfigDirectory);
                    }
                }
                else
                {
                    startupSettings.ConfigDirectory = Path.Combine(Path.GetDirectoryName(thisAssembly.Location), configDirectory);
                }

                startupSettings.AddAddInsFromDirectory(Path.Combine(startupSettings.ApplicationRootPath, "AddIns"));

                // allows testing addins without having to install them, by providing them in a command line
                const string addinCommandStart = "addindir:";
                foreach (string parameter in startupSettings.ParameterList)
                {
                    if (parameter.StartsWith(addinCommandStart, StringComparison.OrdinalIgnoreCase))
                    {
                        startupSettings.AddAddInsFromDirectory(parameter.Substring(addinCommandStart.Length));
                    }
                }

                // Start ServiceSystem, PropertyService, ResourceService, Load Addins
                InitializeApplication(startupSettings); // initialize core, load all addins

                if (startupSettings.RequestedFileList.Length > 0)
                {
                    if (LoadFilesInPreviousInstance(startupSettings.RequestedFileList))
                    {
                        Current.Log.Info("Aborting startup, arguments will be handled by previous instance");
                        return;
                    }
                }

                updateInstaller = Altaxo.Current.GetService <Altaxo.Main.Services.IAutoUpdateInstallationService>();
                if (null != updateInstaller)
                {
                    if (updateInstaller.Run(true, startupArguments.StartupArgs))
                    {
                        return;
                    }
                }

                // Start Com
                var comManager = Altaxo.Current.GetService <Altaxo.Main.IComManager>();
                if (null != comManager)
                {
                    if (!comManager.ProcessStartupArguments(startupArguments.StartupArgs))
                    {
                        return;
                    }
                }

                RunWorkbench(
                    startupSettings,
                    () =>
                {
                    var splashScreen = SplashScreenForm.SplashScreen;
                    if (splashScreen != null)
                    {
                        splashScreen.BeginInvoke(new MethodInvoker(splashScreen.Dispose));
                        SplashScreenForm.SplashScreen = null;
                    }
                }, null);
            }
            finally
            {
                Current.Log.Info("Leaving RunApplication()");
            }

            updateInstaller?.Run(false, null);
        }