/// <summary> /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. /// </summary> /// <param name="app"></param> /// <param name="env"></param> /// <param name="loggerFactory"></param> /// <param name="context"></param> public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, BatchServerContext context) { // Setup logging loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); var logger = loggerFactory.CreateLogger("GAB.BatchServer.API"); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseDefaultFiles(); app.UseStaticFiles(); app.UseMvc(); if (Configuration.GetValue <bool>("BatchServer:RedirectToHttps")) { // Setup rewriting var options = new RewriteOptions() .AddRedirectToHttps(); app.UseRewriter(options); } // Set the App_Data folder var baseDir = env.ContentRootPath; AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(baseDir, "App_Data")); // Initialize database DbInitializer.Initialize(context, logger, env.IsDevelopment()); // Initialize storage Storage.Initialize(Configuration, logger, env.IsDevelopment()); // Initialize event hub pool EventHubs.Initialize(Configuration, logger); // Setup swagger if (Configuration.GetValue <bool>("BatchServer:SwaggerEnabled")) { // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "GAB Science Lab Batch Server v1.0"); }); } }
private async Task SendEventHubNotificationAsync(Input input, LabUser user, Output output, SeligaParsedOutput seligaOutput) { var client = EventHubs.EventHubClient(_configuration); var messageData = new { inputId = input.InputId, batchId = input.BatchId, outputId = output.OutputId, deploymentId = _configuration["BatchServer:DeploymentId"], user = new { email = user.EMail, fullName = user.FullName, location = user.Location, teamName = user.TeamName, companyName = user.CompanyName, countryCode = user.CountryCode }, score = new { totalItems = seligaOutput.Outputs.Count, maxScore = seligaOutput.MaxScore, avgScore = seligaOutput.AvgScore, totalScore = seligaOutput.TotalScore } }; var message = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(messageData)); if (client == null) { _logger.LogWarning("Event hubs disabled: {message}", message); } else { await client.SendAsync(new Microsoft.Azure.EventHubs.EventData(Encoding.UTF8.GetBytes(message))); } }
public TelemetryRepository(EventHubs eventHubs) { _eventHubs = eventHubs; }
private async Task SendEventHubNotificationAsync(Input input, LabUser user, Output output, OutputContent result) { // Set input URL as external URL var externalStorageBaseUrl = _configuration.GetValue <string>("BatchServer:ExternalStorageBaseUrl"); if (!string.IsNullOrEmpty(externalStorageBaseUrl) && !externalStorageBaseUrl.EndsWith("/")) { externalStorageBaseUrl += "/"; } if (string.IsNullOrEmpty(externalStorageBaseUrl)) { input.Parameters = Storage.InputsContainer.GetBlobReference(input.Parameters).Uri.ToString(); } else { input.Parameters = externalStorageBaseUrl + input.Parameters; } // Send the message to the event hub var client = EventHubs.EventHubClient(_configuration); var messageData = new { inputId = input.InputId, // int batchId = input.BatchId, // Guid outputId = output.OutputId, // int deploymentId = _configuration["BatchServer:DeploymentId"], // string (i.e. "North Europe") user = new { email = user.EMail, // string fullName = user.FullName, // string location = user.Location, // string teamName = user.TeamName, // string companyName = user.CompanyName, // string countryCode = user.CountryCode // string }, score = new { containerId = result.containerid, clientVersion = result.clientversion, ticId = result.ticid, sector = result.sector, camera = result.camera, ccd = result.ccd, ra = result.ra, dec = result.dec, tmag = result.tmag, tpf = input.Parameters, lc = output.Result, per = output.Frequencies, isPlanet = result.isplanet, // double isNotPlanet = result.isnotplanet, // double totalScore = (int)(result.isplanet * 1000) + (int)(result.isnotplanet * 100) // int } }; var message = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(messageData)); if (client == null) { _logger.LogWarning("Event hubs disabled: {message}", message); } else { await client.SendAsync(new Microsoft.Azure.EventHubs.EventData(Encoding.UTF8.GetBytes(message))); } }