示例#1
0
        /// <summary>
        /// Method to start the server.
        /// </summary>
        public static void Start()
        {
            // Check if the server is started.
            if (!HttpWebServerApplication.IsStarted)
            {
                try
                {
                    // Try to get server informations
                    ServerData server = ApplicationBase.Options.Remote.Servers.FindDefaultFirst();

                    if (server != null)
                    {
                        HttpWebServerApplication.Start(server.Host, server.Port);
                        log.Info(Properties.Logs.ServerStarted);
                    }

                    NotifyServerStarted();
                }
                catch (Exception ex)
                {
                    log.Error(ex.Output(), ex);
                    MessageBoxs.Warning(ex.Output(), ex.GetType().Name);

                    NotifyServerFailed();
                }
            }
            else
            {
                log.Warn("Server is already started.");
            }
        }
示例#2
0
        /// <summary>
        /// Method called on remove server from firwall click.
        /// </summary>
        public static void RemoveNetworkAcl()
        {
            log.Info("Disabling external server access. Please wait.");

            Task.Run(() =>
            {
                // Try to get server informations
                ServerData server = ApplicationBase.Options.Remote.Servers.FindDefaultFirst();

                if (server != null)
                {
                    XtrmAddons.Net.Network.NetworkAclChecker.NetshDeleteAddress(XtrmAddons.Net.Network.NetworkAclChecker.FormatURL(server.Host, server.Port));
                }
            });

            log.Info("Disabling external server access. Done.");
        }
示例#3
0
        /// <summary>
        /// Method to auto start the application Server.
        /// </summary>
        public void AutoStartServer()
        {
            // Get default server in preferences.
            log.Info("Auto start HTTP server connection. Please wait...");

            ServerData server = InitializeServer();

            // Try to start server.
            try
            {
                if (server != null)
                {
                    if (!server.AutoStart)
                    {
                        log.Debug("Auto start HTTP server connection. Aborted !");
                        log.Info("Auto start HTTP server connection. Done !");
                        return;
                    }

                    HttpServerBase.AddNetworkAcl();
                    HttpServerBase.Start();

                    log.Info("Server started : [" + server.Host + ":" + server.Port + "]");
                }
                else
                {
                    log.Error("Server preferences not found !");
                }
            }

            // Catch server start exception.
            catch (Exception e)
            {
                log.Error("Auto start HTTP server connection failed : [" + server?.Host + ":" + server?.Port + "]", e);
                MessageBox.Show("Starting server : [" + server?.Host + ":" + server?.Port + "] failed !", Local.Properties.Translations.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            log.Info("Auto start HTTP server connection. Done !");
        }
示例#4
0
        /// <summary>
        /// Method to initialize application Server.
        /// </summary>
        public ServerData InitializeServer()
        {
            ServerData server = ApplicationBase.Options.Remote.Servers.FindDefaultFirst();

            // Create default server parameters if not exists.
            if (server == null || server.Key == null)
            {
                server = new ServerData
                {
                    Key       = "default",
                    Name      = "Default Server",
                    IsDefault = true
                };

                ApplicationBase.Options.Remote.Servers.AddDefaultSingle(server);
            }


            // Initialize web server host or ip address.
            if (server.Host.IsNullOrWhiteSpace())
            {
                server.Host = NetworkInformations.GetLocalNetworkIp(false);
                ApplicationBase.Options.Remote.Servers.AddKeySingle(server);
            }

            // Initialize web server port.
            if (server.Port.IsNullOrWhiteSpace())
            {
                server.Port = $"{NetworkInformations.GetAvailablePort(9293)}";
                ApplicationBase.Options.Remote.Servers.AddKeySingle(server);
            }

            server = ApplicationBase.Options.Remote.Servers.FindDefaultFirst();
            Trace.TraceInformation($"{Local.Properties.Logs.ServerAddress} : http://{server.Host}:{server.Host}");

            return(server);
        }
示例#5
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        /// <param name="disposing">Track whether Dispose has been called.</param>
        protected override void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    Server = null;
                }

                // Call the appropriate methods to clean up unmanaged resources here.
                // If disposing is false, only the following code is executed.


                // Note disposing has been done.
                disposed = true;
            }

            // Call base class implementation.
            base.Dispose(disposing);
        }
示例#6
0
 /// <summary>
 /// Method to initialize the model.
 /// </summary>
 protected void InitializeModel()
 {
     Server = ApplicationBase.Options.Remote.Servers.FindDefaultFirst();
 }