-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from rajeevmv/master
Merge changes that are part of version 2.0.6
- Loading branch information
Showing
92 changed files
with
2,819 additions
and
1,696 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
773 changes: 579 additions & 194 deletions
773
Microsoft.Azure.Amqp.Android/Microsoft.Azure.Amqp.Android.csproj
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
692 changes: 517 additions & 175 deletions
692
Microsoft.Azure.Amqp.PCL/Microsoft.Azure.Amqp.PCL.csproj
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
709 changes: 530 additions & 179 deletions
709
Microsoft.Azure.Amqp.Uwp/Microsoft.Azure.Amqp.Uwp.csproj
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
//---------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//---------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Amqp | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Amqp.Sasl; | ||
using Microsoft.Azure.Amqp.Transport; | ||
|
||
public class AmqpConnectionFactory | ||
{ | ||
public Task<AmqpConnection> OpenConnectionAsync(string address) | ||
{ | ||
return this.OpenConnectionAsync(address, AmqpConstants.DefaultTimeout); | ||
} | ||
|
||
public Task<AmqpConnection> OpenConnectionAsync(string address, TimeSpan timeout) | ||
{ | ||
return this.OpenConnectionAsync(new Uri(address), timeout); | ||
} | ||
|
||
public Task<AmqpConnection> OpenConnectionAsync(Uri addressUri, TimeSpan timeout) | ||
{ | ||
SaslHandler saslHandler = null; | ||
|
||
if (!string.IsNullOrEmpty(addressUri.UserInfo)) | ||
{ | ||
string[] parts = addressUri.UserInfo.Split(':'); | ||
if (parts.Length > 2) | ||
{ | ||
throw new ArgumentException("addressUri.UserInfo " + addressUri.UserInfo); | ||
} | ||
|
||
string userName = Uri.UnescapeDataString(parts[0]); | ||
string password = parts.Length > 1 ? Uri.UnescapeDataString(parts[1]) : string.Empty; | ||
|
||
#if !PCL | ||
saslHandler = new SaslPlainHandler() { AuthenticationIdentity = userName, Password = password }; | ||
#endif | ||
} | ||
|
||
return OpenConnectionAsync(addressUri, saslHandler, timeout); | ||
} | ||
|
||
public async Task<AmqpConnection> OpenConnectionAsync(Uri addressUri, SaslHandler saslHandler, TimeSpan timeout) | ||
{ | ||
TransportSettings transportSettings; | ||
if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqp, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
transportSettings = new TcpTransportSettings() | ||
{ | ||
Host = addressUri.Host, | ||
Port = addressUri.Port > -1 ? addressUri.Port : AmqpConstants.DefaultPort | ||
}; | ||
} | ||
else if (addressUri.Scheme.Equals(AmqpConstants.SchemeAmqps, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
TcpTransportSettings tcpSettings = new TcpTransportSettings() | ||
{ | ||
Host = addressUri.Host, | ||
Port = addressUri.Port > -1 ? addressUri.Port : AmqpConstants.DefaultSecurePort | ||
}; | ||
|
||
transportSettings = new TlsTransportSettings(tcpSettings) { TargetHost = addressUri.Host }; | ||
} | ||
#if NET45 | ||
else if (addressUri.Scheme.Equals(WebSocketTransport.WebSockets, StringComparison.OrdinalIgnoreCase) || | ||
addressUri.Scheme.Equals(WebSocketTransport.SecureWebSockets, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
transportSettings = new WebSocketTransportSettings() { Uri = addressUri }; | ||
} | ||
#endif | ||
else | ||
{ | ||
throw new NotSupportedException(addressUri.Scheme); | ||
} | ||
|
||
AmqpSettings settings = new AmqpSettings(); | ||
|
||
if (saslHandler != null) | ||
{ | ||
// Provider for "AMQP3100" | ||
SaslTransportProvider saslProvider = new SaslTransportProvider(); | ||
saslProvider.Versions.Add(new AmqpVersion(1, 0, 0)); | ||
saslProvider.AddHandler(saslHandler); | ||
settings.TransportProviders.Add(saslProvider); | ||
} | ||
|
||
// Provider for "AMQP0100" | ||
AmqpTransportProvider amqpProvider = new AmqpTransportProvider(); | ||
amqpProvider.Versions.Add(new AmqpVersion(new Version(1, 0, 0, 0))); | ||
settings.TransportProviders.Add(amqpProvider); | ||
|
||
AmqpTransportInitiator initiator = new AmqpTransportInitiator(settings, transportSettings); | ||
TransportBase transport = await Task.Factory.FromAsync( | ||
(c, s) => initiator.BeginConnect(timeout, c, s), | ||
(r) => initiator.EndConnect(r), | ||
null); | ||
|
||
try | ||
{ | ||
AmqpConnectionSettings connectionSettings = new AmqpConnectionSettings() | ||
{ | ||
ContainerId = Guid.NewGuid().ToString(), | ||
HostName = addressUri.Host | ||
}; | ||
|
||
AmqpConnection connection = new AmqpConnection(transport, settings, connectionSettings); | ||
await connection.OpenAsync(timeout); | ||
|
||
return connection; | ||
} | ||
catch | ||
{ | ||
transport.Abort(); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.