private ITopicPublishService <JobContextDto> Get(string topicName, string subscriptionName)
        {
            var config = new TopicConfiguration(servicebusConnectionString,
                                                topicName, subscriptionName, 10, maximumCallbackTimeSpan: TimeSpan.FromMinutes(40));

            return(new TopicPublishService <JobContextDto>(config, serializationService));
        }
 public OrderListener(SubscriptionConfiguration subscriptionConfiguration,
                      TopicConfiguration topicConfiguration,
                      RestaurantManagementContext restaurantManagementContext)
 {
     this._subscriptionClient          = new SubscriptionClient(subscriptionConfiguration.ConnectionString, subscriptionConfiguration.Topic, subscriptionConfiguration.Name);
     _topicClient                      = new TopicClient(topicConfiguration.ConnectionString, topicConfiguration.Name);
     this._restaurantManagementContext = restaurantManagementContext;
 }
Exemplo n.º 3
0
        private ITopicClientWrapper InstantiateTopic(TopicConfiguration config, IVeStatsDClient statsDClient, string topicId)
        {
            _creator.SetTopic(config.ConnectionString, config.TopicName, config.Update);
            var messagingFactory = GetMessagingFactory(config.ConnectionString, config.BatchFlushInterval);
            var client           = messagingFactory.CreateTopicClient(config.TopicName);
            var topic            = new TopicClientWrapper(client, statsDClient);

            _topics.Add(topicId, topic);
            return(topic);
        }
Exemplo n.º 4
0
 public ITopicClientWrapper CreateTopicClient(TopicConfiguration config, IVeStatsDClient statsDClient)
 {
     lock (_lock)
     {
         string topicId = GetHash(config.ConnectionString, config.TopicName);
         if (_topics.ContainsKey(topicId))
         {
             return(_topics[topicId]);
         }
         return(InstantiateTopic(config, statsDClient, topicId));
     }
 }
 public OrderListener(SubscriptionConfiguration subscriptionConfiguration,
                      TopicConfiguration topicConfiguration,
                      RestaurantManagementContext restaurantManagementContext,
                      IMapper mapper)
 {
     this._subscriptionClient          = new SubscriptionClient(subscriptionConfiguration.ConnectionString, subscriptionConfiguration.Topic, subscriptionConfiguration.Name);
     _topicClient                      = new TopicClient(topicConfiguration.ConnectionString, topicConfiguration.Name);
     this._subscriptionConfiguration   = subscriptionConfiguration;
     this._topicConfiguration          = topicConfiguration;
     this._restaurantManagementContext = restaurantManagementContext;
     this._mapper                      = mapper;
     _serviceBusMessageSender          = new ServiceBusMessageSender(topicConfiguration);
 }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddSingleton<ServiceBusConfiguration>(Configuration.GetValue<ServiceBusConfiguration>("OrderPlacedSubscription"));
            //services.AddSingleton<SubscriptionConfiguration>(Configuration.GetSection("ServiceBusConfiguration").Get<ServiceBusConfiguration>());
            // services.AddMvc();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1.0", new Info {
                    Title = "SearchManager", Version = "1.0"
                });
                c.OperationFilter <HeaderFilter>();
            });

            var mapperConfig = new MapperConfiguration(mc => {
                mc.AddProfile(new CommonEntitiyProfile());
            });

            IMapper mapper = mapperConfig.CreateMapper();

            services.AddSingleton(mapper);

            services.AddDbContext <RestaurantManagementContext>(options =>
                                                                options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnectionString"),
                                                                                     b => b.MigrationsAssembly("MT.OnlineRestaurant.DataLayer")));

            services.AddMvc()
            .AddMvcOptions(options =>
            {
                options.Filters.Add(new Authorization());
                //options.Filters.Add(new LoggingFilter(Configuration["ConnectionString:DatabaseConnectionString"]));
                //options.Filters.Add(new ErrorHandlingFilter(Configuration["ConnectionString:DatabaseConnectionString"]));
                options.Filters.Add(new LoggingFilter(Configuration.GetConnectionString("DatabaseConnectionString")));
                options.Filters.Add(new ErrorHandlingFilter(Configuration.GetConnectionString("DatabaseConnectionString")));
            });

            services.AddTransient <IRestaurantBusiness, RestaurantBusiness>();
            services.AddTransient <ISearchRepository, SearchRepository>();
            services.AddTransient <IListener, OrderListener>((service) =>
            {
                var orderPlacedSubscription = Configuration.GetSection("OrderPlacedSubscription").Get <SubscriptionConfiguration>();
                RestaurantManagementContext restaurantManagementContext = service.GetService <RestaurantManagementContext>();
                TopicConfiguration itemOutOfStockTopicConfiguration     = Configuration.GetSection("ItemOutOfStockTopic").Get <TopicConfiguration>();;

                var orderListener = new OrderListener(orderPlacedSubscription, itemOutOfStockTopicConfiguration, restaurantManagementContext, mapper);
                return(orderListener);
            });

            MessageListenerRegistrar.RegisterListners(services.BuildServiceProvider().GetService <IListener>());
        }
Exemplo n.º 7
0
        /// <summary>
        /// This method makes the call to the PutBucketNotificationAsync method.
        /// </summary>
        /// <param name="client">An initialized Amazon S3 client used to call
        /// the PutBucketNotificationAsync method.</param>
        /// <param name="bucketName">The name of the bucket for which
        /// notifications will be turned on.</param>
        /// <param name="snsTopic">The ARN for the Amazon Simple Notification
        /// Service (Amazon SNS) topic associated with the S3 bucket.</param>
        /// <param name="sqsQueue">The ARN of the Amazon Simple Queue Service
        /// (Amazon SQS) queue to which notifications will be pushed.</param>
        public static async Task EnableNotificationAsync(
            IAmazonS3 client,
            string bucketName,
            string snsTopic,
            string sqsQueue)
        {
            try
            {
                // The bucket for which we are setting up notifications.
                var request = new PutBucketNotificationRequest()
                {
                    BucketName = bucketName,
                };

                // Defines the topic to use when sending a notification.
                var topicConfig = new TopicConfiguration()
                {
                    Events = new List <EventType> {
                        EventType.ObjectCreatedCopy
                    },
                    Topic = snsTopic,
                };
                request.TopicConfigurations = new List <TopicConfiguration>
                {
                    topicConfig,
                };
                request.QueueConfigurations = new List <QueueConfiguration>
                {
                    new QueueConfiguration()
                    {
                        Events = new List <EventType> {
                            EventType.ObjectCreatedPut
                        },
                        Queue = sqsQueue,
                    },
                };

                // Now apply the notification settings to the bucket.
                PutBucketNotificationResponse response = await client.PutBucketNotificationAsync(request);
            }
            catch (AmazonS3Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }
        }
Exemplo n.º 8
0
        static void SetBucketNotification()
        {
            try
            {
                FilterRule filterRule1 = new FilterRule();
                filterRule1.Name  = FilterNameEnum.Prefix;
                filterRule1.Value = "smn";
                TopicConfiguration topicConfiguration1 = new TopicConfiguration();
                topicConfiguration1.Id    = "Id001";
                topicConfiguration1.Topic = "urn:smn:globrg:35667523534:topic1";
                topicConfiguration1.Events.Add(EventTypeEnum.ObjectCreatedAll);
                topicConfiguration1.FilterRules = new List <FilterRule>();
                topicConfiguration1.FilterRules.Add(filterRule1);

                FilterRule filterRule2 = new FilterRule();
                filterRule2.Name  = FilterNameEnum.Suffix;
                filterRule2.Value = ".jpg";
                TopicConfiguration topicConfiguration2 = new TopicConfiguration();
                topicConfiguration2.Id    = "Id002";
                topicConfiguration2.Topic = "urn:smn:globrg:35667523535:topic2";
                topicConfiguration2.Events.Add(EventTypeEnum.ObjectRemovedAll);
                topicConfiguration2.FilterRules = new List <FilterRule>();
                topicConfiguration2.FilterRules.Add(filterRule2);

                NotificationConfiguration notificationConfiguration = new NotificationConfiguration();
                notificationConfiguration.TopicConfigurations = new List <TopicConfiguration>();
                notificationConfiguration.TopicConfigurations.Add(topicConfiguration1);
                notificationConfiguration.TopicConfigurations.Add(topicConfiguration2);

                SetBucketNotificationRequest request = new SetBucketNotificationRequest
                {
                    BucketName    = bucketName,
                    Configuration = notificationConfiguration,
                };
                SetBucketNotificationResponse response = client.SetBucketNotification(request);
                Console.WriteLine("Set bucket notification response: {0}", response.StatusCode);
            }
            catch (ObsException ex)
            {
                Console.WriteLine("Exception errorcode: {0}, when set bucket notification.", ex.ErrorCode);
                Console.WriteLine("Exception errormessage: {0}", ex.ErrorMessage);
            }
        }
Exemplo n.º 9
0
        private static ContainerBuilder BuildContainerBuilder()
        {
            var containerBuilder = new ContainerBuilder();

            var serviceFabricConfigurationService = new ServiceFabricConfigurationService();

            var statelessServiceConfiguration = serviceFabricConfigurationService.GetConfigSectionAsStatelessServiceConfiguration();

            // get ServiceBus, Azurestorage config values and register container
            var serviceBusOptions = serviceFabricConfigurationService.GetConfigSectionAs <ServiceBusConfig>("StatelessServiceConfiguration");

            containerBuilder.RegisterInstance(serviceBusOptions).As <IServiceBusConfig>().SingleInstance();

            var topicSubscribeConfig = new TopicConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.SubscriptionName,
                1,
                maximumCallbackTimeSpan: TimeSpan.FromMinutes(60));

            containerBuilder.Register(c =>
            {
                var topicSubscriptionSevice =
                    new TopicSubscriptionSevice <JobContextMessage>(
                        topicSubscribeConfig,
                        c.Resolve <ISerializationService>(),
                        c.Resolve <ILogger>());
                return(topicSubscriptionSevice);
            }).As <ITopicSubscriptionService <JobContextMessage> >();

            containerBuilder.RegisterModule(new StatelessServiceModule(statelessServiceConfiguration));
            containerBuilder.RegisterModule <SerializationModule>();
            containerBuilder.RegisterType <JobContextMessageHandler>().As <IMessageHandler <JobContextMessage> >();

            var summarisationDataOptions = serviceFabricConfigurationService.GetConfigSectionAs <SummarisationDataOptions>("ReferenceDataSection");

            containerBuilder.RegisterModule(new SummarisationModule(summarisationDataOptions));

            return(containerBuilder);
        }
Exemplo n.º 10
0
        static async Task EnableNotificationAsync()
        {
            try
            {
                PutBucketNotificationRequest request = new PutBucketNotificationRequest
                {
                    BucketName = bucketName
                };

                TopicConfiguration c = new TopicConfiguration
                {
                    Events = new List <EventType> {
                        EventType.ObjectCreatedCopy
                    },
                    Topic = snsTopic
                };
                request.TopicConfigurations = new List <TopicConfiguration>();
                request.TopicConfigurations.Add(c);
                request.QueueConfigurations = new List <QueueConfiguration>();
                request.QueueConfigurations.Add(new QueueConfiguration()
                {
                    Events = new List <EventType> {
                        EventType.ObjectCreatedPut
                    },
                    Queue = sqsQueue
                });

                PutBucketNotificationResponse response = await client.PutBucketNotificationAsync(request);
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered on server. Message:'{0}' ", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown error encountered on server. Message:'{0}' ", e.Message);
            }
        }
Exemplo n.º 11
0
        private static ContainerBuilder RegisterQueuesAndTopics(this ContainerBuilder containerBuilder, INcsServiceConfiguration ncsServiceConfiguration)
        {
            var topicSubscriptionConfig = new TopicConfiguration(ncsServiceConfiguration.ServiceBusConnectionString, ncsServiceConfiguration.TopicName, ncsServiceConfiguration.SubscriptionName, 1, maximumCallbackTimeSpan: TimeSpan.FromMinutes(40));

            containerBuilder.Register(c => new TopicSubscriptionSevice <JobContextDto>(
                                          topicSubscriptionConfig,
                                          c.Resolve <IJsonSerializationService>(),
                                          c.Resolve <ILogger>())).As <ITopicSubscriptionService <JobContextDto> >();

            containerBuilder.Register(c =>
            {
                var topicPublishService =
                    new TopicPublishService <JobContextDto>(
                        topicSubscriptionConfig,
                        c.Resolve <IJsonSerializationService>());
                return(topicPublishService);
            }).As <ITopicPublishService <JobContextDto> >();

            containerBuilder.Register(c =>
            {
                var auditPublishConfig = new QueueConfiguration(ncsServiceConfiguration.ServiceBusConnectionString, ncsServiceConfiguration.AuditQueueName, 1);

                return(new QueuePublishService <AuditingDto>(
                           auditPublishConfig,
                           c.Resolve <IJsonSerializationService>()));
            }).As <IQueuePublishService <AuditingDto> >();

            containerBuilder.Register(c =>
            {
                var jobStatusPublishConfig = new QueueConfiguration(ncsServiceConfiguration.ServiceBusConnectionString, ncsServiceConfiguration.JobStatusQueueName, 1);

                return(new QueuePublishService <JobStatusDto>(
                           jobStatusPublishConfig,
                           c.Resolve <IJsonSerializationService>()));
            }).As <IQueuePublishService <JobStatusDto> >();

            return(containerBuilder);
        }
        public void QueueEventsToDispatch(TopicConfiguration topicConfiguration, IEnumerable <EventGridEvent> events)
        {
            foreach (var ev in events)
            {
                var eventsToDispatch = GetMatchingSubscriptions(ev, topicConfiguration.Subscriptions)
                                       .Select(s => new DispatchedEvent
                {
                    DispatcherStrategy = s.DispatchStrategy,
                    EndpointUrl        = s.EndpointUrl,
                    Payload            = ev
                }).ToList();

                if (eventsToDispatch.Count == 0)
                {
                    _logger.LogInfo($"No matching subscriptions found for event {ev.Id} (Type: {ev.EventType})");
                }

                foreach (var de in eventsToDispatch)
                {
                    _eventQueue.Enqueue(de);
                }
            }
        }
 public SNSPublisher(IAmazonSimpleNotificationService amazonSNSClient, TopicConfiguration topicConfiguration)
 {
     _amazonSNSClient = amazonSNSClient;
     _topicConfiguration = topicConfiguration;
 }
Exemplo n.º 14
0
        private static ContainerBuilder BuildContainer()
        {
            Console.WriteLine($"BuildContainer:1");
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterModule <PreValidationServiceModule>();

            Console.WriteLine($"BuildContainer:2");

            // get ServiceBus, Azurestorage config values and register container
            var configHelper      = new ConfigurationHelper();
            var serviceBusOptions =
                configHelper.GetSectionValues <ServiceBusOptions>("ServiceBusSettings");

            containerBuilder.RegisterInstance(serviceBusOptions).As <ServiceBusOptions>().SingleInstance();

            Console.WriteLine($"BuildContainer:3");
            var azureStorageOptions =
                configHelper.GetSectionValues <AzureStorageModel>("AzureStorageSection");

            containerBuilder.RegisterInstance(azureStorageOptions).As <AzureStorageModel>().SingleInstance();
            containerBuilder.RegisterInstance(azureStorageOptions).As <IAzureStorageKeyValuePersistenceServiceConfig>().SingleInstance();

            Console.WriteLine($"BuildContainer:4");

            // register logger
            var loggerOptions =
                configHelper.GetSectionValues <LoggerOptions>("LoggerSection");

            containerBuilder.RegisterInstance(loggerOptions).As <LoggerOptions>().SingleInstance();
            containerBuilder.RegisterModule <LoggerModule>();

            Console.WriteLine($"BuildContainer:5");
            var azureRedisCacheOptions = configHelper.GetSectionValues <AzureRedisCacheOptions>("AzureRedisSection");

            containerBuilder.Register(c => new RedisKeyValuePersistenceServiceConfig()
            {
                ConnectionString = azureRedisCacheOptions.RedisCacheConnectionString,
                KeyExpiry        = new TimeSpan(14, 0, 0, 0)
            }).As <IRedisKeyValuePersistenceServiceConfig>().SingleInstance();

            containerBuilder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .Keyed <IKeyValuePersistenceService>(PersistenceStorageKeys.Redis)
            .As <IKeyValuePersistenceService>()
            .InstancePerLifetimeScope();

            containerBuilder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .Keyed <IKeyValuePersistenceService>(PersistenceStorageKeys.AzureStorage)
            .As <IKeyValuePersistenceService>()
            .As <IStreamableKeyValuePersistenceService>()
            .InstancePerLifetimeScope();

            Console.WriteLine($"BuildContainer:6");

            // service bus queue configuration
            // var topicConfiguration = new ServiceBusTopicConfiguration(
            //    serviceBusOptions.ServiceBusConnectionString,
            //    serviceBusOptions.TopicName,
            //    serviceBusOptions.SubscriptionName);
            var topicSubscribeConfig = new TopicConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.SubscriptionName,
                1,
                maximumCallbackTimeSpan: TimeSpan.FromMinutes(20));

            Console.WriteLine($"BuildContainer:8");
            var auditPublishConfig = new ServiceBusQueueConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.AuditQueueName,
                Environment.ProcessorCount);

            Console.WriteLine($"BuildContainer:9");

            // register queue services
            containerBuilder.Register(c =>
            {
                var topicSubscriptionSevice =
                    new TopicSubscriptionSevice <JobContextDto>(
                        topicSubscribeConfig,
                        c.Resolve <IJsonSerializationService>(),
                        c.Resolve <ILogger>());
                return(topicSubscriptionSevice);
            }).As <ITopicSubscriptionService <JobContextDto> >();

            Console.WriteLine($"BuildContainer:10");
            containerBuilder.Register(c =>
            {
                var topicPublishService =
                    new TopicPublishService <JobContextDto>(
                        topicSubscribeConfig,
                        c.Resolve <IJsonSerializationService>());
                return(topicPublishService);
            }).As <ITopicPublishService <JobContextDto> >();

            Console.WriteLine($"BuildContainer:11");
            containerBuilder.Register(c => new QueuePublishService <AuditingDto>(
                                          auditPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <AuditingDto> >();

            Console.WriteLine($"BuildContainer:12");

            // Job Status Update Service
            var jobStatusPublishConfig = new JobStatusQueueConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.JobStatusQueueName,
                Environment.ProcessorCount);

            Console.WriteLine($"BuildContainer:13");
            containerBuilder.Register(c => new QueuePublishService <JobStatusDto>(
                                          jobStatusPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <JobStatusDto> >();

            Console.WriteLine($"BuildContainer:14");

            // register job context manager
            containerBuilder.RegisterType <DefaultJobContextMessageMapper <JobContextMessage> >().As <IMapper <JobContextMessage, JobContextMessage> >();

            Console.WriteLine($"BuildContainer:16");
            containerBuilder.RegisterType <MessageHandler>().As <IMessageHandler <JobContextMessage> >();

            Console.WriteLine($"BuildContainer:17");

            containerBuilder.RegisterType <JobContextManager <JobContextMessage> >().As <IJobContextManager <JobContextMessage> >().InstancePerLifetimeScope();

            Console.WriteLine($"BuildContainer:19");
            containerBuilder.RegisterType <JobContextMessage>().As <IJobContextMessage>().InstancePerLifetimeScope();

            Console.WriteLine($"BuildContainer:20");

            return(containerBuilder);
        }
        private static ContainerBuilder ConfigureContainerBuilder()
        {
            var builder      = new ContainerBuilder();
            var configHelper = new ConfigurationHelper();

            builder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .As <IKeyValuePersistenceService>().InstancePerLifetimeScope();

            builder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .Keyed <IKeyValuePersistenceService>(IOPersistenceKeys.Blob)
            .As <IStreamableKeyValuePersistenceService>().InstancePerLifetimeScope();

            // register reference data configs
            var referenceDataConfig = configHelper.GetSectionValues <ReferenceDataConfig>("ReferenceDataSection");

            builder.RegisterInstance(referenceDataConfig).As <IReferenceDataConfig>().SingleInstance();

            // get ServiceBus, Azurestorage config values and register container
            var serviceBusOptions = configHelper.GetSectionValues <ServiceBusConfig>("ServiceBusSettings");

            builder.RegisterInstance(serviceBusOptions).As <IServiceBusConfig>().SingleInstance();

            // register logger
            var loggerOptions = configHelper.GetSectionValues <LoggerConfig>("LoggerSection");

            builder.RegisterInstance(loggerOptions).As <ILoggerConfig>().SingleInstance();
            builder.RegisterModule <LoggerModule>();

            var topicAndTaskSectionOptions = configHelper.GetSectionValues <TopicAndTaskSectionConfig>("TopicAndTaskSection");

            builder.RegisterInstance(topicAndTaskSectionOptions).As <ITopicAndTaskSectionConfig>().SingleInstance();

            // auditing
            var auditPublishConfig = new QueueConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.AuditQueueName,
                Environment.ProcessorCount);

            builder.Register(c => new QueuePublishService <AuditingDto>(
                                 auditPublishConfig,
                                 c.Resolve <ISerializationService>()))
            .As <IQueuePublishService <AuditingDto> >();

            // register Jobcontext services
            var topicSubscribeConfig = new TopicConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.FundingCalcSubscriptionName,
                1,
                maximumCallbackTimeSpan: TimeSpan.FromHours(12));

            // register Jobcontext services
            var topicPublishConfig = new TopicConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.DataStoreSubscriptionName,
                Environment.ProcessorCount);

            builder.RegisterModule <StatelessModule>();

            builder.Register(c =>
            {
                var topicSubscriptionSevice =
                    new TopicSubscriptionSevice <JobContextDto>(
                        topicSubscribeConfig,
                        c.Resolve <ISerializationService>(),
                        c.Resolve <ILogger>());
                return(topicSubscriptionSevice);
            }).As <ITopicSubscriptionService <JobContextDto> >();

            builder.Register(c =>
            {
                var topicPublishSevice =
                    new TopicPublishService <JobContextDto>(
                        topicPublishConfig,
                        c.Resolve <ISerializationService>());
                return(topicPublishSevice);
            }).As <ITopicPublishService <JobContextDto> >();

            // register MessageHandler
            builder.RegisterType <MessageHandler>().As <IMessageHandler <JobContextMessage> >().InstancePerLifetimeScope();

            // register Azure blob storage config
            var azureStorageConfig = configHelper.GetSectionValues <AzureStorageOptions>("AzureStorageSection");

            builder.Register(c =>
                             new AzureStorageKeyValuePersistenceServiceConfig(
                                 azureStorageConfig.AzureBlobConnectionString,
                                 azureStorageConfig.AzureBlobContainerName))
            .As <IAzureStorageKeyValuePersistenceServiceConfig>().SingleInstance();

            var jobStatusPublishConfig = new QueueConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.JobStatusQueueName,
                Environment.ProcessorCount);

            builder.Register(c => new QueuePublishService <JobStatusDto>(
                                 jobStatusPublishConfig,
                                 c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <JobStatusDto> >();

            // register ilrfile provider service
            builder.RegisterType <IlrFileProviderService>().As <IIlrFileProviderService>().InstancePerLifetimeScope();

            builder.RegisterType <DefaultJobContextMessageMapper <JobContextMessage> >().As <IMapper <JobContextMessage, JobContextMessage> >().InstancePerLifetimeScope();

            // Register the Autofac magic for Service Fabric support.
            builder.RegisterServiceFabricSupport();

            // Register the stateless service.
            builder.RegisterStatelessService <Stateless>("ESFA.DC.ILR.1819.FundingService.StatelessType");

            return(builder);
        }
 //public ServiceBusTopicSender(ServiceBusConfiguration serviceBusConfiguration)
 //{
 //    this._serviceBusConfiguration = serviceBusConfiguration;
 //    ConfigureTopic();
 //}
 public ServiceBusMessageSender(TopicConfiguration topicConfiguration)
 {
     //this._serviceBusConfiguration = serviceBusConfiguration;
     this._topicConfiguration = topicConfiguration;
     ConfigureTopic();
 }
Exemplo n.º 17
0
        public static ContainerBuilder BuildContainer(IConfigurationHelper configHelper)
        {
            var containerBuilder = new ContainerBuilder();

            // register azure blob storage service
            var azureBlobStorageOptions = configHelper.GetSectionValues <AzureStorageOptions>("AzureStorageSection");

            containerBuilder.Register(c =>
                                      new AzureStorageKeyValuePersistenceConfig(
                                          azureBlobStorageOptions.AzureBlobConnectionString,
                                          azureBlobStorageOptions.AzureBlobContainerName))
            .As <IAzureStorageKeyValuePersistenceServiceConfig>().SingleInstance();

            containerBuilder.Register(c =>
                                      new AzureStorageFileServiceConfiguration()
            {
                ConnectionString = azureBlobStorageOptions.AzureBlobConnectionString
            })
            .As <IAzureStorageFileServiceConfiguration>().SingleInstance();

            containerBuilder.RegisterType <AzureStorageFileService>().As <IFileService>().InstancePerLifetimeScope();

            containerBuilder.RegisterType <AzureStorageKeyValuePersistenceService>()
            .As <IKeyValuePersistenceService>()
            .InstancePerLifetimeScope();

            // register serialization
            containerBuilder.RegisterType <JsonSerializationService>()
            .As <IJsonSerializationService>();
            containerBuilder.RegisterType <XmlSerializationService>()
            .As <IXmlSerializationService>();

            // get ServiceBus, Azurestorage config values and register container
            var serviceBusOptions =
                configHelper.GetSectionValues <ServiceBusOptions>("ServiceBusSettings");

            containerBuilder.RegisterInstance(serviceBusOptions).As <ServiceBusOptions>().SingleInstance();

            // persis data options
            var persistDataConfig =
                configHelper.GetSectionValues <PersistDataConfiguration>("DataStoreSection");

            containerBuilder.RegisterInstance(persistDataConfig).As <PersistDataConfiguration>().SingleInstance();

            // Version info
            var versionInfo = configHelper.GetSectionValues <DataStore.Dto.VersionInfo>("VersionSection");

            containerBuilder.RegisterInstance(versionInfo).As <DataStore.Dto.VersionInfo>().SingleInstance();

            // register logger
            var loggerOptions =
                configHelper.GetSectionValues <LoggerOptions>("LoggerSection");

            containerBuilder.RegisterInstance(loggerOptions).As <LoggerOptions>().SingleInstance();
            containerBuilder.RegisterModule <LoggerModule>();

            // auditing
            var auditPublishConfig = new ServiceBusQueueConfig(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.AuditQueueName,
                Environment.ProcessorCount);

            containerBuilder.Register(c => new QueuePublishService <AuditingDto>(
                                          auditPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <AuditingDto> >();

            // get job status queue config values and register container
            var jobStatusQueueOptions =
                configHelper.GetSectionValues <JobStatusQueueOptions>("JobStatusSection");

            containerBuilder.RegisterInstance(jobStatusQueueOptions).As <JobStatusQueueOptions>().SingleInstance();

            // Job Status Update Service
            var jobStatusPublishConfig = new JobStatusQueueConfig(
                jobStatusQueueOptions.JobStatusConnectionString,
                jobStatusQueueOptions.JobStatusQueueName,
                Environment.ProcessorCount);

            containerBuilder.Register(c => new QueuePublishService <JobStatusDto>(
                                          jobStatusPublishConfig,
                                          c.Resolve <IJsonSerializationService>()))
            .As <IQueuePublishService <JobStatusDto> >();

            // register Jobcontext services
            var topicConfig = new TopicConfiguration(
                serviceBusOptions.ServiceBusConnectionString,
                serviceBusOptions.TopicName,
                serviceBusOptions.DataStoreSubscriptionName,
                1,
                maximumCallbackTimeSpan: TimeSpan.FromMinutes(30));

            containerBuilder.Register(c =>
            {
                var topicSubscriptionSevice =
                    new TopicSubscriptionSevice <JobContextDto>(
                        topicConfig,
                        c.Resolve <IJsonSerializationService>(),
                        c.Resolve <ILogger>());
                return(topicSubscriptionSevice);
            }).As <ITopicSubscriptionService <JobContextDto> >();

            containerBuilder.Register(c =>
            {
                var topicPublishSevice =
                    new TopicPublishService <JobContextDto>(
                        topicConfig,
                        c.Resolve <IJsonSerializationService>());
                return(topicPublishSevice);
            }).As <ITopicPublishService <JobContextDto> >();

            containerBuilder.RegisterType <DateTimeProvider.DateTimeProvider>().As <IDateTimeProvider>().SingleInstance();

            // register message mapper
            containerBuilder.RegisterType <DefaultJobContextMessageMapper <JobContextMessage> >().As <IMapper <JobContextMessage, JobContextMessage> >();

            // register MessageHandler
            containerBuilder.RegisterType <MessageHandler>().As <IMessageHandler <JobContextMessage> >().InstancePerLifetimeScope();

            // register Entrypoint
            containerBuilder.RegisterType <EntryPoint>().As <IEntryPoint>()
            .WithAttributeFiltering()
            .InstancePerLifetimeScope();

            // register ValidationError service
            containerBuilder.Register(b => new ValidationErrors(persistDataConfig.IlrValidationErrorsConnectionString))
            .As <IValidationErrors>().InstancePerDependency();

            containerBuilder.RegisterType <JobContextManager <JobContextMessage> >().As <IJobContextManager <JobContextMessage> >()
            .InstancePerLifetimeScope();

            containerBuilder.RegisterType <JobContextMessage>().As <IJobContextMessage>()
            .InstancePerLifetimeScope();

            RegisterMappers(containerBuilder);
            RegisterProviders(containerBuilder);
            RegisterPersistence(containerBuilder);

            return(containerBuilder);
        }