本文整理汇总了C#中RouteCollection.First方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.First方法的具体用法?C# RouteCollection.First怎么用?C# RouteCollection.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteCollection
的用法示例。
在下文中一共展示了RouteCollection.First方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContentRoute_IsAdded
public void ContentRoute_IsAdded()
{
RouteCollection rc = new RouteCollection();
rc.MapContentRoute("content", MockRepository.GenerateStub<IEngine>());
Assert.That(rc.Count, Is.EqualTo(1));
Assert.That(rc.First(), Is.InstanceOf<ContentRoute>());
}
示例2: ContentRoute_IsInsertedBefore_NonContentRoute
public void ContentRoute_IsInsertedBefore_NonContentRoute()
{
RouteCollection rc = new RouteCollection();
rc.MapRoute("mvc", "{controller}/{action}");
rc.MapContentRoute("content", MockRepository.GenerateStub<IEngine>());
Assert.That(rc.Count, Is.EqualTo(2));
Assert.That(rc.First(), Is.InstanceOf<ContentRoute>());
}
示例3: GenericContentRoute_IsntPushedBackBy_ContentRoute
public void GenericContentRoute_IsntPushedBackBy_ContentRoute()
{
RouteCollection rc = new RouteCollection();
rc.MapContentRoute<Models.RegularPage>("area", MockRepository.GenerateStub<IEngine>());
rc.MapContentRoute("content", MockRepository.GenerateStub<IEngine>());
Assert.That(rc.Count, Is.EqualTo(2));
Assert.That(rc.First(), Is.InstanceOf<ContentRoute<Models.RegularPage>>());
Assert.That(rc.Skip(1).First(), Is.InstanceOf<ContentRoute>());
}
示例4: RegisterRoutes_IgnoresAxd
public void RegisterRoutes_IgnoresAxd()
{
RouteCollection routes = new RouteCollection();
config.RegisterRoutes(routes);
Route expected = new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler());
Route actual = routes.First() as Route;
Assert.Equal(expected.RouteHandler.GetType(), actual.RouteHandler.GetType());
Assert.Equal(expected.Url, actual.Url);
}
示例5: ContentRoute_IsInsertedBetween_OtherContentRoutes_AndNonContentRoute
public void ContentRoute_IsInsertedBetween_OtherContentRoutes_AndNonContentRoute()
{
RouteCollection rc = new RouteCollection();
rc.MapRoute("mvc", "{controller}/{action}");
rc.MapContentRoute<Models.RegularPage>("area", MockRepository.GenerateStub<IEngine>());
rc.MapContentRoute("content", MockRepository.GenerateStub<IEngine>());
Assert.That(rc.Count, Is.EqualTo(3));
Assert.That(rc.First(), Is.InstanceOf<ContentRoute<Models.RegularPage>>());
Assert.That(rc.Skip(1).First(), Is.InstanceOf<ContentRoute>());
}
示例6: Publishing
/// <summary>
/// 发布前。
/// </summary>
/// <param name="routeDescriptors">路由描述符。</param>
public void Publishing(IEnumerable<RouteDescriptor> routeDescriptors)
{
var preloading = new RouteCollection();
foreach (var routeDescriptor in routeDescriptors)
{
// WebApi 路由注册
var httpRouteDescriptor = routeDescriptor as HttpRouteDescriptor;
if (httpRouteDescriptor == null)
continue;
var httpRouteCollection = new RouteCollection();
httpRouteCollection.MapHttpRoute(httpRouteDescriptor.Name, httpRouteDescriptor.RouteTemplate, httpRouteDescriptor.Defaults, httpRouteDescriptor.Constraints);
routeDescriptor.Route = httpRouteCollection.First();
preloading.Add(routeDescriptor.Name, routeDescriptor.Route);
}
}
示例7: Publish
public void Publish(IEnumerable<RouteDescriptor> routes)
{
var routesArray = routes
.OrderByDescending(r => r.Priority)
.ToArray();
// this is not called often, but is intended to surface problems before
// the actual collection is modified
var preloading = new RouteCollection();
foreach (var routeDescriptor in routesArray) {
// extract the WebApi route implementation
var httpRouteDescriptor = routeDescriptor as HttpRouteDescriptor;
if (httpRouteDescriptor != null) {
var httpRouteCollection = new RouteCollection();
httpRouteCollection.MapHttpRoute(httpRouteDescriptor.Name, httpRouteDescriptor.RouteTemplate, httpRouteDescriptor.Defaults, httpRouteDescriptor.Constraints);
routeDescriptor.Route = httpRouteCollection.First();
}
preloading.Add(routeDescriptor.Name, routeDescriptor.Route);
}
using (_routeCollection.GetWriteLock()) {
// existing routes are removed while the collection is briefly inaccessable
_routeCollection
.OfType<HubRoute>()
.ForEach(x => x.ReleaseShell(_shellSettings));
// new routes are added
foreach (var routeDescriptor in routesArray) {
// Loading session state information.
var defaultSessionState = SessionStateBehavior.Default;
ExtensionDescriptor extensionDescriptor = null;
if(routeDescriptor.Route is Route) {
object extensionId;
var route = routeDescriptor.Route as Route;
if(route.DataTokens != null && route.DataTokens.TryGetValue("area", out extensionId) ||
route.Defaults != null && route.Defaults.TryGetValue("area", out extensionId)) {
extensionDescriptor = _extensionManager.GetExtension(extensionId.ToString());
}
}
else if(routeDescriptor.Route is IRouteWithArea) {
var route = routeDescriptor.Route as IRouteWithArea;
extensionDescriptor = _extensionManager.GetExtension(route.Area);
}
if (extensionDescriptor != null) {
// if session state is not define explicitly, use the one define for the extension
if (routeDescriptor.SessionState == SessionStateBehavior.Default) {
Enum.TryParse(extensionDescriptor.SessionState, true /*ignoreCase*/, out defaultSessionState);
}
}
// Route-level setting overrides module-level setting (from manifest).
var sessionStateBehavior = routeDescriptor.SessionState == SessionStateBehavior.Default ? defaultSessionState : routeDescriptor.SessionState ;
var shellRoute = new ShellRoute(routeDescriptor.Route, _shellSettings, _workContextAccessor, _runningShellTable) {
IsHttpRoute = routeDescriptor is HttpRouteDescriptor,
SessionState = sessionStateBehavior
};
var area = extensionDescriptor == null ? "" : extensionDescriptor.Id;
var matchedHubRoute = _routeCollection.FirstOrDefault(x => {
var hubRoute = x as HubRoute;
if (hubRoute == null) {
return false;
}
return routeDescriptor.Priority == hubRoute.Priority && hubRoute.Area.Equals(area, StringComparison.OrdinalIgnoreCase) && hubRoute.Name == routeDescriptor.Name;
}) as HubRoute;
if (matchedHubRoute == null) {
matchedHubRoute = new HubRoute(routeDescriptor.Name, area, routeDescriptor.Priority, _runningShellTable);
int index;
for (index = 0; index < _routeCollection.Count; index++) {
var hubRoute = _routeCollection[index] as HubRoute;
if (hubRoute == null) {
continue;
}
if (hubRoute.Priority < matchedHubRoute.Priority) {
break;
}
}
_routeCollection.Insert(index, matchedHubRoute);
}
matchedHubRoute.Add(shellRoute, _shellSettings);
}
}
}
示例8: Publish
public void Publish(IEnumerable<RouteDescriptor> routes) {
var routesArray = routes
.OrderByDescending(r => r.Priority)
.ToArray();
// this is not called often, but is intended to surface problems before
// the actual collection is modified
var preloading = new RouteCollection();
foreach (var routeDescriptor in routesArray) {
// extract the WebApi route implementation
var httpRouteDescriptor = routeDescriptor as HttpRouteDescriptor;
if (httpRouteDescriptor != null) {
var httpRouteCollection = new RouteCollection();
httpRouteCollection.MapHttpRoute(httpRouteDescriptor.Name, httpRouteDescriptor.RouteTemplate, httpRouteDescriptor.Defaults);
routeDescriptor.Route = httpRouteCollection.First();
}
preloading.Add(routeDescriptor.Name, routeDescriptor.Route);
}
using (_routeCollection.GetWriteLock()) {
// existing routes are removed while the collection is briefly inaccessable
var cropArray = _routeCollection
.OfType<ShellRoute>()
.Where(sr => sr.ShellSettingsName == _shellSettings.Name)
.ToArray();
foreach(var crop in cropArray) {
_routeCollection.Remove(crop);
}
// new routes are added
foreach (var routeDescriptor in routesArray) {
// Loading session state information.
var defaultSessionState = SessionStateBehavior.Default;
ExtensionDescriptor extensionDescriptor = null;
if(routeDescriptor.Route is Route) {
object extensionId;
var route = routeDescriptor.Route as Route;
if(route.DataTokens != null && route.DataTokens.TryGetValue("area", out extensionId) ||
route.Defaults != null && route.Defaults.TryGetValue("area", out extensionId)) {
extensionDescriptor = _extensionManager.GetExtension(extensionId.ToString());
}
}
else if(routeDescriptor.Route is IRouteWithArea) {
var route = routeDescriptor.Route as IRouteWithArea;
extensionDescriptor = _extensionManager.GetExtension(route.Area);
}
if (extensionDescriptor != null) {
// if session state is not define explicitly, use the one define for the extension
if (routeDescriptor.SessionState == SessionStateBehavior.Default) {
Enum.TryParse(extensionDescriptor.SessionState, true /*ignoreCase*/, out defaultSessionState);
}
}
// Route-level setting overrides module-level setting (from manifest).
var sessionStateBehavior = routeDescriptor.SessionState == SessionStateBehavior.Default ? defaultSessionState : routeDescriptor.SessionState ;
var shellRoute = new ShellRoute(routeDescriptor.Route, _shellSettings, _workContextAccessor, _runningShellTable) {
IsHttpRoute = routeDescriptor is HttpRouteDescriptor,
SessionState = sessionStateBehavior
};
_routeCollection.Add(routeDescriptor.Name, shellRoute);
}
}
}