Esempio n. 1
0
 public static void Main()
 {
     LogViewer.App app = new LogViewer.App();
     app.InitializeComponent();
     app.Run();
 }
Esempio n. 2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            logger.Trace("OnStartup");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Current.DispatcherUnhandledException       += Current_DispatcherUnhandledException;

            if (e.Args.Any(x => (x.EndsWith(".txt") || x.EndsWith(".log")) && File.Exists(x)))
            {
                IsManualStartup = true;

                try
                {
                    if (!mutex.WaitOne(TimeSpan.Zero, true))
                    {
                        var proc           = Process.GetCurrentProcess();
                        var processName    = proc.ProcessName.Replace(".vshost", "");
                        var runningProcess = Process.GetProcesses()
                                             .FirstOrDefault(x => (x.ProcessName == processName || x.ProcessName == proc.ProcessName || x.ProcessName == proc.ProcessName + ".vshost") && x.Id != proc.Id);

                        if (runningProcess == null)
                        {
                            var app = new App();
                            app.InitializeComponent();
                            var window = new MainWindow();
                            MVVM.Views.MainWindow.HandleParameter(e.Args);
                            app.Run(window);
                            return;
                        }

                        UnsafeNative.SendMessage(runningProcess.MainWindowHandle, string.Join(" ", e.Args));

                        Environment.Exit(0);
                    }
                }
                catch (Exception exception)
                {
                    logger.Warn(exception, "OnStartup check mutext exception (open with arguments)");
                }
            }

            Settings.Instance.Load();

            if (Settings.Instance.OnlyOneAppInstance)
            {
                try
                {
                    if (mutex.WaitOne(TimeSpan.Zero, true))
                    {
                        mutex.ReleaseMutex();
                    }
                    else
                    {
                        logger.Trace("OnStartup: one instance of Log Viewer already started");
                        MessageBox.Show(Locals.OnlyOneInstanceCanBeStartedMessageBoxText);
                        Environment.Exit(0);
                    }
                }
                catch (Exception exception)
                {
                    logger.Warn(exception, "OnStartup check mutext exception");
                }
            }

            try
            {
                if (!IsAssociated())
                {
                    var filePath = Process.GetCurrentProcess().MainModule.FileName;

                    SetAssociation(".txt", "LogViewer", filePath);
                    SetAssociation(".log", "LogViewer", filePath);
                }
            }
            catch (Exception exception)
            {
                logger.Warn(exception, "OnStartup set file association exception");
            }

            base.OnStartup(e);

            Task.Run(() =>
            {
                // даем время прогрузиться окну
                Thread.Sleep(5000);
                UpdateManager.StartCheckUpdate();
            });
        }