private IRouteTableProvider CreateRouteTableProvider() { if (Provider == null) { return(null); } Type providerType = Type.GetType(Provider.Type, false, true); if (providerType == null) { return(null); } if (!typeof(IRouteTableProvider).IsAssignableFrom(providerType)) { throw Error.IncompatibleRouteTableProvider(providerType); } IRouteTableProvider provider = (IRouteTableProvider)ServiceLocator.Instance.GetService(providerType); ValueDictionary settings = new ValueDictionary(); foreach (string key in Provider.Settings.AllKeys) { settings.Add(key, Provider.Settings[key].Value); } provider.Init(settings); return(provider); }
public static IAssociationLoader <IEnumerable <TAssociation> > Multiple <TAssociation>(MetaAssociation association, IValueSet source) { // Gonna move to DbQueryGenerator MetaType otherType = Configuration.Instance.Factory.CreateMapping(typeof(TAssociation)); StringBuilder builder = new StringBuilder(); builder.Append("SELECT "); foreach (MetaMember member in otherType.Members) { builder.Append('[').Append(member.GetMemberKey()).Append("],"); } builder.Length--; builder.Append(" FROM "); if (!String.IsNullOrEmpty(otherType.Schema)) { builder.Append('[').Append(otherType.Schema).Append("]."); } builder.Append('[').Append(otherType.Table).Append("] WHERE [") .Append(association.OtherKey).Append("]=@").Append(association.OtherKey); ValueDictionary arguments = new ValueDictionary(); arguments.Add(association.OtherKey, source.GetValue <object>(association.ThisKey)); return(new MultipleMappedAssociationLoader <TAssociation>(new DbCommandDescriptor(builder.ToString(), arguments))); }
protected BaseEnum(TKey key, TValue value) { if (key == null || value == null) { throw new ArgumentNullException(); } Value = value; Key = key; KeyDictionary.Add(key, this); ValueDictionary.Add(value, this); }
protected ICollection <T> ReadCollection(BindingContext context) { Type elementType = typeof(T); SortedDictionary <int, T> convertedValues = new SortedDictionary <int, T>(); ValueProviderResult result = context.GetValue(); object value = (result == null) ? null : result.GetValue <string>(); if (value != null && IsSimpleType) { string[] split = ((string)value).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < split.Length; ++i) { string elementKey = CreateSubMemberName(context.ModelName, i.ToString()); ValueDictionary bindingData = new ValueDictionary(); bindingData.Add(elementKey, split[i]); BindingContext inner = new BindingContext(context, elementType, elementKey, new DictionaryValueProvider(bindingData), context.ModelState); value = ElementBinder.Bind(inner); convertedValues[i] = ValidateElement(context, elementKey, value); } } else { foreach (string kvp in context.ValueProvider.Keys) { int?index = GetItemIndex(kvp, context.ModelName); if (!index.HasValue) { continue; } if (convertedValues.ContainsKey(index.Value)) { continue; } string elementKey = CreateSubMemberName(context.ModelName, index.ToString()); BindingContext inner = new BindingContext(context, elementType, elementKey, context.ValueProvider, context.ModelState); value = ElementBinder.Bind(inner); convertedValues[index.Value] = ValidateElement(context, elementKey, value); } } return(convertedValues.Values); }
private static IValueSet BindDataSource(IValueProvider provider) { ValueDictionary values = new ValueDictionary(); foreach (string key in provider.Keys) { ValueProviderResult result = provider.GetValue(key); if (result == null) continue; values.Add(key, result.Value); } return values; }
private static IValueSet BindDataSource(IValueProvider provider) { ValueDictionary values = new ValueDictionary(); foreach (string key in provider.Keys) { ValueProviderResult result = provider.GetValue(key); if (result == null) { continue; } values.Add(key, result.Value); } return(values); }
protected virtual ValueDictionary ProcessTokens( NameValueConfigurationCollection collection) { ValueDictionary tokens = new ValueDictionary(); if (collection == null) { return(tokens); } foreach (string key in collection.AllKeys) { tokens.Add(key, collection[key].Value); } return(tokens); }
public static ValueDictionary ExtractArgumentsToDictionary(MethodCallExpression expression) { Precondition.Require(expression, () => Error.ArgumentNull("expression")); ValueDictionary plist = new ValueDictionary(); ParameterInfo[] parameters = expression.Method.GetParameters(); if (parameters.Length > 0) { for (int i = 0; i < parameters.Length; i++) { plist.Add(parameters[i].Name, ExtractArgumentValue(expression.Arguments[i])); } } return(plist); }
private void MatchCatchAll(ContentSegment segment, IEnumerable <string> remainingSegments, ValueDictionary defaults, ValueDictionary matchedValues) { object value; string remainingPart = String.Join(String.Empty, remainingSegments.ToArray()); ParameterSubsegment parameter = (segment.Segments.FirstOrDefault() as ParameterSubsegment); if (remainingPart.Length > 0) { value = remainingPart; } else { defaults.TryGetValue(parameter.ParameterName, out value); } matchedValues.Add(parameter.ParameterName, value); }
public ValueDictionary Match(string virtualPath, ValueDictionary variables, ValueDictionary defaults) { List<string> parts = new List<string>(RouteParser.SplitUrl(virtualPath)); defaults = defaults ?? new ValueDictionary(); variables = variables ?? new ValueDictionary(); ValueDictionary values = new ValueDictionary(); bool hasAdditionalParameters = false; bool isCatchAll = false; AssignVariableValues(variables); for (int i = 0; i < _segments.Count; i++) { SeparatorSegment separator = (_segments[i] as SeparatorSegment); ContentSegment content = (_segments[i] as ContentSegment); if (parts.Count <= i) hasAdditionalParameters = true; string part = (hasAdditionalParameters) ? null : parts[i]; if (separator != null) { if (!hasAdditionalParameters && !RouteParser.IsSeparator(part)) return null; } if (content != null) { if (content.IsCatchAll) { MatchCatchAll(content, parts.Skip(i), defaults, values); isCatchAll = true; } else if (!MatchContent(content, part, defaults, values)) return null; } } if (!isCatchAll && _segments.Count < parts.Count) { for (int j = _segments.Count; j < parts.Count; j++) { if (!RouteParser.IsSeparator(parts[j])) return null; } } if (defaults != null) { foreach (KeyValuePair<string, object> kvp in defaults) { if (!values.ContainsKey(kvp.Key)) values.Add(kvp.Key, kvp.Value); } } return values; }
public ValueDictionary Match(string virtualPath, ValueDictionary variables, ValueDictionary defaults) { List <string> parts = new List <string>(RouteParser.SplitUrl(virtualPath)); defaults = defaults ?? new ValueDictionary(); variables = variables ?? new ValueDictionary(); ValueDictionary values = new ValueDictionary(); bool hasAdditionalParameters = false; bool isCatchAll = false; AssignVariableValues(variables); for (int i = 0; i < _segments.Count; i++) { SeparatorSegment separator = (_segments[i] as SeparatorSegment); ContentSegment content = (_segments[i] as ContentSegment); if (parts.Count <= i) { hasAdditionalParameters = true; } string part = (hasAdditionalParameters) ? null : parts[i]; if (separator != null) { if (!hasAdditionalParameters && !RouteParser.IsSeparator(part)) { return(null); } } if (content != null) { if (content.IsCatchAll) { MatchCatchAll(content, parts.Skip(i), defaults, values); isCatchAll = true; } else if (!MatchContent(content, part, defaults, values)) { return(null); } } } if (!isCatchAll && _segments.Count < parts.Count) { for (int j = _segments.Count; j < parts.Count; j++) { if (!RouteParser.IsSeparator(parts[j])) { return(null); } } } if (defaults != null) { foreach (KeyValuePair <string, object> kvp in defaults) { if (!values.ContainsKey(kvp.Key)) { values.Add(kvp.Key, kvp.Value); } } } return(values); }
private bool MatchContent(ContentSegment segment, string pathSegment, ValueDictionary defaults, ValueDictionary matchedValues) { if (String.IsNullOrEmpty(pathSegment)) { if (segment.Segments.Count > 0) { object value; ParameterSubsegment ps = (segment.Segments.FirstOrDefault( s => (s is ParameterSubsegment)) as ParameterSubsegment); if (ps == null) { return(false); } if (defaults.TryGetValue(ps.ParameterName, out value)) { matchedValues.Add(ps.ParameterName, value); return(true); } } return(false); } int segmentLength = pathSegment.Length; int segmentIndex = (segment.Segments.Count - 1); ParameterSubsegment lastParameter = null; LiteralSubsegment lastLiteral = null; while (segmentIndex >= 0) { int index = segmentLength; ParameterSubsegment parameter = (segment.Segments[segmentIndex] as ParameterSubsegment); LiteralSubsegment literal = (segment.Segments[segmentIndex] as LiteralSubsegment); if (parameter != null) { lastParameter = parameter; } if (literal != null) { lastLiteral = literal; int literalIndex = pathSegment.LastIndexOf(literal.Literal, segmentLength - 1, StringComparison.OrdinalIgnoreCase); if (literalIndex == -1) { return(false); } if ((segmentIndex == segment.Segments.Count - 1) && ((literalIndex + literal.Literal.Length) != pathSegment.Length)) { return(false); } index = literalIndex; } if (lastParameter != null && ((lastLiteral != null && parameter == null) || segmentIndex == 0)) { int startIndex; int lastIndex; if (lastLiteral == null) { startIndex = (segmentIndex == 0) ? 0 : index + lastLiteral.Literal.Length; lastIndex = segmentLength; } else if (segmentIndex == 0 && parameter != null) { startIndex = 0; lastIndex = segmentLength; } else { startIndex = index + lastLiteral.Literal.Length; lastIndex = segmentLength - startIndex; } string part = pathSegment.Substring(startIndex, lastIndex); if (String.IsNullOrEmpty(part)) { return(false); } matchedValues.Add(lastParameter.ParameterName, part); lastParameter = null; lastLiteral = null; } segmentLength = index; segmentIndex--; } if (segmentLength != 0) { return(segment.Segments[0] is ParameterSubsegment); } return(true); }
public BoundUrl Bind(ValueDictionary currentValues, ValueDictionary values, ValueDictionary variables, ValueDictionary defaults) { currentValues = currentValues ?? new ValueDictionary(); values = values ?? new ValueDictionary(); variables = variables ?? new ValueDictionary(); defaults = defaults ?? new ValueDictionary(); ValueDictionary acceptedValues = new ValueDictionary(); HashSet <string> unusedValues = new HashSet <string>( values.Keys, StringComparer.OrdinalIgnoreCase); AssignVariableValues(variables); ForEachParameter(_segments, segment => { object value; object currentValue; string parameterName = segment.ParameterName; bool hasValue = values.TryGetValue(parameterName, out value); if (hasValue) { unusedValues.Remove(parameterName); } bool hasCurrentValue = currentValues.TryGetValue(parameterName, out currentValue); if (hasValue && hasCurrentValue && !RoutePartsEqual(currentValue, value)) { return(false); } if (hasValue) { if (IsRoutePartNonEmpty(value)) { acceptedValues.Add(parameterName, value); } } else if (hasCurrentValue) { acceptedValues.Add(parameterName, currentValue); } return(true); }); foreach (KeyValuePair <string, object> kvp in values) { if (IsRoutePartNonEmpty(kvp.Value) && !acceptedValues.ContainsKey(kvp.Key)) { acceptedValues.Add(kvp.Key, kvp.Value); } } foreach (KeyValuePair <string, object> kvp in currentValues) { if (!acceptedValues.ContainsKey(kvp.Key) && GetParameterSubsegment(_segments, kvp.Key) == null) { acceptedValues.Add(kvp.Key, kvp.Value); } } ForEachParameter(_segments, segment => { object value; if (!acceptedValues.ContainsKey(segment.ParameterName) && !IsParameterRequired(segment, defaults, out value)) { acceptedValues.Add(segment.ParameterName, value); } return(true); }); if (!ForEachParameter(_segments, segment => { object value; if (IsParameterRequired(segment, defaults, out value) && !acceptedValues.ContainsKey(segment.ParameterName)) { return(false); } return(true); })) { return(null); } ValueDictionary others = new ValueDictionary( (IDictionary <string, object>)defaults); ForEachParameter(_segments, segment => { others.Remove(segment.ParameterName); return(true); }); foreach (KeyValuePair <string, object> kvp in others) { object value; if (values.TryGetValue(kvp.Key, out value)) { unusedValues.Remove(kvp.Key); if (!RoutePartsEqual(value, kvp.Value)) { return(null); } } } return(BuildUrl(defaults, acceptedValues, unusedValues)); }
protected virtual ValueDictionary ProcessDefaults( NameValueConfigurationCollection collection) { ValueDictionary defaults = new ValueDictionary(); if(collection == null) return defaults; foreach (string key in collection.AllKeys) defaults.Add(key, collection[key].Value); return defaults; }
public BoundUrl Bind(ValueDictionary currentValues, ValueDictionary values, ValueDictionary variables, ValueDictionary defaults) { currentValues = currentValues ?? new ValueDictionary(); values = values ?? new ValueDictionary(); variables = variables ?? new ValueDictionary(); defaults = defaults ?? new ValueDictionary(); ValueDictionary acceptedValues = new ValueDictionary(); HashSet<string> unusedValues = new HashSet<string>( values.Keys, StringComparer.OrdinalIgnoreCase); AssignVariableValues(variables); ForEachParameter(_segments, segment => { object value; object currentValue; string parameterName = segment.ParameterName; bool hasValue = values.TryGetValue(parameterName, out value); if (hasValue) unusedValues.Remove(parameterName); bool hasCurrentValue = currentValues.TryGetValue(parameterName, out currentValue); if (hasValue && hasCurrentValue && !RoutePartsEqual(currentValue, value)) return false; if (hasValue) { if (IsRoutePartNonEmpty(value)) acceptedValues.Add(parameterName, value); } else if (hasCurrentValue) acceptedValues.Add(parameterName, currentValue); return true; }); foreach (KeyValuePair<string, object> kvp in values) { if (IsRoutePartNonEmpty(kvp.Value) && !acceptedValues.ContainsKey(kvp.Key)) acceptedValues.Add(kvp.Key, kvp.Value); } foreach (KeyValuePair<string, object> kvp in currentValues) { if (!acceptedValues.ContainsKey(kvp.Key) && GetParameterSubsegment(_segments, kvp.Key) == null) acceptedValues.Add(kvp.Key, kvp.Value); } ForEachParameter(_segments, segment => { object value; if (!acceptedValues.ContainsKey(segment.ParameterName) && !IsParameterRequired(segment, defaults, out value)) acceptedValues.Add(segment.ParameterName, value); return true; }); if (!ForEachParameter(_segments, segment => { object value; if (IsParameterRequired(segment, defaults, out value) && !acceptedValues.ContainsKey(segment.ParameterName)) return false; return true; })) { return null; } ValueDictionary others = new ValueDictionary( (IDictionary<string, object>)defaults); ForEachParameter(_segments, segment => { others.Remove(segment.ParameterName); return true; }); foreach (KeyValuePair<string, object> kvp in others) { object value; if (values.TryGetValue(kvp.Key, out value)) { unusedValues.Remove(kvp.Key); if (!RoutePartsEqual(value, kvp.Value)) return null; } } return BuildUrl(defaults, acceptedValues, unusedValues); }
private void MatchCatchAll(ContentSegment segment, IEnumerable<string> remainingSegments, ValueDictionary defaults, ValueDictionary matchedValues) { object value; string remainingPart = String.Join(String.Empty, remainingSegments.ToArray()); ParameterSubsegment parameter = (segment.Segments.FirstOrDefault() as ParameterSubsegment); if (remainingPart.Length > 0) value = remainingPart; else defaults.TryGetValue(parameter.ParameterName, out value); matchedValues.Add(parameter.ParameterName, value); }
protected virtual ValueDictionary ProcessTokens( NameValueConfigurationCollection collection) { ValueDictionary tokens = new ValueDictionary(); if (collection == null) return tokens; foreach (string key in collection.AllKeys) tokens.Add(key, collection[key].Value); return tokens; }
private bool MatchContent(ContentSegment segment, string pathSegment, ValueDictionary defaults, ValueDictionary matchedValues) { if (String.IsNullOrEmpty(pathSegment)) { if (segment.Segments.Count > 0) { object value; ParameterSubsegment ps = (segment.Segments.FirstOrDefault( s => (s is ParameterSubsegment)) as ParameterSubsegment); if (ps == null) return false; if (defaults.TryGetValue(ps.ParameterName, out value)) { matchedValues.Add(ps.ParameterName, value); return true; } } return false; } int segmentLength = pathSegment.Length; int segmentIndex = (segment.Segments.Count - 1); ParameterSubsegment lastParameter = null; LiteralSubsegment lastLiteral = null; while (segmentIndex >= 0) { int index = segmentLength; ParameterSubsegment parameter = (segment.Segments[segmentIndex] as ParameterSubsegment); LiteralSubsegment literal = (segment.Segments[segmentIndex] as LiteralSubsegment); if (parameter != null) lastParameter = parameter; if (literal != null) { lastLiteral = literal; int literalIndex = pathSegment.LastIndexOf(literal.Literal, segmentLength - 1, StringComparison.OrdinalIgnoreCase); if (literalIndex == -1) return false; if ((segmentIndex == segment.Segments.Count - 1) && ((literalIndex + literal.Literal.Length) != pathSegment.Length)) return false; index = literalIndex; } if (lastParameter != null && ((lastLiteral != null && parameter == null) || segmentIndex == 0)) { int startIndex; int lastIndex; if (lastLiteral == null) { startIndex = (segmentIndex == 0) ? 0 : index + lastLiteral.Literal.Length; lastIndex = segmentLength; } else if (segmentIndex == 0 && parameter != null) { startIndex = 0; lastIndex = segmentLength; } else { startIndex = index + lastLiteral.Literal.Length; lastIndex = segmentLength - startIndex; } string part = pathSegment.Substring(startIndex, lastIndex); if (String.IsNullOrEmpty(part)) return false; matchedValues.Add(lastParameter.ParameterName, part); lastParameter = null; lastLiteral = null; } segmentLength = index; segmentIndex--; } if (segmentLength != 0) return (segment.Segments[0] is ParameterSubsegment); return true; }
/// <inheritdoc /> public void Add(string key, object value) => ValueDictionary.Add(key, new KeyValuePair <string, object>(key, value));
/// <inheritdoc /> public void Add(KeyValuePair <string, object> item) => ValueDictionary.Add(item.Key, item);
public void Add(string key, object value) { _values.Add(key, value); }