/// <summary>
        /// Initializes a new <see cref="MongoDBSubscriptionTrackingService"/>
        /// </summary>
        /// <param name="options">Options governing the behavior of the service</param>
        public MongoDBSubscriptionTrackingService(MongoDBSubscriptionTrackingOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            var myCollectionName = string.IsNullOrWhiteSpace(options.CollectionName)
                ? DefaultCollectionName
                : options.CollectionName;

            _diagnosticService = options.DiagnosticService ?? DiagnosticService.DefaultInstance;
            _subscriptions     = options.Database.GetCollection <SubscriptionDocument>(myCollectionName);
        }
示例#2
0
        /// <inheritdoc />
        public Task <ISubscriptionTrackingService> CreateSubscriptionTrackingService(IConfiguration configuration)
        {
            var connectionName = configuration?["connectionName"];

            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ConfigurationErrorsException(
                          "Attribute 'connectionName' is required for MongoDB subscription tracking service");
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];

            if (connectionStringSettings == null)
            {
                throw new ConfigurationErrorsException("Connection string settings \"" + connectionName + "\" not found");
            }

            var databaseName   = configuration?["database"];
            var collectionName = configuration?["collection"];
            var database       = MongoDBHelper.Connect(connectionStringSettings, databaseName);
            var subscriptionTrackingOptions = new MongoDBSubscriptionTrackingOptions(database)
            {
                CollectionName = collectionName
            };
            var subscriptionTrackingService = new MongoDBSubscriptionTrackingService(subscriptionTrackingOptions);

            var multicastSection = configuration?.GetSection("multicast");
            var multicastEnabled = multicastSection?.GetValue("enabled", true) ?? false;

            if (!multicastEnabled)
            {
                return(Task.FromResult <ISubscriptionTrackingService>(subscriptionTrackingService));
            }

            var ipAddress = multicastSection.GetValue("address", IPAddress.Parse("239.255.21.80"));
            var port      = multicastSection.GetValue("port", 52181);
            var multicastTrackingService = new MulticastSubscriptionTrackingService(
                subscriptionTrackingService, ipAddress, port);

            return(Task.FromResult <ISubscriptionTrackingService>(multicastTrackingService));
        }
示例#3
0
        /// <inheritdoc />
        public Task <ISubscriptionTrackingService> CreateSubscriptionTrackingService(SubscriptionTrackingElement configuration)
        {
            var connectionName = configuration.GetString("connectionName");

            if (string.IsNullOrWhiteSpace(connectionName))
            {
                throw new ConfigurationErrorsException(
                          "Attribute 'connectionName' is required for MongoDB subscription tracking service");
            }

            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];

            if (connectionStringSettings == null)
            {
                throw new ConfigurationErrorsException("Connection string settings \"" + connectionName + "\" not found");
            }

            var databaseName   = configuration.GetString("database");
            var collectionName = configuration.GetString("collection");
            var database       = MongoDBHelper.Connect(connectionStringSettings, databaseName);
            var subscriptionTrackingOptions = new MongoDBSubscriptionTrackingOptions(database)
            {
                CollectionName = collectionName
            };
            var subscriptionTrackingService = new MongoDBSubscriptionTrackingService(subscriptionTrackingOptions);

            var multicast = configuration.Multicast;

            if (multicast == null || !multicast.Enabled)
            {
                return(Task.FromResult <ISubscriptionTrackingService>(subscriptionTrackingService));
            }

            var multicastTrackingService = new MulticastSubscriptionTrackingService(
                subscriptionTrackingService, multicast.Address, multicast.Port);

            return(Task.FromResult <ISubscriptionTrackingService>(multicastTrackingService));
        }