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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
#pragma warning disable 1634, 1691
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
using System;
using System.Text;
using System.Workflow.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Workflow.Runtime;
namespace System.Workflow.Activities
{
[Serializable]
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public sealed class EventQueueName : IComparable
{
Type interfaceType;
string operation;
CorrelationProperty[] correlationValues;
string activityId;
[NonSerialized]
string assemblyQualifiedName;
[NonSerialized]
String stringifiedKey;
private string AssemblyQualifiedName
{
get
{
if (assemblyQualifiedName == null)
{
assemblyQualifiedName = this.interfaceType.AssemblyQualifiedName;
}
return assemblyQualifiedName;
}
}
public EventQueueName(Type interfaceType, string operation)
{
if (interfaceType == null)
throw new ArgumentNullException("interfaceType");
if (operation == null)
throw new ArgumentNullException("operation");
this.interfaceType = interfaceType;
this.operation = operation;
}
public EventQueueName(Type interfaceType, string operation, ICollection<CorrelationProperty> propertyValues)
: this(interfaceType, operation)
{
if (propertyValues != null)
{
this.correlationValues = new CorrelationProperty[propertyValues.Count];
propertyValues.CopyTo(this.correlationValues, 0);
}
}
internal EventQueueName(Type interfaceType, string operation, string activityId)
: this(interfaceType, operation)
{
this.activityId = activityId;
}
// properties
public Type InterfaceType
{
get
{
return this.interfaceType;
}
}
public string MethodName
{
get
{
return this.operation;
}
}
public CorrelationProperty[] GetCorrelationValues()
{
return this.correlationValues;
}
public int CompareTo(Object toCompare)
{
if (toCompare is EventQueueName)
return this.CompareTo(toCompare as EventQueueName);
else
return -1;
}
// IComparable implementation
public int CompareTo(EventQueueName eventQueueName)
{
if (eventQueueName == null)
return -1;
// compare operation
int compared = StringComparer.Ordinal.Compare(this.MethodName, eventQueueName.MethodName);
if (compared == 0)
{
// compare type names
#pragma warning disable 56506
compared = StringComparer.Ordinal.Compare(AssemblyQualifiedName, eventQueueName.AssemblyQualifiedName);
#pragma warning restore 56506
if (compared == 0)
{
if (this.correlationValues != null)
{
compared = (eventQueueName.correlationValues != null) ? (this.correlationValues.Length - eventQueueName.correlationValues.Length) : -1;
if (compared == 0)
{
// compare correlation values
for (int i = 0; i < this.correlationValues.Length; i++)
{
if (this.correlationValues[i] == null || eventQueueName.correlationValues[i] == null)
{
compared = -1;
break; // match failed
}
object leftValue = this.correlationValues[i].Value;
object rightValue = FindCorrelationValue(this.correlationValues[i].Name, eventQueueName.correlationValues);
#pragma warning suppress 56506
if (leftValue == null && rightValue == null)
{
continue;
}
// do the explicit equals check
if (leftValue != null)
{
IComparable comparable = leftValue as IComparable;
if (comparable != null)
{
compared = comparable.CompareTo(rightValue);
if (compared != 0)
{
break; // match failed
}
}
else if ((!leftValue.Equals(rightValue)))
{
compared = -1;
break; // match failed
}
}
else
{
compared = -1;
break; // match failed
}
}
}
}
}
}
return compared;
}
public override bool Equals(object obj)
{
EventQueueName k = obj as EventQueueName;
//Without the cast we end up in op_Equality below
if ((object)k == null)
return false;
return 0 == CompareTo(k);
}
public static bool operator ==(EventQueueName queueKey1, EventQueueName queueKey2)
{
bool equality = false;
if ((object)queueKey1 != null)
{
if ((object)queueKey2 != null)
{
equality = (0 == queueKey1.CompareTo(queueKey2));
}
}
else if ((object)queueKey2 == null)
{
equality = true;
}
return equality;
}
public static bool operator !=(EventQueueName queueKey1, EventQueueName queueKey2)
{
return !(queueKey1 == queueKey2);
}
public static bool operator <(EventQueueName queueKey1, EventQueueName queueKey2)
{
if (queueKey1 == null)
throw new ArgumentNullException("queueKey1");
if (queueKey2 == null)
throw new ArgumentNullException("queueKey2");
return (queueKey1.CompareTo(queueKey2) < 0);
}
public static bool operator >(EventQueueName queueKey1, EventQueueName queueKey2)
{
if (queueKey1 == null)
throw new ArgumentNullException("queueKey1");
if (queueKey2 == null)
throw new ArgumentNullException("queueKey2");
return (queueKey1.CompareTo(queueKey2) > 0);
}
public override int GetHashCode()
{
if (String.IsNullOrEmpty(this.activityId))
return (AssemblyQualifiedName.GetHashCode() ^ this.operation.GetHashCode());
return (AssemblyQualifiedName.GetHashCode() ^ this.operation.GetHashCode() ^ this.activityId.GetHashCode());
}
public override string ToString()
{
if (stringifiedKey == null)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Message Properties");
stringBuilder.AppendLine("Interface Type:" + this.interfaceType.ToString());
stringBuilder.AppendLine("Method Name:" + this.operation.ToString());
stringBuilder.AppendLine("CorrelationValues:");
if (correlationValues != null)
{
foreach (CorrelationProperty pred in correlationValues)
{
if (pred != null && pred.Value != null)
stringBuilder.AppendLine(pred.Value.ToString());
}
}
stringifiedKey = stringBuilder.ToString();
}
return stringifiedKey;
}
object FindCorrelationValue(string name, CorrelationProperty[] correlationValues)
{
object value = null;
foreach (CorrelationProperty property in correlationValues)
{
if (property != null && property.Name == name)
{
value = property.Value;
break;
}
}
return value;
}
}
}
|