Example #1
0
        private void SubscribeEvents()
        {
            ServerSettings.YesNoRequired += (sender, args) =>
            {
                System.Windows.Forms.DialogResult dr =
                    System.Windows.Forms.MessageBox.Show(args.Reason, args.FormTitle,
                                                         MessageBoxButtons.YesNo);
                if (dr == System.Windows.Forms.DialogResult.No)
                {
                    args.Cancel = true;
                }
            };
            ServerSettings.LocateFile += (sender, args) =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "JMM config|JMMServer.exe.config;settings.json";
                DialogResult browseFile = openFileDialog.ShowDialog();
                if (browseFile == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(openFileDialog.FileName.Trim()))
                {
                    args.FileName = openFileDialog.FileName;
                }
            };

            Utils.ErrorMessage +=
                (sender, args) => MessageBox.Show(this, args.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            AniDBHelper.LoginFailed += (a, e) => Application.Current.Dispatcher.Invoke(() =>
            {
                MessageBox.Show(Shoko.Commons.Properties.Resources.InitialSetup_LoginFail,
                                Shoko.Commons.Properties.Resources.Error,
                                MessageBoxButton.OK, MessageBoxImage.Error);

                InitialSetupForm frm = new InitialSetupForm();
                frm.ShowDialog();
            });
            ShokoServer.Instance.LoginFormNeeded += (a, e) => Application.Current.Dispatcher.Invoke(() => new InitialSetupForm().ShowDialog());

            ServerSettings.MigrationStarted += (a, e) =>
            {
                // Display the migration form.
                var migrationForm = new MigrationForm();
                migrationForm.Show();
            };

            ShokoServer.Instance.DBSetupCompleted += DBSetupCompleted;
            ShokoServer.Instance.DatabaseSetup    += (sender, args) => ShowDatabaseSetup();
        }
        private void SubscribeEvents()
        {
            Utils.YesNoRequired += (sender, args) =>
            {
                DialogResult dr =
                    System.Windows.Forms.MessageBox.Show(args.Reason, args.FormTitle,
                                                         MessageBoxButtons.YesNo);
                if (dr == System.Windows.Forms.DialogResult.No)
                {
                    args.Cancel = true;
                }
            };
            ServerSettings.LocateFile += (sender, args) =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = @"JMM config|JMMServer.exe.config;settings.json";
                DialogResult browseFile = openFileDialog.ShowDialog();
                if (browseFile == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(openFileDialog.FileName.Trim()))
                {
                    args.FileName = openFileDialog.FileName;
                }
            };

            Utils.ErrorMessage +=
                (sender, args) => MessageBox.Show(this, args.Message, args.Title ?? (args.IsError ? "Error" : "Message"), MessageBoxButton.OK, args.IsError ? MessageBoxImage.Error : MessageBoxImage.Information);
            Utils.OnEvents +=
                (sender, args) =>
            {
                DoEvents();
            };
            Utils.OnDispatch +=
                action =>
            {
                Application.Current.Dispatcher.Invoke(action);
            };
            AniDBHelper.LoginFailed += (a, e) => Application.Current.Dispatcher.Invoke(() =>
            {
                if (AniDBLoginOpen && LoginWindow != null)
                {
                    LoginWindow.Focus();
                    return;
                }

                LoginWindow       = new InitialSetupForm();
                LoginWindow.Owner = this;
                LoginWindow.ShowDialog();
            });
            ShokoServer.Instance.LoginFormNeeded += (a, e) => Application.Current.Dispatcher.Invoke(() =>
            {
                if (AniDBLoginOpen && LoginWindow != null)
                {
                    LoginWindow.Focus();
                    return;
                }
                LoginWindow       = new InitialSetupForm();
                LoginWindow.Owner = this;
                LoginWindow.ShowDialog();
            });

            ServerSettings.MigrationStarted += (a, e) =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    // Display the migration form.
                    var migrationForm = new MigrationForm();
                    migrationForm.Show();
                });
            };

            ShokoServer.Instance.
            DBSetupCompleted += DBSetupCompleted;
            ShokoServer.Instance.DatabaseSetup += (sender, args) => ShowDatabaseSetup();
        }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

            if (!ShokoServer.Instance.StartUpServer())
            {
                MessageBox.Show(Commons.Properties.Resources.Server_Running,
                                Commons.Properties.Resources.ShokoServer, MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(0);
            }

            ServerSettings.DebugSettingsToLog();

            //Create an instance of the NotifyIcon Class
            TippuTrayNotify = new System.Windows.Forms.NotifyIcon();

            // This icon file needs to be in the bin folder of the application
            TippuTrayNotify = new System.Windows.Forms.NotifyIcon();
            Stream iconStream =
                Application.GetResourceStream(new Uri("pack://application:,,,/ShokoServer;component/db.ico")).Stream;

            TippuTrayNotify.Icon = new System.Drawing.Icon(iconStream);
            iconStream.Dispose();

            //show the Tray Notify IconbtnRemoveMissingFiles.Click
            TippuTrayNotify.Visible = true;

            //-- for winforms applications
            System.Windows.Forms.Application.ThreadException -= UnhandledExceptionManager.ThreadExceptionHandler;
            System.Windows.Forms.Application.ThreadException += UnhandledExceptionManager.ThreadExceptionHandler;

            CreateMenus();

            ServerState.Instance.DatabaseAvailable = false;
            ServerState.Instance.ServerOnline      = false;
            ServerState.Instance.BaseImagePath     = ImageUtils.GetBaseImagesPath();

            this.Closing      += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
            this.StateChanged += new EventHandler(MainWindow_StateChanged);
            TippuTrayNotify.MouseDoubleClick +=
                new System.Windows.Forms.MouseEventHandler(TippuTrayNotify_MouseDoubleClick);

            btnToolbarShutdown.Click += new RoutedEventHandler(btnToolbarShutdown_Click);
            btnHasherPause.Click     += new RoutedEventHandler(btnHasherPause_Click);
            btnHasherResume.Click    += new RoutedEventHandler(btnHasherResume_Click);
            btnGeneralPause.Click    += new RoutedEventHandler(btnGeneralPause_Click);
            btnGeneralResume.Click   += new RoutedEventHandler(btnGeneralResume_Click);
            btnImagesPause.Click     += new RoutedEventHandler(btnImagesPause_Click);
            btnImagesResume.Click    += new RoutedEventHandler(btnImagesResume_Click);
            btnAdminMessages.Click   += btnAdminMessages_Click;

            btnRemoveMissingFiles.Click += new RoutedEventHandler(btnRemoveMissingFiles_Click);
            btnRunImport.Click          += new RoutedEventHandler(btnRunImport_Click);
            btnSyncHashes.Click         += BtnSyncHashes_Click;
            btnSyncMedias.Click         += BtnSyncMedias_Click;
            btnSyncMyList.Click         += new RoutedEventHandler(btnSyncMyList_Click);
            btnSyncVotes.Click          += new RoutedEventHandler(btnSyncVotes_Click);
            btnUpdateTvDBInfo.Click     += new RoutedEventHandler(btnUpdateTvDBInfo_Click);
            btnUpdateAllStats.Click     += new RoutedEventHandler(btnUpdateAllStats_Click);
            btnSyncTrakt.Click          += new RoutedEventHandler(btnSyncTrakt_Click);
            btnImportManualLinks.Click  += new RoutedEventHandler(btnImportManualLinks_Click);
            btnUpdateAniDBInfo.Click    += new RoutedEventHandler(btnUpdateAniDBInfo_Click);
            btnLaunchWebUI.Click        += new RoutedEventHandler(btnLaunchWebUI_Click);
            btnUpdateImages.Click       += new RoutedEventHandler(btnUpdateImages_Click);
            btnUploadAzureCache.Click   += new RoutedEventHandler(btnUploadAzureCache_Click);
            btnUpdateTraktInfo.Click    += BtnUpdateTraktInfo_Click;
            btnSyncPlex.Click           += BtnSyncPlexOn_Click;

            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);

            txtServerPort.Text = ServerSettings.JMMServerPort;

            btnToolbarHelp.Click     += new RoutedEventHandler(btnToolbarHelp_Click);
            btnApplyServerPort.Click += new RoutedEventHandler(btnApplyServerPort_Click);
            btnUpdateMediaInfo.Click += new RoutedEventHandler(btnUpdateMediaInfo_Click);

            //StartUp();

            cboDatabaseType.Items.Clear();
            ShokoServer.Instance.GetSupportedDatabases().ForEach(s => cboDatabaseType.Items.Add(s));
            cboDatabaseType.SelectionChanged +=
                new System.Windows.Controls.SelectionChangedEventHandler(cboDatabaseType_SelectionChanged);

            btnChooseImagesFolder.Click += new RoutedEventHandler(btnChooseImagesFolder_Click);
            btnSetDefault.Click         += BtnSetDefault_Click;


            btnSaveDatabaseSettings.Click   += new RoutedEventHandler(btnSaveDatabaseSettings_Click);
            btnRefreshMSSQLServerList.Click += new RoutedEventHandler(btnRefreshMSSQLServerList_Click);
            // btnInstallMSSQLServer.Click += new RoutedEventHandler(btnInstallMSSQLServer_Click);
            btnMaxOnStartup.Click               += new RoutedEventHandler(toggleMinimizeOnStartup);
            btnMinOnStartup.Click               += new RoutedEventHandler(toggleMinimizeOnStartup);
            btnLogs.Click                       += new RoutedEventHandler(btnLogs_Click);
            btnChooseVLCLocation.Click          += new RoutedEventHandler(btnChooseVLCLocation_Click);
            btnJMMEnableStartWithWindows.Click  += new RoutedEventHandler(btnJMMEnableStartWithWindows_Click);
            btnJMMDisableStartWithWindows.Click += new RoutedEventHandler(btnJMMDisableStartWithWindows_Click);
            btnUpdateAniDBLogin.Click           += new RoutedEventHandler(btnUpdateAniDBLogin_Click);

            btnHasherClear.Click  += new RoutedEventHandler(btnHasherClear_Click);
            btnGeneralClear.Click += new RoutedEventHandler(btnGeneralClear_Click);
            btnImagesClear.Click  += new RoutedEventHandler(btnImagesClear_Click);

            //automaticUpdater.MenuItem = mnuCheckForUpdates;

            ServerState.Instance.LoadSettings();

            cboLanguages.SelectionChanged += new SelectionChangedEventHandler(cboLanguages_SelectionChanged);

            InitCulture();
            Instance = this;

            ServerSettings.YesNoRequired += (sender, args) =>
            {
                System.Windows.Forms.DialogResult dr =
                    System.Windows.Forms.MessageBox.Show(args.Reason, args.FormTitle,
                                                         MessageBoxButtons.YesNo);
                if (dr == System.Windows.Forms.DialogResult.No)
                {
                    args.Cancel = true;
                }
            };
            ServerSettings.LocateFile += (sender, args) =>
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "JMM config|JMMServer.exe.config;settings.json";
                DialogResult browseFile = openFileDialog.ShowDialog();
                if (browseFile == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(openFileDialog.FileName.Trim()))
                {
                    args.FileName = openFileDialog.FileName;
                }
            };

            Utils.ErrorMessage +=
                (sender, args) => MessageBox.Show(this, args.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

            AniDBHelper.LoginFailed += (a, e) => Application.Current.Dispatcher.Invoke(() =>
            {
                MessageBox.Show(Shoko.Commons.Properties.Resources.InitialSetup_LoginFail,
                                Shoko.Commons.Properties.Resources.Error,
                                MessageBoxButton.OK, MessageBoxImage.Error);

                InitialSetupForm frm = new InitialSetupForm();
                frm.ShowDialog();
            });

            ServerSettings.MigrationStarted += (a, e) =>
            {
                // Display the migration form.
                var migrationForm = new MigrationForm();
                migrationForm.Show();
            };
        }