Skip to content

Commit

Permalink
rename hub to notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Aug 16, 2018
1 parent 42d3a2d commit 80a49e5
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion bitwarden-core.sln
Expand Up @@ -43,7 +43,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventsProcessor", "src\Even
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Admin", "src\Admin\Admin.csproj", "{B131CEF3-89FB-4C90-ADB0-9E9C4246EB56}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hub", "src\Hub\Hub.csproj", "{28635027-20E5-42FA-B218-B6C878DE5350}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notifications", "src\Notifications\Notifications.csproj", "{28635027-20E5-42FA-B218-B6C878DE5350}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Expand Up @@ -11,19 +11,21 @@
using Microsoft.WindowsAzure.Storage.Queue;
using Newtonsoft.Json;

namespace Bit.Hub
namespace Bit.Notifications
{
public class AzureQueueHostedService : IHostedService, IDisposable
{
private readonly ILogger _logger;
private readonly IHubContext<SyncHub> _hubContext;
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly GlobalSettings _globalSettings;

private Task _executingTask;
private CancellationTokenSource _cts;
private CloudQueue _queue;

public AzureQueueHostedService(ILogger<AzureQueueHostedService> logger, IHubContext<SyncHub> hubContext,
public AzureQueueHostedService(
ILogger<AzureQueueHostedService> logger,
IHubContext<NotificationsHub> hubContext,
GlobalSettings globalSettings)
{
_logger = logger;
Expand Down Expand Up @@ -56,7 +58,7 @@ public void Dispose()

private async Task ExecuteAsync(CancellationToken cancellationToken)
{
var storageAccount = CloudStorageAccount.Parse(_globalSettings.Events.ConnectionString);
var storageAccount = CloudStorageAccount.Parse(_globalSettings.Notifications.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient();
_queue = queueClient.GetQueueReference("notifications");

Expand Down
Expand Up @@ -5,23 +5,23 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;

namespace Bit.Hub
namespace Bit.Notifications
{
[Authorize("Internal")]
[SelfHosted(SelfHostedOnly = true)]
public class NotificationsController : Controller
{
private readonly IHubContext<SyncHub> _syncHubContext;
private readonly IHubContext<NotificationsHub> _hubContext;

public NotificationsController(IHubContext<SyncHub> syncHubContext)
public NotificationsController(IHubContext<NotificationsHub> hubContext)
{
_syncHubContext = syncHubContext;
_hubContext = hubContext;
}

[HttpPost("~/notifications")]
public async Task PostNotification([FromBody]PushNotificationData<object> model)
{
await HubHelpers.SendNotificationToHubAsync(model, _syncHubContext);
await HubHelpers.SendNotificationToHubAsync(model, _hubContext);
}
}
}
4 changes: 2 additions & 2 deletions src/Hub/HubHelpers.cs → src/Notifications/HubHelpers.cs
Expand Up @@ -4,12 +4,12 @@
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;

namespace Bit.Hub
namespace Bit.Notifications
{
public static class HubHelpers
{
public static async Task SendNotificationToHubAsync(PushNotificationData<object> notification,
IHubContext<SyncHub> hubContext, CancellationToken cancellationToken = default(CancellationToken))
IHubContext<NotificationsHub> hubContext, CancellationToken cancellationToken = default(CancellationToken))
{
switch(notification.Type)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Hub/Hub.csproj → src/Notifications/Notifications.csproj
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<Version>1.23.0</Version>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>Bit.Hub</RootNamespace>
<UserSecretsId>bitwarden-Hub</UserSecretsId>
<RootNamespace>Bit.Notifications</RootNamespace>
<UserSecretsId>bitwarden-Notifications</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Hub/SyncHub.cs → src/Notifications/NotificationsHub.cs
Expand Up @@ -3,10 +3,10 @@
using Bit.Core;
using Microsoft.AspNetCore.Authorization;

namespace Bit.Hub
namespace Bit.Notifications
{
[Authorize("Application")]
public class SyncHub : Microsoft.AspNetCore.SignalR.Hub
public class NotificationsHub : Microsoft.AspNetCore.SignalR.Hub
{
public override async Task OnConnectedAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Program.cs → src/Notifications/Program.cs
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace Bit.Hub
namespace Bit.Notifications
{
public class Program
{
Expand Down
Expand Up @@ -15,7 +15,7 @@
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Bit.Hub": {
"Notifications": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:5000",
Expand Down
10 changes: 7 additions & 3 deletions src/Hub/Startup.cs → src/Notifications/Startup.cs
Expand Up @@ -10,7 +10,7 @@
using Microsoft.IdentityModel.Logging;
using Serilog.Events;

namespace Bit.Hub
namespace Bit.Notifications
{
public class Startup
{
Expand Down Expand Up @@ -61,7 +61,11 @@ public void ConfigureServices(IServiceCollection services)
services.AddMvc();

// Hosted Services
services.AddHostedService<AzureQueueHostedService>();
if(!globalSettings.SelfHosted &&
CoreHelpers.SettingHasValue(globalSettings.Notifications?.ConnectionString))
{
services.AddHostedService<AzureQueueHostedService>();
}
}

public void Configure(
Expand Down Expand Up @@ -101,7 +105,7 @@ public void ConfigureServices(IServiceCollection services)
// Add SignlarR
app.UseSignalR(routes =>
{
routes.MapHub<SyncHub>("/sync");
routes.MapHub<NotificationsHub>("/notifications-hub");
});

// Add MVC to the request pipeline.
Expand Down
@@ -1,7 +1,7 @@
using IdentityModel;
using Microsoft.AspNetCore.SignalR;

namespace Bit.Hub
namespace Bit.Notifications
{
public class SubjectUserIdProvider : IUserIdProvider
{
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 80a49e5

Please sign in to comment.