示例#1
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);

            ConfigureBindings();

            var boundUris = HostnameUtil.GetUriParams(4567);
            _host = new NancyHost(boundUris);
            _host.Start();

            _core = _kernel.Get<IMuroCore>();

            try
            {
                if (args.Any())
                {
                    _core.Initialise(args[0]);
                }
                else
                {
                    _core.Initialise();
                }
            }
            catch (Exception)
            {
                _core.Shutdown();
                throw;
            }
        }
示例#2
0
 static void Main(string[] args)
 {
     var nancyHost = new NancyHost(new Uri("http://localhost:8888/"));
     nancyHost.Start();
     Console.WriteLine("Nancy now listening - navigating to http://localhost:8888/nancy/. Press enter to stop");
     Console.ReadLine();
 }
示例#3
0
        static void Main(string[] args)
        {
            // Note: The URI must *exactly* match the one specified in the URL ACL.
            // This leads to a problem when you use +, because the Uri constructor doesn't like it.
            var uri = "http://localhost:1234/";
            if (args.Length != 0)
                uri = args[0];

            var stop = new ManualResetEvent(false);
            Console.CancelKeyPress += (sender, e) =>
                {
                    Console.WriteLine("^C");
                    stop.Set();
                };

            var host = new NancyHost(new Uri(uri));
            host.Start();

            Console.WriteLine("Nancy Self Host listening on {0}", uri);
            Console.WriteLine("Press Ctrl+C to quit.");

            stop.WaitOne();

            host.Stop();
        }
示例#4
0
        static void Main(string[] args)
        {
            /***
             * Note:
             *  When using multiple network interfaces, you should not use localhost but a fully qualified ip (v4)
             * 
             ***/
            //SSL: For SSL on Windows rewrite http to https
            var uri = new Uri("http://localhost:"+ConvenienceSystemBackendServer.ConvenienceServer.getPort());
            //var uri = new Uri("http://192.168.1.39:" + ConvenienceSystemBackendServer.ConvenienceServer.getPort());


            using (var host = new NancyHost(uri))
            {
                host.Start();

                Console.WriteLine("Your application is running on " + uri);
                /*Console.WriteLine("Enter 'q' and press [Enter] to close the host.");

                while (true)
                {
                    string line = Console.ReadLine();
                    if (line == "q")
                        break;
                }*/
                while (true)
                    Thread.Sleep(50000);

                /*
                * Remark:
                *   using Sleep here because ReadLine/yield on Unix/Linux often has problems with nohup execution resulting in continously high load on the server
                */
            }
        }
示例#5
0
文件: Program.cs 项目: yodiwo/plegma
        static void Main(string[] args)
        {
            var port = 3400;
            HostConfiguration hostConfigs = new HostConfiguration();
            hostConfigs.UrlReservations.CreateAutomatically = true;

            while (true)
            {
                try
                {
                    using (var host = new NancyHost(hostConfigs, new Uri("http://localhost:" + port)))
                    {
                        host.Start();

                        Console.WriteLine("Your application is running on port " + port);
                        Console.WriteLine("Press any key to close the host.");
                        Console.ReadKey();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    port++;
                }
            }
        }
        public void Init()
        {
            _host = new NancyHost(new Uri(RestBaseUrl));
            _host.Start();

            StartHub();
        }
示例#7
0
        public void Run()
        {
            EnsureInstallation();

            foreach (var service in _services)
            {
                Console.WriteLine("Starting service {0}", service.ServiceName);
                service.Start();
            }

            _nancy = new NancyHost(_uris);
            _nancy.Start();

            Console.WriteLine("Running server at {0}", string.Join(", ", _uris
                .Select(u => u.ToString())
            ));

            Console.ReadLine();

            Console.WriteLine("Stopping server");
            _nancy.Stop();

            foreach (var service in _services)
            {
                Console.WriteLine("Stopping service {0}", service.ServiceName);
                service.Stop();
            }
        }
示例#8
0
 public void Start()
 {
     Log.Debug("Starting self hosted website");
     _nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:1234"));
     _nancyHost.Start();
     Log.Debug("Done starting self hosted website");
 }
示例#9
0
        static void Main(string[] args)
        {
            var host = new NancyHost(new Uri(startUrl));

            Console.WriteLine("Launching Email Visualiser.");
            try
            {
                host.Start();
                Console.WriteLine("Server has launched.");
                Console.WriteLine("Launching browser...");
                Process.Start(startUrl);
                Console.WriteLine("Press any key to stop the server.");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                TextWriter errorWriter = Console.Error; //TODO change to a logger
                errorWriter.WriteLine("------An error has been encountered.------");
                errorWriter.WriteLine(e.Message);
            #if DEBUG
                errorWriter.WriteLine(e.InnerException);
                errorWriter.WriteLine(e.StackTrace);
            #endif
                errorWriter.WriteLine("------The application will now close.------");
            }
            finally
            {
                host.Stop();
            }
        }
        public void Run(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
                return;

            var nancyConfig = new HostConfiguration
            {
                UrlReservations = new UrlReservations
                {
                    CreateAutomatically = true
                }
            };

            var bootstrapper = new ApiBootstrapper(_repository);

            var host = new NancyHost(bootstrapper, nancyConfig, _baseUri);
            cancellationToken.Register(() =>
            {
                Log.InfoFormat("Stopping Nancy host at \"{0}\".", _baseUri);
                host.Stop();
                Log.InfoFormat("Nancy host at \"{0}\" successfully stopped.", _baseUri);
            });

            Log.InfoFormat(CultureInfo.InvariantCulture, "Starting Nancy host at \"{0}\".", _baseUri);
            host.Start();
        }
示例#11
0
 public WebServer(INancyBootstrapper bootstrapper)
 {
     _nancyHost = new NancyHost(new Uri("http://localhost:1234"), bootstrapper, new HostConfiguration
     {
         RewriteLocalhost = false
     });
 }
示例#12
0
 public void Start()
 {
     var hostUrls = ConfigurationManager.AppSettings["hostUrls"];
     var urlList = hostUrls.Split(',').Select(f => new Uri(f)).ToArray();
     _nancyHost = new NancyHost(urlList);
     _nancyHost.Start();
 }
示例#13
0
文件: Program.cs 项目: woohn/Pisces
        static void Main(string[] argList)
        {
            if (!jrdebug)
            {
                if (argList.Length == 0)
                {
                    ShowHelp();
                    return;
                }
            }
            else
            {
                argList    = new string[1];
                argList[0] = "--server";
            }


            Arguments args = new Arguments(argList);

            if (args.Contains("server"))
            {
                // Start web service
                var serverUri = "http://localhost:8080/";
                var cfg       = new HostConfiguration();
                var host      = new Nancy.Hosting.Self.NancyHost(cfg, new Uri(serverUri));
                using (host)
                {
                    host.Start();
                    Console.WriteLine("HDB API is now listening on "
                                      + serverUri.Replace("localhost", Environment.MachineName)
                                      + ". Press ctrl-c to stop");
                    Console.ReadLine();
                }
            }
        }
示例#14
0
 public void Start()
 {
     Log.Debug("NancySelfHost - Starting...");
      _nancyHost = new NancyHost(new Uri("http://localhost:8888/coffeeshop/"));
      _nancyHost.Start();
      Console.WriteLine("Nancy now listening - http://localhost:8888/coffeeshop/. Press ctrl-c to stop");
 }
示例#15
0
        /// <summary>
        /// 监听端口 启动站点
        /// </summary>
        /// <param name="urls">监听ip端口列表</param>
        public static NancyHost Start(int port)
        {
            try
            {
                _host = new NancyHost(new Uri(string.Format("http://localhost:{0}", port)));
                _host.Start();
                LogHelper.WriteLog("Web管理站点启动成功,请打开 http://127.0.0.1:" + port + "进行浏览");

                if (SystemConfig.WebPort != port)
                {
                    //更新系统参数配置表监听端口
                    SystemConfig.WebPort = port;
                    ConfigManager.UpdateValueByKey("SystemConfig", "WebPort", port.ToString());
                }
                return _host;
            }
            catch (HttpListenerException ex)
            {
                LogHelper.WriteLog("Web管理站点启动失败", ex);
                Random random = new Random();
                port = random.Next(port - 1000, port + 1000);
                Console.WriteLine(ex.Message);
                Console.WriteLine(" 重新尝试端口:" + port);
                return Start(port);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Web管理站点启动失败", ex);
                throw ex;
            }
        }
 public void Start()
 {
     var address = _settings.Env.HostWebAtAddress;
     _host = new NancyHost(new Uri(address));
     _host.Start();
     _log.InfoFormat("Web server started at {0}", address);
 }
示例#17
0
        //void run()
        //{
        //    this.running = true;
        //    this.startThread();
        //    this.keepAlive.Start();



        //}


        //public void startThread()
        //{
        //    this.keepAlive = new Thread(() =>
        //    {
        //        while (running)
        //        {
        //            Console.WriteLine("Alive");
        //            System.Threading.Thread.Sleep(1000);
        //        }
        //    });
        //}


        static void Main(String[] args)
        {
            Program foo = new Program();

            foo.start();

            var url = "http://localhost:" + PORT;

            //var configuration = new HostConfiguration()
            //{
            //    UrlReservations = new UrlReservations() { CreateAutomatically = true }
            //};

            var server = new Nancy.Hosting.Self.NancyHost(new Uri(url));


            server.Start();
            Console.WriteLine("Nancy Server listening on {0}", url);
            //Console.Read();



            while (true)
            {
                Thread.Sleep(10000000);
            }
        }
        static void Main(string[] args)
        {
            NancyHost host = new NancyHost(new Uri("http://localhost:8812"));
            host.Start();

            Console.ReadKey();
        }
示例#19
0
        static void Main(string[] args)
        {
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Formatting = Formatting.Indented };

            using (ActionScheduler scheduler = new ActionScheduler())
            using (var host = new NancyHost(new Uri("http://localhost:8090")))
            {
                host.Start();
                Console.WriteLine("Nancy Running at http://localhost:8090");
                Console.WriteLine("Press any key to exit");

                Process.Start("http://localhost:8090/metrics/");

                SampleMetrics.RunSomeRequests();

                scheduler.Start(TimeSpan.FromMilliseconds(500), () =>
                {
                    SetCounterSample.RunSomeRequests();
                    SetMeterSample.RunSomeRequests();
                    UserValueHistogramSample.RunSomeRequests();
                    UserValueTimerSample.RunSomeRequests();
                    SampleMetrics.RunSomeRequests();
                });

                HealthChecksSample.RegisterHealthChecks();

                Console.ReadKey();
            }
        }
示例#20
0
        public static void Main(string[] args)
        {
            // bool from configuration files.
            OsmSharp.Service.Tiles.ApiBootstrapper.BootFromConfiguration();

            // start listening.
            var uri = new Uri("http://localhost:1234");
            HostConfiguration configuration = new HostConfiguration();
            configuration.UrlReservations.CreateAutomatically = true;
            using (var host = new NancyHost(configuration, uri))
            {
                try
                {
                    host.Start();

                    Console.WriteLine("The OsmSharp routing service is running at " + uri);
                    Console.WriteLine("Press [Enter] to close the host.");
                    Console.ReadLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine("Press [Enter] to close the host.");
                    Console.ReadLine();
                }
            }
        }
示例#21
0
        static void Main(string[] args)
        {
            try
            {
                var uri = "http://localhost:8888";
                Console.WriteLine(uri);

                XmlConfigurator.Configure();

                ILog logger = LogManager.GetLogger(typeof(Program));
                logger.InfoFormat("Starting DeReader : {0}", uri);

                // initialize an instance of NancyHost (found in the Nancy.Hosting.Self package)
                var host = new NancyHost(new Uri(uri));
                host.Start();  // start hosting

                //Under mono if you deamonize a process a Console.ReadLine with cause an EOF
                //so we need to block another way
                if (args.Any(s => s.Equals("-d", StringComparison.CurrentCultureIgnoreCase)))
                {
                    Thread.Sleep(Timeout.Infinite);
                }
                else
                {
                    Console.ReadKey();
                }

                logger.Info("Stoping DeReader");
                host.Stop();  // stop hosting
            }
            finally
            {
                LogManager.Shutdown();
            }
        }
示例#22
0
 public void Start()
 {
     if (mutex.WaitOne(TimeSpan.Zero, true))
     {
         try
         {
             Log.Write("Starting on " + ServiceUrl);
             var config = new HostConfiguration
             {
                 UnhandledExceptionCallback = e => Log.Error("Self Host Exception", e)
             };
             nancyHost = new NancyHost(config, new Uri(ServiceUrl));
             nancyHost.Start();
         }
         catch (Exception ex)
         {
             Log.Error("Starting ThumbsUp", ex);
         }
         finally
         {
             mutex.ReleaseMutex();
         }
     }
     else
     {
         Log.Write("Cannot start multiple instances. The ThumbsUp Service is already running on " + ServiceUrl);
         Environment.Exit(0);
     }
 }
示例#23
0
        static void Main(string[] args)
        {
            Logging.Log.Info("Starting AnimeRecs web app");

            HostConfiguration config = new HostConfiguration()
            {
                RewriteLocalhost = false
            };

            string portString = ConfigurationManager.AppSettings["Hosting.Port"];
            uint port;
            if (!uint.TryParse(portString, out port))
            {
                throw new Exception("Hosting.Port is not a valid port number.");
            }

            using (var host = new NancyHost(config, new Uri(string.Format("http://localhost:{0}", port))))
            {
                host.Start();
                Logging.Log.InfoFormat("Started listening on port {0}", port);
            #if MONO
                    WaitForUnixStopSignal();
            #else
                Console.ReadLine();
            #endif
                Logging.Log.Info("Got stop signal, stopping web app");
            }
        }
示例#24
0
        private static void Main(string[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                Console.WriteLine("WelcomePage.WebServer url root-directory [-open]");
                return;
            }

            var url = new Uri(args[0]);
            var rootDirectory = args[1];
            bool openBrowser = args.Length == 3 && args[2].Equals("-open", StringComparison.InvariantCultureIgnoreCase);

            var stop = new ManualResetEvent(false);
            Console.CancelKeyPress += (sender, e) =>
                {
                    Console.WriteLine("^C");
                    stop.Set();
                };

            var bootstrapper = new Bootstrapper(rootDirectory);
            var configuration = new HostConfiguration { RewriteLocalhost = false };
            var host = new NancyHost(bootstrapper, configuration, url);
            host.Start();
            Console.WriteLine("Nancy host listening on '{0}'. Press Ctrl+C to quit.", url);

            if (openBrowser)
                Process.Start(url.ToString());

            stop.WaitOne();

            host.Stop();
        }
 public void Stop()
 {
     if (null == TheNancyHost)
         return;
     TheNancyHost.Stop();
     TheNancyHost = null;
 }
示例#26
0
文件: Program.cs 项目: xxy1991/cozy
        static void Main(string[] args) {

            using (var host = new NancyHost(new Uri("http://localhost:1024"))) {
                host.Start();
                Console.ReadKey();
            }
        }
示例#27
0
        static void Main(string[] args)
        {
            var ip = "10.0.1.15";
            var port = "3580";
            var selection = "";

            Console.WriteLine("Enter IP address. Default is 10.0.1.15");
            selection = Console.ReadLine();
            if (!string.IsNullOrEmpty(selection))
                ip = selection;

            Console.WriteLine("Enter port. Default is 3580");
            selection = Console.ReadLine();
            if (!string.IsNullOrEmpty(selection))
                port = selection;



            var uri = new Uri(string.Format("http://{0}:{1}",ip, port));

            RegisterService(ip, port);

            using (var host1 = new NancyHost(uri))
            //using (var customerService = new CustomerServiceReciever(busFactory, translationService))
            {
                host1.Start();

                Console.WriteLine("Your application is running on " + uri);
                Console.ReadLine();
            }
        }
示例#28
0
 public TestBase()
 {
     var bootstrapper = new Bootstrapper();
     host = new NancyHost(bootstrapper, new Uri(path));
     host.Start();
     Console.WriteLine("*** Host listening on " + path);
 }
示例#29
0
 public void Start()
 {
     Stop();
     _host = new NancyHost(_bootstrapper, NancyConfig.HostConfiguration, _baseUri);
     _host.Start();
     _log.InfoFormat("Started {0}", _baseUri.OriginalString);
 }
        static int Main(string[] args)
        {
            if (args.Length == 0 ||
                string.IsNullOrEmpty(UserKey = args[0]))
            {
                Console.WriteLine("userKey argument is required");
                return 1;
            }

            const int port = 40001;
            var address = string.Format("http://localhost:{0}", port);

            var hostConfig = new HostConfiguration
            {
                UrlReservations = new UrlReservations
                {
                    CreateAutomatically = true
                }
            };

            using (var host = new NancyHost(hostConfig, new Uri(address)))
            {
                host.Start();
                var scheduler = ApiBootstrapper.Container.Resolve<Scheduler>();

                Console.WriteLine("started {0}", port);

                while (scheduler.State != SystemState.Finished)
                {
                    Thread.Sleep(1000);
                }
            }

            return 0;
        }
        /// <summary>
        /// Method called at startup.
        /// </summary>
        public void Run()
        {
            Logger.Info("Starting Nancy host on http://localhost:8888/nancy/");
            _nancyHost = new NancyHost(new Uri("http://localhost:8888/nancy/"));
            _nancyHost.Start();

        }
示例#32
0
 public void StopWebService()
 {
     if (host != null)
     {
         host.Dispose();
         host = null;
         log.Info("Web-Service stopped");
     }
 }
示例#33
0
        public static void addHost(String ip, Int32 port)
        {
            string DOMAIN = "http://" + ip + ":" + port;

            Console.WriteLine("打印服务器的地址是" + DOMAIN);
            NancyHost nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri(DOMAIN));
            Thread    td        = new Thread(new ParameterizedThreadStart(StartDomain));

            td.Start(nancyHost);
        }
示例#34
0
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            Program.logger.Info("SERVICE Starting");


            _cancelSource = new CancellationTokenSource();

            int numOfInstances = 3;

            int.TryParse(Devmasters.Core.Util.Config.GetConfigValue("NumOfInstances"), out numOfInstances);
            try
            {
                HlidacStatu.Util.WebShot.Workers.CreateAndStartWorkers(numOfInstances, _cancelSource);

                var url = Devmasters.Core.Util.Config.GetConfigValue("ListeningUrl");
                if (string.IsNullOrEmpty(url))
                {
                    url = "http://127.0.0.1:9090";
                }

                var hostConfiguration = new HostConfiguration
                {
                    UrlReservations = new UrlReservations()
                    {
                        CreateAutomatically = false
                    },
                    RewriteLocalhost = false
                };
                host = new Nancy.Hosting.Self.NancyHost(new Uri(url));
                host.Start();
                Program.logger.Info($"Nancy Server listening on {url}");
                if (isConsole)
                {
                    do
                    {
                        System.Threading.Thread.Sleep(1000);
                    } while (true);
                }
            }
            finally
            {
                if (isConsole)
                {
                    Program.logger.Info($"Canceling threads");

                    _cancelSource?.Cancel(false);
                    System.Threading.Thread.Sleep(3000);
                    HlidacStatu.Util.WebShot.Workers.CancelWorkers();

                    _cancelSource?.Dispose();
                }
            }
        }
示例#35
0
        //Hosts,starts and stops the nancy server using the default bootstrap
        static void Main(string[] args)
        {
            HostConfiguration hostConfigs = new HostConfiguration();

            hostConfigs.UrlReservations.CreateAutomatically = true;
            var nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:9664/"), new DefaultNancyBootstrapper(), hostConfigs);

            nancyHost.Start();
            Console.WriteLine("The Backflipt statistics server is running now!!" + DateTime.Now);
            Console.ReadLine();
            nancyHost.Stop();
        }
示例#36
0
    public void RunWebService()
    {
        int port = 50005;

        int.TryParse(BauerLib.Registry.ServicePort, out port);

        if (PortInUse(port))
        {
            log.ErrorFormat("Error {0} in use !", port);
            return;
        }

        string baseAddress = string.Format("http://localhost:{0}/", port);

        DotLiquid.Template.NamingConvention = new DotLiquid.NamingConventions.CSharpNamingConvention();

        Nancy.Hosting.Self.HostConfiguration hostConfigs = new Nancy.Hosting.Self.HostConfiguration();

        // netsh http add urlacl url=http://+:50005/ user=EVERYONE
        // netsh http add urlacl url=http://+:50005/ user=JEDER
        hostConfigs.UrlReservations.CreateAutomatically = false;
        hostConfigs.RewriteLocalhost = true;

        int retries = 6;

        while (retries > 0)
        {
            try
            {
                host = new Nancy.Hosting.Self.NancyHost(hostConfigs, new Uri(baseAddress));
                host.Start();

                retries = -1;
            }
            catch (Exception ex)
            {
                log.Error($"Error starting web-service ({ex.Message})", ex);
                retries--;
                if (retries <= 3)
                {
                    hostConfigs.UrlReservations.CreateAutomatically = true;
                }

                System.Threading.Thread.Sleep(500);
            }
        }
        log.InfoFormat("Running on {0}", baseAddress);

        if (Environment.UserInteractive)
        {
            System.Diagnostics.Process.Start(baseAddress);
        }
    }
示例#37
0
        static void Main(string[] args)
        {
            HostConfiguration hostConfigs = new HostConfiguration();

            hostConfigs.UrlReservations.CreateAutomatically = true;
            var nancyHost = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:9664"), new DefaultNancyBootstrapper(), hostConfigs);

            EwsXenLib.Oodly.loggerconfig();
            nancyHost.Start();
            Console.WriteLine("Web server running...");
            Console.ReadLine();
            nancyHost.Stop();
        }
示例#38
0
        static void Main(string[] args)
        {
            var hostUrl = "http://localhost:" + ConfigurationManager.AppSettings["Port"];
            HostConfiguration hostConfigs = new HostConfiguration();

            hostConfigs.UrlReservations.CreateAutomatically = true;
            var nancyHost = new Nancy.Hosting.Self.NancyHost(hostConfigs, new Uri(hostUrl));

            nancyHost.Start();

            Console.WriteLine("Nancy host listening on " + hostUrl);

            Console.ReadLine();
            nancyHost.Stop();
        }
示例#39
0
        static void Main(string[] args)
        {
            var config = new HostConfiguration()
            {
                UrlReservations = new UrlReservations {
                    CreateAutomatically = true
                }
            };

            using (var host = new Nancy.Hosting.Self.NancyHost(config, CurrentAddress))
            {
                host.Start();
                Console.WriteLine("Running on {0}. Press any key to stop.", CurrentAddress);
                Console.ReadKey();
            }
        }
示例#40
0
        static void Main(string[] args)
        {
            //DumpKundenTabelle();

            var loConfig = new HostConfiguration {
                AllowChunkedEncoding = false
            };

            loConfig.UrlReservations.CreateAutomatically = true; //Wird Programm unter Admin gestartet braucht man das nicht

            var nancyHost = new Nancy.Hosting.Self.NancyHost(loConfig, new Uri(DOMAIN));

            // start
            nancyHost.Start();
            Console.WriteLine("REST service listening on " + DOMAIN);
            // stop with an <Enter> key press
            Console.ReadLine();
            nancyHost.Stop();
        }
示例#41
0
 public void Initialize(string pluginName, IScheduler sched)
 {
     _NancyHost = new Nancy.Hosting.Self.NancyHost(new Uri("http://localhost:8888"));
     Scheduler  = sched;
 }
示例#42
0
        /// <summary>
        /// Examples:
        ///
        /// --cgi=sites --propertyFilter=program:agrimet --json_required_properties=json_extra
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var  siteType            = ""; // agrimet, hydromet (blank means all)
            var  cgi                 = "";
            var  json_property_stubs = "";
            var  payload             = "";
            var  p        = new OptionSet();
            var  format   = "json";
            var  verbose  = false;
            bool selfHost = false;
            var  sqLiteDatabaseFileName = "";

            p.Add("server", x => selfHost = true);
            p.Add("cgi=", "required cgi to execute cgi=sites or cgi=series", x => cgi = x);
            p.Add("json_property_stubs=", "comma separated list of properties (i.e. 'region,url,') to created empty stubs if neeed ",
                  x => json_property_stubs = x);
            p.Add("site-type=", "filter agrimet sites", x => siteType   = BasicDBServer.SafeSqlLikeClauseLiteral(x));
            p.Add("payload=", "test query data for a CGI", x => payload = x);
            p.Add("format=", "format json(default) | csv ", x => format = x);
            p.Add("verbose", " get more details", x => verbose          = true);
            p.Add("database", "filename for SQLite database", x => sqLiteDatabaseFileName = x);

            try
            {
                p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            Database.InitDB(args);
            var db = Database.DB();

            if (selfHost)
            {
                try
                {
                    var serverUri = "http://localhost:8080";
                    var cfg       = new HostConfiguration();
                    //cfg.RewriteLocalhost = false;
                    //c..fg.UrlReservations.CreateAutomatically=true;
                    var host = new Nancy.Hosting.Self.NancyHost(cfg, new Uri(serverUri));
                    //var host = new Nancy.Hosting.Self.NancyHost();
                    using (host)
                    {
                        host.Start();
                        Console.WriteLine("Running on " + serverUri);
                        Console.ReadLine();
                    }
                }
                catch (Exception nancyEx)
                {
                    Console.WriteLine(nancyEx.Message);
                }
                return;
            }

            if (cgi == "")
            {
                ShowHelp(p);
                return;
            }

            if (verbose)
            {
                Console.Write("Content-type: text/html\n\n");
                Logger.EnableLogger();
                Logger.WriteLine("verbose=true");
                Logger.WriteLine("payload = " + payload);
            }

            if (cgi == "inventory")
            {
                Console.Write("Content-Type: text/html\n\n");
                db.Inventory();
            }
            else if (cgi == "sites")
            {
                if (format == "json")
                {
                    JSONSites d = new JSONSites(db);
                    d.Execute(json_property_stubs.Split(','), siteType);
                }
                else if (format == "csv")
                {
                    SiteCsvTable c = new SiteCsvTable(db);
                    c.Execute(siteType);
                }
            }
            else if (cgi == "instant" || cgi == "daily")
            {
                try
                {
                    WebTimeSeriesWriter c = null;
                    if (cgi == "instant")
                    {
                        c = new WebTimeSeriesWriter(db, TimeInterval.Irregular, payload);
                    }

                    else
                    if (cgi == "daily")
                    {
                        c = new WebTimeSeriesWriter(db, TimeInterval.Daily, payload);
                    }

                    c.Run();
                }
                catch (Exception e)
                {
                    Logger.WriteLine("Error: " + e.Message);
                }
            }
            else if (cgi == "wyreport")
            {
                try
                {
                    WaterYearReport wy = new WaterYearReport(db, payload);
                    wy.Run();
                }
                catch (Exception e)
                {
                    Logger.WriteLine("Error: " + e.Message);
                }
            }
            else if (cgi == "site")
            {
                SiteInfoCGI si = new SiteInfoCGI(db);
                si.Run(payload);
            }
            else if (cgi == "test-perf-large")
            {
                var c = new HydrometGCITests();
                c.CGI_PerfTestLarge();
            }
            else if (cgi == "test-perf-small")
            {
                var c = new HydrometGCITests();
                c.CGI_PerfTestSmall();
            }
            else if (cgi == "dump")
            {
                var c = new HydrometGCITests();
                c.DumpTest();
            }
            else
            {
                Console.WriteLine("invalid cgi: " + cgi);
            }
        }
示例#43
-1
        public static void Main(string[] args)
        {
            Models.Benchmark.Initialize ();
            Models.Configuration.Initialize ();
            Models.Counter.Initialize ();
            Models.Device.Initialize ();
            Models.Project.Initialize ();
            Models.Recipe.Initialize ();
            Models.Revision.Initialize ();
            Models.Run.Initialize ();
            Models.Sample.Initialize ();

            var nancyHost = new NancyHost (new Uri ("http://127.0.0.1:8080/"), new Uri ("http://10.1.12.185:8080/"));

            nancyHost.Start ();

            StaticConfiguration.DisableErrorTraces = false;
            StaticConfiguration.Caching.EnableRuntimeViewUpdates = true;

            Console.WriteLine ("Nancy now listening on http://127.0.0.1:8080/. Press key to stop");

            while (true) {
                if (Console.ReadKey ().Key == ConsoleKey.Enter) {
                    break;
                }

                Thread.Sleep (100);
            }

            nancyHost.Stop ();
            nancyHost.Dispose ();

            Console.WriteLine ("The End;");
        }