Ejemplo n.º 1
0
        void btnApplyServerPort_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtServerPort.Text))
            {
                MessageBox.Show(Shoko.Commons.Properties.Resources.Server_EnterAnyValue,
                                Shoko.Commons.Properties.Resources.Error,
                                MessageBoxButton.OK, MessageBoxImage.Error);
                txtServerPort.Focus();
                return;
            }

            ushort port    = 0;
            bool   success = ushort.TryParse(txtServerPort.Text, out port);

            if (!success || port <= 0 || port > 65535)
            {
                MessageBox.Show(Shoko.Commons.Properties.Resources.Server_EnterCertainValue,
                                Shoko.Commons.Properties.Resources.Error,
                                MessageBoxButton.OK, MessageBoxImage.Error);
                txtServerPort.Focus();
                return;
            }
            if (!Utils.IsAdministrator())
            {
                MessageBox.Show(Shoko.Commons.Properties.Resources.Settings_ChangeServerPortFail,
                                Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            try
            {
                this.Cursor = Cursors.Wait;
                if (!ShokoServer.Instance.SetNancyPort(port))
                {
                    MessageBox.Show(Shoko.Commons.Properties.Resources.Settings_ChangeServerPortFail,
                                    Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }
                this.Cursor = Cursors.Arrow;
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                MessageBox.Show(ex.Message, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        public bool SetNancyPort(ushort port)
        {
            if (!Utils.IsAdministrator())
            {
                return(false);
            }


            StopHost();

            ServerSettings.Instance.ServerPort = port;

            bool started = NetPermissionWrapper(StartNancyHost);

            if (!started)
            {
                StopHost();
                throw new Exception("Failed to start all of the network hosts");
            }

            return(true);
        }
Ejemplo n.º 3
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);
        }