本文整理汇总了C#中RouteValueDictionary.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# RouteValueDictionary.ToDictionary方法的具体用法?C# RouteValueDictionary.ToDictionary怎么用?C# RouteValueDictionary.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteValueDictionary
的用法示例。
在下文中一共展示了RouteValueDictionary.ToDictionary方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Matches
public bool Matches(RouteValueDictionary rvs)
{
Dictionary<string, object> adjustedRvs = rvs.ToDictionary(rv => rv.Key, rv => rv.Value); // clone
if (adjustedRvs.ContainsKey("originalAction"))
{
adjustedRvs["action"] = adjustedRvs["originalAction"];
adjustedRvs.Remove("originalAction");
}
return adjustedRvs.All(kvp => kvp.Key == "controller"
|| !Defaults.ContainsKey(kvp.Key)
|| Defaults.Contains(kvp)
|| UrlVariables.Contains(kvp.Key))
&& UrlVariables.All(uv => adjustedRvs.ContainsKey(uv));
}
示例2: GetVirtualPath
/// <summary>
/// 尝试从路由值创建虚拟路径
/// </summary>
/// <param name="requestContext">当前请求上下文</param>
/// <param name="values">路由值</param>
/// <returns>虚拟路径信息</returns>
public override VirtualPathData GetVirtualPath( RequestContext requestContext, RouteValueDictionary values )
{
var cache = requestContext.HttpContext.Cache;
var _values = values.ToDictionary( pair => pair.Key, pair => pair.Value == null ? null : pair.Value.ToString(), StringComparer.OrdinalIgnoreCase );
var cacheKey = CreateCacheKey( _values );
var virtualPath = cache.Get( cacheKey ) as string;
if ( virtualPath != null )
return new VirtualPathData( this, virtualPath );
var keySet = new HashSet<string>( _values.Keys, StringComparer.OrdinalIgnoreCase );
var candidateRules = _rules
.Where( r => !r.Oneway ) //不是单向路由规则
.Where( r => keySet.IsSupersetOf( r.RouteKeys ) ) //所有路由键都必须匹配
.Where( r => keySet.IsSubsetOf( r.AllKeys ) || !r.LimitedQueries ) //所有路由键和查询字符串键必须能涵盖要设置的键。
.Where( r => r.IsMatch( _values ) ) //必须满足路由规则所定义的路由数据。
.ToArray();
if ( !candidateRules.Any() )
return null;
var bestRule = BestRule( candidateRules );
virtualPath = bestRule.CreateVirtualPath( _values );
if ( MvcCompatible )
virtualPath = virtualPath.Substring( 2 );
cache.Insert( cacheKey, virtualPath, CacheItemPriority.AboveNormal );
var data = new VirtualPathData( this, virtualPath );
foreach ( var pair in bestRule.DataTokens )
data.DataTokens.Add( pair.Key, pair.Value );
data.DataTokens["RoutingRuleName"] = bestRule.Name;
return data;
}
示例3: RequestDataSpecification
public RequestDataSpecification(RouteValueDictionary rvs, bool isContent)
{
if (rvs != null)
{
Controller = rvs["controller"] as string;
Action = (rvs["originalAction"] as string) ?? (rvs["action"] as string);
RouteData = rvs.ToDictionary(rv => rv.Key, rv => rv.Value);
}
if (rvs != null && isContent)
Path = SiteStructure.Current.GetUrl(rvs);
else
Path = HttpContext.Current.Request.Path;
}
示例4: GetVirtualPath
/// <summary>
/// 尝试从路由值创建虚拟路径
/// </summary>
/// <param name="requestContext">当前请求上下文</param>
/// <param name="values">路由值</param>
/// <returns>虚拟路径信息</returns>
public override VirtualPathData GetVirtualPath( RequestContext requestContext, RouteValueDictionary values )
{
var cache = requestContext.HttpContext.Cache;
var _values = values.ToDictionary( pair => pair.Key, pair => pair.Value == null ? null : pair.Value.ToString(), StringComparer.OrdinalIgnoreCase );
var cacheKey = CreateCacheKey( _values );
var virtualPath = cache.Get( cacheKey ) as string;
if ( virtualPath != null )
return new VirtualPathData( this, virtualPath );
var keySet = new HashSet<string>( _values.Keys, StringComparer.OrdinalIgnoreCase );
var candidateRules = _rules
.Where( r => !r.Oneway ) //不是单向路由规则
.Where( r => keySet.IsSupersetOf( r.RouteKeys ) ) //所有路由键都必须匹配
.Where( r => keySet.IsSubsetOf( r.AllKeys ) || !r.LimitedQueries ) //所有路由键和查询字符串键必须能涵盖要设置的键。
.Where( r => r.IsMatch( _values ) ) //必须满足路由规则所定义的路由数据。
.ToArray();
if ( !candidateRules.Any() )
return null;
var bestRule = BestRule( candidateRules );
virtualPath = bestRule.CreateVirtualPath( _values );
if ( IsIgnoredPath( virtualPath ) )//如果产生的虚拟路径是被忽略的,则返回 null
{
if ( DebugMode )
Trace( string.Format( "名为 \"{0}\" 路由表的 \"{1}\" 路由规则产生的虚拟路径 {2} 被该路由表忽略", Name, bestRule.Name, virtualPath ), TraceLevel.Warning );
else
return null;
}
if ( MvcCompatible )
virtualPath = virtualPath.Substring( 2 );
cache.Insert( cacheKey, virtualPath, CacheItemPriority.AboveNormal );
return CreateVirtualPathData( virtualPath, bestRule );
}
示例5: Transform
private static RouteValueDictionary Transform(RouteValueDictionary values,
IDictionary<Guid, Token> tokenMap)
{
var reverseMap = tokenMap.ToDictionary(
item => (object) item.Value,
item => item.Key);
return new RouteValueDictionary(
values.ToDictionary(
item => item.Key,
item => reverseMap.ContainsKey(item.Value)
? reverseMap[item.Value]
: item.Value));
}
示例6: ToDictionary
/// <summary>
/// To a dictionary.
/// </summary>
/// <param name="item">The item.</param>
/// <returns></returns>
public static Dictionary<string, object> ToDictionary(dynamic item)
{
var ret = new RouteValueDictionary(item);
var d = ret.ToDictionary(s => s.Key, s2 => s2.Value);
return d;
}
示例7: SubController_SubmitChangeLocation
public void SubController_SubmitChangeLocation()
{
var sub = Data.Data.Simpltest1();
var loc = sub.Accounts[0].Location;
var newLoc = Data.Data.Simplloc1();
//var expected = Data.Data.LocDetailsViewModel(newLoc);
var result = _subscriberController.SubmitChangeLocation(loc.ID, newLoc.ID, sub.ID) as RedirectToRouteResult;
//Validate action result
var expectedRoute = new RouteValueDictionary
{
{"ID", newLoc.ID},
{"message", "Location Changed Successfully"},
{"action", "Location"},
{"controller", "Subscriber"}
};
if (result != null)
{
var actualRoute = result.RouteValues;
Common.Validation.Validate(expectedRoute.ToDictionary(x => x.Key, x => x.Value.ToString()), actualRoute.ToDictionary(x => x.Key, x => x.Value.ToString()), "RouteValueDictionary");
}
//Validate Location changed
using (var client = new RosettianClient())
{
var actualSub = client.LoadSubscriber(sub.ID, _user);
client.LoadLocation(actualSub.Accounts[0].Location.ID, _user);
Common.Validation.ValidateLocation(newLoc, actualSub.Accounts[0].Location);
}
}
示例8: SubController_ClearLocation
public void SubController_ClearLocation()
{
var sub = Data.Data.Simpltest1();
//var expected = Data.Data.LocDetailsViewModel(new Location());
var result = _subscriberController.ClearLocation(sub.ID) as RedirectToRouteResult;
//Validate action result
var expectedRoute = new RouteValueDictionary
{
{"ID", sub.ID},
{"message", "Location Cleared Successfully"},
{"action", "Index"},
{"controller", "Subscriber"}
};
if (result != null)
{
var actualRoute = result.RouteValues;
Common.Validation.Validate(expectedRoute.ToDictionary(x => x.Key, x => x.Value.ToString()), actualRoute.ToDictionary(x => x.Key, x => x.Value.ToString()), "RouteValueDictionary");
}
using (var client = new RosettianClient())
{
var actualSub = client.LoadSubscriber(sub.ID, _user);
var actualLoc = actualSub.Accounts[0].Location;
Assert.IsTrue(string.IsNullOrEmpty(actualLoc.ID), actualLoc.ID);
}
}
示例9: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
if (!values.ContainsKey(Constants.Store))
{
values.Add(Constants.Store, SiteContext.Current.Shop.StoreId);
}
//var storeId = SettingsHelper.SeoDecode(values[Constants.Store].ToString(), SeoUrlKeywordTypes.Store, values[Constants.Language] as string);
var storeSlug = values[Constants.Store].ToString();
var store = SiteContext.Current.GetShopBySlug(storeSlug, values[Constants.Language] as string);
if (!values.ContainsKey(Constants.Language))
{
values.Add(Constants.Language, Thread.CurrentThread.CurrentUICulture.Name);
}
if (store != null && !this.IsValidStoreLanguage(store, values[Constants.Language].ToString()))
{
//Reset to default language if validation fails
values[Constants.Language] = store.DefaultLanguage;
}
var isLanguageNeeded = this.IsLanguageNeeded(store, values[Constants.Language] as string);
var isStoreNeeded = this.IsStoreNeeded(store);
var excludedRouteValuesNames = new List<string>();
if(!isStoreNeeded)
excludedRouteValuesNames.Add(Constants.Store);
if(!isLanguageNeeded)
excludedRouteValuesNames.Add(Constants.Language);
if (excludedRouteValuesNames.Any())
{
/*
//Need to be in lock to make sure other thread does not change originalUrl in this block
lock (this.thisLock)
{
var modifiedUrl = this.Url;
//If for request store URL is used do not show it in path
if (!isStoreNeeded)
{
modifiedUrl = modifiedUrl.Replace(string.Format("/{{{0}}}", Constants.Store), string.Empty);
values.Remove(Constants.Store);
}
else
{
this.EncodeVirtualPath(values, SeoUrlKeywordTypes.Store);
}
if (!isLanguageNeeded)
{
modifiedUrl = modifiedUrl.Replace(string.Format("{{{0}}}", Constants.Language), string.Empty);
values.Remove(Constants.Language);
}
//The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
if (modifiedUrl.StartsWith("/") || modifiedUrl.StartsWith("~"))
{
modifiedUrl = modifiedUrl.Substring(1, modifiedUrl.Length - 1);
}
var originalUrl = this.Url;
this.Url = modifiedUrl;
var retVal = base.GetVirtualPath(requestContext, values);
//Restore original URL
if (!string.IsNullOrEmpty(originalUrl) && !originalUrl.Equals(this.Url))
{
this.Url = originalUrl;
}
return retVal;
}
* */
this.EncodeVirtualPath(values, SeoUrlKeywordTypes.Store);
var excludedRouteValues = new RouteValueDictionary(values.ToDictionary(pair => pair.Key, pair => pair.Value));
var token = "!VIRTOTOKENREMOVE!";
excludedRouteValuesNames.ForEach(x => excludedRouteValues[x] = token);
var vpd = base.GetVirtualPath(requestContext, excludedRouteValues);
if (vpd != null)
{
var path = vpd.VirtualPath;
path = path.Replace(token, String.Empty);
path = path.Replace("//", "/");
path = path.TrimStart("/");
vpd.VirtualPath = path;
}
return vpd;
}
//.........这里部分代码省略.........
示例10: CreateSession
/// <summary>
/// The create_session() method of the OpenTokSDK object to create a new OpenTok session and obtain a session ID.
/// </summary>
/// <param name="location">n IP address that TokBox will use to situate the session in its global network. In general, you should not pass in a location hint; if no location hint is passed in, the session uses a media server based on the location of the first client connecting to the session. Pass a location hint in only if you know the general geographic region (and a representative IP address) and you think the first client connecting may not be in that region.</param>
/// <param name="options">
/// Optional. An object used to define peer-to-peer preferences for the session.
///
/// - p2p_preference (p2p.preference) : "disabled" or "enabled"
/// - multiplexer_switchType (multiplexer.switchType)
/// - multiplexer_switchTimeout (multiplexer.switchTimeout)
/// - multiplexer_numOuputStreams (multiplexer.numOutputStreams)
/// - echoSuppression_enabled (echoSuppression.enabled)
///
/// </param>
/// <returns>sessionId</returns>
public string CreateSession(string location, object options = null)
{
var paremeters = new RouteValueDictionary(options ?? new object()) {
{"location", location},
{"partner_id", ApiKey}
};
var dictionary = paremeters.ToDictionary(x => CleanupKey(x.Key), v => v.Value);
var xmlDoc = CreateSessionId(string.Format("{0}/session/create", Server), dictionary);
var sessionId = xmlDoc.GetElementsByTagName("session_id")[0].ChildNodes[0].Value;
return sessionId;
}