/// <summary> /// Initializes the subscription field. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The subscription.</returns> private SubscriptionDescription GetSubscription(EventHubJobSettings settings) { var topicPath = settings.Subscription.TopicPath; var subscriptionName = settings.Subscription.Name; if (!this.TopicExists) { throw new InvalidOperationException(string.Format("The topic '{0}' does not exist.", topicPath)); } var subscriptionExists = this.NamespaceManager.SubscriptionExists(topicPath, subscriptionName); if (!subscriptionExists) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Creating Subscription '{0}' for topic '{1}'.", subscriptionName, topicPath)); return(this.CreateSubscription(settings.Subscription)); } if (settings.RecreateSubscription) { ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Deleting Subscription '{0}' for topic '{1}'.", subscriptionName, topicPath)); this.NamespaceManager.DeleteSubscription(topicPath, subscriptionName); ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Creating Subscription '{0}' for topic '{1}'.", subscriptionName, topicPath)); return(this.CreateSubscription(settings.Subscription)); } ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Using Subscription '{0}' for topic '{1}'.", subscriptionName, topicPath)); return(this.NamespaceManager.GetSubscription(topicPath, subscriptionName)); }
/// <summary> /// Initializes a new instance of the <see cref="EventHubJobManager" /> class. /// </summary> /// <param name="context">The organization service context.</param> /// <param name="settings">The settings.</param> public EventHubJobManager(CrmDbContext context, EventHubJobSettings settings) { this.Settings = settings; this.organizationId = new Lazy <Guid>(() => GetOrganizationId(context), LazyThreadSafetyMode.PublicationOnly); this.Reset(); }
/// <summary> /// Creates the subscription client. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The subscription client.</returns> private SubscriptionClient GetSubscriptionClient(EventHubJobSettings settings) { if (this.Subscription != null) { var topicPath = this.Subscription.TopicPath; var subscriptionName = this.Subscription.Name; return(SubscriptionClient.CreateFromConnectionString(settings.ConnectionString, topicPath, subscriptionName)); } throw new InvalidOperationException(string.Format("The subscription '{0}' for topic '{1}' is not ready.", settings.Subscription.Name, settings.Subscription.TopicPath)); }
/// <summary> /// Initializes the topic exists field. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The topic exists flag.</returns> private bool GetTopicExists(EventHubJobSettings settings) { var topicPath = settings.Subscription.TopicPath; var exists = this.NamespaceManager.TopicExists(topicPath); if (!exists) { throw new InvalidOperationException(string.Format("The topic '{0}' does not exist.", topicPath)); } return(true); }
/// <summary> /// Initializes the namespace manager field. /// </summary> /// <param name="settings">The settings.</param> /// <returns>The namespace manager.</returns> private static Func <NamespaceManager> CreateNamespaceManager(EventHubJobSettings settings) { return(() => NamespaceManager.CreateFromConnectionString(settings.ConnectionString)); }