本文整理匯總了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);
}
示例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;
}
示例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."));
}
示例4: FindModuleInfo
protected virtual ModuleInfo FindModuleInfo(HttpRequestMessage request)
{
return request.FindModuleInfo();
}
示例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));
}
示例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());
}