public void Create(string orderId, string Message)
        {
            var item = new Messages()
            {
                OrderID = orderId,
                Message = Message,
                Time    = DateTime.Now
            };

            messagesRepository.Create(item);
        }
Example #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver = new DefaultContractResolver();
            });

            services.AddSwaggerGen(options =>
            {
                options.DefaultLykkeConfiguration("v1", "SlackNotifications Job API");
            });

            var builder         = new ContainerBuilder();
            var settingsManager = Configuration.LoadSettings <AppSettings>();

            Log = CreateLogWithSlack(services, settingsManager);
            builder.RegisterInstance(Log).As <ILog>().SingleInstance();

            var settings = settingsManager.CurrentValue;

            builder.RegisterInstance(settings.SlackNotificationsJobSettings).SingleInstance();
            builder.RegisterType <SlackNotifcationsConsumer>();

            if (!string.IsNullOrEmpty(settings.SlackNotificationsJobSettings.ForwardMonitorMessagesQueueConnString))
            {
                builder.RegisterInstance <IMsgForwarder>(new MsgForwarder(AzureQueueExt.Create(
                                                                              settingsManager.ConnectionString(x => x.SlackNotificationsJobSettings.ForwardMonitorMessagesQueueConnString),
                                                                              "slack-notifications-monitor"))).SingleInstance();
            }
            else
            {
                builder.RegisterInstance <IMsgForwarder>(new MsgForwarderStub()).SingleInstance();
            }

            builder.RegisterType <NotificationFilter>().As <INotificationFilter>().SingleInstance();
            builder
            .RegisterType <SrvSlackNotifications>()
            .WithParameter(TypedParameter.From(settings.SlackIntegration))
            .WithParameter(TypedParameter.From(settings))
            .As <ISlackNotificationSender>();
            builder
            .Register(c => MessagesRepository.Create(settingsManager.Nested(s => s.SlackNotificationsJobSettings.FullMessagesConnString)))
            .As <IMessagesRepository>();

            builder.AddTriggers(pool =>
            {
                pool.AddDefaultConnection(settingsManager.ConnectionString(x => x.SlackNotificationsJobSettings.SharedStorageConnString));
            });

            builder.RegisterType <UnmuteHandler>()
            .As <IStartable>()
            .AutoActivate()
            .SingleInstance();

            builder.Populate(services);

            ApplicationContainer = builder.Build();

            var serviceProvider = new AutofacServiceProvider(ApplicationContainer);

            _triggerHost = new TriggerHost(serviceProvider);
            _triggerHost.ProvideAssembly(typeof(SlackNotifcationsConsumer).Assembly);

            return(serviceProvider);
        }
 public Message Send(Message message)
 {
     message.IsToxic = _sentimentAnalysisService.IsToxic(message.Content);
     return(_messagesRepository.Create(message));
 }
 public IMessage Create(INewMessage m)
 {
     return(_repo.Create(m));
 }