internal void Add(CorrelationKeyCalculator.CorrelationCacheKey key, CorrelationKey value) { lock (this.cacheLock) { this.cache.Add(key, value); } }
internal void Add(CorrelationCacheKey key, CorrelationKey value) { Fx.Assert(key != null, "Cannot add a null CorrelationCacheKey to the cache."); lock (this.cacheLock) { this.cache.Add(key, value); } }
private CorrelationKey GetInstanceKey(Dictionary <string, string> values) { CorrelationKey key; if (values.Count > 3) { return(new CorrelationKey(values, this.parent.scopeName.ToString(), null)); } CorrelationKeyCalculator.CorrelationCacheKey key2 = CorrelationKeyCalculator.CorrelationCacheKey.CreateKey(values); if (!this.parent.keyCache.TryGetValue(key2, out key)) { key = new CorrelationKey(values, this.parent.scopeName.ToString(), null); this.parent.keyCache.Add(key2, key); } return(key); }
CorrelationKey GetInstanceKey(Dictionary <string, string> values) { // We only optimize for upto 3 keys if (values.Count <= 3) { CorrelationKey correlationKey; CorrelationCacheKey cacheKey = CorrelationCacheKey.CreateKey(values); if (this.parent.keyCache.TryGetValue(cacheKey, out correlationKey)) { return(correlationKey); } correlationKey = new CorrelationKey(values, this.parent.scopeName.ToString(), null); this.parent.keyCache.Add(cacheKey, correlationKey); return(correlationKey); } return(new CorrelationKey(values, this.parent.scopeName.ToString(), null)); }
public bool CalculateKeys(T target, Message messageToReadHeaders, out InstanceKey instanceKey, out ICollection <InstanceKey> additionalKeys) { CorrelationKeyCalculator.SelectRuntime runtime; instanceKey = InstanceKey.InvalidKey; additionalKeys = null; if (!this.ExecuteWhere(target, messageToReadHeaders, this.parent.whereRuntime, out runtime)) { return(false); } Dictionary <string, string> values = new Dictionary <string, string>(); if (runtime.Select.Count > 0) { bool flag = true; foreach (KeyValuePair <MessageQuery, string> pair in this.ExecuteSelect(target, messageToReadHeaders, runtime.Select, runtime.IsContextQuery)) { if (!(pair.Key is OptionalMessageQuery)) { flag = false; } if (!string.IsNullOrEmpty(pair.Value)) { values.Add(runtime.Select[pair.Key], pair.Value); } } if (values.Count == 0) { if (!flag) { throw FxTrace.Exception.AsError(new ProtocolException(System.ServiceModel.Activities.SR.EmptyCorrelationQueryResults)); } } else { instanceKey = this.GetInstanceKey(values); if (TD.TraceCorrelationKeysIsEnabled()) { this.TraceCorrelationKeys(instanceKey, values); } } } foreach (KeyValuePair <string, MessageQueryTable <string> > pair2 in runtime.SelectAdditional) { if (additionalKeys == null) { additionalKeys = new List <InstanceKey>(); } values.Clear(); InstanceKey invalidKey = InstanceKey.InvalidKey; bool flag2 = true; foreach (KeyValuePair <MessageQuery, string> pair3 in this.ExecuteSelect(target, messageToReadHeaders, pair2.Value, runtime.IsContextQuery)) { if (!(pair3.Key is OptionalMessageQuery)) { flag2 = false; } if (!string.IsNullOrEmpty(pair3.Value)) { values.Add(pair2.Value[pair3.Key], pair3.Value); } } if (values.Count == 0) { if (!flag2) { throw FxTrace.Exception.AsError(new ProtocolException(System.ServiceModel.Activities.SR.EmptyCorrelationQueryResults)); } } else { CorrelationKey key2 = new CorrelationKey(values, this.parent.scopeName.ToString(), null) { Name = pair2.Key }; invalidKey = key2; if (TD.TraceCorrelationKeysIsEnabled()) { this.TraceCorrelationKeys(invalidKey, values); } } additionalKeys.Add(invalidKey); } return(true); }
internal bool TryGetValue(CorrelationKeyCalculator.CorrelationCacheKey key, out CorrelationKey value) { value = (CorrelationKey)this.cache.GetValue(this.cacheLock, key); return(value != null); }
public bool CalculateKeys(T target, Message messageToReadHeaders, out InstanceKey instanceKey, out ICollection <InstanceKey> additionalKeys) { SelectRuntime select; instanceKey = InstanceKey.InvalidKey; additionalKeys = null; // this is a query on the serverside, either Receive or SendReply // Where if (!this.ExecuteWhere(target, messageToReadHeaders, this.parent.whereRuntime, out select)) { return(false); } Dictionary <string, string> values = new Dictionary <string, string>(); // Select if (select.Select.Count > 0) { bool allOptional = true; foreach (KeyValuePair <MessageQuery, string> result in this.ExecuteSelect(target, messageToReadHeaders, select.Select, select.IsContextQuery)) { if (!(result.Key is OptionalMessageQuery)) { allOptional = false; } if (!string.IsNullOrEmpty(result.Value)) { values.Add(select.Select[result.Key], result.Value); } } if (values.Count == 0) { if (!allOptional) { throw FxTrace.Exception.AsError(new ProtocolException(SR2.EmptyCorrelationQueryResults)); } } else { instanceKey = this.GetInstanceKey(values); if (TD.TraceCorrelationKeysIsEnabled()) { TraceCorrelationKeys(instanceKey, values); } } } // SelectAdditional foreach (KeyValuePair <string, MessageQueryTable <string> > item in select.SelectAdditional) { if (additionalKeys == null) { additionalKeys = new List <InstanceKey>(); } values.Clear(); InstanceKey additionalKey = InstanceKey.InvalidKey; bool allOptional = true; foreach (KeyValuePair <MessageQuery, string> result in this.ExecuteSelect(target, messageToReadHeaders, item.Value, select.IsContextQuery)) { if (!(result.Key is OptionalMessageQuery)) { allOptional = false; } if (!string.IsNullOrEmpty(result.Value)) { values.Add(item.Value[result.Key], result.Value); } } if (values.Count == 0) { if (!allOptional) { throw FxTrace.Exception.AsError(new ProtocolException(SR2.EmptyCorrelationQueryResults)); } } else { additionalKey = new CorrelationKey(values, this.parent.scopeName.ToString(), null) { Name = item.Key }; if (TD.TraceCorrelationKeysIsEnabled()) { TraceCorrelationKeys(additionalKey, values); } } additionalKeys.Add(additionalKey); } return(true); }