From fa677aa82da3ee0fa654372d998563d8d652a787 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Tue, 15 Jun 2010 17:51:10 +0000 Subject: QPID-2589 - Patch from Chuck Rolke More API cleanup and new examples (to match the examples for other languages) git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@954983 13f79535-47bb-0310-9956-ffa450edef68 --- .../csharp.direct.receiver.cs | 47 ++--- .../csharp.direct.receiver.csproj | 4 +- .../csharp.direct.sender/csharp.direct.sender.cs | 42 ++--- .../csharp.direct.sender.csproj | 4 +- .../Properties/AssemblyInfo.cs | 36 ++++ .../csharp.example.client/csharp.example.client.cs | 70 ++++++++ .../csharp.example.client.csproj | 81 +++++++++ .../Properties/AssemblyInfo.cs | 36 ++++ .../csharp.example.declare_queues.cs | 61 +++++++ .../csharp.example.declare_queues.csproj | 81 +++++++++ .../examples/csharp.example.drain/Options.cs | 181 ++++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++ .../csharp.example.drain/csharp.example.drain.cs | 85 +++++++++ .../csharp.example.drain.csproj | 82 +++++++++ .../Properties/AssemblyInfo.cs | 36 ++++ .../csharp.example.server/csharp.example.server.cs | 61 +++++++ .../csharp.example.server.csproj | 81 +++++++++ .../examples/csharp.example.spout/Options.cs | 189 +++++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++ .../csharp.example.spout/csharp.example.spout.cs | 117 +++++++++++++ .../csharp.example.spout.csproj | 82 +++++++++ .../csharp.map.callback.receiver.csproj | 4 +- .../csharp.map.callback.sender.cs | 41 ++++- .../csharp.map.callback.sender.csproj | 4 +- .../csharp.map.receiver/csharp.map.receiver.csproj | 4 +- .../csharp.map.receiver/csharp.map.recevier.cs | 11 +- .../csharp.map.sender/csharp.map.sender.cs | 47 ++++- .../csharp.map.sender/csharp.map.sender.csproj | 4 +- .../qpid/dotnet/org.apache.qpid.messaging.sln | 93 +++++++++- qpid/cpp/bindings/qpid/dotnet/src/Message.cpp | 146 ++++++++++++++-- qpid/cpp/bindings/qpid/dotnet/src/Message.h | 22 ++- qpid/cpp/bindings/qpid/dotnet/src/Session.cpp | 102 ++++++++++- qpid/cpp/bindings/qpid/dotnet/src/Session.h | 6 +- ...rg.apache.qpid.messaging.sessionreceiver.csproj | 4 +- .../dotnet/test/messaging.test/messaging.test.cs | 31 ++++ .../test/messaging.test/messaging.test.csproj | 4 +- 36 files changed, 1879 insertions(+), 92 deletions(-) create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/Properties/AssemblyInfo.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.csproj create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/Properties/AssemblyInfo.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.csproj create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Options.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Properties/AssemblyInfo.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.csproj create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/Properties/AssemblyInfo.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.csproj create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Options.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Properties/AssemblyInfo.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs create mode 100644 qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.csproj (limited to 'qpid/cpp') diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs index 98531ebcce..af0b398da6 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.cs @@ -32,6 +32,7 @@ namespace CSharpDirect // Direct receiver example // // Receive 10 messages from localhost:5672, amq.direct/key + // Messages are assumed to be printable strings. // static void Main(string[] args) { @@ -52,39 +53,27 @@ namespace CSharpDirect Console.WriteLine("nMsg : {0}", nMsg); Console.WriteLine(); - Connection conn = new Connection(host); - - conn.Open(); - - if (!conn.IsOpen()) - { - Console.WriteLine("Failed to open connection to host : {0}", host); - } - else + Connection connection = null; + try { - - Session sess = conn.CreateSession(); - - Duration dura = new Duration(3600000); // wait forever - - Receiver rcv = sess.CreateReceiver(addr); - - Message msg = new Message(""); - - for (int i = 0; i < nMsg; i++) - { - try - { - Message msg2 = rcv.Fetch(dura); + connection = new Connection(host); + connection.Open(); + if (!connection.IsOpen()) { + Console.WriteLine("Failed to open connection to host : {0}", host); + } else { + Session session = connection.CreateSession(); + Receiver receiver = session.CreateReceiver(addr); + Message message = new Message(""); + for (int i = 0; i < nMsg; i++) { + Message msg2 = receiver.Fetch(DurationConstants.FORVER); Console.WriteLine("Rcvd msg {0} : {1}", i, msg2.GetContent()); } - catch (Exception e) - { - Console.WriteLine("Exception {0}.", e); - } + connection.Close(); } - - conn.Close(); + } catch (Exception e) { + Console.WriteLine("Exception {0}.", e); + if (null != connection) + connection.Close(); } } } diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.csproj index 96b4540275..172e25a9cb 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.receiver/csharp.direct.receiver.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {52F880E7-D677-4C91-8516-D679CE0F46A8} Exe @@ -67,7 +67,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs index 71ab75ccae..b287af2563 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.cs @@ -29,6 +29,11 @@ namespace csharp.direct.sender { class Program { + // Direct sender example + // + // Send 10 messages from localhost:5672, amq.direct/key + // Messages are assumed to be printable strings. + // static void Main(string[] args) { String host = "localhost:5672"; @@ -48,28 +53,27 @@ namespace csharp.direct.sender Console.WriteLine("nMsg : {0}", nMsg); Console.WriteLine(); - Connection conn = new Connection(host); - - conn.Open(); - - if (!conn.IsOpen()) - { - Console.WriteLine("Failed to open connection to host : {0}", host); - } - else + Connection connection = null; + try { - Session sess = conn.CreateSession(); + connection = new Connection(host); + connection.Open(); - Sender snd = sess.CreateSender(addr); - - for (int i = 0; i < nMsg; i++) - { - Message msg = new Message(String.Format("Test Message {0}", i)); - - snd.Send(msg); + if (!connection.IsOpen()) { + Console.WriteLine("Failed to open connection to host : {0}", host); + } else { + Session session = connection.CreateSession(); + Sender sender = session.CreateSender(addr); + for (int i = 0; i < nMsg; i++) { + Message message = new Message(String.Format("Test Message {0}", i)); + sender.Send(message); + } + connection.Close(); } - - conn.Close(); + } catch (Exception e) { + Console.WriteLine("Exception {0}.", e); + if (null != connection) + connection.Close(); } } } diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.csproj index 4543222675..8e8371c97e 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.direct.sender/csharp.direct.sender.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {7B71CE78-8E78-4632-ADBE-F4D5DFAE0068} Exe @@ -67,7 +67,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/Properties/AssemblyInfo.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..95433e4489 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("csharp.direct.receiver")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("csharp.direct.receiver")] +[assembly: AssemblyCopyright("Copyright ? 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c60b17ab-a82c-4edf-ba95-1e88bd4c3e75")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs new file mode 100644 index 0000000000..93459b6684 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.cs @@ -0,0 +1,70 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using Org.Apache.Qpid.Messaging; + +namespace Org.Apache.Qpid.Messaging.Examples { + class Client { + static void Main(string[] args) { + String url = "amqp:tcp:127.0.0.1:5672"; + + if (args.Length > 0) + url = args[0]; + + Connection connection = new Connection(url); + try + { + connection.Open(); + + Session session = connection.CreateSession(); + + Sender sender = session.CreateSender("service_queue"); + + Address responseQueue = new Address("#response-queue; {create:always, delete:always}"); + Receiver receiver = session.CreateReceiver(responseQueue); + + String[] s = new String[] { + "Twas brillig, and the slithy toves", + "Did gire and gymble in the wabe.", + "All mimsy were the borogroves,", + "And the mome raths outgrabe." + }; + + Message request = new Message(""); + request.SetReplyTo(responseQueue); + + for (int i = 0; i < s.Length; i++) { + request.SetContent(s[i]); + sender.Send(request); + Message response = receiver.Fetch(); + Console.WriteLine("{0} -> {1}", request.GetContent(), response.GetContent()); + } + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine("Exception {0}.", e); + connection.Close(); + } + } + } +} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.csproj new file mode 100644 index 0000000000..76fb1c5e19 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.client/csharp.example.client.csproj @@ -0,0 +1,81 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {0DE01712-C2D1-4CA4-B42C-5856456A8696} + Exe + Properties + csharp.example.client + csharp.example.client + v3.5 + 512 + + + true + full + false + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\..\src\Release\ + TRACE + prompt + 4 + + + true + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + ..\..\..\..\..\src\Release\ + TRACE + true + pdbonly + x86 + prompt + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + {AA5A3B83-5F98-406D-A01C-5A921467A57D} + Org.Apache.Qpid.Messaging + + + + + diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/Properties/AssemblyInfo.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..95433e4489 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("csharp.direct.receiver")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("csharp.direct.receiver")] +[assembly: AssemblyCopyright("Copyright ? 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c60b17ab-a82c-4edf-ba95-1e88bd4c3e75")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.cs new file mode 100644 index 0000000000..7f116f1aaa --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.cs @@ -0,0 +1,61 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Org.Apache.Qpid.Messaging; + +namespace Org.Apache.Qpid.Messaging.Examples { + class DeclareQueues { + // + // Sample invocation: csharp.example.declare_queues.exe localhost:5672 my-queue + // + static void Main(string[] args) { + string addr = "localhost:5672"; + string queue = "my-queue"; + + if (args.Length > 0) + addr = args[0]; + if (args.Length > 1) + queue = args[1]; + + Connection connection = null; + try + { + connection = new Connection(addr); + connection.Open(); + Session session = connection.CreateSession(); + String queueName = queue + "; {create: always}"; + Sender sender = session.CreateSender(queueName); + session.Close(); + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine("Exception {0}.", e); + if (null != connection) + connection.Close(); + } + } + } +} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.csproj new file mode 100644 index 0000000000..fb7e950dea --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.declare_queues/csharp.example.declare_queues.csproj @@ -0,0 +1,81 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {E31B349C-830C-4583-8BD9-30DA4398349F} + Exe + Properties + csharp.example.declare_queues + csharp.example.declare_queues + v3.5 + 512 + + + true + full + false + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\..\src\Release\ + TRACE + prompt + 4 + + + true + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + ..\..\..\..\..\src\Release\ + TRACE + true + pdbonly + x86 + prompt + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + {AA5A3B83-5F98-406D-A01C-5A921467A57D} + Org.Apache.Qpid.Messaging + + + + + diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Options.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Options.cs new file mode 100644 index 0000000000..808e22728a --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Options.cs @@ -0,0 +1,181 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +namespace Org.Apache.Qpid.Messaging.Examples +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Diagnostics; + using System.IO; + using System.Text; + using System.Xml; + + public class Options + { + private string url; + private string address; + private UInt64 timeout; + private int count; + private string id; + private string replyTo; + //private string[] properties; + //private string[] entries; + private string content; + private string connectionOptions; + private bool forever; + + public Options(string[] args) + { + this.url = "amqp:tcp:127.0.0.1:5672"; + this.address = ""; + this.timeout = 0; + this.count = 1; + this.id = ""; + this.replyTo = ""; + this.content = ""; + this.connectionOptions = ""; + this.forever = false; + Parse(args); + } + + private void Parse(string[] args) + { + int argCount = args.Length; + int current = 0; + + while ((current + 1) < argCount) + { + string arg = args[current]; + if (arg == "--broker") + { + this.url = args[++current]; + } + else if (arg == "--address") + { + this.address = args[++current]; + } + else if (arg == "--timeout") + { + arg = args[++current]; + UInt64 i = UInt64.Parse(arg); + if (i >= 0) + { + this.timeout = i; + } + } + else if (arg == "--count") + { + arg = args[++current]; + int i = int.Parse(arg); + if (i >= 0) + { + this.count = i; + } + } + else if (arg == "--id") + { + this.id = args[++current]; + } + else if (arg == "--reply-to") + { + this.replyTo = args[++current]; + } + else if (arg == "--properties") + { + throw new ArgumentException("TODO: properties not implemented"); + } + else if (arg == "--entries") + { + throw new ArgumentException("TODO: entries not implemented"); + } + else if (arg == "--content") + { + this.content = args[++current]; + } + else if (arg == "--connection-options") + { + this.connectionOptions = args[++current]; + } + else if (arg == "--forever") + { + this.forever = true; + } + else + { + throw new ArgumentException(String.Format("unknown argument \"{0}\"", arg)); + } + + current++; + } + + if (current == argCount) + { + throw new ArgumentException("missing argument: address"); + } + + address = args[current]; + } + + public string Url + { + get { return this.url; } + } + + public string Address + { + get { return this.address; } + } + + public UInt64 Timeout + { + get { return this.timeout; } + } + + public int Count + { + get { return this.count; } + } + + public string Id + { + get { return this.id; } + } + + public string ReplyTo + { + get { return this.replyTo; } + } + + public string Content + { + get { return content; } + } + + public string ConnectionOptions + { + get { return this.connectionOptions; } + } + + public bool Forever + { + get { return this.forever; } + } + } +} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Properties/AssemblyInfo.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..95433e4489 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("csharp.direct.receiver")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("csharp.direct.receiver")] +[assembly: AssemblyCopyright("Copyright ? 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c60b17ab-a82c-4edf-ba95-1e88bd4c3e75")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs new file mode 100644 index 0000000000..6740e6a076 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.cs @@ -0,0 +1,85 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Org.Apache.Qpid.Messaging; + +namespace Org.Apache.Qpid.Messaging.Examples { + class Drain { + // + // Sample invocation: csharp.example.drain.exe --broker localhost:5672 --timeout 30 my-queue + // + static void Main(string[] args) { + Options options = new Options(args); + + Connection connection = null; + try + { + connection = new Connection(options.Url, options.ConnectionOptions); + connection.Open(); + Session session = connection.CreateSession(); + Receiver receiver = session.CreateReceiver(options.Address); + Duration timeout = options.Forever ? + DurationConstants.FORVER : + DurationConstants.SECOND * options.Timeout; + Message message = new Message(); + while (receiver.Fetch(message, timeout)) + { + Dictionary properties = new Dictionary(); + properties = message.GetProperties(); + Console.Write("Message(properties={0}, content='", + message.MapAsString(properties)); + + if ("amqp/map" == message.GetContentType()) + { + Dictionary content = new Dictionary(); + message.GetContent(content); + Console.Write(message.MapAsString(content)); + } + else if ("amqp/list" == message.GetContentType()) + { + Collection content = new Collection(); + message.GetContent(content); + Console.Write(message.ListAsString(content)); + } + else + { + Console.Write(message.GetContent()); + } + Console.WriteLine("')"); + session.Acknowledge(); + } + receiver.Close(); + session.Close(); + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine("Exception {0}.", e); + if (null != connection) + connection.Close(); + } + } + } +} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.csproj new file mode 100644 index 0000000000..198900ceb5 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.drain/csharp.example.drain.csproj @@ -0,0 +1,82 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {C43DEB69-8088-420B-B0CA-C699535E6D08} + Exe + Properties + csharp.example.drain + csharp.example.drain + v3.5 + 512 + + + true + full + false + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\..\src\Release\ + TRACE + prompt + 4 + + + true + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + ..\..\..\..\..\src\Release\ + TRACE + true + pdbonly + x86 + prompt + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + {AA5A3B83-5F98-406D-A01C-5A921467A57D} + Org.Apache.Qpid.Messaging + + + + + diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/Properties/AssemblyInfo.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..95433e4489 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("csharp.direct.receiver")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("csharp.direct.receiver")] +[assembly: AssemblyCopyright("Copyright ? 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c60b17ab-a82c-4edf-ba95-1e88bd4c3e75")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs new file mode 100644 index 0000000000..af01e4b0f9 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.cs @@ -0,0 +1,61 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using Org.Apache.Qpid.Messaging; + +namespace Org.Apache.Qpid.Messaging.Examples { + class Server { + static void Main(string[] args) { + String url = "amqp:tcp:127.0.0.1:5672"; + + if (args.Length > 0) + url = args[0]; + + try { + Connection connection = new Connection(url); + connection.Open(); + Session session = connection.CreateSession(); + Receiver receiver = session.CreateReceiver("service_queue; {create: always}"); + + while (true) { + Message request = receiver.Fetch(); + Address address = request.GetReplyTo(); + + if (null != address) { + Sender sender = session.CreateSender(address); + String s = request.GetContent(); + Message response = new Message(s.ToUpper()); + sender.Send(response); + Console.WriteLine("Processed request: {0} -> {1}", request.GetContent(), response.GetContent()); + session.Acknowledge(); + } else { + Console.WriteLine("Error: no reply address specified for request: {0}", request.GetContent()); + session.Reject(request); + } + } + // connection.Close(); // unreachable in this example + } catch (Exception e) { + Console.WriteLine("Exception {0}.", e); + } + } + } +} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.csproj new file mode 100644 index 0000000000..1fa2cc0bc0 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.server/csharp.example.server.csproj @@ -0,0 +1,81 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {090A081D-E8B5-4949-AA43-EE182B7101E3} + Exe + Properties + csharp.example.server + csharp.example.server + v3.5 + 512 + + + true + full + false + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\..\src\Release\ + TRACE + prompt + 4 + + + true + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + ..\..\..\..\..\src\Release\ + TRACE + true + pdbonly + x86 + prompt + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + {AA5A3B83-5F98-406D-A01C-5A921467A57D} + Org.Apache.Qpid.Messaging + + + + + diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Options.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Options.cs new file mode 100644 index 0000000000..be55c1e0d4 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Options.cs @@ -0,0 +1,189 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +namespace Org.Apache.Qpid.Messaging.Examples +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.Diagnostics; + using System.IO; + using System.Text; + using System.Xml; + + public class Options + { + private string url; + private string address; + private int timeout; + private int count; + private string id; + private string replyTo; + private Collection properties; + private Collection entries; + private string content; + private string connectionOptions; + private bool forever; + + public Options(string[] args) + { + this.url = "amqp:tcp:127.0.0.1:5672"; + this.address = ""; + this.timeout = 0; + this.count = 1; + this.id = ""; + this.replyTo = ""; + properties = new Collection(); + entries = new Collection(); + this.content = ""; + this.connectionOptions = ""; + this.forever = false; + Parse(args); + } + + private void Parse(string[] args) + { + int argCount = args.Length; + int current = 0; + + while ((current + 1) < argCount) + { + string arg = args[current]; + if (arg == "--broker") + { + this.url = args[++current]; + } + else if (arg == "--address") + { + this.address = args[++current]; + } + else if (arg == "--timeout") + { + arg = args[++current]; + int i = int.Parse(arg); + if (i >= 0) + { + this.timeout = i; + } + } + else if (arg == "--count") + { + arg = args[++current]; + int i = int.Parse(arg); + if (i >= 0) + { + this.count = i; + } + } + else if (arg == "--id") + { + this.id = args[++current]; + } + else if (arg == "--reply-to") + { + this.replyTo = args[++current]; + } + else if (arg == "--properties") + { + this.properties.Add(args[++current]); + } + else if (arg == "--map") + { + this.entries.Add(args[++current]); + } + else if (arg == "--content") + { + this.content = args[++current]; + } + else if (arg == "--connection-options") + { + this.connectionOptions = args[++current]; + } + else if (arg == "--forever") + { + this.forever = true; + } + else + { + throw new ArgumentException(String.Format("unknown argument \"{0}\"", arg)); + } + + current++; + } + + if (current == argCount) + { + throw new ArgumentException("missing argument: address"); + } + + address = args[current]; + } + + public string Url + { + get { return this.url; } + } + + public string Address + { + get { return this.address; } + } + + public int Timeout + { + get { return this.timeout; } + } + + public int Count + { + get { return this.count; } + } + + public string Id + { + get { return this.id; } + } + + public string ReplyTo + { + get { return this.replyTo; } + } + + public Collection Entries + { + get { return this.entries; } + } + + public string Content + { + get { return content; } + } + + public string ConnectionOptions + { + get { return this.connectionOptions; } + } + + public bool Forever + { + get { return this.forever; } + } + } +} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Properties/AssemblyInfo.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..95433e4489 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("csharp.direct.receiver")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("csharp.direct.receiver")] +[assembly: AssemblyCopyright("Copyright ? 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c60b17ab-a82c-4edf-ba95-1e88bd4c3e75")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs new file mode 100644 index 0000000000..7eeece3194 --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.cs @@ -0,0 +1,117 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +using System; +using System.Diagnostics; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Org.Apache.Qpid.Messaging; + +namespace Org.Apache.Qpid.Messaging.Examples { + class Spout { + // + // Sample invocation: csharp.example.drain.exe --broker localhost:5672 --timeout 30 my-queue + // This pro + static bool NameVal(string In, out string nameOut, out string valueOut) + { + int pos = In.IndexOf("="); + if (-1 == pos) { + nameOut = In; + valueOut = ""; + return false; + } else { + nameOut = In.Substring(0, pos); + if (pos + 1 < In.Length) { + valueOut = In.Substring(pos + 1); + return true; + } else { + valueOut = ""; + return false; + } + } + } + + static void SetEntries(Collection entries, Dictionary content) + { + foreach (String entry in entries) + { + string name = ""; + string value = ""; + if (NameVal(entry, out name, out value)) + content.Add(name, value); + else + content.Add(name, ""); + } + } + + static void Main(string[] args) { + Options options = new Options(args); + + Connection connection = null; + try + { + connection = new Connection(options.Url); + connection.Open(); + Session session = connection.CreateSession(); + Sender sender = session.CreateSender(options.Address); + Message message; + if (options.Entries.Count > 0) + { + Dictionary content = new Dictionary(); + SetEntries(options.Entries, content); + message = new Message(content); + } + else + { + message = new Message(options.Content); + message.SetContentType("text/plain"); + } + Address replyToAddr = new Address(options.ReplyTo); + + Stopwatch stopwatch = new Stopwatch(); + TimeSpan timespan = new TimeSpan(0,0,options.Timeout); + stopwatch.Start(); + for (int count = 0; + (0 == options.Count || count < options.Count) && + (0 == options.Timeout || stopwatch.Elapsed <= timespan); + count++) + { + if ("" != options.ReplyTo) message.SetReplyTo(replyToAddr); + string id = options.Id ; + if ("" == id) { + Guid g = Guid.NewGuid(); + id = g.ToString(); + } + string spoutid = id + ":" + count; + message.SetProperty("spout-id", spoutid); + sender.Send(message); + } + connection.Close(); + } catch (Exception e) { + Console.WriteLine("Exception {0}.", e); + if (null != connection) + connection.Close(); + } + } + } +} + diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.csproj new file mode 100644 index 0000000000..15fc644c8c --- /dev/null +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.example.spout/csharp.example.spout.csproj @@ -0,0 +1,82 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {EB36626D-36C2-41B3-B65E-762BAF27F137} + Exe + Properties + csharp.example.spout + csharp.example.spout + v3.5 + 512 + + + true + full + false + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\..\..\..\..\src\Release\ + TRACE + prompt + 4 + + + true + ..\..\..\..\..\src\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + ..\..\..\..\..\src\Release\ + TRACE + true + pdbonly + x86 + prompt + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + {AA5A3B83-5F98-406D-A01C-5A921467A57D} + Org.Apache.Qpid.Messaging + + + + + diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.csproj index 24b5cd4378..c32574a694 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.receiver/csharp.map.callback.receiver.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {68A43817-2358-4A31-8FDF-FE21722BFBCF} Exe @@ -67,7 +67,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging {B0A51CEC-30A2-4C2E-90BE-AE95107EAA05} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.cs index 761ac0aac2..2b17052b3e 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.cs +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.cs @@ -100,20 +100,55 @@ namespace Org.Apache.Qpid.Messaging.Examples Dictionary subMap = new Dictionary(); Collection colors = new Collection(); + // add simple types content["id"] = 987654321; content["name"] = "Widget"; content["percent"] = 0.99; + // add nested amqp/map subMap["name"] = "Smith"; subMap["number"] = 354; + content["nestedMap"] = subMap; - content["nested"] = subMap; - + // add an amqp/list colors.Add("red"); colors.Add("green"); colors.Add("white"); + content["colorsList"] = colors; + + // add one of each supported amqp data type + bool mybool = true; + content["mybool"] = mybool; + + byte mybyte = 4; + content["mybyte"] = mybyte; + + UInt16 myUInt16 = 5; + content["myUInt16"] = myUInt16; + + UInt32 myUInt32 = 6; + content["myUInt32"] = myUInt32; + + UInt64 myUInt64 = 7; + content["myUInt64"] = myUInt64; + + char mychar = 'h'; + content["mychar"] = mychar; + + Int16 myInt16 = 9; + content["myInt16"] = myInt16; + + Int32 myInt32 = 10; + content["myInt32"] = myInt32; + + Int64 myInt64 = 11; + content["myInt64"] = myInt64; + + Single mySingle = (Single)12.12; + content["mySingle"] = mySingle; - content["colors"] = colors; + Double myDouble = 13.13; + content["myDouble"] = myDouble; // // Construct a message with the map content and send it synchronously diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.csproj index 26f2c5b997..1f37ce8dfe 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.callback.sender/csharp.map.callback.sender.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {12F1C14F-5C7D-4075-9BAE-C091394FF99A} Exe @@ -69,7 +69,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.receiver.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.receiver.csproj index 06017fb55d..c3d87ee276 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.receiver.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.receiver.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {AD9E53D7-DB10-4DA2-84D2-A81BE09B04E9} Exe @@ -67,7 +67,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging {B0A51CEC-30A2-4C2E-90BE-AE95107EAA05} diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.recevier.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.recevier.cs index 41ed9f30b5..242944be92 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.recevier.cs +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.receiver/csharp.map.recevier.cs @@ -27,6 +27,11 @@ namespace Org.Apache.Qpid.Messaging.examples { class MapReceiver { + // csharp.map.receiver example + // + // Send an amqp/map message to amqp:tcp:localhost:5672 amq.direct/map_example + // The map message + // static void Main(string[] args) { string url = "amqp:tcp:localhost:5672"; @@ -47,16 +52,16 @@ namespace Org.Apache.Qpid.Messaging.examples Receiver receiver = session.CreateReceiver("amq.direct/map_example"); // - // Fetch the message from the broker (wait indefinitely by default) + // Fetch the message from the broker // - Message message = receiver.Fetch(new Duration(60000)); + Message message = receiver.Fetch(DurationConstants.MINUTE); // // Extract the structured content from the message. // Dictionary content = new Dictionary(); message.GetContent(content); - Console.WriteLine("Received: {0}", content); + Console.WriteLine("Received: {0}", message.AsString(content)); // // Acknowledge the receipt of all received messages. diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.cs b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.cs index d1ccc65f2c..55172262fe 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.cs +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.cs @@ -30,6 +30,12 @@ namespace Org.Apache.Qpid.Messaging.examples { class MapSender { + // csharp.map.sender example + // + // Send an amqp/map message to amqp:tcp:localhost:5672 amq.direct/map_example + // The map message contains simple types, a nested amqp/map, + // an ampq/list, and specific instances of each supported type. + // static void Main(string[] args) { string url = "amqp:tcp:localhost:5672"; @@ -57,20 +63,55 @@ namespace Org.Apache.Qpid.Messaging.examples Dictionary subMap = new Dictionary(); Collection colors = new Collection(); + // add simple types content["id"] = 987654321; content["name"] = "Widget"; content["percent"] = 0.99; + // add nested amqp/map subMap["name"] = "Smith"; subMap["number"] = 354; + content["nestedMap"] = subMap; - content["nested"] = subMap; - + // add an amqp/list colors.Add("red"); colors.Add("green"); colors.Add("white"); + content["colorsList"] = colors; + + // add one of each supported amqp data type + bool mybool = true; + content["mybool"] = mybool; + + byte mybyte = 4; + content["mybyte"] = mybyte; + + UInt16 myUInt16 = 5 ; + content["myUInt16"] = myUInt16; + + UInt32 myUInt32 = 6; + content["myUInt32"] = myUInt32; + + UInt64 myUInt64 = 7; + content["myUInt64"] = myUInt64; + + char mychar = 'h'; + content["mychar"] = mychar; + + Int16 myInt16 = 9; + content["myInt16"] = myInt16; + + Int32 myInt32 = 10; + content["myInt32"] = myInt32; + + Int64 myInt64 = 11; + content["myInt64"] = myInt64; + + Single mySingle = (Single)12.12; + content["mySingle"] = mySingle; - content["colors"] = colors; + Double myDouble = 13.13; + content["myDouble"] = myDouble; // // Construct a message with the map content and send it synchronously diff --git a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.csproj b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.csproj index a3a2ac2300..516e7cc07a 100644 --- a/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/examples/csharp.map.sender/csharp.map.sender.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {5D8252F5-E1D3-44A0-94C7-7CB75E843C10} Exe @@ -67,7 +67,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging diff --git a/qpid/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln b/qpid/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln index 5cd4b1ac8e..7269dad1f6 100644 --- a/qpid/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln +++ b/qpid/cpp/bindings/qpid/dotnet/org.apache.qpid.messaging.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 10.00 # Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "org.apache.qpid.messaging", "src\org.apache.qpid.messaging.vcproj", "{AA5A3B83-5F98-406D-A01C-5A921467A57D}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Org.Apache.Qpid.Messaging", "src\org.apache.qpid.messaging.vcproj", "{AA5A3B83-5F98-406D-A01C-5A921467A57D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{34C477FB-B0CC-4AB9-A346-EA7B055469AC}" EndProject @@ -43,6 +43,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.map.callback.receive EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.map.callback.sender", "examples\csharp.map.callback.sender\csharp.map.callback.sender.csproj", "{12F1C14F-5C7D-4075-9BAE-C091394FF99A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client-Server", "Client-Server", "{9232212E-F3C6-4D18-8D25-0C31DD5FF3DB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.example.client", "examples\csharp.example.client\csharp.example.client.csproj", "{0DE01712-C2D1-4CA4-B42C-5856456A8696}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.example.server", "examples\csharp.example.server\csharp.example.server.csproj", "{090A081D-E8B5-4949-AA43-EE182B7101E3}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Drain-Spout", "Drain-Spout", "{89CE04CB-21DE-4ABB-9236-50529DD8C022}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.example.drain", "examples\csharp.example.drain\csharp.example.drain.csproj", "{C43DEB69-8088-420B-B0CA-C699535E6D08}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.example.spout", "examples\csharp.example.spout\csharp.example.spout.csproj", "{EB36626D-36C2-41B3-B65E-762BAF27F137}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp.example.declare_queues", "examples\csharp.example.declare_queues\csharp.example.declare_queues.csproj", "{E31B349C-830C-4583-8BD9-30DA4398349F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -180,6 +194,76 @@ Global {12F1C14F-5C7D-4075-9BAE-C091394FF99A}.Release|Win32.ActiveCfg = Release|Any CPU {12F1C14F-5C7D-4075-9BAE-C091394FF99A}.Release|x86.ActiveCfg = Release|x86 {12F1C14F-5C7D-4075-9BAE-C091394FF99A}.Release|x86.Build.0 = Release|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Debug|Win32.ActiveCfg = Debug|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Debug|x86.ActiveCfg = Debug|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Debug|x86.Build.0 = Debug|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Release|Any CPU.Build.0 = Release|Any CPU + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Release|Mixed Platforms.Build.0 = Release|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Release|Win32.ActiveCfg = Release|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Release|x86.ActiveCfg = Release|x86 + {0DE01712-C2D1-4CA4-B42C-5856456A8696}.Release|x86.Build.0 = Release|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Debug|Win32.ActiveCfg = Debug|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Debug|x86.ActiveCfg = Debug|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Debug|x86.Build.0 = Debug|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Release|Any CPU.Build.0 = Release|Any CPU + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Release|Mixed Platforms.Build.0 = Release|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Release|Win32.ActiveCfg = Release|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Release|x86.ActiveCfg = Release|x86 + {090A081D-E8B5-4949-AA43-EE182B7101E3}.Release|x86.Build.0 = Release|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Debug|Win32.ActiveCfg = Debug|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Debug|x86.ActiveCfg = Debug|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Debug|x86.Build.0 = Debug|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Release|Any CPU.Build.0 = Release|Any CPU + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Release|Mixed Platforms.Build.0 = Release|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Release|Win32.ActiveCfg = Release|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Release|x86.ActiveCfg = Release|x86 + {C43DEB69-8088-420B-B0CA-C699535E6D08}.Release|x86.Build.0 = Release|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Debug|Win32.ActiveCfg = Debug|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Debug|x86.ActiveCfg = Debug|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Debug|x86.Build.0 = Debug|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Release|Any CPU.Build.0 = Release|Any CPU + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Release|Mixed Platforms.Build.0 = Release|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Release|Win32.ActiveCfg = Release|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Release|x86.ActiveCfg = Release|x86 + {EB36626D-36C2-41B3-B65E-762BAF27F137}.Release|x86.Build.0 = Release|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E31B349C-830C-4583-8BD9-30DA4398349F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E31B349C-830C-4583-8BD9-30DA4398349F}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Debug|Win32.ActiveCfg = Debug|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Debug|x86.ActiveCfg = Debug|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Debug|x86.Build.0 = Debug|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E31B349C-830C-4583-8BD9-30DA4398349F}.Release|Any CPU.Build.0 = Release|Any CPU + {E31B349C-830C-4583-8BD9-30DA4398349F}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Release|Mixed Platforms.Build.0 = Release|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Release|Win32.ActiveCfg = Release|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Release|x86.ActiveCfg = Release|x86 + {E31B349C-830C-4583-8BD9-30DA4398349F}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -188,6 +272,8 @@ Global {DE58D329-10DC-4C8D-9EFA-230A57314089} = {34C477FB-B0CC-4AB9-A346-EA7B055469AC} {878FDDF8-A870-41D6-9E36-0A050EC5ACAB} = {34C477FB-B0CC-4AB9-A346-EA7B055469AC} {E99FEFEE-B866-4BBA-9AA3-79DDF1C92960} = {34C477FB-B0CC-4AB9-A346-EA7B055469AC} + {9232212E-F3C6-4D18-8D25-0C31DD5FF3DB} = {34C477FB-B0CC-4AB9-A346-EA7B055469AC} + {89CE04CB-21DE-4ABB-9236-50529DD8C022} = {34C477FB-B0CC-4AB9-A346-EA7B055469AC} {7B71CE78-8E78-4632-ADBE-F4D5DFAE0068} = {DE58D329-10DC-4C8D-9EFA-230A57314089} {52F880E7-D677-4C91-8516-D679CE0F46A8} = {DE58D329-10DC-4C8D-9EFA-230A57314089} {AF2FBC78-266C-430C-BC29-9477AB596A36} = {39E9D1BF-3A0B-4D86-BF6B-F463E1A2245A} @@ -195,5 +281,10 @@ Global {AD9E53D7-DB10-4DA2-84D2-A81BE09B04E9} = {E99FEFEE-B866-4BBA-9AA3-79DDF1C92960} {68A43817-2358-4A31-8FDF-FE21722BFBCF} = {E99FEFEE-B866-4BBA-9AA3-79DDF1C92960} {12F1C14F-5C7D-4075-9BAE-C091394FF99A} = {E99FEFEE-B866-4BBA-9AA3-79DDF1C92960} + {0DE01712-C2D1-4CA4-B42C-5856456A8696} = {9232212E-F3C6-4D18-8D25-0C31DD5FF3DB} + {090A081D-E8B5-4949-AA43-EE182B7101E3} = {9232212E-F3C6-4D18-8D25-0C31DD5FF3DB} + {C43DEB69-8088-420B-B0CA-C699535E6D08} = {89CE04CB-21DE-4ABB-9236-50529DD8C022} + {EB36626D-36C2-41B3-B65E-762BAF27F137} = {89CE04CB-21DE-4ABB-9236-50529DD8C022} + {E31B349C-830C-4583-8BD9-30DA4398349F} = {89CE04CB-21DE-4ABB-9236-50529DD8C022} EndGlobalSection EndGlobal diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp b/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp index 3f748f177c..743afce964 100644 --- a/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp +++ b/qpid/cpp/bindings/qpid/dotnet/src/Message.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "qpid/messaging/Message.h" #include "qpid/types/Variant.h" @@ -100,6 +101,25 @@ namespace Messaging { } } + + // Create from bytes + Message::Message(array ^ bytes) + { + pin_ptr pBytes = &bytes[0]; + messagep = new ::qpid::messaging::Message((char *)pBytes, bytes->Length); + } + + // Create from byte array slice + Message::Message(array ^ bytes, int offset, int size) + { + if ((offset + size) > bytes->Length) + throw gcnew QpidException("Message::Message Create from byte array slice: buffer length exceeded"); + + pin_ptr pBytes = &bytes[offset]; + messagep = new ::qpid::messaging::Message((char *)pBytes, size); + } + + // Create from received message Message::Message(::qpid::messaging::Message * msgp) : messagep(msgp) @@ -278,7 +298,7 @@ namespace Messaging { messagep->setRedelivered(redelivered); } - + // Properties System::Collections::Generic::Dictionary< System::String^, System::Object^> ^ Message::GetProperties() { @@ -297,7 +317,29 @@ namespace Messaging { } - void Message::SetContent(System::String ^ content) + void Message::SetProperty(System::String ^ name, System::Object ^ value) + { + ::qpid::types::Variant entryValue; + TypeTranslator::ManagedToNativeObject(value, entryValue); + + messagep->getProperties()[QpidMarshal::ToNative(name)] = entryValue; + } + + + void Message::SetProperties(System::Collections::Generic::Dictionary< + System::String^, System::Object^> ^ properties) + { + for each (System::Collections::Generic::KeyValuePair + kvp in properties) + { + SetProperty(kvp.Key, kvp.Value); + } + } + + + + // Content + void Message::SetContent(System::String ^ content) { messagep->setContent(QpidMarshal::ToNative(content)); } @@ -342,8 +384,9 @@ namespace Messaging { } // - // User wants content as bytes. - // result array must be correct size already + // Return message content to raw byte array. + // On entry message size must not be zero and + // caller's byte array must be equal to message size. // void Message::GetRaw(array ^ arr) { @@ -353,16 +396,11 @@ namespace Messaging { throw gcnew QpidException("Message::GetRaw - message size is zero"); if (arr->Length != size) - throw gcnew QpidException("Message::GetRaw - receive buffer is too small"); + throw gcnew QpidException("Message::GetRaw - receive buffer is wrong size"); - const char * ptr = messagep->getContentPtr(); - - // TODO: System::Runtime::InteropServices::Marshal::Copy(ptr, arr, 0, size); - - for (UInt32 i = 0; i < size; i++) - { - arr[i] = ptr[i]; - } + const char * pMsgSrc = messagep->getContentPtr(); + pin_ptr pArr = &arr[0]; + memcpy(pArr, pMsgSrc, size); } @@ -370,4 +408,86 @@ namespace Messaging { { return messagep->getContentSize(); } + + + System::String ^ Message::MapAsString(System::Collections::Generic::Dictionary< + System::String^, System::Object^> ^ dict) + { + System::String ^ leading = ""; + System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("{"); + + for each (System::Collections::Generic::KeyValuePair + kvp in dict) + { + sb->Append(leading); + leading = ", "; + + if (QpidTypeCheck::ObjectIsMap(kvp.Value)) + { + sb->AppendFormat( + "{0}={1}", + kvp.Key, + MapAsString((System::Collections::Generic::Dictionary ^)kvp.Value)); + } + else if (QpidTypeCheck::ObjectIsList(kvp.Value)) + { + sb->AppendFormat( + "{0}={1}", + kvp.Key, + ListAsString((System::Collections::ObjectModel::Collection< + System::Object^> ^)kvp.Value)); + } + else + sb->AppendFormat("{0}={1}", kvp.Key, kvp.Value); + } + sb->Append("}"); + + System::String ^ result = gcnew System::String(sb->ToString()); + return result; + } + + /// + /// A function to display a ampq/list message packaged as a List. + /// + /// The AMQP list + System::String ^ Message::ListAsString(System::Collections::ObjectModel::Collection ^ list) + { + System::String ^ leading = ""; + System::Text::StringBuilder ^ sb = gcnew System::Text::StringBuilder("["); + + for each (System::Object ^ obj in list) + { + sb->Append(leading); + leading = ", "; + + if (QpidTypeCheck::ObjectIsMap(obj)) + { + sb->Append(MapAsString((System::Collections::Generic::Dictionary< + System::String^, System::Object^> ^)obj)); + } + else if (QpidTypeCheck::ObjectIsList(obj)) + { + sb->Append(ListAsString((System::Collections::ObjectModel::Collection< + System::Object^> ^)obj)); + } + else + sb->Append(obj->ToString()); + } + sb->Append("]"); + + System::String ^ result = gcnew System::String(sb->ToString()); + return result; + } + + System::String ^ Message::AsString(System::Object ^ obj) + { + if (QpidTypeCheck::ObjectIsMap(obj)) + return MapAsString((System::Collections::Generic::Dictionary< + System::String^, System::Object^> ^)obj); + else if (QpidTypeCheck::ObjectIsList(obj)) + return ListAsString((System::Collections::ObjectModel::Collection< + System::Object^> ^)obj); + else + return obj->ToString(); + } }}}} diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Message.h b/qpid/cpp/bindings/qpid/dotnet/src/Message.h index 0a932a907b..99d0b8667e 100644 --- a/qpid/cpp/bindings/qpid/dotnet/src/Message.h +++ b/qpid/cpp/bindings/qpid/dotnet/src/Message.h @@ -58,8 +58,11 @@ namespace Messaging { // Create from object Message(System::Object ^ theValue); - // TODO: Create from bytes - // Message(System::Byte [] ^ bytes); + // Create from byte array + Message(array ^ bytes); + + // Create from byte array slice + Message(array ^ bytes, int offset, int size); // Create from received message Message(::qpid::messaging::Message * msgp); @@ -108,6 +111,11 @@ namespace Messaging { System::Collections::Generic::Dictionary< System::String^, System::Object^> ^ GetProperties(); + void SetProperty(System::String ^ name, System::Object ^ value); + + void SetProperties(System::Collections::Generic::Dictionary< + System::String^, System::Object^> ^ properties); + void SetContent(System::String ^ content); //TODO:: void setContent(Bytes{} bytes, offset, length); @@ -129,6 +137,16 @@ namespace Messaging { System::UInt64 GetContentSize(); + // A message has been returned to managed code through GetContent(). + // Display the content of that System::Object as a string. + System::String ^ AsString(System::Object ^ obj); + + System::String ^ MapAsString(System::Collections::Generic::Dictionary< + System::String^, System::Object^> ^ dict); + + System::String ^ ListAsString(System::Collections::ObjectModel::Collection< + System::Object^> ^ list); + //TODO: EncodingException // Note: encode/decode functions are in TypeTranslator diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp b/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp index c8d85b00ee..04fbb61e87 100644 --- a/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp +++ b/qpid/cpp/bindings/qpid/dotnet/src/Session.cpp @@ -27,6 +27,7 @@ #include "qpid/messaging/exceptions.h" #include "QpidMarshal.h" +#include "Address.h" #include "Session.h" #include "Connection.h" #include "Duration.h" @@ -205,6 +206,54 @@ namespace Messaging { Sender ^ Session::CreateSender (System::String ^ address) + { + System::Exception ^ newException = nullptr; + ::qpid::messaging::Sender * senderp = NULL; + Sender ^ newSender = nullptr; + + try + { + // allocate a native sender + ::qpid::messaging::Sender * senderp = new ::qpid::messaging::Sender ; + + // create the sender + *senderp = sessionp->::qpid::messaging::Session::createSender(QpidMarshal::ToNative(address)); + + // create a managed sender + newSender = gcnew Sender(senderp, this); + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + finally + { + if (newException != nullptr) + { + if (newSender != nullptr) + { + delete newSender; + } + else + { + if (senderp != NULL) + { + delete senderp; + } + } + } + } + if (newException != nullptr) + { + throw newException; + } + + return newSender; + } + + + Sender ^ Session::CreateSender (Address ^ address) { System::Exception ^ newException = nullptr; ::qpid::messaging::Sender * senderp = NULL; @@ -216,7 +265,7 @@ namespace Messaging { ::qpid::messaging::Sender * senderp = new ::qpid::messaging::Sender ; // create the sender - *senderp = sessionp->::qpid::messaging::Session::createSender(QpidMarshal::ToNative(address)); + *senderp = sessionp->::qpid::messaging::Session::createSender(*(address->NativeAddress)); // create a managed sender newSender = gcnew Sender(senderp, this); @@ -251,7 +300,8 @@ namespace Messaging { return newSender; } - Receiver ^ Session::CreateReceiver(System::String ^ address) + + Receiver ^ Session::CreateReceiver(System::String ^ address) { System::Exception ^ newException = nullptr; ::qpid::messaging::Receiver * receiverp = NULL; @@ -299,6 +349,54 @@ namespace Messaging { } + Receiver ^ Session::CreateReceiver(Address ^ address) + { + System::Exception ^ newException = nullptr; + ::qpid::messaging::Receiver * receiverp = NULL; + Receiver ^ newReceiver = nullptr; + + try + { + // allocate a native receiver + receiverp = new ::qpid::messaging::Receiver; + + // create the receiver + *receiverp = sessionp->createReceiver(*(address->NativeAddress)); + + // create a managed receiver + newReceiver = gcnew Receiver(receiverp, this); + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + finally + { + if (newException != nullptr) + { + if (newReceiver != nullptr) + { + delete newReceiver; + } + else + { + if (receiverp != NULL) + { + delete receiverp; + } + } + } + } + if (newException != nullptr) + { + throw newException; + } + + return newReceiver; + } + + Receiver ^ Session::CreateReceiver() { System::Exception ^ newException = nullptr; diff --git a/qpid/cpp/bindings/qpid/dotnet/src/Session.h b/qpid/cpp/bindings/qpid/dotnet/src/Session.h index babb99d30e..4b84eec55f 100644 --- a/qpid/cpp/bindings/qpid/dotnet/src/Session.h +++ b/qpid/cpp/bindings/qpid/dotnet/src/Session.h @@ -45,6 +45,7 @@ namespace Messaging { /// Session is a managed wrapper for a ::qpid::messaging::Session /// + ref class Address; ref class Connection; ref class Duration; ref class Receiver; @@ -99,8 +100,11 @@ namespace Messaging { Receiver ^ NextReceiver(Duration ^ timeout); - Sender ^ CreateSender (System::String ^ address); + Sender ^ CreateSender(System::String ^ address); + Sender ^ CreateSender(Address ^ address); + Receiver ^ CreateReceiver(System::String ^ address); + Receiver ^ CreateReceiver(Address ^ address); Receiver ^ CreateReceiver(); Sender ^ GetSender(System::String ^ name); diff --git a/qpid/cpp/bindings/qpid/dotnet/src/sessionreceiver/org.apache.qpid.messaging.sessionreceiver.csproj b/qpid/cpp/bindings/qpid/dotnet/src/sessionreceiver/org.apache.qpid.messaging.sessionreceiver.csproj index 04ddc17720..8e324a4ec2 100644 --- a/qpid/cpp/bindings/qpid/dotnet/src/sessionreceiver/org.apache.qpid.messaging.sessionreceiver.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/src/sessionreceiver/org.apache.qpid.messaging.sessionreceiver.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {B0A51CEC-30A2-4C2E-90BE-AE95107EAA05} Library @@ -67,7 +67,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging diff --git a/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs b/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs index 923952bff9..5763077637 100644 --- a/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs +++ b/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.cs @@ -83,6 +83,37 @@ namespace Org.Apache.Qpid.Messaging Console.WriteLine("Got raw array size {0}", m2Size); for (UInt64 i = 0; i < m2Size; i++) Console.Write("{0} ", myRaw[i].ToString()); + Console.WriteLine(); + + // + // Raw message creation + // + byte[] rawData = new byte[10]; + for (byte i=0; i<10; i++) + rawData[i] = i; + Message m3 = new Message(rawData); + + byte[] rawDataReadback = new byte[m3.GetContentSize()]; + m3.GetRaw(rawDataReadback); + for (UInt64 i = 0; i < m3.GetContentSize(); i++) + Console.Write("{0} ", rawDataReadback[i].ToString()); + Console.WriteLine(); + + // + // Raw message from array slice + // + byte[] rawData4 = new byte[256]; + for (int i = 0; i <= 255; i++) + rawData4[i] = (byte)i; + + Message m4 = new Message(rawData4, 246, 10); + + byte[] rawDataReadback4 = new byte[m4.GetContentSize()]; + m4.GetRaw(rawDataReadback4); + for (UInt64 i = 0; i < m4.GetContentSize(); i++) + Console.Write("{0} ", rawDataReadback4[i].ToString()); + Console.WriteLine(); + } } } diff --git a/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.csproj b/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.csproj index 5dddc590ad..e4f1175211 100644 --- a/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.csproj +++ b/qpid/cpp/bindings/qpid/dotnet/test/messaging.test/messaging.test.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {AF2FBC78-266C-430C-BC29-9477AB596A36} Exe @@ -67,7 +67,7 @@ {AA5A3B83-5F98-406D-A01C-5A921467A57D} - org.apache.qpid.messaging + Org.Apache.Qpid.Messaging -- cgit v1.2.1