Пример #1
0
        /// <summary>
        /// Configures the container.
        /// </summary>
        /// <param name="iocContainer">The ioc container.</param>
        /// <returns></returns>
        public BootStrap ConfigureContainer(HttpConfiguration configuration, IContainer iocContainer = null)
        {
            if (iocContainer == null)
            {
                // No. Create anew one.
                iocContainer = new Container();

                iocContainer.Configure
                (
                    configure =>
                {
                    configure.For <IHub>().Use <SignalrHub>();
                    configure.For <IDeploymentRequestHandler>().Use <DeployRequestHandler>();
                    configure.For <ISqlDeploymentRequestHandler>().Use <SqlDeploymentHandler>();
                    configure.For <IClearCacheHelper>().Use <ClearCacheHelper>();
                    configure.For <IServerResetHelper>().Use <ServerResetHelper>();
                    configure.For <IServerStartHelper>().Use <ServerStartHelper>();
                    configure.For <IServerStopHelper>().Use <ServerStopHelper>();
                    configure.For <ISqlScriptExecutor>().Use <SqlScriptExecutor>();
                    configure.For <IClearSourceScriptsHelper>().Use <ClearSourceScriptsHelper>();
                }
                );
            }
            HttpRouteCollectionExtensions.MapHttpRoute(configuration.Routes, "Api default", "api/{controller}/{id}", (object)new
            {
                id = RouteParameter.Optional
            });
            configuration.Services.Replace
            (
                typeof(IHttpControllerActivator),
                new StructureMapActivator(iocContainer)
            );
            return(this);
        }
        public void Initialize(HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (this.domains != null)
            {
                config.SetCrossDomainOrigins(this.domains);
            }

            // register the controller as an exclusion so it does not map to /api
            MobileAppConfiguration mobileAppConfig = config.GetMobileAppConfiguration();

            mobileAppConfig.AddBaseRouteExclusion(CrossDomainControllerName);

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: CrossDomainBridgeRouteName,
                routeTemplate: "crossdomain/bridge",
                defaults: new { controller = CrossDomainControllerName });

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: CrossDomainLoginReceiverRouteName,
                routeTemplate: "crossdomain/loginreceiver",
                defaults: new { controller = CrossDomainControllerName });
        }
        /// <summary>
        /// </summary>
        /// <param name="config">HttpConfiguration</param>
        public void Initialize(HttpConfiguration config)
        {
            HashSet <string>            tableControllerNames      = config.GetTableControllerNames();
            SetRouteConstraint <string> tableControllerConstraint = new SetRouteConstraint <string>(tableControllerNames, matchOnExcluded: false);

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: TablesRouteName,
                routeTemplate: "tables/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: new { controller = tableControllerConstraint });
        }
        private static void MapApiControllers(HttpConfiguration config)
        {
            HashSet <string>            tableControllerNames    = config.GetMobileAppControllerNames();
            SetRouteConstraint <string> apiControllerConstraint = new SetRouteConstraint <string>(tableControllerNames, matchOnExcluded: false);

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: RouteNames.Apis,
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: new { controller = apiControllerConstraint });
        }
Пример #5
0
        public void Initialize(HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: HomeRouteName,
                routeTemplate: String.Empty,
                defaults: new { controller = "Home", action = "Index" });
        }
        public void Initialize(HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: NotificationInstallationsRouteName,
                routeTemplate: PushRoutePrefix + "{installationId}",
                defaults: new { controller = "notificationinstallations" });
        }
Пример #7
0
        public static SwaggerEnabledConfiguration EnableSwagger(
            this HttpConfiguration httpConfig,
            string routeTemplate,
            Action <SwaggerDocsConfig> configure = null)
        {
            SwaggerDocsConfig config = new SwaggerDocsConfig();

            if (configure != null)
            {
                configure(config);
            }
            HttpRouteCollectionExtensions.MapHttpRoute(httpConfig.get_Routes(), "swagger_docs" + routeTemplate, routeTemplate, (object)null, (object)new
            {
                apiVersion = ".+"
            }, (HttpMessageHandler) new SwaggerDocsHandler(config));
            return(new SwaggerEnabledConfiguration(httpConfig, new Func <HttpRequestMessage, string>(config.GetRootUrl), config.GetApiVersions().Select <string, string>((Func <string, string>)(version => routeTemplate.Replace("{apiVersion}", version)))));
        }
        public void Initialize(HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // register the controller as an exclusion so it does not map to /api
            MobileAppConfiguration mobileAppConfig = config.GetMobileAppConfiguration();

            mobileAppConfig.AddBaseRouteExclusion(PushControllerName);

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: NotificationInstallationsRouteName,
                routeTemplate: PushRoutePrefix + "{installationId}",
                defaults: new { controller = PushControllerName });
        }
Пример #9
0
        /// <summary>
        /// </summary>
        /// <param name="config">HttpConfiguration</param>
        public void Initialize(HttpConfiguration config)
        {
            HashSet <string>            tableControllerNames      = config.GetTableControllerNames();
            SetRouteConstraint <string> tableControllerConstraint = new SetRouteConstraint <string>(tableControllerNames, matchOnExcluded: false);

            // register all TableControllers as exclusions so they do not map to /api
            MobileAppConfiguration mobileAppConfig = config.GetMobileAppConfiguration();

            foreach (string controllerName in tableControllerNames)
            {
                mobileAppConfig.AddBaseRouteExclusion(controllerName);
            }

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: TablesRouteName,
                routeTemplate: "tables/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: new { controller = tableControllerConstraint });
        }
Пример #10
0
        public void EnableSwaggerUi(string routeTemplate, Action <SwaggerUiConfig> configure = null)
        {
            SwaggerUiConfig config = new SwaggerUiConfig(this._discoveryPaths, this._rootUrlResolver);

            if (configure != null)
            {
                configure(config);
            }
            HttpRouteCollectionExtensions.MapHttpRoute(this._httpConfig.get_Routes(), "swagger_ui" + routeTemplate, routeTemplate, (object)null, (object)new
            {
                assetPath = ".+"
            }, (HttpMessageHandler) new SwaggerUiHandler(config));
            if (!(routeTemplate == SwaggerEnabledConfiguration.DefaultRouteTemplate))
            {
                return;
            }
            HttpRouteCollectionExtensions.MapHttpRoute(this._httpConfig.get_Routes(), "swagger_ui_shortcut", "swagger", (object)null, (object)new
            {
                uriResolution = new HttpRouteDirectionConstraint((HttpRouteDirection)0)
            }, (HttpMessageHandler) new RedirectHandler(this._rootUrlResolver, "swagger/ui/index"));
        }
Пример #11
0
        public void Initialize(HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            if (this.domains != null)
            {
                config.SetCrossDomainOrigins(this.domains);
            }

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: CrossDomainBridgeRouteName,
                routeTemplate: "crossdomain/bridge",
                defaults: new { controller = "crossdomain" });

            HttpRouteCollectionExtensions.MapHttpRoute(
                config.Routes,
                name: CrossDomainLoginReceiverRouteName,
                routeTemplate: "crossdomain/loginreceiver",
                defaults: new { controller = "crossdomain" });
        }
Пример #12
0
        private void StartWebServer()
        {
            string port = Settings.Default.Port;
            HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost:" + port);

            string ModifyTemplate1 = "2010-04-01/Accounts/{sid}/{controller}/{id}.json";
            string ModifyTemplate2 = "2010-04-01/Accounts/{sid}/{controller}/{id}";
            object modifydefaults  = (object)new
            {
                action = "Modify"
            };

            object emptydefaults = (object)new
            {
            };

            string routeTemplate1 = "2010-04-01/Accounts/{sid}/{controller}.json";
            string routeTemplate2 = "2010-04-01/Accounts/{sid}/{controller}";


            // special for sms
            string SMSTemplate  = "2010-04-01/Accounts/{sid}/{controller}/Messages";
            string SMSTemplate2 = "2010-04-01/Accounts/{sid}/{controller}/Messages.json";

            //var TwoSegContraint = new HttpRouteValueDictionary { { "seg2", "[A-Za-z]{1,*}" } };//  new Dictionary<string, IHttpRouteConstraint>();


            HttpRouteCollectionExtensions.MapHttpRoute(configuration.Routes, "SMS1", SMSTemplate);
            HttpRouteCollectionExtensions.MapHttpRoute(configuration.Routes, "SMS2", SMSTemplate2);
            HttpRouteCollectionExtensions.MapHttpRoute(configuration.Routes, "ModifyDefault", ModifyTemplate1, modifydefaults);
            HttpRouteCollectionExtensions.MapHttpRoute(configuration.Routes, "ModifyDirect", ModifyTemplate2, modifydefaults);
            HttpRouteCollectionExtensions.MapHttpRoute(configuration.Routes, "Default", routeTemplate1);
            HttpRouteCollectionExtensions.MapHttpRoute(configuration.Routes, "Direct", routeTemplate2);

            JsonMediaTypeFormatter jsonFormatter = configuration.Formatters.JsonFormatter;
            JsonSerializerSettings jSettings     = new Newtonsoft.Json.JsonSerializerSettings()
            {
                Formatting           = Formatting.Indented,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc
            };

            jSettings.Converters.Add(new TwilioDateTimeConvertor());
            jsonFormatter.SerializerSettings = jSettings;

            // Logging messaanger

            var messageLogger = new HttpLoggingMessageHandler();

            messageLogger.OnHttpLog += new EventHandler <HttpLoggingEventArgs>(messageLogger_OnHttpLog);
            configuration.MessageHandlers.Add(messageLogger);



            HttpSelfHostServer httpSelfHostServer = new HttpSelfHostServer(configuration);

            try
            {
                httpSelfHostServer.OpenAsync().Wait();
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException.Message.Contains("Your process does not have access rights to this namespace"))
                {
                    throw new Exception("You don't have rights to open this port - Try running as administrator or giving permission via NETSTAT", (Exception)ex);
                }
                else
                {
                    throw ex;
                }
            }
            this.ActivePort = int.Parse(port);
        }