예제 #1
0
        private void LoadProject(string projectFileName, bool restoreLayout)
        {
            ProjectData projectData   = ProjectPersister.LoadProjectData(projectFileName);
            bool        hasLayoutData = projectData.tabLayoutXml != null;

            if (hasLayoutData && restoreLayout && logWindowList.Count > 0)
            {
                ProjectLoadDlg dlg = new ProjectLoadDlg();
                if (DialogResult.Cancel != dlg.ShowDialog())
                {
                    switch (dlg.ProjectLoadResult)
                    {
                    case ProjectLoadDlgResult.IgnoreLayout:
                        hasLayoutData = false;
                        break;

                    case ProjectLoadDlgResult.CloseTabs:
                        CloseAllTabs();
                        break;

                    case ProjectLoadDlgResult.NewWindow:
                        LogExpertProxy.NewWindow(new string[] { projectFileName });
                        return;
                    }
                }
            }

            if (projectData != null)
            {
                foreach (string fileName in projectData.memberList)
                {
                    if (hasLayoutData)
                    {
                        AddFileTabDeferred(fileName, false, null, true, null);
                    }
                    else
                    {
                        AddFileTab(fileName, false, null, true, null);
                    }
                }

                if (hasLayoutData && restoreLayout)
                {
                    // Re-creating tool (non-document) windows is needed because the DockPanel control would throw strange errors
                    DestroyToolWindows();
                    InitToolWindows();
                    RestoreLayout(projectData.tabLayoutXml);
                }
            }
        }
        private void LogTabWindow_Closing(object sender, CancelEventArgs e)
        {
            try
            {
                shouldStop = true;
                statusLineEventHandle.Set();
                statusLineEventWakeupHandle.Set();
                ledThread.Join();
                statusLineThread.Join();

                IList <LogWindow> deleteLogWindowList = new List <LogWindow>();
                ConfigManager.Settings.alwaysOnTop = TopMost && ConfigManager.Settings.preferences.allowOnlyOneInstance;
                SaveLastOpenFilesList();

                foreach (LogWindow logWindow in logWindowList)
                {
                    deleteLogWindowList.Add(logWindow);
                }

                foreach (LogWindow logWindow in deleteLogWindowList)
                {
                    RemoveAndDisposeLogWindow(logWindow, true);
                }

                DestroyBookmarkWindow();

                ConfigManager.Instance.ConfigChanged -= ConfigChanged;

                SaveWindowPosition();
                ConfigManager.Save(SettingsFlags.WindowPosition | SettingsFlags.FileHistory);
            }
            catch (Exception)
            {
                // ignore error (can occur then multipe instances are closed simultaneously or if the
                // window was not constructed completely because of errors)
            }
            finally
            {
                if (LogExpertProxy != null)
                {
                    LogExpertProxy.WindowClosed(this);
                }
            }
        }
예제 #3
0
		private static void Sub_Main(string[] orgArgs)
		{
			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
			Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

			Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

			Logger.logInfo("============================================================================");
			Logger.logInfo("LogExpert " + Assembly.GetExecutingAssembly().GetName().Version.Major + "." +
						   Assembly.GetExecutingAssembly().GetName().Version.Minor + "/" +
						   Assembly.GetExecutingAssembly().GetName().Version.Build.ToString() +
						   " started.");
			Logger.logInfo("============================================================================");

			List<string> argsList = new List<string>();
			foreach (string fileArg in orgArgs)
			{
				try
				{
					FileInfo info = new FileInfo(fileArg);
					if (info.Exists)
					{
						argsList.Add(info.FullName);
					}
					else
					{
						argsList.Add(fileArg);
					}
				}
				catch (Exception)
				{
					MessageBox.Show("File name " + fileArg + " is not a valid file name!", "LogExpert Error");
				}
			}
			string[] args = argsList.ToArray();

			int pId = Process.GetCurrentProcess().SessionId;

			try
			{
				Settings settings = ConfigManager.Settings;
				bool isCreated = false;
				Mutex mutex = new System.Threading.Mutex(false, "Local\\LogExpertInstanceMutex" + pId, out isCreated);
				if (isCreated)
				{
					// first application instance
					Application.EnableVisualStyles();
					Application.SetCompatibleTextRenderingDefault(false);
					LogTabWindow logWin = new LogTabWindow(args.Length > 0 ? args : null, 1, false);

					// first instance
					//WindowsIdentity wi = WindowsIdentity.GetCurrent();
					IpcServerChannel ipcChannel = new IpcServerChannel("LogExpert" + pId);
					ChannelServices.RegisterChannel(ipcChannel, false);
					RemotingConfiguration.RegisterWellKnownServiceType(typeof(LogExpertProxy),
						"LogExpertProxy",
						WellKnownObjectMode.Singleton);
					LogExpertProxy proxy = new LogExpertProxy(logWin);
					RemotingServices.Marshal(proxy, "LogExpertProxy");

					LogExpertApplicationContext context = new LogExpertApplicationContext(proxy, logWin);
					Application.Run(context);

					ChannelServices.UnregisterChannel(ipcChannel);
				}
				else
				{
					int counter = 3;
					string errMsg = "";
					IpcClientChannel ipcChannel = new IpcClientChannel("LogExpertClient#" + pId, null);
					ChannelServices.RegisterChannel(ipcChannel, false);
					while (counter > 0)
					{
						try
						{
							// another instance already exists
							//WindowsIdentity wi = WindowsIdentity.GetCurrent();
							LogExpertProxy proxy = (LogExpertProxy)Activator.GetObject(typeof(LogExpertProxy),
								"ipc://LogExpert" + pId + "/LogExpertProxy");
							if (settings.preferences.allowOnlyOneInstance)
							{
								proxy.LoadFiles(args);
							}
							else
							{
								proxy.NewWindowOrLockedWindow(args);
							}
							break;
						}
						catch (RemotingException e)
						{
							Logger.logError("IpcClientChannel error: " + e.Message);
							errMsg = e.Message;
							counter--;
							Thread.Sleep(500);
						}
					}
					if (counter == 0)
					{
						Logger.logError("IpcClientChannel error, giving up: " + errMsg);
						MessageBox.Show("Cannot open connection to first instance (" + errMsg + ")", "LogExpert");
					}
				}
				mutex.Close();
			}
			catch (Exception ex)
			{
				Logger.logError("Mutex error, giving up: " + ex.Message);
				MessageBox.Show("Cannot open connection to first instance (" + ex.Message + ")", "LogExpert");
			}
		}
예제 #4
0
        private static void Sub_Main(string[] orgArgs)
        {
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            Logger.logInfo("============================================================================");
            Logger.logInfo("LogExpert " + Assembly.GetExecutingAssembly().GetName().Version.Major + "." +
                           Assembly.GetExecutingAssembly().GetName().Version.Minor + "/" +
                           Assembly.GetExecutingAssembly().GetName().Version.Build.ToString() +
                           " started.");
            Logger.logInfo("============================================================================");

            CmdLine       cmdLine    = new CmdLine();
            CmdLineString configFile = new CmdLineString("config", false, "A configuration (settings) file");

            cmdLine.RegisterParameter(configFile);
            string[] remainingArgs = cmdLine.Parse(orgArgs);

            List <string> argsList = new List <string>();

            // This loop tries to convert relative file names into absolute file names (assuming that platform file names are given).
            // It tolerates errors, to give file system plugins (e.g. sftp) a change later.
            // TODO: possibly should be moved to LocalFileSystem plugin
            foreach (string fileArg in remainingArgs)
            {
                try
                {
                    FileInfo info = new FileInfo(fileArg);
                    if (info.Exists)
                    {
                        argsList.Add(info.FullName);
                    }
                    else
                    {
                        argsList.Add(fileArg);
                    }
                }
                catch (Exception)
                {
                    argsList.Add(fileArg);
                }
            }
            string[] args = argsList.ToArray();
            if (configFile.Exists)
            {
                FileInfo cfgFileInfo = new FileInfo(configFile.Value);
                if (cfgFileInfo.Exists)
                {
                    ConfigManager.Import(cfgFileInfo, ExportImportFlags.All);
                }
                else
                {
                    MessageBox.Show("Config file not found", "LogExpert");
                }
            }

            int pId = Process.GetCurrentProcess().SessionId;

            try
            {
                Settings settings  = ConfigManager.Settings;
                bool     isCreated = false;
                Mutex    mutex     = new System.Threading.Mutex(false, "Local\\LogExpertInstanceMutex" + pId, out isCreated);
                if (isCreated)
                {
                    // first application instance
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    LogTabWindow logWin = new LogTabWindow(args.Length > 0 ? args : null, 1, false);

                    // first instance
                    //WindowsIdentity wi = WindowsIdentity.GetCurrent();
                    IpcServerChannel ipcChannel = new IpcServerChannel("LogExpert" + pId);
                    ChannelServices.RegisterChannel(ipcChannel, false);
                    RemotingConfiguration.RegisterWellKnownServiceType(typeof(LogExpertProxy),
                                                                       "LogExpertProxy",
                                                                       WellKnownObjectMode.Singleton);
                    LogExpertProxy proxy = new LogExpertProxy(logWin);
                    RemotingServices.Marshal(proxy, "LogExpertProxy");

                    LogExpertApplicationContext context = new LogExpertApplicationContext(proxy, logWin);
                    Application.Run(context);

                    ChannelServices.UnregisterChannel(ipcChannel);
                }
                else
                {
                    int              counter    = 3;
                    string           errMsg     = "";
                    IpcClientChannel ipcChannel = new IpcClientChannel("LogExpertClient#" + pId, null);
                    ChannelServices.RegisterChannel(ipcChannel, false);
                    while (counter > 0)
                    {
                        try
                        {
                            // another instance already exists
                            //WindowsIdentity wi = WindowsIdentity.GetCurrent();
                            LogExpertProxy proxy = (LogExpertProxy)Activator.GetObject(typeof(LogExpertProxy),
                                                                                       "ipc://LogExpert" + pId + "/LogExpertProxy");
                            if (settings.preferences.allowOnlyOneInstance)
                            {
                                proxy.LoadFiles(args);
                            }
                            else
                            {
                                proxy.NewWindowOrLockedWindow(args);
                            }
                            break;
                        }
                        catch (RemotingException e)
                        {
                            Logger.logError("IpcClientChannel error: " + e.Message);
                            errMsg = e.Message;
                            counter--;
                            Thread.Sleep(500);
                        }
                    }
                    if (counter == 0)
                    {
                        Logger.logError("IpcClientChannel error, giving up: " + errMsg);
                        MessageBox.Show("Cannot open connection to first instance (" + errMsg + ")", "LogExpert");
                    }
                }
                mutex.Close();
            }
            catch (Exception ex)
            {
                Logger.logError("Mutex error, giving up: " + ex.Message);
                MessageBox.Show("Cannot open connection to first instance (" + ex.Message + ")", "LogExpert");
            }
        }
예제 #5
0
        private static void Sub_Main(string[] orgArgs)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            Logger.logInfo("============================================================================");
            Logger.logInfo("LogExpert " + Assembly.GetExecutingAssembly().GetName().Version.Major + "." +
                           Assembly.GetExecutingAssembly().GetName().Version.Minor + "/" +
                           Assembly.GetExecutingAssembly().GetName().Version.Build.ToString() +
                           " started.");
            Logger.logInfo("============================================================================");

            List <string> argsList = new List <string>();

            foreach (string fileArg in orgArgs)
            {
                try
                {
                    FileInfo info = new FileInfo(fileArg);
                    if (info.Exists)
                    {
                        argsList.Add(info.FullName);
                    }
                    else
                    {
                        argsList.Add(fileArg);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("File name " + fileArg + " is not a valid file name!", "LogExpert Error");
                }
            }
            string[] args = argsList.ToArray();

            int pId = Process.GetCurrentProcess().SessionId;

            try
            {
                Settings settings  = ConfigManager.Settings;
                bool     isCreated = false;
                Mutex    mutex     = new System.Threading.Mutex(false, "Local\\LogExpertInstanceMutex" + pId, out isCreated);
                if (isCreated)
                {
                    // first application instance
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    LogTabWindow logWin = new LogTabWindow(args.Length > 0 ? args : null, 1, false);

                    // first instance
                    //WindowsIdentity wi = WindowsIdentity.GetCurrent();
                    IpcServerChannel ipcChannel = new IpcServerChannel("LogExpert" + pId);
                    ChannelServices.RegisterChannel(ipcChannel, false);
                    RemotingConfiguration.RegisterWellKnownServiceType(typeof(LogExpertProxy),
                                                                       "LogExpertProxy",
                                                                       WellKnownObjectMode.Singleton);
                    LogExpertProxy proxy = new LogExpertProxy(logWin);
                    RemotingServices.Marshal(proxy, "LogExpertProxy");

                    LogExpertApplicationContext context = new LogExpertApplicationContext(proxy, logWin);
                    Application.Run(context);

                    ChannelServices.UnregisterChannel(ipcChannel);
                }
                else
                {
                    int              counter    = 3;
                    string           errMsg     = "";
                    IpcClientChannel ipcChannel = new IpcClientChannel("LogExpertClient#" + pId, null);
                    ChannelServices.RegisterChannel(ipcChannel, false);
                    while (counter > 0)
                    {
                        try
                        {
                            // another instance already exists
                            //WindowsIdentity wi = WindowsIdentity.GetCurrent();
                            LogExpertProxy proxy = (LogExpertProxy)Activator.GetObject(typeof(LogExpertProxy),
                                                                                       "ipc://LogExpert" + pId + "/LogExpertProxy");
                            if (settings.preferences.allowOnlyOneInstance)
                            {
                                proxy.LoadFiles(args);
                            }
                            else
                            {
                                proxy.NewWindowOrLockedWindow(args);
                            }
                            break;
                        }
                        catch (RemotingException e)
                        {
                            Logger.logError("IpcClientChannel error: " + e.Message);
                            errMsg = e.Message;
                            counter--;
                            Thread.Sleep(500);
                        }
                    }
                    if (counter == 0)
                    {
                        Logger.logError("IpcClientChannel error, giving up: " + errMsg);
                        MessageBox.Show("Cannot open connection to first instance (" + errMsg + ")", "LogExpert");
                    }
                }
                mutex.Close();
            }
            catch (Exception ex)
            {
                Logger.logError("Mutex error, giving up: " + ex.Message);
                MessageBox.Show("Cannot open connection to first instance (" + ex.Message + ")", "LogExpert");
            }
        }
예제 #6
0
 public LogExpertApplicationContext(LogExpertProxy proxy, LogTabWindow firstLogWin)
 {
     this.proxy = proxy;
     this.proxy.LastWindowClosed += proxy_LastWindowClosed;
     firstLogWin.Show();
 }
		public LogExpertApplicationContext(LogExpertProxy proxy, LogTabWindow firstLogWin)
		{
			this.proxy = proxy;
			this.proxy.LastWindowClosed += proxy_LastWindowClosed;
			firstLogWin.Show();
		}