Example #1
0
        protected override void OnStartup(StartupEventArgs eventArgs)
        {
            try
            {
                bool isBackupInstance;
                bool.TryParse(ConfigurationManager.AppSettings["IsBackupInstance"], out isBackupInstance);
                if ((!Mutex.WaitOne(5000) &&
                     (MessageBox.Show(resources._query_StartAnotherInstance, resources._caption_Confirmation,
                                      MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) ||
                     (isBackupInstance && MessageBox.Show(resources._query_StartBackupInstance,
                                                          resources._caption_Confirmation, MessageBoxButton.YesNo) != MessageBoxResult.Yes)))
                {
                    _isShutdown = true;
                    Shutdown(0);
                    return;
                }
            }
            catch (AbandonedMutexException)
            {
                Mutex.ReleaseMutex();
                Mutex.WaitOne();
            }
            base.OnStartup(eventArgs);

            try
            {
                SplashScreenView.Current?.Notify("Initializing engines...");
                EngineController.Initialize();
            }
            catch (TypeInitializationException e)
            {
                MessageBox.Show(string.Format(resources._message_CantInitializeEngines, e.InnerException),
                                resources._caption_Error, MessageBoxButton.OK, MessageBoxImage.Error);
                _isShutdown = true;
                Shutdown(1);
            }
            catch (Exception e)
            {
                var message =
#if DEBUG
                    $"{e}";
#else
                    $"{e.Source}:{e.GetType().Name} {e.Message}";
#endif
                MessageBox.Show(string.Format(resources._message_CantInitializeEngines, message), resources._caption_Error,
                                MessageBoxButton.OK, MessageBoxImage.Error);
                _isShutdown = true;
                Shutdown(1);
            }

            var splash = MainWindow as SplashScreenView;
            if (!_isShutdown)
            {
                AppDomain.CurrentDomain.SetThreadPrincipal(new GenericPrincipal(new LocalUser(), new string[0]));
                SplashScreenView.Current?.Notify("Creating views...");
                MainWindow = new MainWindow();
                MainWindow.Show();
            }
            splash?.Close();
        }
Example #2
0
        protected static void ExecuteApp(bool userInteractive)
        {
            EngineController.Initialize();
            if (userInteractive)
            {
                try
                {
                    while (true)
                    {
                        Console.Write('>');
                        var line = Console.ReadLine();
                        if (string.IsNullOrEmpty(line))
                        {
                            continue;
                        }
                        var lineParts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (lineParts.Length > 0)
                        {
                            switch (lineParts[0].ToLower())
                            {
                            // console commands here
                            case "quit":
                            case "q":
                                return;

                            case "gc":
                                Debug.WriteLine("Garbage collection requested.");
                                GC.Collect(GC.MaxGeneration);
                                Console.WriteLine("Garbage collection requested.");
                                break;

                            case "help":
                            case "?":
                                DisplayHelpInfo();
                                break;

                            default:
                                Console.WriteLine("Command not recognized. Type help to get list of available commands.");
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    EngineController.ShutDown();
                }
            }
        }
Example #3
0
        public MainWindowViewmodel()
        {
            if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                return;
            }
            try
            {
                SplashScreenView.Current?.Notify("Initializing engines...");
                EngineController.Initialize();
                Tabs = new List <ViewModelBase>(
                    EngineController.Engines.Select(engine =>
                {
                    SplashScreenView.Current?.Notify($"Creating {engine.EngineName}...");
                    return(new ChannelViewmodel(engine, true, true));
                }));
            }
            catch (TypeInitializationException e)
            {
                MessageBox.Show(string.Format(resources._message_CantInitializeEngines, e.InnerException),
                                resources._caption_Error, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception e)
            {
                var exceptionToShow = e;
                while (exceptionToShow.InnerException != null)
                {
                    exceptionToShow = exceptionToShow.InnerException;
                }
                var message =
#if DEBUG
                    $"{e}";
#else
                    $"{exceptionToShow.GetType().Name} {exceptionToShow.Message}";
#endif
                MessageBox.Show(string.Format(resources._message_CantInitializeEngines, message),
                                resources._caption_Error,
                                MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown(1);
            }
        }
Example #4
0
 public MainWindowViewmodel()
 {
     if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
     {
         try
         {
             EngineController.Initialize();
             var engines = EngineController.Engines;
             _channels = new List <ChannelViewmodel>(engines.Select(engine => new ChannelViewmodel(engine, true, true, true)));
         }
         catch (TypeInitializationException e)
         {
             MessageBox.Show(string.Format(resources._message_CantInitializeEngines, e.InnerException), resources._caption_Error, MessageBoxButton.OK, MessageBoxImage.Error);
             Application.Current.Shutdown(1);
         }
         catch (Exception e)
         {
             MessageBox.Show(string.Format(resources._message_CantInitializeEngines, e), resources._caption_Error, MessageBoxButton.OK, MessageBoxImage.Error);
             Application.Current.Shutdown(1);
         }
     }
 }
Example #5
0
 protected override void OnStart(string[] args)
 {
     base.OnStart(args);
     EngineController.Initialize();
 }