当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequestMessage.FindModuleInfo方法代码示例

本文整理汇总了C#中System.Net.Http.HttpRequestMessage.FindModuleInfo方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.FindModuleInfo方法的具体用法?C# HttpRequestMessage.FindModuleInfo怎么用?C# HttpRequestMessage.FindModuleInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.FindModuleInfo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SelectController

        public HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            var routeData = request.GetRouteData();
            var module = request.FindModuleInfo();

            // Handle the app-api queries
            if (routeData.Route.RouteTemplate.Contains("DesktopModules/2sxc/API/app-api/") && module.DesktopModule.ModuleName == "2sxc-app")
            {
                var portalSettings = PortalSettings.Current;
                var sexy = request.GetSxcOfModuleContext();

                // previously we assumed that there is a sub-folder with a future-app-id, but 2015-05-15 decided it's probably not worth trying, because each request currently needs tokens anyhow
                // if ((string) routeData.Values["appFolder"] != "auto-detect-app" && (string) routeData.Values["appFolder"] != sexy.App.Folder)
                //    throw new HttpException("AppFolder was not correct - was " + routeData.Values["appFolder"] + " but should be " + sexy.App.Folder);

                var controllerTypeName = routeData.Values["controller"] + "Controller";

                var controllerPath = Path.Combine(SexyContent.AppBasePath(portalSettings), sexy.App.Folder,
                    "Api/" + controllerTypeName + ".cs");

                if (File.Exists(HostingEnvironment.MapPath(controllerPath)))
                {
                    var assembly = BuildManager.GetCompiledAssembly(controllerPath);
                    var type = assembly.GetType(controllerTypeName);
                    return new HttpControllerDescriptor(_config, controllerTypeName, type);
                }
                throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "Controller " + controllerTypeName + " not found in app."));
            }
            return PreviousSelector.SelectController(request);
        }
开发者ID:BravoSierra,项目名称:2sxc,代码行数:30,代码来源:AppApiControllerSelector.cs

示例2: GetSxcOfApiRequest

        internal static SxcInstance GetSxcOfApiRequest(HttpRequestMessage request)
        {
            string cbidHeader = "ContentBlockId";
            var moduleInfo = request.FindModuleInfo();

            // get url parameters and provide override values to ensure all configuration is
            // preserved in AJAX calls
            List<KeyValuePair<string, string>> urlParams = null;
            var requestParams = request.GetQueryNameValuePairs();
            var origParams = requestParams.Where(p => p.Key == "originalparameters").ToList();
            if (origParams.Any())
            {
                var paramSet = origParams.First().Value;

                // Workaround for deserializing KeyValuePair -it requires lowercase properties(case sensitive), which seems to be a bug in some Newtonsoft.Json versions: http://stackoverflow.com/questions/11266695/json-net-case-insensitive-property-deserialization
                var items = Json.Deserialize<List<UpperCaseStringKeyValuePair>>(paramSet);
                urlParams = items.Select(a => new KeyValuePair<string, string>(a.Key, a.Value)).ToList();

                //urlParams = requestParams
                //    .Where(keyValuePair => keyValuePair.Key.IndexOf("orig", StringComparison.Ordinal) == 0)
                //    .Select(pair => new KeyValuePair<string, string>(pair.Key.Substring(4), pair.Value))
                //    .ToList();
            }
            // first, check the special overrides
            //var origparams = requestParams.Select(np => np.Key == "urlparameters").ToList();
            //if (origparams.Any())
            //{
            //    var paramSet = origparams.First();
            //}

            // then add remaining params

            IContentBlock contentBlock = new ModuleContentBlock(moduleInfo, urlParams);

            // check if we need an inner block
            if (request.Headers.Contains(cbidHeader)) {
                var cbidh = request.Headers.GetValues(cbidHeader).FirstOrDefault();
                int cbid;
                Int32.TryParse(cbidh, out cbid);
                if (cbid < 0)   // negative id, so it's an inner block
                    contentBlock = new EntityContentBlock(contentBlock, cbid);
            }

            return contentBlock.SxcInstance;
        }
开发者ID:2sic,项目名称:2sxc,代码行数:45,代码来源:Helpers.cs

示例3: SelectController

        public HttpControllerDescriptor SelectController(HttpRequestMessage request)
        {
            var routeData = request.GetRouteData();
            var module = request.FindModuleInfo();

            // Handle the app-api queries
            if (!routeData.Route.RouteTemplate.Contains("DesktopModules/2sxc/API/app-api/") ||
                module.DesktopModule.ModuleName != "2sxc-app")
                return PreviousSelector.SelectController(request);

            var controllerTypeName = routeData.Values["controller"] + "Controller";

            try
            {
                var portalSettings = PortalSettings.Current;
                var sexy = Helpers.GetSxcOfApiRequest(request);// request.GetSxcOfModuleContext();

                // previously we assumed that there is a sub-folder with a future-app-id, but 2015-05-15 decided it's probably not worth trying, because each request currently needs tokens anyhow
                // if ((string) routeData.Values["appFolder"] != "auto-detect-app" && (string) routeData.Values["appFolder"] != sexy.App.Folder)
                //    throw new HttpException("AppFolder was not correct - was " + routeData.Values["appFolder"] + " but should be " + sexy.App.Folder);

                var controllerPath = Path.Combine(AppHelpers.AppBasePath(portalSettings), sexy.App.Folder,
                    "Api/" + controllerTypeName + ".cs");

                if (File.Exists(HostingEnvironment.MapPath(controllerPath)))
                {
                    var assembly = BuildManager.GetCompiledAssembly(controllerPath);
                    var type = assembly.GetType(controllerTypeName);
                    return new HttpControllerDescriptor(_config, controllerTypeName, type);
                }
            }
            catch (Exception e)
            {
                var exception = new Exception("Error while selecting / compiling a controller for the request. Pls check the event-log and the code. See the inner exception for more details.", e);
                DotNetNuke.Services.Exceptions.Exceptions.LogException(exception);
                throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.InternalServerError, exception.Message, e));
            }

            throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.NotFound, "Controller " + controllerTypeName + " not found in app."));
        }
开发者ID:2sic,项目名称:2sxc,代码行数:40,代码来源:AppApiControllerSelector.cs

示例4: FindModuleInfo

 protected virtual ModuleInfo FindModuleInfo(HttpRequestMessage request)
 {
     return request.FindModuleInfo();
 }
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:4,代码来源:SupportedModulesAttribute.cs

示例5: FindModuleInfoTriesAllProviders

        public void FindModuleInfoTriesAllProviders()
        {
            //Arrange
            var request = new HttpRequestMessage();
            var configuration = new HttpConfiguration();
            var provider = new Mock<ITabAndModuleInfoProvider>();
            ModuleInfo moduleInfo;
            provider.Setup(x => x.TryFindModuleInfo(request, out moduleInfo)).Returns(false);
            configuration.AddTabAndModuleInfoProvider(provider.Object);
            configuration.AddTabAndModuleInfoProvider(provider.Object);
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;

            //Act
            request.FindModuleInfo();

            //Assert
            provider.Verify(x => x.TryFindModuleInfo(request, out moduleInfo), Times.Exactly(2));
        }
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:18,代码来源:HttpRequestMessageExtensionsTests.cs

示例6: FindModuleInfoStopCallingProvidersAfterOneSuccess

        public void FindModuleInfoStopCallingProvidersAfterOneSuccess()
        {
            //Arrange
            var request = new HttpRequestMessage();
            var configuration = new HttpConfiguration();
            var provider = new Mock<ITabAndModuleInfoProvider>();
            ModuleInfo moduleInfo;
            provider.Setup(x => x.TryFindModuleInfo(request, out moduleInfo)).Returns(true);
            configuration.AddTabAndModuleInfoProvider(provider.Object);
            configuration.AddTabAndModuleInfoProvider(provider.Object);
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;

            //Act
            request.FindModuleInfo();

            //Assert
            provider.Verify(x => x.TryFindModuleInfo(request, out moduleInfo), Times.Once());
        }
开发者ID:VegasoftTI,项目名称:Dnn.Platform,代码行数:18,代码来源:HttpRequestMessageExtensionsTests.cs


注:本文中的System.Net.Http.HttpRequestMessage.FindModuleInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。