private static ValueDictionary CreateDefaults(IValueSet defaults) { ValueDictionary values = new ValueDictionary(defaults); values.Remove("controller"); values.Remove("action"); return values; }
private static ValueDictionary CreateDefaults(IValueSet defaults) { ValueDictionary values = new ValueDictionary(defaults); values.Remove("controller"); values.Remove("action"); return(values); }
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); }
/// <summary> /// 测试 /// </summary> internal void Test() { dictionary.Clear(); start(CallbackType.Asynchronous, TestType.DictionarySetNodeCache); AutoCSer.CacheServer.DataStructure.Parameter.OperationBool setNode = dictionary.GetSetNode(count - 1, int.MaxValue - count); for (int index = count; index != 0;) { --index; setNode.Operation(setCallbackReturnParameter); } wait(); dictionary.Clear(); start(CallbackType.Asynchronous, TestType.DictionarySet); for (int index = count; index != 0;) { --index; dictionary.Set(index, count - index, setCallbackReturnParameter); } wait(); start(CallbackType.Asynchronous, TestType.DictionaryGetNodeCache); AutoCSer.CacheServer.DataStructure.Parameter.QueryReturnValue <int> getNode = dictionary.GetNode(count - 1); for (int index = count; index != 0;) { --index; getNode.Query(getCallbackReturnParameter); } wait(); start(CallbackType.Asynchronous, TestType.DictionaryGet); for (int index = count; index != 0; dictionary.Get(--index, getCallbackReturnParameter)) { ; } wait(); start(CallbackType.Asynchronous, TestType.DictionaryRemove); for (int index = count; index != 0; dictionary.Remove(--index, setCallbackReturnParameter)) { ; } wait(); dictionary.Clear(); start(CallbackType.Synchronous, TestType.DictionarySet); for (int index = count; index != 0;) { --index; setCallback(dictionary.Set(index, count - index)); } wait(); start(CallbackType.Synchronous, TestType.DictionaryGet); for (int index = count; index != 0;) { --index; getCallback(dictionary.Get(index)); } wait(); dictionary.Clear(); }
/// <inheritdoc /> public bool Remove(KeyValuePair <string, object> item) => ValueDictionary.Remove(new KeyValuePair <string, KeyValuePair <string, object> >(item.Key, item));
/// <inheritdoc /> public bool Remove(string key) => ValueDictionary.Remove(key);
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)); }
public bool Remove(string key) { return(_values.Remove(key)); }