Skip to content

Commit 5053258

Browse files
author
Emile Joubert
committed
Merged bug25552 (again)
2 parents 6edc109 + 95d3f1c commit 5053258

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+662
-272
lines changed

Local.props.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<PropTargetFramework>v3.5</PropTargetFramework>
4+
<PropTargetFramework>v3.0</PropTargetFramework>
55
<PropAssemblyVersion>0.0.0.0</PropAssemblyVersion>
66
<PropUsingMono>false</PropUsingMono>
77

projects/client/Apigen/src/apigen/AmqpClass.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42-
using System.Collections;
42+
using System.Collections.Generic;
4343
using System.Xml;
4444

4545
namespace RabbitMQ.Client.Apigen {
4646
public class AmqpClass: AmqpEntity {
47-
public ArrayList m_Methods;
48-
public ArrayList m_Fields;
47+
public IList<AmqpMethod> m_Methods;
48+
public IList<AmqpField> m_Fields;
4949

5050
public AmqpClass(XmlNode n)
5151
: base(n)
5252
{
53-
m_Methods = new ArrayList();
53+
m_Methods = new List<AmqpMethod>();
5454
foreach (XmlNode m in n.SelectNodes("method")) {
5555
m_Methods.Add(new AmqpMethod(m));
5656
}
57-
m_Fields = new ArrayList();
57+
m_Fields = new List<AmqpField>();
5858
foreach (XmlNode f in n.SelectNodes("field")) {
5959
m_Fields.Add(new AmqpField(f));
6060
}

projects/client/Apigen/src/apigen/AmqpMethod.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42-
using System.Collections;
42+
using System.Collections.Generic;
4343
using System.Xml;
4444

4545
namespace RabbitMQ.Client.Apigen {
4646
public class AmqpMethod: AmqpEntity {
47-
public ArrayList m_Fields;
48-
public ArrayList m_ResponseMethods;
47+
public IList<AmqpField> m_Fields;
48+
public IList<string> m_ResponseMethods;
4949

5050
public AmqpMethod(XmlNode n)
5151
: base(n)
5252
{
53-
m_Fields = new ArrayList();
53+
m_Fields = new List<AmqpField>();
5454
foreach (XmlNode f in n.SelectNodes("field")) {
5555
m_Fields.Add(new AmqpField(f));
5656
}
57-
m_ResponseMethods = new ArrayList();
57+
m_ResponseMethods = new List<string>();
5858
foreach (XmlNode r in n.SelectNodes("response")) {
5959
m_ResponseMethods.Add(Apigen.GetString(r, "@name"));
6060
}

projects/client/Apigen/src/apigen/Apigen.cs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42-
using System.Collections;
42+
using System.CodeDom;
43+
using System.CodeDom.Compiler;
44+
using System.Collections.Generic;
4345
using System.IO;
4446
using System.Reflection;
4547
using System.Text;
@@ -53,7 +55,7 @@ public class Apigen {
5355
// Entry point
5456

5557
public static void Main(string[] args) {
56-
Apigen instance = new Apigen(new ArrayList(args));
58+
Apigen instance = new Apigen(new List<string>(args));
5759
instance.Generate();
5860
}
5961

@@ -118,8 +120,8 @@ public static string MangleConstant(string name) {
118120
return MangleClass(name);
119121
}
120122

121-
public static ArrayList IdentifierParts(string name) {
122-
ArrayList result = new ArrayList();
123+
public static IList<string> IdentifierParts(string name) {
124+
IList<string> result = new List<string>();
123125
foreach (String s1 in name.Split(new Char[] { '-' })) {
124126
foreach (String s2 in s1.Split(new Char[] { ' ' })) {
125127
result.Add(s2);
@@ -171,24 +173,27 @@ public static string MangleMethodClass(AmqpClass c, AmqpMethod m) {
171173
public bool m_emitComments = false;
172174

173175
public Type m_modelType = typeof(RabbitMQ.Client.Impl.IFullModel);
174-
public ArrayList m_modelTypes = new ArrayList();
175-
public ArrayList m_constants = new ArrayList();
176-
public ArrayList m_classes = new ArrayList();
177-
public Hashtable m_domains = new Hashtable();
176+
public IList<Type> m_modelTypes = new List<Type>();
177+
public IList<KeyValuePair<string, int>> m_constants = new List<KeyValuePair<string, int>>();
178+
public IList<AmqpClass> m_classes = new List<AmqpClass>();
179+
public IDictionary<string, string> m_domains = new Dictionary<string, string>();
180+
181+
public static IDictionary<string, string> m_primitiveTypeMap;
182+
public static IDictionary<string, bool> m_primitiveTypeFlagMap;
183+
184+
private CodeDomProvider m_csharpProvider;
178185

179-
public static Hashtable m_primitiveTypeMap;
180-
public static Hashtable m_primitiveTypeFlagMap;
181186
static Apigen() {
182-
m_primitiveTypeMap = new Hashtable();
183-
m_primitiveTypeFlagMap = new Hashtable();
187+
m_primitiveTypeMap = new Dictionary<string, string>();
188+
m_primitiveTypeFlagMap = new Dictionary<string, bool>();
184189
InitPrimitiveType("octet", "byte", false);
185190
InitPrimitiveType("shortstr", "string", true);
186191
InitPrimitiveType("longstr", "byte[]", true);
187192
InitPrimitiveType("short", "ushort", false);
188193
InitPrimitiveType("long", "uint", false);
189194
InitPrimitiveType("longlong", "ulong", false);
190195
InitPrimitiveType("bit", "bool", false);
191-
InitPrimitiveType("table", "System.Collections.IDictionary", true);
196+
InitPrimitiveType("table", "System.Collections.Generic.IDictionary<string, object>", true);
192197
InitPrimitiveType("timestamp", "AmqpTimestamp", false);
193198
InitPrimitiveType("content", "byte[]", true);
194199
}
@@ -227,7 +232,7 @@ public void Usage() {
227232
Environment.Exit(1);
228233
}
229234

230-
public Apigen(ArrayList args) {
235+
public Apigen(IList<string> args) {
231236
while (args.Count > 0 && ((string) args[0]).StartsWith("/")) {
232237
HandleOption((string) args[0]);
233238
args.RemoveAt(0);
@@ -239,6 +244,7 @@ public Apigen(ArrayList args) {
239244
}
240245
m_inputXmlFilename = (string) args[0];
241246
m_outputFilename = (string) args[1];
247+
this.m_csharpProvider = CodeDomProvider.CreateProvider("C#");
242248
}
243249

244250
///////////////////////////////////////////////////////////////////////////
@@ -289,7 +295,7 @@ public void ParseSpec() {
289295
}
290296
}
291297
foreach (XmlNode n in m_spec.SelectNodes("/amqp/constant")) {
292-
m_constants.Add(new DictionaryEntry(GetString(n, "@name"), GetInt(n, "@value")));
298+
m_constants.Add(new KeyValuePair<string, int>(GetString(n, "@name"), GetInt(n, "@value")));
293299
}
294300
foreach (XmlNode n in m_spec.SelectNodes("/amqp/class")) {
295301
m_classes.Add(new AmqpClass(n));
@@ -311,7 +317,7 @@ public void ReflectModel() {
311317
}
312318

313319
public string ResolveDomain(string d) {
314-
while (m_domains[d] != null) {
320+
while (m_domains.ContainsKey(d)) {
315321
string newD = (string) m_domains[d];
316322
if (d.Equals(newD))
317323
break;
@@ -418,7 +424,7 @@ public void EmitPublic() {
418424
EmitContentHeaderReader();
419425
EmitLine(" }");
420426
EmitLine(" public class Constants {");
421-
foreach (DictionaryEntry de in m_constants) {
427+
foreach (KeyValuePair<string, int> de in m_constants) {
422428
EmitLine(" ///<summary>(= "+de.Value+")</summary>");
423429
EmitLine(" public const int "+MangleConstant((string) de.Key)+" = "+de.Value+";");
424430
}
@@ -771,7 +777,7 @@ public Attribute Attribute(ICustomAttributeProvider p, Type t) {
771777
return Attribute(p.GetCustomAttributes(t, false), t);
772778
}
773779

774-
public Attribute Attribute(IEnumerable attributes, Type t) {
780+
public Attribute Attribute(IEnumerable<object> attributes, Type t) {
775781
if (t.IsSubclassOf(typeof(AmqpApigenAttribute))) {
776782
AmqpApigenAttribute result = null;
777783
foreach (AmqpApigenAttribute candidate in attributes) {
@@ -794,7 +800,7 @@ public Attribute Attribute(IEnumerable attributes, Type t) {
794800
public void EmitModelImplementation() {
795801
EmitLine(" public class Model: RabbitMQ.Client.Impl.ModelBase {");
796802
EmitLine(" public Model(RabbitMQ.Client.Impl.ISession session): base(session) {}");
797-
ArrayList asynchronousHandlers = new ArrayList();
803+
IList<MethodInfo> asynchronousHandlers = new List<MethodInfo>();
798804
foreach (Type t in m_modelTypes) {
799805
foreach (MethodInfo method in t.GetMethods()) {
800806
if (method.DeclaringType.Namespace != null &&
@@ -852,11 +858,14 @@ public void MaybeEmitModelMethod(MethodInfo method) {
852858
}
853859

854860
public string SanitisedFullName(Type t) {
855-
if (t == typeof(void)) {
856-
return "void";
857-
} else {
858-
return t.FullName;
861+
CodeTypeReferenceExpression tre = new CodeTypeReferenceExpression(t.FullName);
862+
StringBuilder sb = new StringBuilder();
863+
using (StringWriter writer = new StringWriter(sb))
864+
{
865+
this.m_csharpProvider.GenerateCodeFromExpression(tre, writer, new CodeGeneratorOptions());
859866
}
867+
868+
return sb.ToString().Trim(' ', '\t', '\r', '\n');
860869
}
861870

862871
public void EmitModelMethodPreamble(MethodInfo method) {
@@ -1086,7 +1095,7 @@ public void EmitModelMethod(MethodInfo method) {
10861095
EmitLine(" }");
10871096
}
10881097

1089-
public void EmitAsynchronousHandlers(ArrayList asynchronousHandlers) {
1098+
public void EmitAsynchronousHandlers(IList<MethodInfo> asynchronousHandlers) {
10901099
EmitLine(" public override bool DispatchAsynchronous(RabbitMQ.Client.Impl.Command cmd) {");
10911100
EmitLine(" RabbitMQ.Client.Impl.MethodBase __method = (RabbitMQ.Client.Impl.MethodBase) cmd.Method;");
10921101
EmitLine(" switch ((__method.ProtocolClassId << 16) | __method.ProtocolMethodId) {");

projects/client/RabbitMQ.Client/RabbitMQ.Client.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@
136136
<Reference Include="System" />
137137
<Reference Include="System.Data" />
138138
<Reference Include="System.Xml" />
139+
<Reference Include="System.Configuration" />
140+
<Reference Include="System.ServiceModel" />
139141
</ItemGroup>
140142

141143
<!-- Mono compatibility workarounds -->

projects/client/RabbitMQ.Client/src/client/api/AmqpTcpEndpoint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42-
using System.Collections;
42+
using System.Collections.Generic;
4343
using System.Text.RegularExpressions;
4444
using RabbitMQ.Client.Impl;
4545

@@ -283,14 +283,14 @@ public static AmqpTcpEndpoint Parse(IProtocol protocol, string address) {
283283
///</remarks>
284284
public static AmqpTcpEndpoint[] ParseMultiple(IProtocol protocol, string addresses) {
285285
string[] partsArr = addresses.Split(new char[] { ',' });
286-
ArrayList results = new ArrayList();
286+
List<AmqpTcpEndpoint> results = new List<AmqpTcpEndpoint>();
287287
foreach (string partRaw in partsArr) {
288288
string part = partRaw.Trim();
289289
if (part.Length > 0) {
290290
results.Add(Parse(protocol, part));
291291
}
292292
}
293-
return (AmqpTcpEndpoint[]) results.ToArray(typeof(AmqpTcpEndpoint));
293+
return results.ToArray();
294294
}
295295
}
296296
}

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
using System.Net;
4444
using System.Net.Security;
4545
using System.Net.Sockets;
46-
using System.Collections;
46+
using System.Collections.Generic;
4747

4848
using RabbitMQ.Client.Impl;
4949
using RabbitMQ.Client.Exceptions;
@@ -149,7 +149,7 @@ public class ConnectionFactory
149149

150150
/// <summary>Dictionary of client properties to be sent to the
151151
/// server</summary>
152-
public IDictionary ClientProperties = ConnectionBase.DefaultClientProperties();
152+
public IDictionary<string, object> ClientProperties = ConnectionBase.DefaultClientProperties();
153153

154154
///<summary>Ssl options setting</summary>
155155
public SslOption Ssl = new SslOption();
@@ -207,16 +207,16 @@ public ConnectionFactory() { }
207207

208208
protected virtual IConnection FollowRedirectChain
209209
(int maxRedirects,
210-
IDictionary connectionAttempts,
211-
IDictionary connectionErrors,
210+
IDictionary<AmqpTcpEndpoint, int> connectionAttempts,
211+
IDictionary<AmqpTcpEndpoint, Exception> connectionErrors,
212212
ref AmqpTcpEndpoint[] mostRecentKnownHosts,
213213
AmqpTcpEndpoint endpoint)
214214
{
215215
AmqpTcpEndpoint candidate = endpoint;
216216
try {
217217
while (true) {
218218
int attemptCount =
219-
connectionAttempts.Contains(candidate)
219+
connectionAttempts.ContainsKey(candidate)
220220
? (int) connectionAttempts[candidate]
221221
: 0;
222222
connectionAttempts[candidate] = attemptCount + 1;
@@ -261,8 +261,8 @@ protected virtual IConnection FollowRedirectChain
261261
}
262262

263263
protected virtual IConnection CreateConnection(int maxRedirects,
264-
IDictionary connectionAttempts,
265-
IDictionary connectionErrors,
264+
IDictionary<AmqpTcpEndpoint, int> connectionAttempts,
265+
IDictionary<AmqpTcpEndpoint, Exception> connectionErrors,
266266
params AmqpTcpEndpoint[] endpoints)
267267
{
268268
foreach (AmqpTcpEndpoint endpoint in endpoints)
@@ -320,8 +320,8 @@ protected virtual IConnection CreateConnection(int maxRedirects,
320320
///each endpoint tried.</summary>
321321
public virtual IConnection CreateConnection(int maxRedirects)
322322
{
323-
IDictionary connectionAttempts = new Hashtable();
324-
IDictionary connectionErrors = new Hashtable();
323+
IDictionary<AmqpTcpEndpoint, int> connectionAttempts = new Dictionary<AmqpTcpEndpoint, int>();
324+
Dictionary<AmqpTcpEndpoint, Exception> connectionErrors = new Dictionary<AmqpTcpEndpoint, Exception>();
325325
IConnection conn = CreateConnection(maxRedirects,
326326
connectionAttempts,
327327
connectionErrors,
@@ -346,7 +346,7 @@ public virtual IConnection CreateConnection()
346346
public AuthMechanismFactory AuthMechanismFactory(string[] mechs) {
347347
// Our list is in order of preference, the server one is not.
348348
foreach (AuthMechanismFactory f in AuthMechanisms) {
349-
if (((IList)mechs).Contains(f.Name)) {
349+
if (((IList<string>)mechs).Contains(f.Name)) {
350350
return f;
351351
}
352352
}

projects/client/RabbitMQ.Client/src/client/api/ExchangeType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41-
using System.Collections;
41+
using System.Collections.Generic;
4242

4343
namespace RabbitMQ.Client
4444
{
@@ -66,7 +66,7 @@ public class ExchangeType
6666
private ExchangeType() {}
6767

6868
///<summary>Retrieve a collection containing all standard exchange types.</summary>
69-
public static ICollection All()
69+
public static ICollection<string> All()
7070
{
7171
return new string[] {
7272
Fanout,

projects/client/RabbitMQ.Client/src/client/api/IBasicProperties.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42-
using System.Collections;
42+
using System.Collections.Generic;
4343

4444
namespace RabbitMQ.Client
4545
{
@@ -68,8 +68,8 @@ public interface IBasicProperties : IContentHeader
6868
///<summary> MIME content encoding </summary>
6969
string ContentEncoding { get; set; }
7070

71-
///<summary> message header field table </summary>
72-
IDictionary Headers { get; set; }
71+
///<summary> message header field table. Is of type <see cref="System.Collections.Generic.IDictionary{TKey,TValue}" />.</summary>
72+
IDictionary<string, object> Headers { get; set; }
7373

7474
///<summary> non-persistent (1) or persistent (2) </summary>
7575
byte DeliveryMode { get; set; }

projects/client/RabbitMQ.Client/src/client/api/IConnection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//---------------------------------------------------------------------------
4040

4141
using System;
42-
using System.Collections;
42+
using System.Collections.Generic;
4343
using RabbitMQ.Client.Events;
4444

4545
namespace RabbitMQ.Client
@@ -105,12 +105,12 @@ public interface IConnection: IDisposable
105105

106106
///<summary>A copy of the client properties that has been sent to the
107107
///server.</summary>
108-
IDictionary ClientProperties { get; }
108+
IDictionary<string, object> ClientProperties { get; }
109109

110110
///<summary>A dictionary of the server properties sent by the server
111111
///while establishing the connection. This typically includes
112112
///the product name and version of the server.</summary>
113-
IDictionary ServerProperties { get; }
113+
IDictionary<string, object> ServerProperties { get; }
114114

115115
///<summary>Returns the known hosts that came back from the
116116
///broker in the connection.open-ok method at connection
@@ -281,7 +281,7 @@ public interface IConnection: IDisposable
281281
///<summary>Returns the list of ShutdownReportEntry objects that
282282
///contain information about any errors reported while closing the
283283
///connection in the order they appeared</summary>
284-
IList ShutdownReport { get; }
284+
IList<ShutdownReportEntry> ShutdownReport { get; }
285285

286286

287287
///<summary>Handle incoming Connection.Blocked methods.</summary>

0 commit comments

Comments
 (0)