예제 #1
0
 /// <summary>
 /// Initializes the publisher asynchronously.
 /// </summary>
 /// <param name="description">
 /// The <see cref="PublisherDescription">publisher description</see>.
 /// </param>
 /// <returns>
 /// A <see cref="Task"/> representing the initialization operation.
 /// </returns>
 public Task InitializeAsync(PublisherDescription description)
 {
     return(Task.Run(
                () =>
     {
         Assert.IsFalse(this.IsClosed, "The publisher must not be closed when initialized.");
         this.Description = description;
         this.IsInitialized = true;
     }));
 }
 /// <summary>
 /// Initializes the publisher asynchronously.
 /// </summary>
 /// <param name="description">
 /// The <see cref="PublisherDescription">publisher description</see>.
 /// </param>
 /// <returns>
 /// A <see cref="Task"/> representing the initialization operation.
 /// </returns>
 public Task InitializeAsync(PublisherDescription description)
 {
     return Task.Run(
         () =>
             {
                 Assert.IsFalse(this.IsClosed, "The publisher must not be closed when initialized.");
                 this.Description = description;
                 this.IsInitialized = true;
             });
 }
예제 #3
0
 /// <summary>
 /// Initializes the publisher asynchronously.
 /// </summary>
 /// <param name="description">
 /// The <see cref="PublisherDescription">publisher description</see>.
 /// </param>
 /// <returns>
 /// A <see cref="Task"/> representing the initialization operation.
 /// </returns>
 public async Task InitializeAsync(PublisherDescription description)
 {
     await Task.Run(
         () =>
             {
                 var baseUri = new Uri(NormalizeConnectionString(description.ConnectionString));
                 var entityUri = new Uri(description.Entity, UriKind.Relative);
                 this.PublishUri = new Uri(baseUri, entityUri);
                 this.Certificate = GetClientCertificate(description.Certificate);
             });
 }
예제 #4
0
 /// <summary>
 /// The publisher initialize.
 /// </summary>
 /// <param name="publisher">
 /// The publisher.
 /// </param>
 /// <param name="description">
 /// The description.
 /// </param>
 /// <returns>
 /// The <see cref="IDisposable"/>.
 /// </returns>
 public IDisposable PublisherInitialize(IPublisher publisher, PublisherDescription description)
 {
     return(GetActivityTracker(
                () =>
     {
         var args = new PublisherInitializingEventArgs {
             Description = description
         };
         this.OnPublisherInitializing(publisher, args);
     },
                t =>
     {
         var args = new PublisherInitializedEventArgs {
             Elapsed = t, Description = description
         };
         this.OnPublisherInitialized(publisher, args);
     }));
 }
        /// <summary>
        /// Gets the publisher for the message bus entity asynchronously.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// The <see cref="IPublisher"/>
        /// </returns>
        private IPublisher GetPublisher(string entity)
        {
            return(this.Publishers.GetOrAdd(
                       entity,
                       s =>
            {
                var publisher = this.Description.Factory.CreatePublisher();
                var cs = this.Description.ConnectionString;
                var cert = this.Description.Certificate;

                var description = new PublisherDescription
                {
                    ConnectionString = cs,
                    Certificate = cert,
                    Entity = entity
                };
                publisher.InitializeAsync(description).Wait();
                return publisher;
            }));
        }
        /// <summary>
        /// Initializes the publisher asynchronously.
        /// </summary>
        /// <param name="description">
        /// The <see cref="PublisherDescription">publisher description</see>.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the initialization operation.
        /// </returns>
        public async Task InitializeAsync(PublisherDescription description)
        {
            using (ActivityMonitor.Instance.PublisherInitialize(this, description))
            {
                try
                {
                    await this.EnsureEventHubExistsAsync(description);

                    var cs = description.ConnectionString;
                    var hub = description.Entity;

                    this.Client = EventHubClient.CreateFromConnectionString(cs, hub);
                }
                catch (Exception e)
                {
                    ActivityMonitor.Instance.ReportPublisherException(this, e, false);
                    throw new AzureEventHubException(e.Message, e);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Initializes the publisher asynchronously.
        /// </summary>
        /// <param name="description">
        /// The <see cref="PublisherDescription">publisher description</see>.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the initialization operation.
        /// </returns>
        public async Task InitializeAsync(PublisherDescription description)
        {
            using (ActivityMonitor.Instance.PublisherInitialize(this, description))
            {
                try
                {
                    await this.EnsureEventHubExistsAsync(description);

                    var cs  = description.ConnectionString;
                    var hub = description.Entity;

                    this.Client = EventHubClient.CreateFromConnectionString(cs, hub);
                }
                catch (Exception e)
                {
                    ActivityMonitor.Instance.ReportPublisherException(this, e, false);
                    throw new AzureEventHubException(e.Message, e);
                }
            }
        }
        /// <summary>
        /// Initializes the publisher asynchronously.
        /// </summary>
        /// <param name="description">
        /// The <see cref="PublisherDescription">publisher description</see>.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the initialization operation.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// Occurs when the description is null.
        /// </exception>
        public async Task InitializeAsync(PublisherDescription description)
        {
            using (ActivityMonitor.Instance.PublisherInitialize(this, description))
            {
                if (description == null)
                {
                    var exception = new ArgumentNullException("description");
                    ActivityMonitor.Instance.ReportPublisherException(this, exception, false);
                    throw exception;
                }

                try
                {
                    await this.EnsureTopicExistsAsync(description);
                    this.InitializeClient(description);
                }
                catch (Exception e)
                {
                    ActivityMonitor.Instance.ReportPublisherException(this, e, false);
                    throw new AzureServiceBusException(e.Message, e);
                }
            }
        }
        /// <summary>
        /// Initializes the publisher asynchronously.
        /// </summary>
        /// <param name="description">
        /// The <see cref="PublisherDescription">publisher description</see>.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the initialization operation.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// Occurs when the description is null.
        /// </exception>
        public async Task InitializeAsync(PublisherDescription description)
        {
            using (ActivityMonitor.Instance.PublisherInitialize(this, description))
            {
                if (description == null)
                {
                    var exception = new ArgumentNullException("description");
                    ActivityMonitor.Instance.ReportPublisherException(this, exception, false);
                    throw exception;
                }

                try
                {
                    await this.EnsureTopicExistsAsync(description);

                    this.InitializeClient(description);
                }
                catch (Exception e)
                {
                    ActivityMonitor.Instance.ReportPublisherException(this, e, false);
                    throw new AzureServiceBusException(e.Message, e);
                }
            }
        }
 /// <summary>
 /// The publisher initialize.
 /// </summary>
 /// <param name="publisher">
 /// The publisher.
 /// </param>
 /// <param name="description">
 /// The description.
 /// </param>
 /// <returns>
 /// The <see cref="IDisposable"/>.
 /// </returns>
 public IDisposable PublisherInitialize(IPublisher publisher, PublisherDescription description)
 {
     return GetActivityTracker(
         () =>
             {
                 var args = new PublisherInitializingEventArgs { Description = description };
                 this.OnPublisherInitializing(publisher, args);
             }, 
         t =>
             {
                 var args = new PublisherInitializedEventArgs { Elapsed = t, Description = description };
                 this.OnPublisherInitialized(publisher, args);
             });
 }
        /// <summary>
        /// Gets the publisher for the message bus entity asynchronously.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// The <see cref="IPublisher"/>
        /// </returns>
        private IPublisher GetPublisher(string entity)
        {
            return this.Publishers.GetOrAdd(
                entity, 
                s =>
                    {
                        var publisher = this.Description.Factory.CreatePublisher();
                        var cs = this.Description.ConnectionString;
                        var cert = this.Description.Certificate;

                        var description = new PublisherDescription
                                               {
                                                   ConnectionString = cs,
                                                   Certificate = cert,
                                                   Entity = entity
                                               };
                        publisher.InitializeAsync(description).Wait();
                        return publisher;
                    });
        }