protected bool TryCreateRemoteLink(Attach attach, out AmqpLink link)
{
link = null;
if (this.linkFactory == null)
{
return(false);
}
AmqpLinkSettings linkSettings = AmqpLinkSettings.Create(attach);
Exception error = null;
try
{
link = this.LinkFactory.CreateLink(this, linkSettings);
}
catch (Exception exception)
{
if (Fx.IsFatal(exception))
{
throw;
}
AmqpException amqpException = exception as AmqpException;
if (amqpException != null &&
amqpException.Error != null &&
(amqpException.Error.Condition.Equals(AmqpErrorCode.ResourceLimitExceeded) ||
amqpException.Error.Condition.Equals(AmqpErrorCode.ResourceLocked)))
{
// out of handle or link name exists
throw;
}
AmqpTrace.Provider.AmqpLogError(this, "CreateLink", exception.Message);
// detach requires a handle so the error link has to be attached first
link = new ErrorLink(this, linkSettings);
error = exception;
}
link.RemoteHandle = attach.Handle;
this.linksByRemoteHandle.Add(attach.Handle.Value, link);
if (error != null)
{
link.SafeClose(error);
return(false);
}
return(true);
}