1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-13 05:38:25 -05:00

upgrade to aspnet core 3.1

This commit is contained in:
Kyle Spearrin
2020-01-10 08:33:13 -05:00
parent 8026912eeb
commit 29580684a3
60 changed files with 429 additions and 420 deletions

View File

@ -9,8 +9,7 @@ using Bit.Core.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using Azure.Storage.Queues;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -23,7 +22,7 @@ namespace Bit.EventsProcessor
private Task _executingTask;
private CancellationTokenSource _cts;
private CloudQueue _queue;
private QueueClient _queueClient;
private IEventWriteService _eventWriteService;
public AzureQueueHostedService(
@ -67,23 +66,19 @@ namespace Bit.EventsProcessor
var repo = new Core.Repositories.TableStorage.EventRepository(storageConnectionString);
_eventWriteService = new RepositoryEventWriteService(repo);
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient();
_queue = queueClient.GetQueueReference("event");
_queueClient = new QueueClient(storageConnectionString, "event");
while(!cancellationToken.IsCancellationRequested)
{
try
{
var messages = await _queue.GetMessagesAsync(32, TimeSpan.FromMinutes(1),
null, null, cancellationToken);
if(messages.Any())
var messages = await _queueClient.ReceiveMessagesAsync(32);
if(messages.Value?.Any() ?? false)
{
foreach(var message in messages)
foreach(var message in messages.Value)
{
await ProcessQueueMessageAsync(message.AsString, cancellationToken);
await _queue.DeleteMessageAsync(message);
await ProcessQueueMessageAsync(message.MessageText, cancellationToken);
await _queueClient.DeleteMessageAsync(message.MessageId, message.PopReceipt);
}
}
else

View File

@ -2,16 +2,11 @@
<PropertyGroup>
<Version>1.33.0</Version>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Bit.EventsProcessor</RootNamespace>
<UserSecretsId>bitwarden-EventsProcessor</UserSecretsId>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
using Bit.Core.Utilities;
using Serilog.Events;
using Microsoft.Extensions.Hosting;
namespace Bit.EventsProcessor
{
@ -9,11 +9,14 @@ namespace Bit.EventsProcessor
{
public static void Main(string[] args)
{
WebHost
Host
.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging((hostingContext, logging) =>
logging.AddSerilog(hostingContext, e => e.Level >= LogEventLevel.Warning))
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureLogging((hostingContext, logging) =>
logging.AddSerilog(hostingContext, e => e.Level >= LogEventLevel.Warning));
})
.Build()
.Run();
}

View File

@ -6,13 +6,14 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Logging;
namespace Bit.EventsProcessor
{
public class Startup
{
public Startup(IHostingEnvironment env, IConfiguration configuration)
public Startup(IWebHostEnvironment env, IConfiguration configuration)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
Configuration = configuration;
@ -20,7 +21,7 @@ namespace Bit.EventsProcessor
}
public IConfiguration Configuration { get; }
public IHostingEnvironment Environment { get; set; }
public IWebHostEnvironment Environment { get; set; }
public void ConfigureServices(IServiceCollection services)
{
@ -36,18 +37,18 @@ namespace Bit.EventsProcessor
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
IApplicationLifetime appLifetime,
IWebHostEnvironment env,
IHostApplicationLifetime appLifetime,
GlobalSettings globalSettings)
{
IdentityModelEventSource.ShowPII = true;
app.UseSerilog(env, appLifetime, globalSettings);
app.Map("/alive", HandleMapAlive);
}
private static void HandleMapAlive(IApplicationBuilder app)
{
app.Run(async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString()));
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/alive",
async context => await context.Response.WriteAsync(System.DateTime.UtcNow.ToString()));
});
}
}
}