void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //ServerInfo.Instance.RefreshImportFolders();

            if (ServerSettings.MinimizeOnStartup)
            {
                MinimizeToTray();
            }

            tabControl1.SelectedIndex = 4; // Settings

            logger.Info("Clearing Cache...");

            Utils.ClearAutoUpdateCache();

            if (ServerSettings.FirstRun)
            {
                logger.Info("Initializing DB...");
                ShokoServer.RunWorkSetupDB();
            }

            ShokoServer.Instance.CheckForUpdates();
            ShokoServer.Instance.UpdateAvailable += (s, args) => new UpdateForm {
                Owner = Instance
            }.ShowDialog();
        }
Ejemplo n.º 2
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //ServerInfo.Instance.RefreshImportFolders();

            if (ServerSettings.MinimizeOnStartup)
            {
                MinimizeToTray();
            }

            tabControl1.SelectedIndex = 6; // setup

            if (ServerSettings.AniDB_Username.Equals("jonbaby", StringComparison.InvariantCultureIgnoreCase) ||
                ServerSettings.AniDB_Username.Equals("jmediamanager", StringComparison.InvariantCultureIgnoreCase))
            {
                btnUploadAzureCache.Visibility = System.Windows.Visibility.Visible;
            }
            logger.Info("Clearing Cache...");

            Utils.ClearAutoUpdateCache();

            ShowDatabaseSetup();
            logger.Info("Initializing DB...");

            ShokoServer.RunWorkSetupDB();
            ShokoServer.Instance.CheckForUpdates();
            ShokoServer.Instance.UpdateAvailable += (s, args) => new UpdateForm {
                Owner = Instance
            }.ShowDialog();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            for (int x = 0; x < args.Length; x++)
            {
                if (args[x].Equals("instance", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (x + 1 < args.Length)
                    {
                        ServerSettings.DefaultInstance = args[x + 1];
                    }
                }
            }

            ServerSettings.LoadSettings();
            ServerState.Instance.LoadSettings();
            ShokoServer.Instance.StartUpServer();

            ShokoServer.RunWorkSetupDB();

            bool running = true;

            ShokoServer.Instance.ServerShutdown += (sender, eventArgs) => running = false;
            Utils.YesNoRequired += (sender, e) =>
            {
                e.Cancel = true;
            };

            ShokoService.CmdProcessorGeneral.OnQueueStateChangedEvent +=
                ev => Console.WriteLine($"Queue state change: {ev.QueueState.formatMessage()}");

            while (running)
            {
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(60));
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            for (int x = 0; x < args.Length; x++)
            {
                if (args[x].Equals("instance", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (x + 1 < args.Length)
                    {
                        ServerSettings.DefaultInstance = args[x + 1];
                    }
                }
            }

            ShokoServer.Instance.InitLogger();

            ServerSettings.LoadSettings();
            ServerState.Instance.LoadSettings();
            ShokoServer.Instance.StartUpServer();

            // Ensure that the AniDB socket is initialized. Try to Login, then start the server if successful.
            ShokoServer.Instance.RestartAniDBSocket();
            if (!ServerSettings.Instance.FirstRun)
            {
                ShokoServer.RunWorkSetupDB();
            }
            else
            {
                logger.Warn("The Server is NOT STARTED. It needs to be configured via webui or the settings.json");
            }

            bool running = true;

            ShokoServer.Instance.ServerShutdown += (sender, eventArgs) => running = false;
            Utils.YesNoRequired += (sender, e) =>
            {
                e.Cancel = true;
            };

            ServerState.Instance.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "StartupFailedMessage" && ServerState.Instance.StartupFailed)
                {
                    Console.WriteLine("Startup failed! Error message: " + ServerState.Instance.StartupFailedMessage);
                }
            };
            ShokoService.CmdProcessorGeneral.OnQueueStateChangedEvent +=
                ev => Console.WriteLine($"Queue state change: {ev.QueueState.formatMessage()}");

            while (running)
            {
                System.Threading.Thread.Sleep(TimeSpan.FromSeconds(60));
            }
        }
Ejemplo n.º 5
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            if (!string.IsNullOrEmpty(Args?.Instance))
            {
                ServerSettings.DefaultInstance = Args.Instance;
            }

            ShokoServer.Instance.InitLogger();

            ServerSettings.LoadSettings();
            ServerState.Instance.LoadSettings();
            if (!ShokoServer.Instance.StartUpServer())
            {
                return;
            }

            // Ensure that the AniDB socket is initialized. Try to Login, then start the server if successful.
            ShokoServer.Instance.RestartAniDBSocket();
            if (!ServerSettings.Instance.FirstRun)
            {
                ShokoServer.RunWorkSetupDB();
            }
            else
            {
                Logger.Warn("The Server is NOT STARTED. It needs to be configured via webui or the settings.json");
            }

            ShokoServer.Instance.ServerShutdown += (sender, eventArgs) => AppLifetime.StopApplication();
            Utils.YesNoRequired += (sender, e) =>
            {
                e.Cancel = true;
            };

            ServerState.Instance.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "StartupFailedMessage" && ServerState.Instance.StartupFailed)
                {
                    Console.WriteLine("Startup failed! Error message: " + ServerState.Instance.StartupFailedMessage);
                }
            };
            ShokoService.CmdProcessorGeneral.OnQueueStateChangedEvent +=
                ev => Console.WriteLine($"General Queue state change: {ev.QueueState.formatMessage()}");
        }
Ejemplo n.º 6
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //ServerInfo.Instance.RefreshImportFolders();

            if (ServerSettings.Instance.MinimizeOnStartup)
            {
                MinimizeToTray();
            }

            tabControl1.SelectedIndex = 4; // Settings

            logger.Info("Clearing Cache...");

            Utils.ClearAutoUpdateCache();

            if (ServerSettings.Instance.FirstRun || !ShokoService.AnidbProcessor.ValidAniDBCredentials())
            {
                ShokoServer.Instance.RestartAniDBSocket();

                if (!ShokoService.AnidbProcessor.Login())
                {
                    ShowAniDBLoginDialog();
                }

                while (AniDBLoginOpen)
                {
                    Thread.Sleep(100);
                }

                if (ShokoService.AnidbProcessor.ValidAniDBCredentials())
                {
                    logger.Info("Initializing DB...");
                    ShokoServer.RunWorkSetupDB();
                }
            }

            ShokoServer.Instance.CheckForUpdates();
            ShokoServer.Instance.UpdateAvailable += (s, args) => new UpdateForm {
                Owner = Instance
            }.ShowDialog();
        }
Ejemplo n.º 7
0
 private object StartServer()
 {
     if (ServerState.Instance.ServerOnline)
     {
         return(APIStatus.BadRequest("Already Running"));
     }
     if (ServerState.Instance.ServerStarting)
     {
         return(APIStatus.BadRequest("Already Starting"));
     }
     try
     {
         ShokoServer.RunWorkSetupDB();
     }
     catch (Exception e)
     {
         logger.Error($"There was an error starting the server: {e}");
         return(APIStatus.InternalError($"There was an error starting the server: {e}"));
     }
     return(APIStatus.OK());
 }
Ejemplo n.º 8
0
 public ActionResult StartServer()
 {
     if (ServerState.Instance.ServerOnline)
     {
         return(BadRequest("Already Running"));
     }
     if (ServerState.Instance.ServerStarting)
     {
         return(BadRequest("Already Starting"));
     }
     try
     {
         ShokoServer.RunWorkSetupDB();
     }
     catch (Exception e)
     {
         logger.Error($"There was an error starting the server: {e}");
         return(InternalError($"There was an error starting the server: {e}"));
     }
     return(Ok());
 }
Ejemplo n.º 9
0
        public MainWindow()
        {
            InitializeComponent();

            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Instance.Culture);
            ShokoServer.Instance.OAuthProvider    = new AuthProvider(this);
            if (!ShokoServer.Instance.StartUpServer())
            {
                MessageBox.Show(Commons.Properties.Resources.Server_Running,
                                Commons.Properties.Resources.ShokoServer, MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(0);
            }

            //Create an instance of the NotifyIcon Class
            TippuTrayNotify = new NotifyIcon();

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

            TippuTrayNotify.Icon = new 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();

            Closing      += MainWindow_Closing;
            StateChanged += MainWindow_StateChanged;
            TippuTrayNotify.MouseDoubleClick += TippuTrayNotify_MouseDoubleClick;

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

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

            Loaded += MainWindow_Loaded;

            txtServerPort.Text = ServerSettings.Instance.ServerPort.ToString(CultureInfo.InvariantCulture);

            btnToolbarHelp.Click     += btnToolbarHelp_Click;
            btnApplyServerPort.Click += btnApplyServerPort_Click;
            btnUpdateMediaInfo.Click += btnUpdateMediaInfo_Click;

            //StartUp();

            cboDatabaseType.Items.Clear();
            ShokoServer.Instance.GetSupportedDatabases().ForEach(s => cboDatabaseType.Items.Add(s));
            cboDatabaseType.SelectionChanged +=
                cboDatabaseType_SelectionChanged;

            btnChooseImagesFolder.Click += btnChooseImagesFolder_Click;
            btnSetDefault.Click         += BtnSetDefault_Click;


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

            btnHasherClear.Click  += btnHasherClear_Click;
            btnGeneralClear.Click += btnGeneralClear_Click;
            btnImagesClear.Click  += btnImagesClear_Click;

            //automaticUpdater.MenuItem = mnuCheckForUpdates;

            ServerState.Instance.LoadSettings();

            cboLanguages.SelectionChanged += cboLanguages_SelectionChanged;

            InitCulture();
            Instance = this;

            if (!ServerSettings.Instance.FirstRun && ShokoService.AnidbProcessor.ValidAniDBCredentials())
            {
                logger.Info("Already been set up... Initializing DB...");
                ShokoServer.RunWorkSetupDB();
                cboLanguages.IsEnabled = true;
            }

            SubscribeEvents();
        }
Ejemplo n.º 10
0
        void btnSaveDatabaseSettings_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                btnSaveDatabaseSettings.IsEnabled   = false;
                cboDatabaseType.IsEnabled           = false;
                btnRefreshMSSQLServerList.IsEnabled = false;

                if (ServerState.Instance.DatabaseIsSQLite)
                {
                    ServerSettings.Instance.Database.Type = DatabaseTypes.Sqlite;
                }
                else if (ServerState.Instance.DatabaseIsSQLServer)
                {
                    if (string.IsNullOrEmpty(txtMSSQL_DatabaseName.Text) ||
                        string.IsNullOrEmpty(txtMSSQL_Password.Password) ||
                        string.IsNullOrEmpty(cboMSSQLServerList.Text) ||
                        string.IsNullOrEmpty(txtMSSQL_Username.Text))
                    {
                        MessageBox.Show(Commons.Properties.Resources.Server_FillOutSettings,
                                        Commons.Properties.Resources.Error,
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                        txtMSSQL_DatabaseName.Focus();
                        return;
                    }

                    ServerSettings.Instance.Database.Type     = DatabaseTypes.SqlServer;
                    ServerSettings.Instance.Database.Schema   = txtMSSQL_DatabaseName.Text;
                    ServerSettings.Instance.Database.Password = txtMSSQL_Password.Password;
                    ServerSettings.Instance.Database.Hostname = cboMSSQLServerList.Text;
                    ServerSettings.Instance.Database.Username = txtMSSQL_Username.Text;
                }
                else if (ServerState.Instance.DatabaseIsMySQL)
                {
                    if (string.IsNullOrEmpty(txtMySQL_DatabaseName.Text) ||
                        string.IsNullOrEmpty(txtMySQL_Password.Password) ||
                        string.IsNullOrEmpty(txtMySQL_ServerAddress.Text) ||
                        string.IsNullOrEmpty(txtMySQL_Username.Text))
                    {
                        MessageBox.Show(Commons.Properties.Resources.Server_FillOutSettings,
                                        Commons.Properties.Resources.Error,
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                        txtMySQL_DatabaseName.Focus();
                        return;
                    }

                    ServerSettings.Instance.Database.Type     = DatabaseTypes.MySql;
                    ServerSettings.Instance.Database.Schema   = txtMySQL_DatabaseName.Text;
                    ServerSettings.Instance.Database.Password = txtMySQL_Password.Password;
                    ServerSettings.Instance.Database.Hostname = txtMySQL_ServerAddress.Text;
                    ServerSettings.Instance.Database.Username = txtMySQL_Username.Text;
                }

                logger.Info("Initializing DB...");

                ShokoServer.RunWorkSetupDB();
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                MessageBox.Show(Commons.Properties.Resources.Server_FailedToStart + ex.Message,
                                Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 11
0
        private void OnStartup(object a, StartupEventArgs e)
        {
            Console.CancelKeyPress += (sender, args) => Dispatcher.Invoke(() =>
            {
                args.Cancel = true;
                Shutdown();
            });
            Icon = new TaskbarIcon();
            using (var iconStream = GetResourceStream(new Uri("pack://application:,,,/ShokoServer;component/db.ico"))
                                    ?.Stream)
            {
                if (iconStream != null)
                {
                    Icon.Icon = new Icon(iconStream);
                }
            }
            Icon.ToolTipText = "Shoko Server";
            ContextMenu menu  = new ContextMenu();
            MenuItem    webui = new MenuItem();

            webui.Header = "Open WebUI";
            webui.Click += (sender, args) =>
            {
                try
                {
                    string IP = GetLocalIPv4(NetworkInterfaceType.Ethernet);
                    if (string.IsNullOrEmpty(IP))
                    {
                        IP = "127.0.0.1";
                    }

                    string url = $"http://{IP}:{ServerSettings.Instance.ServerPort}";
                    OpenUrl(url);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, ex.ToString());
                }
            };
            menu.Items.Add(webui);
            webui        = new MenuItem();
            webui.Header = "Exit";
            webui.Click += (sender, args) => Dispatcher.Invoke(Shutdown);
            menu.Items.Add(webui);
            Icon.ContextMenu    = menu;
            Icon.MenuActivation = PopupActivationMode.All;
            Icon.Visibility     = Visibility.Visible;

            string instance = null;

            for (int x = 0; x < e.Args.Length; x++)
            {
                if (!e.Args[x].Equals("instance", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                if (x + 1 >= e.Args.Length)
                {
                    continue;
                }
                instance = e.Args[x + 1];
                break;
            }

            var arguments = new ProgramArguments {
                Instance = instance
            };

            if (!string.IsNullOrEmpty(arguments.Instance))
            {
                ServerSettings.DefaultInstance = arguments.Instance;
            }

            ShokoServer.Instance.InitLogger();

            ServerSettings.LoadSettings();
            ServerState.Instance.LoadSettings();

            if (!ShokoServer.Instance.StartUpServer())
            {
                return;
            }

            // Ensure that the AniDB socket is initialized. Try to Login, then start the server if successful.
            ShokoServer.Instance.RestartAniDBSocket();
            if (!ServerSettings.Instance.FirstRun)
            {
                ShokoServer.RunWorkSetupDB();
            }
            else
            {
                Logger.Warn("The Server is NOT STARTED. It needs to be configured via webui or the settings.json");
            }

            ShokoServer.Instance.ServerShutdown += (sender, eventArgs) => Shutdown();
            Utils.YesNoRequired += (sender, e) =>
            {
                e.Cancel = true;
            };

            ServerState.Instance.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "StartupFailedMessage" && ServerState.Instance.StartupFailed)
                {
                    Console.WriteLine("Startup failed! Error message: " + ServerState.Instance.StartupFailedMessage);
                }
            };
            ShokoService.CmdProcessorGeneral.OnQueueStateChangedEvent +=
                ev => Console.WriteLine($"General Queue state change: {ev.QueueState.formatMessage()}");
        }