示例#1
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // create Wpf.Application.Current
            System.Windows.Application application = new System.Windows.Application
            {
                ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown
            };

            if (System.Windows.Application.Current != null)
            {
                // merge in your application resources
                System.Windows.Application.Current.Resources.MergedDictionaries.Add(
                    System.Windows.Application.LoadComponent(
                        new Uri("/SalaryBook;component/Resources/AppResources.xaml", UriKind.Relative))
                    as System.Windows.ResourceDictionary);
            }

            MainForm mainForm = new MainForm();
            MainView mainView = new MainView();

            mainForm.Element = mainView;

            Bootstrapper.WindowArgs windowArgs = new Bootstrapper.WindowArgs()
            {
                MainForm = mainForm
            };
            Bootstrapper bootstrapper = new Bootstrapper(windowArgs);

            try
            {
                mainView.DataContext = bootstrapper.MainViewModel;
                Application.Run(mainForm);
                application.Shutdown();
            }
            finally
            {
                bootstrapper.Dispose();
                application.Shutdown();
            }
        }
示例#2
0
 static void InitializeWindows()
 {
     WinApp = new System.Windows.Application();
     WinApp.Run(MainWindow = new Projekt.View.Okno());
 }
示例#3
0
            public ProgramContextMenu(Program program)
            {
                AutoAccept = new MenuItem("Auto accept", CheckAndSave)
                {
                    Checked = Settings.Default.AutoAccept
                };
                AutoLock = new MenuItem("Auto lock", CheckAndSave)
                {
                    Checked = Settings.Default.AutoLock
                };
                AutoPick = new MenuItem("Auto pick", (sender, args) =>
                {
                    var window = program.autoPickFormWPF;

                    void OpenNewAutoPick(System.Windows.Application application)
                    => application.Dispatcher.Invoke(() =>
                    {
                        window                  = new AutoPickWPF();
                        window.Closed          += (o, eventArgs) => program.autoPickFormWPF = null;
                        program.autoPickFormWPF = window;
                        window.Show();
                    });

                    if (window == null)
                    {
                        var app = System.Windows.Application.Current;
                        if (app == null)
                        {
                            var thread = new Thread(() =>
                            {
                                app = new System.Windows.Application
                                {
                                    ShutdownMode = ShutdownMode.OnExplicitShutdown
                                };
                                OpenNewAutoPick(app);
                                app.Run();
                            });

                            thread.SetApartmentState(ApartmentState.STA);
                            thread.Start();
                        }
                        else
                        {
                            OpenNewAutoPick(app);
                        }
                    }
                    else
                    {
                        program.autoPickFormWPF.Dispatcher.Invoke(() =>
                        {
                            if (!window.IsVisible)
                            {
                                window.Show();
                            }

                            if (window.WindowState == WindowState.Minimized)
                            {
                                window.WindowState = WindowState.Normal;
                            }

                            window.Activate();
                            window.Topmost = true;                              // important
                            window.Topmost = false;                             // important
                            window.Focus();                                     // important
                        });
                    }

                    //if (program.autoPickForm == null)
                    //{
                    //	program.autoPickForm = new AutoPickForm();
                    //	program.autoPickForm.FormClosed += (o, eventArgs) => program.autoPickForm = null;
                    //	var thread = new Thread(() => Application.Run(program.autoPickForm));
                    //	thread.SetApartmentState(ApartmentState.STA);
                    //	thread.Start();
                    //}
                    //else
                    //{
                    //	program.autoPickForm.BringToFront();
                    //}
                });
#if DEBUG
                AutoPick.PerformClick();
#endif
                var rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

                string currentRegValue = (string)rkApp?.GetValue(nameof(LolAutoAccept));
                if (currentRegValue != null && currentRegValue != Application.ExecutablePath)
                {
                    rkApp.SetValue(nameof(LolAutoAccept), Application.ExecutablePath);
                }
                AutoLoad = new MenuItem("Autoload on startup",
                                        (sender, args) =>
                {
                    ((MenuItem)sender).Checked = !((MenuItem)sender).Checked;
                    if (((MenuItem)sender).Checked)
                    {
                        //string src = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                        //string dest = "C:\\temp\\" + System.Diagnostics.Process.GetCurrentProcess().MainModule.ModuleName;
                        //System.IO.File.Copy(src, dest);

                        // Add the value in the registry so that the application runs at startup
                        rkApp?.SetValue(nameof(LolAutoAccept), Application.ExecutablePath);
                    }
                    else
                    {
                        // Remove the value from the registry so that the application doesn't start
                        rkApp?.DeleteValue(nameof(LolAutoAccept), false);
                    }
                })
                {
                    Checked = currentRegValue != null
                };

                CapturePattern = new MenuItem("CapturePattern (for dev only)",
                                              (sender, args) =>
                {
                    program.patternCaptureForm             = new PatterCaptureForm();
                    program.patternCaptureForm.FormClosed += (o, eventArgs) => program.patternCaptureForm = null;
                    var thread = new Thread(() => Application.Run(program.patternCaptureForm));
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                });

                SearchMatchingPatternSize = new MenuItem("SearchMatchingPatternSize (for dev only)",
                                                         (sender, args) =>
                {
                    var thread = new Thread(() => Application.Run(new SearchMatchingSizeForm()));
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                });

                MenuItems.AddRange(new[]
                {
                    AutoAccept, AutoLock, Divider1, AutoPick, Divider2, AutoLoad, Divider3, CapturePattern, SearchMatchingPatternSize, Divider4, Exit
                });
            }
示例#4
0
        static void Main()
        {
            var args = Environment.GetCommandLineArgs();

            if (GetCommandLineSwitch("/?", args) || GetCommandLineSwitch("/h", args) || GetCommandLineSwitch("/help", args))
            {
                PrintCommandLineParameters();
                Environment.Exit(0);
                return;
            }

            var logFile = GetCommandLineParameter("/log", args);

            if (logFile != null)
            {
                try
                {
                    Logger.Out = File.CreateText(logFile);
                }
                catch (Exception e)
                {
                    Logger.LogWarn(e, "Unable to open log file at '{0}'", logFile);
                }
            }

#if DEBUG
            Logger.LogLevel = 5;
#endif
            if (int.TryParse(GetCommandLineParameter("/loglevel", args), NumberStyles.Any, null, out var logLevel))
            {
                Logger.LogLevel = logLevel;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.VisualStyleState = VisualStyleState.ClientAndNonClientAreasEnabled;
            Application.ThreadException += ApplicationThreadException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException   += CurrentDomainUnhandledException;
            AppDomain.CurrentDomain.FirstChanceException += CurrentDomainFirstChanceException;
            ThreadPool.SetMaxThreads(50, 200);
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            // Permit unmanaged code permissions
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();

            DisableExceptionReporter = GetCommandLineSwitch("/DisableExceptionReporter", args);

#if DEBUG
            System.Windows.Forms.Timer watchdogTimer;
#endif

            bool mutexAquired = false;
            using (var mutex = new Mutex(false, GlobalMutexId))
            {
                Logger.LogNotice($"ContactPoint IP Phone version: {typeof(Program).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}");
                Logger.LogNotice($"Main Thread Culture is '{Thread.CurrentThread.CurrentCulture}'");
                Logger.LogNotice($"UI Thread Culture is '{Thread.CurrentThread.CurrentUICulture}'");

#if DEBUG
                if (args.Contains("/debugger", StringComparer.InvariantCultureIgnoreCase))
                {
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    else
                    {
                        Debugger.Launch();
                    }
                }
#endif

#if DEBUG
                watchdogTimer = new System.Windows.Forms.Timer {
                    Interval = 3000
                };
                watchdogTimer.Tick += (s, e) => { _watcherLastActivity = DateTime.Now; };
                watchdogTimer.Start();

                _watcherTargetThread = Thread.CurrentThread;
                _watcherLastActivity = DateTime.Now;

                ThreadPool.QueueUserWorkItem(WatcherThreadFunc);
#endif

                var makeCallMessage = StartPhoneCallCommand.CreateFromCommandLine(GetCommandLineParameter("/call", args));
                try
                {
                    try
                    {
                        if (!WaitForMutex(mutex))
                        {
                            SharedFileMessageTransportHost.SendMessage(makeCallMessage);
                            Environment.Exit(0);
                            return;
                        }
                        else
                        {
                            mutexAquired = true;
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.LogError(e);
                        Environment.Exit(-1);
                    }

                    using (AppContext = new MainFormApplicationContext())
                    {
                        if (!GetCommandLineSwitch("/DisableSplashScreen", args))
                        {
                            LoaderForm = new LoaderForm();
                            ThreadPool.QueueUserWorkItem(ShowSplashScreen);
                        }

                        CoreLoader.LoadingFailed += LoadingFailed;
                        CoreLoader.PartLoading   += PartLoading;

                        foreach (var assembly in typeof(Program).Assembly.GetReferencedAssemblies())
                        {
                            PartLoading($"Load dependency: {assembly.Name} v{assembly.Version}");
                            AppDomain.CurrentDomain.Load(assembly);
                        }

                        PartLoading("Initialize Exception Reporter");
                        ExceptionReporter = new ExceptionReporter.ExceptionReporter();
                        ExceptionReporter.Config.ShowFlatButtons          = false;
                        ExceptionReporter.Config.ShowLessMoreDetailButton = true;
                        ExceptionReporter.Config.CompanyName  = "ContactPoint";
                        ExceptionReporter.Config.ContactEmail = "*****@*****.**";
                        ExceptionReporter.Config.WebUrl       = "http://www.contactpoint.com.ua/";
#if DEBUG
                        ExceptionReporter.Config.ShowFullDetail = true;
#else
                        ExceptionReporter.Config.ShowFullDetail = false;
#endif

                        // Create WPF application in order to let WPF controls work correctly
                        PartLoading("Initialize WPF Infrastructure");
                        System.Windows.Application wpfApp = null;
                        Window wpfWnd = null;
                        try
                        {
                            PartLoading("Create WPF Application");
                            wpfApp = new System.Windows.Application();

                            PartLoading("Create WPF Window");
                            wpfWnd = new Window
                            {
                                Visibility    = Visibility.Hidden,
                                ShowInTaskbar = false,
                                Width         = 1,
                                Height        = 1
                            };

                            PartLoading("Core infrastructure");
                            using (var core = CoreLoader.CreateCore(AppContext.MainForm))
                            {
                                PartLoading("Audio services");
                                using (new AudioDeviceService(core))
                                {
#if DEBUG
                                    if (args.Contains("/newui"))
                                    {
                                        new PhoneWindow().Show();
                                    }
#endif

                                    PartLoading("Configuring WinForms Infrastructure");
                                    AppContext.ContactPointForm.Core          = core;
                                    AppContext.ContactPointForm.CallOnStartup = makeCallMessage;
                                    AppContext.ContactPointForm.DisableSettingsFormAutoStartup = GetCommandLineSwitch("/DisableSettingsFormAutoStartup", args);

                                    AppContext.ContactPointForm.Shown += MainFormShown;

                                    PartLoading("Starting WinForms UI");
                                    Application.Run(AppContext);
                                }
                            }
                        }
                        finally
                        {
                            wpfWnd?.Close();
                            wpfApp?.Shutdown(0);
                        }
                    }
                }
                finally
                {
                    if (mutexAquired)
                    {
                        mutex.ReleaseMutex();
                    }

#if DEBUG
                    _watcherThreadShutdown = true;
                    watchdogTimer.Stop();
#endif
                }
            }
        }