Example #1
0
        async Task Init()
        {
            try {
                _driver = new DriverInterface();
            }
            catch (Win32Exception ex) when(ex.NativeErrorCode == 2)
            {
                // driver not loaded or not installed
                bool isAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);

                if (isAdmin)
                {
                    await InstallAndLoadDriverAsync();
                    await Init();
                }
                else
                {
                    if (UI.MessageBoxService.ShowMessage("Requried driver is not loaded or not installed. Restart application with elevated provileges?",
                                                         App.Title, MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK)
                    {
                        var startInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().Location)
                        {
                            Verb = "runas",
                        };
                        Process.Start(startInfo);
                    }
                    Application.Current.Shutdown();
                }
            }
            catch (Exception ex) {
                UI.MessageBoxService.ShowMessage($"Error: {ex.Message}", App.Title);
                Application.Current.Shutdown(1);
            }

            if (_driver != null)
            {
                _jobManager = new JobManager(_driver);
                JobDetails  = new JobDetailsViewModel(this);

                IsInitialized = true;

                await Refresh();
            }
        }
Example #2
0
        public MainViewModel(IUIServices ui)
        {
            UI = ui;
            Thread.CurrentThread.Priority = ThreadPriority.Highest;

            Init();

            if (_driver != null)
            {
                _jobManager = new JobManager(_driver);
                JobDetails  = new JobDetailsViewModel(this);

                IsInitialized = true;

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Refresh();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            }
        }