1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
using System.ServiceModel.Activities;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using SR2 = System.ServiceModel.Activities.SR;
public class CorrelationQuery
{
Collection<MessageQuerySet> selectAdditional;
public CorrelationQuery()
{
}
[SuppressMessage(FxCop.Category.Usage, FxCop.Rule.CollectionPropertiesShouldBeReadOnly,
Justification = "TODO 87762, remove the set")]
[SuppressMessage(FxCop.Category.Xaml, FxCop.Rule.PropertyExternalTypesMustBeKnown,
Justification = "This property is XAML friendly, no need to add KnownXamlExternal")]
[DefaultValue(null)]
public MessageQuerySet Select
{
get;
set;
}
public Collection<MessageQuerySet> SelectAdditional
{
get
{
if (this.selectAdditional == null)
{
this.selectAdditional = new QueryCollection();
}
return this.selectAdditional;
}
}
[SuppressMessage(FxCop.Category.Xaml, FxCop.Rule.PropertyExternalTypesMustBeKnown,
Justification = "This property is XAML friendly, no need to add KnownXamlExternal")]
[DefaultValue(null)]
public MessageFilter Where
{
get;
set;
}
internal bool IsDefaultContextQuery
{
get;
set;
}
public override bool Equals(object other)
{
if (object.ReferenceEquals(this, other))
{
return true;
}
CorrelationQuery otherQuery = other as CorrelationQuery;
if (otherQuery == null)
{
return false;
}
if (this.Where == null)
{
return otherQuery.Where == null;
}
return this.Where.Equals(otherQuery.Where);
}
public override int GetHashCode()
{
return (this.Where != null) ? this.Where.GetHashCode() : 0;
}
internal static bool IsQueryCollectionSearchable(IEnumerable<CorrelationQuery> queries)
{
foreach (CorrelationQuery query in queries)
{
if (!(query.Where is CorrelationActionMessageFilter || query.Where is ActionMessageFilter))
{
return false;
}
}
return true;
}
internal static CorrelationQuery FindCorrelationQueryForAction(IEnumerable<CorrelationQuery> queries, string action)
{
string localAction = action != null ? action : String.Empty;
foreach (CorrelationQuery query in queries)
{
// if the action is wildcard, we have a match all
if (query.Where is CorrelationActionMessageFilter)
{
if (((CorrelationActionMessageFilter)query.Where).Action == localAction || localAction == MessageHeaders.WildcardAction)
{
return query;
}
}
else if (query.Where is ActionMessageFilter)
{
if (((ActionMessageFilter)query.Where).Actions.Contains(localAction) || localAction == MessageHeaders.WildcardAction)
{
return query;
}
}
}
return null;
}
internal CorrelationQuery Clone()
{
CorrelationQuery cloneQuery = new CorrelationQuery
{
Select = this.Select,
IsDefaultContextQuery = this.IsDefaultContextQuery,
Where = this.Where,
};
if (this.selectAdditional != null)
{
foreach (MessageQuerySet messageQuerySet in this.selectAdditional)
{
cloneQuery.SelectAdditional.Add(messageQuerySet);
}
}
return cloneQuery;
}
class QueryCollection : Collection<MessageQuerySet>
{
public QueryCollection()
{
}
protected override void InsertItem(int index, MessageQuerySet item)
{
if (item == null)
{
throw FxTrace.Exception.ArgumentNull("item");
}
base.InsertItem(index, item);
}
protected override void SetItem(int index, MessageQuerySet item)
{
if (item == null)
{
throw FxTrace.Exception.ArgumentNull("item");
}
base.SetItem(index, item);
}
}
}
}
|