Beispiel #1
0
        void InitCulture()
        {
            try
            {
                string currentCulture = ServerSettings.Culture;

                cboLanguages.ItemsSource = UserCulture.SupportedLanguages;

                for (int i = 0; i < cboLanguages.Items.Count; i++)
                {
                    UserCulture ul = cboLanguages.Items[i] as UserCulture;
                    if (ul.Culture.Trim().ToUpper() == currentCulture.Trim().ToUpper())
                    {
                        cboLanguages.SelectedIndex = i;
                        break;
                    }
                }
                if (cboLanguages.SelectedIndex < 0)
                {
                    cboLanguages.SelectedIndex = 0;
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #2
0
        private void CommandBinding_ScanFolder(object sender, ExecutedRoutedEventArgs e)
        {
            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            try
            {
                if (obj.GetType() == typeof(SVR_ImportFolder))
                {
                    SVR_ImportFolder fldr = (SVR_ImportFolder)obj;

                    ShokoServer.ScanFolder(fldr.ImportFolderID);
                    MessageBox.Show(Shoko.Commons.Properties.Resources.Server_ScanFolder,
                                    Shoko.Commons.Properties.Resources.Success,
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #3
0
        void btnLogs_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string logPath = Path.Combine(ServerSettings.ApplicationPath, "logs");

                Process.Start(new ProcessStartInfo(logPath));
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #4
0
        private void SetCulture()
        {
            if (cboLanguages.SelectedItem == null)
            {
                return;
            }
            UserCulture ul = cboLanguages.SelectedItem as UserCulture;
            bool        isLanguageChanged = ServerSettings.Culture != ul.Culture;

            System.Windows.Forms.DialogResult result;

            try
            {
                CultureInfo ci = new CultureInfo(ul.Culture);
                CultureInfo.DefaultThreadCurrentUICulture = ci;
                CultureManager.UICulture = ci;
                ServerSettings.Culture   = ul.Culture;
                if (isLanguageChanged)
                {
                    result = System.Windows.Forms.MessageBox.Show(Shoko.Commons.Properties.Resources.Language_Info,
                                                                  Shoko.Commons.Properties.Resources.Language_Switch,
                                                                  System.Windows.Forms.MessageBoxButtons.OKCancel,
                                                                  System.Windows.Forms.MessageBoxIcon.Information);

                    if (result != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }

                    System.Windows.Forms.Application.Restart();
                    ShokoServer.Instance.ApplicationShutdown();
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #5
0
        public bool NetPermissionWrapper(Action action)
        {
            try
            {
                action();
            }
            catch (Exception e)
            {
                if (Utils.IsAdministrator())
                {
                    Utils.ShowMessage(null, "Settings the ports, after that JMMServer will quit, run again in normal mode");

                    try
                    {
                        action();
                    }
                    catch (Exception exception)
                    {
                        Utils.ShowErrorMessage("Unable start hosting");
                        logger.Error("Unable to run task: " + (action.Method.Name));
                        logger.Error(exception);
                    }
                    finally
                    {
                        ShutDown();
                    }

                    return(false);
                }

                Utils.ShowErrorMessage("Unable to start hosting, please run JMMServer as administrator once.");
                logger.Error(e);
                ShutDown();
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        void btnHasherClear_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.Cursor = Cursors.Wait;
                ShokoService.CmdProcessorHasher.Stop();

                // wait until the queue stops
                while (ShokoService.CmdProcessorHasher.ProcessingCommands)
                {
                    Thread.Sleep(200);
                }
                Thread.Sleep(200);

                RepoFactory.CommandRequest.Delete(RepoFactory.CommandRequest.GetAllCommandRequestHasher());

                ShokoService.CmdProcessorHasher.Init();
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex.Message);
            }
            this.Cursor = Cursors.Arrow;
        }
Beispiel #7
0
        public bool StartUpServer()
        {
            DepProvider = BuildDi();

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

                // Check if any of the DLL are blocked, common issue with daily builds
                if (!CheckBlockedFiles())
                {
                    Utils.ShowErrorMessage(Resources.ErrorBlockedDll);
                    Environment.Exit(1);
                }

                // Migrate programdata folder from JMMServer to ShokoServer
                // this needs to run before UnhandledExceptionManager.AddHandler(), because that will probably lock the log file
                if (!MigrateProgramDataLocation())
                {
                    Utils.ShowErrorMessage(Resources.Migration_LoadError, Resources.ShokoServer);
                    Environment.Exit(1);
                }

                // First check if we have a settings.json in case migration had issues as otherwise might clear out existing old configurations
                string path = Path.Combine(ServerSettings.ApplicationPath, "settings.json");
                if (File.Exists(path))
                {
                    Thread t = new Thread(UninstallJMMServer)
                    {
                        IsBackground = true
                    };
                    t.Start();
                }

                //HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();

                try
                {
                    UnhandledExceptionManager.AddHandler();
                }
                catch (Exception e)
                {
                    logger.Log(NLog.LogLevel.Error, e);
                }

                try
                {
                    Mutex.OpenExisting(ServerSettings.DefaultInstance + "Mutex");
                    //since it hasn't thrown an exception, then we already have one copy of the app open.
                    return(false);
                    //MessageBox.Show(Shoko.Commons.Properties.Resources.Server_Running,
                    //    Shoko.Commons.Properties.Resources.ShokoServer, MessageBoxButton.OK, MessageBoxImage.Error);
                    //Environment.Exit(0);
                }
                catch (Exception Ex)
                {
                    //since we didn't find a mutex with that name, create one
                    Debug.WriteLine("Exception thrown:" + Ex.Message + " Creating a new mutex...");
                    var _ = new Mutex(true, ServerSettings.DefaultInstance + "Mutex");
                }

                ServerSettings.Instance.DebugSettingsToLog();
                RenameFileHelper.InitialiseRenamers();


                ServerState.Instance.DatabaseAvailable    = false;
                ServerState.Instance.ServerOnline         = false;
                ServerState.Instance.ServerStarting       = false;
                ServerState.Instance.StartupFailed        = false;
                ServerState.Instance.StartupFailedMessage = string.Empty;
                ServerState.Instance.BaseImagePath        = ImageUtils.GetBaseImagesPath();


                workerSetupDB.WorkerReportsProgress = true;
                workerSetupDB.ProgressChanged      += (sender, args) => WorkerSetupDB_ReportProgress();
                workerSetupDB.DoWork             += WorkerSetupDB_DoWork;
                workerSetupDB.RunWorkerCompleted += WorkerSetupDB_RunWorkerCompleted;

#if false
                #region LoggingConfig
                LogManager.Configuration = new NLog.Config.LoggingConfiguration();
                ColoredConsoleTarget conTarget = new ColoredConsoleTarget("console")
                {
                    Layout = "${date:format=HH\\:mm\\:ss}| --- ${message}"
                };
                FileTarget fileTarget = new FileTarget("file")
                {
                    Layout   = "[${shortdate} ${date:format=HH\\:mm\\:ss\\:fff}] ${level}|${stacktrace} ${message}",
                    FileName = "${basedir}/logs/${shortdate}.txt"
                };
                LogManager.Configuration.AddTarget(conTarget);
                LogManager.Configuration.AddTarget(fileTarget);
                LogManager.Configuration.AddRuleForAllLevels(conTarget);

                LogManager.Configuration.AddRule(ServerSettings.Instance.TraceLog ? LogLevel.Trace : LogLevel.Info, LogLevel.Fatal, fileTarget);
                #endregion
#endif

                ServerState.Instance.LoadSettings();

                InitCulture();
                Instance = this;


                SetupNetHosts();

                return(true);
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(false);
            }
        }