Пример #1
0
        void RunWorkbenchInternal(object settings)
        {
            WorkbenchSettings wbSettings = (WorkbenchSettings)settings;

            WorkbenchStartup wbc = new WorkbenchStartup();

            LoggingService.Info("Initializing workbench...");
            wbc.InitializeWorkbench();

            RunWorkbenchInitializedCommands();

            LoggingService.Info("Starting workbench...");
            Exception exception = null;

            // finally start the workbench.
            try {
                callback.BeforeRunWorkbench();
                if (Debugger.IsAttached)
                {
                    wbc.Run(wbSettings.InitialFileList);
                }
                else
                {
                    try {
                        wbc.Run(wbSettings.InitialFileList);
                    } catch (Exception ex) {
                        exception = ex;
                    }
                }
            } finally {
                LoggingService.Info("Unloading services...");
                try {
                    WorkbenchSingleton.OnWorkbenchUnloaded();
                    PropertyService.Save();
                } catch (Exception ex) {
                    LoggingService.Warn("Exception during unloading", ex);
                    if (exception == null)
                    {
                        exception = ex;
                    }
                }
            }
            LoggingService.Info("Finished running workbench.");
            callback.WorkbenchClosed();
            if (exception != null)
            {
                const string errorText = "Unhandled exception terminated the workbench";
                LoggingService.Fatal(exception);
                if (useSharpDevelopErrorHandler)
                {
                    System.Windows.Forms.Application.Run(new ExceptionBox(exception, errorText, true));
                }
                else
                {
                    throw new RunWorkbenchException(errorText, exception);
                }
            }
        }
Пример #2
0
 public void RunWorkbench(WorkbenchSettings settings)
 {
     if (settings.RunOnNewThread)
     {
         Thread t = new Thread(RunWorkbenchInternal);
         t.SetApartmentState(ApartmentState.STA);
         t.Name = "SDmain";
         t.Start(settings);
     }
     else
     {
         RunWorkbenchInternal(settings);
     }
 }
Пример #3
0
		void RunWorkbench(WorkbenchSettings wbSettings)
		{
			if (host == null) {
				StartupSettings startup = new StartupSettings();
				startup.ApplicationName = "HostedSharpDevelop";
				startup.DataDirectory = Path.Combine(Path.GetDirectoryName(typeof(SharpDevelopHost).Assembly.Location), "../data");
				string sdaDir = Path.Combine(Path.GetDirectoryName(typeof(MainForm).Assembly.Location), "SdaAddIns");
				startup.AddAddInFile(Path.Combine(sdaDir, "SdaBase.addin"));
				
				host = new SharpDevelopHost(startup);
				host.InvokeTarget = this;
				host.BeforeRunWorkbench += delegate { groupBox1.Enabled = true; };
				host.WorkbenchClosed += delegate { groupBox1.Enabled = false; runButton.Enabled = true; };
			}
			
			host.RunWorkbench(wbSettings);
		}
Пример #4
0
		void RunWorkbench(WorkbenchSettings wbSettings)
		{
			if (host == null) {
				StartupSettings startup = new StartupSettings();
				startup.ApplicationName = "HostedSharpDevelop";
				startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ICSharpCode\\HostedSharpDevelop4");
				startup.DataDirectory = Path.Combine(Path.GetDirectoryName(typeof(SharpDevelopHost).Assembly.Location), "../data");
				string sdaAddInDir = Path.Combine(Path.GetDirectoryName(typeof(MainForm).Assembly.Location), "SdaAddIns");
				startup.AddAddInsFromDirectory(sdaAddInDir);
				
				host = new SharpDevelopHost(startup);
				host.InvokeTarget = this;
				host.BeforeRunWorkbench += delegate { groupBox1.Enabled = true; };
				host.WorkbenchClosed += delegate { groupBox1.Enabled = false; };
			}
			
			host.RunWorkbench(wbSettings);
		}
Пример #5
0
 /// <summary>
 /// Initializes the workbench (create the MainForm instance, construct menu from AddInTree etc.)
 /// and runs it using the supplied settings.
 /// This starts a new message loop for the workbench. By default the message loop
 /// is created on a new thread, but you can change the settings so that
 /// it is created on the thread calling RunWorkbench.
 /// In that case, RunWorkbench will block until SharpDevelop is shut down!
 /// </summary>
 public void RunWorkbench(WorkbenchSettings settings)
 {
     if (settings == null)
     {
         throw new ArgumentNullException("settings");
     }
     if (initStatus == SDInitStatus.CoreInitialized)
     {
         initStatus = SDInitStatus.Busy;
         helper.RunWorkbench(settings);
         if (settings.RunOnNewThread)
         {
             initStatus = SDInitStatus.WorkbenchInitialized;
         }
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Пример #6
0
		public void RunWorkbench(WorkbenchSettings settings)
		{
			if (settings.RunOnNewThread) {
				Thread t = new Thread(RunWorkbenchInternal);
				t.SetApartmentState(ApartmentState.STA);
				t.Name = "SDmain";
				t.Start(settings);
			} else {
				RunWorkbenchInternal(settings);
			}
		}
Пример #7
0
		void OpenFileButtonClick(object sender, System.EventArgs e)
		{
			using (OpenFileDialog dlg = new OpenFileDialog()) {
				if (dlg.ShowDialog() == DialogResult.OK) {
					if (runButton.Enabled) {
						// create host with InitialFile set
						runButton.Enabled = false;
						unloadHostDomainButton.Enabled = true;
						
						WorkbenchSettings wbSettings = new WorkbenchSettings();
						wbSettings.InitialFileList.Add(dlg.FileName);
						RunWorkbench(wbSettings);
					} else if (host != null) {
						if (host.IsSolutionOrProject(dlg.FileName)) {
							// won't occur because no project types are defined
							// in our reduces .addin file.
							host.OpenProject(dlg.FileName);
						} else {
							host.OpenDocument(dlg.FileName);
						}
					}
				}
			}
		}
Пример #8
0
        void RunWorkbenchInternal(object settings)
        {
            WorkbenchSettings wbSettings = (WorkbenchSettings)settings;

            LoggingService.Info("Initializing workbench...");
#if ModifiedForAltaxo
            // TODO what to do here: WorkbenchSingleton.InitializeWorkbench(typeof(DefaultWorkbench));
#else
            WorkbenchSingleton.InitializeWorkbench();
#endif

            // initialize workbench-dependent services:
            Project.ProjectService.InitializeService();

            LoggingService.Info("Starting workbench...");
            Exception exception = null;
            // finally start the workbench.
            try {
                StartWorkbenchCommand wbc = new StartWorkbenchCommand();
                callback.BeforeRunWorkbench();
                if (Debugger.IsAttached)
                {
                    wbc.Run(wbSettings.InitialFileList);
                }
                else
                {
                    try {
                        wbc.Run(wbSettings.InitialFileList);
                    } catch (Exception ex) {
                        exception = ex;
                    }
                }
            } finally {
                LoggingService.Info("Unloading services...");
                try {
                    Project.ProjectService.CloseSolution();
                    FileService.Unload();
                    PropertyService.Save();
                } catch (Exception ex) {
                    LoggingService.Warn("Exception during unloading", ex);
                    if (exception != null)
                    {
                        exception = ex;
                    }
                }
            }
            LoggingService.Info("Finished running workbench.");
            callback.WorkbenchClosed();
            if (exception != null)
            {
                const string errorText = "Unhandled exception terminated the workbench";
                LoggingService.Fatal(exception);
                if (useSharpDevelopErrorHandler)
                {
                    System.Windows.Forms.Application.Run(new ExceptionBox(exception, errorText, true));
                }
                else
                {
                    throw new RunWorkbenchException(errorText, exception);
                }
            }
        }
Пример #9
0
        static void RunApplication()
        {
            // The output encoding differs based on whether SharpDevelop 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 of SharpDevelop.

            #if DEBUG
            // 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 SharpDevelop doesn't have a console
            }
            #endif

            LoggingService.Info("Starting SharpDevelop...");
            try {
                StartupSettings startup = new StartupSettings();
                #if DEBUG
                startup.UseSharpDevelopErrorHandler = UseExceptionBox;
                #endif

                Assembly exe = typeof(SharpDevelopMain).Assembly;
                startup.ApplicationRootPath = Path.Combine(Path.GetDirectoryName(exe.Location), "..");
                startup.AllowUserAddIns = true;

                string configDirectory = ConfigurationManager.AppSettings["settingsPath"];
                if (String.IsNullOrEmpty(configDirectory)) {
                    startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                           "ICSharpCode/SharpDevelop" + RevisionClass.Major);
                } else {
                    startup.ConfigDirectory = Path.Combine(Path.GetDirectoryName(exe.Location), configDirectory);
                }

                startup.DomPersistencePath = ConfigurationManager.AppSettings["domPersistencePath"];
                if (string.IsNullOrEmpty(startup.DomPersistencePath)) {
                    startup.DomPersistencePath = Path.Combine(Path.GetTempPath(), "SharpDevelop" + RevisionClass.Major + "." + RevisionClass.Minor);
                    #if DEBUG
                    startup.DomPersistencePath = Path.Combine(startup.DomPersistencePath, "Debug");
                    #endif
                } else if (startup.DomPersistencePath == "none") {
                    startup.DomPersistencePath = null;
                }

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

                // allows testing addins without having to install them
                foreach (string parameter in SplashScreenForm.GetParameterList()) {
                    if (parameter.StartsWith("addindir:", StringComparison.OrdinalIgnoreCase)) {
                        startup.AddAddInsFromDirectory(parameter.Substring(9));
                    }
                }

                SharpDevelopHost host = new SharpDevelopHost(AppDomain.CurrentDomain, startup);

                string[] fileList = SplashScreenForm.GetRequestedFileList();
                if (fileList.Length > 0) {
                    if (LoadFilesInPreviousInstance(fileList)) {
                        LoggingService.Info("Aborting startup, arguments will be handled by previous instance");
                        return;
                    }
                }

                host.BeforeRunWorkbench += delegate {
                    if (SplashScreenForm.SplashScreen != null) {
                        SplashScreenForm.SplashScreen.BeginInvoke(new MethodInvoker(SplashScreenForm.SplashScreen.Dispose));
                        SplashScreenForm.SplashScreen = null;
                    }
                };

                WorkbenchSettings workbenchSettings = new WorkbenchSettings();
                workbenchSettings.RunOnNewThread = false;
                for (int i = 0; i < fileList.Length; i++) {
                    workbenchSettings.InitialFileList.Add(fileList[i]);
                }
                SDTraceListener.Install();
                host.RunWorkbench(workbenchSettings);
            } finally {
                LoggingService.Info("Leaving RunApplication()");
            }
        }
Пример #10
0
		private static void RunApplication()
		{
#if ModifiedForAltaxo
			var originalUICulture = System.Globalization.CultureInfo.CurrentUICulture;
			var originalCulture = System.Globalization.CultureInfo.CurrentCulture;
#endif
			// The output encoding differs based on whether SharpDevelop 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 of SharpDevelop.

#if DEBUG
			// 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 SharpDevelop doesn't have a console
			}
#endif

			LoggingService.Info("Starting SharpDevelop...");
			try
			{
				StartupSettings startup = new StartupSettings();
#if DEBUG
				startup.UseSharpDevelopErrorHandler = UseExceptionBox;
#endif

				Assembly exe = typeof(SharpDevelopMain).Assembly;
				startup.ApplicationRootPath = Path.Combine(Path.GetDirectoryName(exe.Location), "..");
				startup.AllowUserAddIns = true;

				string configDirectory = ConfigurationManager.AppSettings["settingsPath"];
				if (String.IsNullOrEmpty(configDirectory))
				{
#if ModifiedForAltaxo
					startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
																								 "Altaxo\\Altaxo4");
					startup.ResourceAssemblyName = "AltaxoStartup";
					ResourceService.RegisterNeutralStrings(new System.Resources.ResourceManager("Resources.AltaxoString", exe));
					ResourceService.RegisterNeutralImages(new System.Resources.ResourceManager("Resources.AltaxoBitmap", exe));
#else
					startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
					                                       "ICSharpCode/SharpDevelop" + RevisionClass.Major + "." + RevisionClass.Minor);
#endif
				}
				else
				{
					startup.ConfigDirectory = Path.Combine(Path.GetDirectoryName(exe.Location), configDirectory);
				}

				startup.DomPersistencePath = ConfigurationManager.AppSettings["domPersistencePath"];
				if (string.IsNullOrEmpty(startup.DomPersistencePath))
				{
					startup.DomPersistencePath = Path.Combine(Path.GetTempPath(), "SharpDevelop" + RevisionClass.Major + "." + RevisionClass.Minor);
#if DEBUG
					startup.DomPersistencePath = Path.Combine(startup.DomPersistencePath, "Debug");
#endif
				}
				else if (startup.DomPersistencePath == "none")
				{
					startup.DomPersistencePath = null;
				}

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

				// allows testing addins without having to install them
				foreach (string parameter in SplashScreenForm.GetParameterList())
				{
					if (parameter.StartsWith("addindir:", StringComparison.OrdinalIgnoreCase))
					{
						startup.AddAddInsFromDirectory(parameter.Substring(9));
					}
				}

				SharpDevelopHost host = new SharpDevelopHost(AppDomain.CurrentDomain, startup);

				string[] fileList = SplashScreenForm.GetRequestedFileList();
				if (fileList.Length > 0)
				{
					if (LoadFilesInPreviousInstance(fileList))
					{
						LoggingService.Info("Aborting startup, arguments will be handled by previous instance");
						return;
					}
				}

				host.BeforeRunWorkbench += delegate
				{
					if (SplashScreenForm.SplashScreen != null)
					{
						SplashScreenForm.SplashScreen.BeginInvoke(new MethodInvoker(SplashScreenForm.SplashScreen.Dispose));
						SplashScreenForm.SplashScreen = null;
					}
				};
#if ModifiedForAltaxo
				Altaxo.Settings.CultureSettingsAtStartup.StartupUICultureInfo = originalUICulture;
				Altaxo.Settings.CultureSettingsAtStartup.StartupDocumentCultureInfo = originalCulture;
				Altaxo.Current.SetPropertyService(new Altaxo.Main.Services.PropertyService());

				Altaxo.Main.Commands.AutostartCommand.EarlyRun(CommandLineArgs);
				if (Altaxo.Serialization.AutoUpdates.UpdateInstallerStarter.Run(true, SharpDevelopMain.CommandLineArgs))
					return;

				var comManager = new Altaxo.Com.ComManager(new Altaxo.Com.AltaxoComApplicationAdapter());
				Altaxo.Current.SetComManager(comManager);
				comManager.ProcessArguments(CommandLineArgs);
				if (comManager.ApplicationShouldExitAfterProcessingArgs)
					return;

				var altaxoWb = new Altaxo.Gui.SharpDevelop.AltaxoSDWorkbench();
				Altaxo.Current.SetWorkbench(altaxoWb);
				WorkbenchSingleton.InitializeWorkbench(altaxoWb, new ICSharpCode.SharpDevelop.Gui.AvalonDockLayout());
				new Altaxo.Main.Commands.AutostartCommand().Run();

				if (comManager.ApplicationWasStartedWithEmbeddingArg)
				{
					//System.Diagnostics.Debugger.Launch();
					comManager.StartLocalServer();
				}
#endif

				WorkbenchSettings workbenchSettings = new WorkbenchSettings();
				workbenchSettings.RunOnNewThread = false;
				for (int i = 0; i < fileList.Length; i++)
				{
					workbenchSettings.InitialFileList.Add(fileList[i]);
				}
				host.RunWorkbench(workbenchSettings);
			}
			finally
			{
				LoggingService.Info("Leaving RunApplication()");
			}

#if ModifiedForAltaxo
			Altaxo.Serialization.AutoUpdates.UpdateInstallerStarter.Run(false, null);
#endif
		}
Пример #11
0
		static void RunApplication()
		{
			LoggingService.Info("Starting SharpDevelop...");
			try {
				StartupSettings startup = new StartupSettings();
				#if DEBUG
				startup.UseSharpDevelopErrorHandler = !Debugger.IsAttached;
				#endif
				
				Assembly exe = typeof(SharpDevelopMain).Assembly;
				startup.ApplicationRootPath = Path.Combine(Path.GetDirectoryName(exe.Location), "..");
				startup.AllowUserAddIns = true;
#if ModifiedForAltaxo
        startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                               "Altaxo/Altaxo2");
        startup.ResourceAssemblyName = "AltaxoStartup";
#else
				startup.ConfigDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
				                                       "ICSharpCode/SharpDevelop2.1");
#endif				
				startup.AddAddInsFromDirectory(Path.Combine(startup.ApplicationRootPath, "AddIns"));
				
				SharpDevelopHost host = new SharpDevelopHost(AppDomain.CurrentDomain, startup);
#if ModifiedForAltaxo
          ResourceService.LoadUserStrings("AltaxoString.resources");
          ResourceService.LoadUserIcons("AltaxoBitmap.resources");
#endif
				
				string[] fileList = SplashScreenForm.GetRequestedFileList();
				if (fileList.Length > 0) {
					if (LoadFilesInPreviousInstance(fileList)) {
						LoggingService.Info("Aborting startup, arguments will be handled by previous instance");
						return;
					}
				}
				
				host.BeforeRunWorkbench += delegate {
					if (SplashScreenForm.SplashScreen != null) {
						SplashScreenForm.SplashScreen.BeginInvoke(new MethodInvoker(SplashScreenForm.SplashScreen.Dispose));
						SplashScreenForm.SplashScreen = null;
					}
				};
#if ModifiedForAltaxo
				WorkbenchSingleton.InitializeWorkbench(typeof(Altaxo.Gui.SharpDevelop.AltaxoSDWorkbench));
        Altaxo.Current.SetWorkbench((Altaxo.Gui.Common.IWorkbench)WorkbenchSingleton.Workbench);
        new Altaxo.Main.Commands.AutostartCommand().Run();
#endif
				
				WorkbenchSettings workbenchSettings = new WorkbenchSettings();
				workbenchSettings.RunOnNewThread = false;
				workbenchSettings.UseTipOfTheDay = true;
				for (int i = 0; i < fileList.Length; i++) {
					workbenchSettings.InitialFileList.Add(fileList[i]);
				}
				host.RunWorkbench(workbenchSettings);
			} finally {
				LoggingService.Info("Leaving RunApplication()");
			}
		}