Exemple #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.Text = Program.SVC_NAME;

            CommonLog.SetGuiControl(this, mmLog);

            RemoteCaller.HttpConnectionLimit = 1000; // by default

            var appSettings = ConfigurationManager.AppSettings;

            var allKeys = appSettings.AllKeys;

            foreach (var key in allKeys)
            {
                if (key == "OutgoingHttpConnectionLimit")
                {
                    RemoteCaller.HttpConnectionLimit = Convert.ToInt32(appSettings[key].ToString());
                }

                if (key == "DefaultRemoteCallTimeout")
                {
                    RemoteCaller.DefaultTimeout = Convert.ToInt32(appSettings[key].ToString());
                }

                if (key == "AppServerSetting")
                {
                    m_ServerSetting = JsonConvert.DeserializeObject <CommonServerContainerSetting>(appSettings[key]);
                }
            }

            if (m_Server == null && m_ServerSetting != null)
            {
                m_Server = new CommonServerContainer();
            }
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            CommonLog.SetGuiControl(this, mmLog);

            var appSettings = ConfigurationManager.AppSettings;

            var allKeys = appSettings.AllKeys;

            /*
             * foreach (var key in allKeys)
             * {
             *  if (key == "InternalServer") m_InternalSetting = JsonConvert.DeserializeObject<ServerSetting>(appSettings[key]);
             *  if (key == "PublicServer") m_PublicSetting = JsonConvert.DeserializeObject<ServerSetting>(appSettings[key]);
             *
             *  if (key == "NodeName") m_NodeName = appSettings[key];
             *  if (key == "GroupName") m_GroupName = appSettings[key];
             *  if (key == "ServerInfoStorageName") m_StorageName = appSettings[key];
             *
             *  if (key == "Services")
             *  {
             *      var fileNames = appSettings[key].Split(',');
             *      m_ServiceFileNames.Clear();
             *      m_ServiceFileNames.AddRange(fileNames);
             *  }
             * }
             *
             * if (m_ServerNode == null)
             * {
             *  m_ServerNode = new ServerNode(m_NodeName, m_GroupName, CommonLog.GetLogger());
             *  m_ServerNode.SetServerInfoStorage(m_StorageName);
             *  m_ServerNode.ResetLocalServiceFiles(m_ServiceFileNames);
             * }
             */

            foreach (var key in allKeys)
            {
                if (key == "AppServerSetting")
                {
                    m_ServerSetting = JsonConvert.DeserializeObject <CommonServerContainerSetting>(appSettings[key]);
                }
            }

            if (m_Server == null && m_ServerSetting != null)
            {
                m_Server = new CommonServerContainer();
            }
        }
        protected override void OnStart(string[] args)
        {
            // TODO: Add code here to start your service.

            RequestAdditionalTime(1000 * Program.EXTRA_START_SVC_SECONDS);

            RemoteCaller.HttpConnectionLimit = 1000; // by default

            CommonLog.Info("=== " + Program.SVC_NAME + " is starting ===");

            ConfigurationManager.RefreshSection("appSettings");

            var appSettings = ConfigurationManager.AppSettings;

            var allKeys = appSettings.AllKeys;

            foreach (var key in allKeys)
            {
                if (key == "OutgoingHttpConnectionLimit")
                {
                    RemoteCaller.HttpConnectionLimit = Convert.ToInt32(appSettings[key].ToString());
                }

                if (key == "DefaultRemoteCallTimeout")
                {
                    RemoteCaller.DefaultTimeout = Convert.ToInt32(appSettings[key].ToString());
                }

                if (key == "AppServerSetting")
                {
                    m_ServerSetting = JsonConvert.DeserializeObject <CommonServerContainerSetting>(appSettings[key]);
                }
            }

            if (m_Server == null && m_ServerSetting != null)
            {
                m_Server = new CommonServerContainer();
            }

            if (m_Server != null && !m_Server.IsWorking() && m_ServerSetting != null)
            {
                m_Server.Start(m_ServerSetting, CommonLog.GetLogger());
                Thread.Sleep(100);
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            LogManager.Configuration = new XmlLoggingConfiguration($"{AppContext.BaseDirectory}/NLog.config");

            Console.WriteLine("Loading app.config...");

            var appSettings = ConfigurationManager.AppSettings;

            var allKeys = appSettings.AllKeys;

            /*
             * foreach (var key in allKeys)
             * {
             *  if (key == "InternalServer") m_InternalSetting = JsonConvert.DeserializeObject<ServerSetting>(appSettings[key]);
             *  if (key == "PublicServer") m_PublicSetting = JsonConvert.DeserializeObject<ServerSetting>(appSettings[key]);
             *
             *  if (key == "NodeName") m_NodeName = appSettings[key];
             *  if (key == "GroupName") m_GroupName = appSettings[key];
             *  if (key == "ServerInfoStorageName") m_StorageName = appSettings[key];
             *
             *  if (key == "Services")
             *  {
             *      var fileNames = appSettings[key].Split(',');
             *      m_ServiceFileNames.Clear();
             *      m_ServiceFileNames.AddRange(fileNames);
             *  }
             * }
             *
             * if (m_ServerNode == null)
             * {
             *  m_ServerNode = new ServerNode(m_NodeName, m_GroupName, CommonLog.GetLogger());
             *  m_ServerNode.SetServerInfoStorage(m_StorageName);
             *  m_ServerNode.ResetLocalServiceFiles(m_ServiceFileNames);
             * }
             */

            foreach (var key in allKeys)
            {
                if (key == "AppServerSetting")
                {
                    m_ServerSetting = JsonConvert.DeserializeObject <CommonServerContainerSetting>(appSettings[key]);
                }
            }

            if (m_Server == null && m_ServerSetting != null)
            {
                m_Server = new CommonServerContainer();
            }

            Console.WriteLine("Start server...");

            /*
             * Task.Run(async () =>
             * {
             *  if (m_ServerNode != null && !m_ServerNode.IsWorking())
             *  {
             *      await m_ServerNode.Start(m_InternalSetting, m_PublicSetting);
             *      //await m_ServerNode.StartStandaloneMode(m_PublicSetting);
             *      await Task.Delay(50);
             *      if (m_ServerNode.IsWorking())
             *      {
             *          CommonLog.Info("Server Started");
             *          if (!m_ServerNode.IsStandalone()) CommonLog.Info("Internal URL: " + m_ServerNode.GetInternalAccessUrl());
             *          CommonLog.Info("Public URL: " + m_ServerNode.GetPublicAccessUrl());
             *      }
             *  }
             *
             *  Console.WriteLine("Press any key to quit...");
             *  Console.ReadLine();
             *
             *  Console.WriteLine("Stop server...");
             *  if (m_ServerNode != null) await m_ServerNode.Stop();
             *
             *  Console.WriteLine("Done!");
             *
             * }).Wait();
             */

            if (m_Server != null && !m_Server.IsWorking() && m_ServerSetting != null)
            {
                Console.WriteLine("Starting...");
                m_Server.Start(m_ServerSetting, CommonLog.GetLogger());

                Console.WriteLine();
                Console.WriteLine("Press any key to quit...");
                Console.ReadLine();

                Console.WriteLine("Stop server...");
                if (m_Server != null)
                {
                    m_Server.Stop();
                }

                Console.WriteLine();
                Console.WriteLine("Press any key again to end the process");
                Console.ReadLine();

                Console.WriteLine("- END -");
            }
        }
        static void Main(string[] args)
        {
            m_AppName = "SimpleSharpServer";

            m_ExtraStopAppSeconds = 2;

            m_Watcher = new ManualResetEvent(false);

            AppDomain.CurrentDomain.ProcessExit += (s, ev) =>
            {
                Console.WriteLine(m_AppName + " - process exit");
                if (m_Watcher != null)
                {
                    m_Watcher.Set();
                }
            };

            Console.CancelKeyPress += (s, ev) =>
            {
                Console.WriteLine(m_AppName + " - Ctrl+C pressed");
                if (m_Watcher != null)
                {
                    m_Watcher.Set();
                }
                ev.Cancel = true;
            };

            LogManager.Configuration = new XmlLoggingConfiguration($"{AppContext.BaseDirectory}/NLog.config");

            RemoteCaller.HttpConnectionLimit = 1000; // by default

            var appSettings = ConfigurationManager.AppSettings;
            var allKeys     = appSettings.AllKeys;

            foreach (var key in allKeys)
            {
                if (key == "ServiceName")
                {
                    m_AppName = appSettings[key];
                }
                if (key == "ExtraStopServiceSeconds")
                {
                    m_ExtraStopAppSeconds = Convert.ToInt32(appSettings[key].ToString());
                }
                if (key == "OutgoingHttpConnectionLimit")
                {
                    RemoteCaller.HttpConnectionLimit = Convert.ToInt32(appSettings[key].ToString());
                }
                if (key == "DefaultRemoteCallTimeout")
                {
                    RemoteCaller.DefaultTimeout = Convert.ToInt32(appSettings[key].ToString());
                }
                if (key == "AppServerSetting")
                {
                    m_ServerSetting = JsonConvert.DeserializeObject <CommonServerContainerSetting>(appSettings[key]);
                }
            }

            if (m_ServerSetting == null)
            {
                CommonLog.Info("Invalid app config");
                return;
            }

            CommonLog.Info("=== " + m_AppName + " is starting ===");

            if (m_Server == null && m_ServerSetting != null)
            {
                m_Server = new CommonServerContainer();
            }
            if (m_Server != null && !m_Server.IsWorking() && m_ServerSetting != null)
            {
                m_Server.Start(m_ServerSetting, CommonLog.GetLogger());
                Thread.Sleep(100);
            }

            if (m_Watcher != null)
            {
                m_Watcher.Reset();
                m_Watcher.WaitOne();
            }

            if (m_Server != null && m_Server.IsWorking())
            {
                m_Server.Stop();
                Thread.Sleep(100);
            }

            CommonLog.Info("=== " + m_AppName + " stopped ===");

            Thread.Sleep(1000 * m_ExtraStopAppSeconds);

            //Console.WriteLine();
            //Console.WriteLine("Press any key to quit...");
            //Console.ReadLine();
        }