public void EndListening() { _ewsMailWatcher.EndListening(); _ewsMailWatcher = null; //dispose of trello. _settingsService = null; _slackService = null; }
public void Setup() { _provider = TestUtility.InitDI(); _logger = Substitute.For <ILogger <SlackNotificationService> >(); _settings = Substitute.For <SettingsService>((IServiceProvider)null); _httpHandler = _provider.GetRequiredService <HttpClientHandler>() as TestHttpHandler; _service = new SlackNotificationService(_logger, _settings, _provider); _settings.Notifications_Slack_WebHook.Returns("https://webhook.example.com/hook"); }
private static void MailRecieved(MessageReceived[] messages) { var slack = new SlackNotificationService(); foreach (var msg in messages) { var text =string.Format("Support email received FROM: {0} => TO: {1} -- RE: {2}", msg.From, string.Join(",", msg.To), msg.Subject); Console.WriteLine(text); slack.Notify(_supportChannelId, text + " -- please allow a litle while for Trello to find and process the email."); } }
public async Task NotifyTest() { var slackNotificationService = new SlackNotificationService(); var result = await slackNotificationService.Notify( "Test", @"https://hooks.slack.com/services/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", "sasaki_y", "sasaki_y"); Assert.IsFalse(result); }
public async Task TestMethod1() { var slackNotificationService = new SlackNotificationService(); var result = await slackNotificationService.Notify( "Test", "hogehoge", "sasaki_y", "sasaki_y"); Assert.IsFalse(result); }
public Service1() { InitializeComponent(); var settingsService = new SettingsService(); var settings = settingsService.GetSettinngs(); var ewsMailWatcher = new EwsMailWatcher(settings.EwsSettings, settings.TrelloSettings.BoardForwardingEmailAddress); var slackService = new SlackNotificationService(); _supportManager = new SupportManager(ewsMailWatcher, slackService, settingsService); }
public async Task TestSlackNotification() { var settings = Options.Create(new SuperDumpSettings()); var fakeDump = CreateFakeDump(); var pathHelper = new PathHelper("", "", ""); var dumpStorage = new FakeDumpStorage(new FakeDump[] { fakeDump }); var dumpRepo = new DumpRepository(dumpStorage, pathHelper, settings); var slackNotificationService = new SlackNotificationService(settings, dumpRepo); var msg = await slackNotificationService.GetMessageModel(fakeDump.MetaInfo); // these assertions are bare mininum for now. Could be improved. Assert.Equal(1, msg.NumNativeExceptions); var msgStr = await slackNotificationService.GetMessage(fakeDump.MetaInfo); Assert.NotNull(msgStr); }
public SupportManager(EwsMailWatcher ewsMailWatcher, SlackNotificationService slackService, SettingsService settingsService) { _ewsMailWatcher = ewsMailWatcher; _slackService = slackService; _settingsService = settingsService; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns, IAuthorizationHelper authorizationHelper, ILoggerFactory loggerFactory) { Task.Run(async() => await app.ApplicationServices.GetService <BundleRepository>().Populate()); Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate()); Task.Run(async() => await app.ApplicationServices.GetService <IdenticalDumpRepository>().Populate()); if (settings.Value.UseJiraIntegration) { Task.Run(async() => await app.ApplicationServices.GetService <JiraIssueRepository>().Populate()); } if (settings.Value.UseHttpsRedirection) { app.UseHttpsRedirection(); } app.UseStaticFiles(); app.UseRouting(); if (settings.Value.UseLdapAuthentication) { app.UseAuthentication(); app.UseAuthorization(); app.UseSwaggerAuthorizationMiddleware(authorizationHelper); } else { app.UseAuthorization(); app.MapWhen(context => context.Request.Path.StartsWithSegments("/Login") || context.Request.Path.StartsWithSegments("/api/Token"), appBuilder => appBuilder.Run(async context => { context.Response.StatusCode = 404; await context.Response.WriteAsync(""); })); } if (settings.Value.UseAllRequestLogging) { ILogger logger = loggerFactory.CreateLogger("SuperDumpServiceRequests"); app.Use(async(context, next) => { logger.LogRequest(context); await next.Invoke(); }); } app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new CustomAuthorizeFilter(authorizationHelper) } }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "download" }, WorkerCount = settings.Value.MaxConcurrentBundleExtraction }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "analysis" }, WorkerCount = settings.Value.MaxConcurrentAnalysis }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "elasticsearch" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "retention" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "similarityanalysis" }, WorkerCount = 8 }); if (settings.Value.UseJiraIntegration) { app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "jirastatus" }, WorkerCount = 2 }); JiraIssueRepository jiraIssueRepository = app.ApplicationServices.GetService <JiraIssueRepository>(); jiraIssueRepository.StartRefreshHangfireJob(); jiraIssueRepository.StartBundleSearchHangfireJob(); } app.ApplicationServices.GetService <DumpRetentionService>().StartService(); if (settings.Value.UseAmazonSqs) { app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "amazon-sqs-poll" }, WorkerCount = 2 }); AmazonSqsPollingService amazonSqsService = app.ApplicationServices.GetService <AmazonSqsPollingService>(); amazonSqsService.StartHangfireJob(); } GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseHealthChecks("/healthcheck"); LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider()); if (env.EnvironmentName == "Development") { app.UseDeveloperExceptionPage(); BrowserLinkExtensions.UseBrowserLink(app); // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method) } else { app.UseExceptionHandler("/Home/Error"); } app.UseWebSockets(); app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>()); //app.UseMvcWithDefaultRoute(); //app.UseMvc(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns, IAuthorizationHelper authorizationHelper) { app.ApplicationServices.GetService <BundleRepository>().Populate(); app.ApplicationServices.GetService <DumpRepository>().Populate(); Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate()); // configure Logger loggerFactory.AddConsole(Configuration.GetSection("Logging")); var fileLogConfig = Configuration.GetSection("FileLogging"); var logPath = Path.GetDirectoryName(fileLogConfig.GetValue <string>("PathFormat")); Directory.CreateDirectory(logPath); loggerFactory.AddFile(Configuration.GetSection("FileLogging")); loggerFactory.AddFile(Configuration.GetSection("RequestFileLogging")); loggerFactory.AddDebug(); if (settings.Value.UseHttpsRedirection) { app.UseHttpsRedirection(); } if (settings.Value.UseLdapAuthentication) { app.UseAuthentication(); app.UseSwaggerAuthorizationMiddleware(authorizationHelper); //TODO remove? } else { app.MapWhen(context => context.Request.Path.StartsWithSegments("/Login") || context.Request.Path.StartsWithSegments("/api/Token"), //TODO find other way to make the Login controller inaccessible appBuilder => appBuilder.Run(async context => { context.Response.StatusCode = 404; await context.Response.WriteAsync(""); })); } ILogger logger = loggerFactory.CreateLogger("SuperDumpServiceRequests"); app.Use(async(context, next) => { logger.LogRequest(context); await next.Invoke(); }); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new CustomAuthorizeFilter(authorizationHelper) } }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "download" }, WorkerCount = settings.Value.MaxConcurrentBundleExtraction }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "analysis" }, WorkerCount = settings.Value.MaxConcurrentAnalysis }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "elasticsearch" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "retention" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "similarityanalysis" }, WorkerCount = 8 }); app.ApplicationServices.GetService <DumpRetentionService>().StartService(); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); app.UseSwagger(); app.UseSwaggerUi(); LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); BrowserLinkExtensions.UseBrowserLink(app); // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method) } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseWebSockets(); app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>()); app.UseMvcWithDefaultRoute(); }
public NotifySlack(SlackNotificationService slackNotificationService) { _slackNotificationService = slackNotificationService; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns) { app.ApplicationServices.GetService <BundleRepository>().Populate(); app.ApplicationServices.GetService <DumpRepository>().Populate(); //foreach(var b in app.ApplicationServices.GetService<BundleRepository>().GetAll()) { // foreach(var d in app.ApplicationServices.GetService<DumpRepository>().Get(b.BundleId)) { // var msg = sns.GetMessage2(d); // Console.WriteLine(msg); // } //} loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new CustomAuthorizeFilter() } }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "download" }, WorkerCount = settings.Value.MaxConcurrentBundleExtraction }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "analysis" }, WorkerCount = settings.Value.MaxConcurrentAnalysis }); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); app.UseSwagger(); app.UseSwaggerUi(); LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseWebSockets(); app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>()); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <SuperDumpSettings> settings, IServiceProvider serviceProvider, SlackNotificationService sns) { app.ApplicationServices.GetService <BundleRepository>().Populate(); app.ApplicationServices.GetService <DumpRepository>().Populate(); Task.Run(async() => await app.ApplicationServices.GetService <RelationshipRepository>().Populate()); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new CustomAuthorizeFilter() } }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "download" }, WorkerCount = settings.Value.MaxConcurrentBundleExtraction }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "analysis" }, WorkerCount = settings.Value.MaxConcurrentAnalysis }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "elasticsearch" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "retention" }, WorkerCount = 1 }); app.UseHangfireServer(new BackgroundJobServerOptions { Queues = new[] { "similarityanalysis" }, WorkerCount = 8 }); app.ApplicationServices.GetService <DumpRetentionService>().StartService(); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 }); app.UseSwagger(); app.UseSwaggerUi(); LogProvider.SetCurrentLogProvider(new ColouredConsoleLogProvider()); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); BrowserLinkExtensions.UseBrowserLink(app); // using the extension method directly somehow did not work in .NET Core 2.0 (ambiguous extension method) } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseWebSockets(); app.MapWebSocketManager("/cmd", serviceProvider.GetService <WebTermHandler>()); app.UseMvcWithDefaultRoute(); }