コード例 #1
0
ファイル: OwinRole.cs プロジェクト: smolyakoff/conreign
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = 20;
            var env = CloudConfigurationManager.GetSetting("Environment");

            if (string.IsNullOrEmpty(env))
            {
                throw new InvalidOperationException("Unable to determine environment.");
            }
            var config   = ConreignApiConfiguration.Load(Environment.CurrentDirectory, env);
            var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["PublicApi"];

            Api        = ConreignApi.Create(config);
            Log.Logger = Api.Logger;
            // Starting appplication
            var baseUri = $"{endpoint.Protocol}://{endpoint.IPEndpoint}";

            _app = WebApp.Start <Startup>(baseUri);
            Log.Logger.Information("Conreign API ({Environment}) is started at {BaseUri}",
                                   Api.Configuration.Environment, baseUri);
            return(base.OnStart());
        }
コード例 #2
0
        public static IDisposable Run(string[] args)
        {
            var apiConfiguration = ConreignApiConfiguration.Load(ApplicationPath.CurrentDirectory, args);
            var api    = ConreignApi.Create(apiConfiguration);
            var logger = api.Logger;

            Log.Logger = logger;
            try
            {
                logger.Information("Starting API...");
                var host = apiConfiguration.IsLocalEnvironment ? "localhost" : "*";
                var url  = $"http://{host}:{apiConfiguration.Port}";
                Startup.Api = api;
                var webApp = WebApp.Start <Startup>(url);
                logger.Information($"API is running at {url}.");
                return(webApp);
            }
            catch (Exception ex)
            {
                logger.Fatal(ex, "Failed to start API.");
                throw;
            }
        }