예제 #1
0
        public void Stop()
        {
            ServantHost.Stop();

            if (Debug)
            {
                Console.WriteLine("Servant was stopped.");
            }
        }
예제 #2
0
        public void Start(ServantConfiguration configuration = null)
        {
            if (configuration == null)
            {
                configuration = Nancy.TinyIoc.TinyIoCContainer.Current.Resolve <ServantConfiguration>();
                Debug         = configuration.Debug;
            }

            if (ServantHost == null)
            {
                var uri = new Uri(configuration.ServantUrl.Replace("*", "localhost"));
                CreateHost(uri);

                //StartLogParsing();
                try
                {
                    ServantHost.Start();
                }
                catch (HttpListenerException)                 // Tries to start Servant on another port
                {
                    var servantUrl   = configuration.ServantUrl.Replace("*", "localhost");
                    var portPosition = servantUrl.LastIndexOf(":");
                    if (portPosition != -1)
                    {
                        servantUrl = servantUrl.Substring(0, portPosition);
                    }
                    servantUrl += ":54445";

                    var newUri = new Uri(servantUrl);
                    CreateHost(uri);
                    ServantHost.Start();

                    configuration.ServantUrl = newUri.ToString();
                    ConfigurationHelper.UpdateConfiguration(configuration);
                }
            }

            if (configuration.EnableErrorMonitoring)
            {
                _timer.Start();
            }

            if (Debug)
            {
                Console.WriteLine("Host started on {0}", configuration.ServantUrl);
            }
        }