├── .gitattributes
├── .github
└── FUNDING.yml
├── .gitignore
├── Calabonga.Chat.API
├── .editorconfig
├── Calabonga.Chat.API.sln
└── Calabonga.Chat.API
│ ├── Calabonga.Chat.API.Data
│ ├── ApplicationDbContext.cs
│ ├── Base
│ │ └── DbContextBase.cs
│ ├── Calabonga.Chat.API.Data.csproj
│ ├── DatabaseInitialization
│ │ └── DatabaseInitializer.cs
│ ├── IApplicaitonDbContext.cs
│ └── ModelConfigurations
│ │ ├── Base
│ │ ├── AuditableModelConfigurationBase.cs
│ │ └── IdentityModelConfigurationBase.cs
│ │ └── LogModelConfiguration.cs
│ ├── Calabonga.Chat.API.Entities
│ ├── Calabonga.Chat.API.Entities.csproj
│ ├── Core
│ │ ├── AppData.Common.cs
│ │ ├── AppData.Exceptions.cs
│ │ ├── AppData.Messages.cs
│ │ ├── EmailMessage.cs
│ │ ├── IMailMessage.cs
│ │ ├── SendEmailResult.cs
│ │ └── StringExtensions.cs
│ └── Log.cs
│ └── Calabonga.Chat.API.Web
│ ├── AppStart
│ ├── ConfigureServices
│ │ ├── ConfigureServicesAuthentication.cs
│ │ ├── ConfigureServicesBase.cs
│ │ ├── ConfigureServicesControllers.cs
│ │ ├── ConfigureServicesCors.cs
│ │ ├── ConfigureServicesMediator.cs
│ │ ├── ConfigureServicesSignalR.cs
│ │ ├── ConfigureServicesSwagger.cs
│ │ └── ConfigureServicesValidators.cs
│ ├── Configures
│ │ ├── ConfigureCommon.cs
│ │ └── ConfigureEndpoints.cs
│ └── SwaggerFilters
│ │ └── ApplySummariesOperationFilter.cs
│ ├── Calabonga.Chat.API.Web.csproj
│ ├── Controllers
│ ├── LogsReadonly2Controller.cs
│ ├── LogsReadonlyController.cs
│ ├── LogsWritable2Controller.cs
│ └── LogsWritableController.cs
│ ├── Extensions
│ ├── ApplicationBuilderExtensions.cs
│ ├── AssemblyExtensions.cs
│ ├── DateTimeExtensions.cs
│ └── EntityValidatorExtensions.cs
│ ├── Hubs
│ ├── ChatConnection.cs
│ ├── ChatManager.cs
│ ├── ChatUser.cs
│ ├── CommunicationHub.cs
│ └── ICommunicationHub.cs
│ ├── Infrastructure
│ ├── Attributes
│ │ ├── SwaggerFormAttribute.cs
│ │ ├── SwaggerGroupAttribute.cs
│ │ └── ValidateModelStateAttribute.cs
│ ├── Auth
│ │ ├── AuthorizationPolicyProvider.cs
│ │ ├── IdentityHelper.cs
│ │ ├── MicroservicePermissionHandler.cs
│ │ └── PermissionRequirement.cs
│ ├── DependencyInjection
│ │ └── CommonRegistrations.cs
│ ├── Engine
│ │ ├── EntityManagers
│ │ │ └── LogManager.cs
│ │ ├── EntityValidators
│ │ │ └── LogValidator.cs
│ │ └── ViewModelFactories
│ │ │ └── LogViewModelFactory.cs
│ ├── EventLogs
│ │ ├── EventNumbers.cs
│ │ └── LoggerExtensions.cs
│ ├── Factories
│ │ └── Base
│ │ │ ├── IViewModel.cs
│ │ │ ├── IViewModelFactory.cs
│ │ │ └── ViewModelFactory.cs
│ ├── Helpers
│ │ ├── AsyncHelper.cs
│ │ ├── EmailHelper.cs
│ │ ├── EnumHelper.cs
│ │ ├── Utilites.cs
│ │ └── ValidationContextHelper.cs
│ ├── Mappers
│ │ ├── Base
│ │ │ ├── IAutoMapper.cs
│ │ │ ├── MapperConfigurationBase.cs
│ │ │ └── PagedListConverter.cs
│ │ └── LogMapperConfiguration.cs
│ ├── Services
│ │ ├── CacheService.cs
│ │ ├── ICacheService.cs
│ │ ├── ILogService.cs
│ │ └── LogService.cs
│ ├── Settings
│ │ ├── Base
│ │ │ └── ServiceBase.cs
│ │ └── CurrentAppSettings.cs
│ └── Validations
│ │ └── LogValidator.cs
│ ├── Mediator
│ ├── Behaviors
│ │ └── ValidationBehavior.cs
│ ├── LogsReadonly
│ │ ├── GetRoles.cs
│ │ ├── LogGetById.cs
│ │ └── LogGetPaged.cs
│ └── LogsWritable
│ │ ├── LogDeleteItem.cs
│ │ ├── LogPostItem.cs
│ │ └── LogPutItem.cs
│ ├── Middlewares
│ ├── ETagMiddleware.cs
│ └── ErrorHandle.cs
│ ├── Program.cs
│ ├── Startup.cs
│ ├── ViewModels
│ └── LogViewModels
│ │ ├── LogCreateViewModel.cs
│ │ ├── LogUpdateViewModel.cs
│ │ └── LogViewModel.cs
│ ├── appsettings.Development.json
│ ├── appsettings.Production.json
│ └── appsettings.json
├── Calabonga.Chat.AuthServer
├── Calabonga.Chat.AuthServer.sln
└── Calabonga.Chat.AuthServer
│ ├── Calabonga.Chat.AuthServer.Data
│ ├── ApplicationDbContext.cs
│ ├── ApplicationRole.cs
│ ├── ApplicationUser.cs
│ ├── ApplicationUserProfile.cs
│ ├── ApplicationUserStore.cs
│ ├── Base
│ │ └── DbContextBase.cs
│ ├── Calabonga.Chat.AuthServer.Data.csproj
│ ├── DatabaseInitialization
│ │ ├── DatabaseInitializer.cs
│ │ └── UserHelper.cs
│ ├── IApplicaitonDbContext.cs
│ ├── MicroservicePermission.cs
│ └── ModelConfigurations
│ │ ├── ApplicationUserModelConfiguration.cs
│ │ ├── ApplicationUserProfileModelConfiguration.cs
│ │ ├── Base
│ │ ├── AuditableModelConfigurationBase.cs
│ │ └── IdentityModelConfigurationBase.cs
│ │ ├── LogModelConfiguration.cs
│ │ └── MicroservicePermissionModelConfiguration.cs
│ ├── Calabonga.Chat.AuthServer.Entities
│ ├── Calabonga.Chat.AuthServer.Entities.csproj
│ ├── Core
│ │ ├── AppData.Common.cs
│ │ ├── AppData.Exceptions.cs
│ │ └── AppData.Messages.cs
│ └── Log.cs
│ └── Calabonga.Chat.AuthServer.Web
│ ├── AppStart
│ ├── ConfigureServices
│ │ ├── ConfigureServicesAuthentication.cs
│ │ ├── ConfigureServicesBase.cs
│ │ ├── ConfigureServicesControllers.cs
│ │ ├── ConfigureServicesCors.cs
│ │ ├── ConfigureServicesMediator.cs
│ │ ├── ConfigureServicesSwagger.cs
│ │ └── ConfigureServicesValidators.cs
│ ├── Configures
│ │ ├── ConfigureAuthentication.cs
│ │ ├── ConfigureCommon.cs
│ │ └── ConfigureEndpoints.cs
│ ├── IdentityServerConfig.cs
│ ├── MapperRegistration.cs
│ └── SwaggerFilters
│ │ └── ApplySummariesOperationFilter.cs
│ ├── Calabonga.Chat.AuthServer.Web.csproj
│ ├── Controllers
│ ├── Account2Controller.cs
│ ├── AccountController.cs
│ ├── AuthenticationController.cs
│ ├── LogsReadOnlyController.cs
│ ├── LogsReadonly2Controller.cs
│ ├── LogsWritable2Controller.cs
│ └── LogsWritableController.cs
│ ├── Extensions
│ ├── ApplicationBuilderExtensions.cs
│ ├── AssemblyExtensions.cs
│ ├── DateTimeExtensions.cs
│ ├── EntityValidatorExtensions.cs
│ └── IdentityExtensions.cs
│ ├── Infrastructure
│ ├── Attributes
│ │ ├── SwaggerFormAttribute.cs
│ │ ├── SwaggerGroupAttribute.cs
│ │ └── ValidateModelStateAttribute.cs
│ ├── Auth
│ │ ├── ApplicationClaimsPrincipalFactory.cs
│ │ ├── AuthData.cs
│ │ ├── AuthorizationPolicyExtensions.cs
│ │ ├── AuthorizationPolicyProvider.cs
│ │ ├── IdentityServerCorsPolicy.cs
│ │ ├── MicroservicePermissionHandler.cs
│ │ ├── PermissionRequirement.cs
│ │ └── UserIdentity.cs
│ ├── DependencyInjection
│ │ └── CommonRegistrations.cs
│ ├── Engine
│ │ ├── EntityManagers
│ │ │ └── LogManager.cs
│ │ ├── EntityValidators
│ │ │ └── LogValidator.cs
│ │ └── ViewModelFactories
│ │ │ └── LogViewModelFactory.cs
│ ├── EventLogs
│ │ ├── EventNumbers.cs
│ │ └── LoggerExtensions.cs
│ ├── Helpers
│ │ └── ValidationContextHelper.cs
│ ├── Mappers
│ │ ├── ApplicationUserProfileMapperConfiguration.cs
│ │ ├── Base
│ │ │ ├── IAutoMapper.cs
│ │ │ ├── MapperConfigurationBase.cs
│ │ │ └── PagedListConverter.cs
│ │ ├── LogMapperConfiguration.cs
│ │ └── UserMapperConfiguration.cs
│ ├── Services
│ │ ├── AccountService.cs
│ │ ├── CacheService.cs
│ │ ├── IAccountService.cs
│ │ ├── ICacheService.cs
│ │ └── IdentityProfileService.cs
│ └── Settings
│ │ └── CurrentAppSettings.cs
│ ├── Mediator
│ ├── Account
│ │ ├── Profile.cs
│ │ └── Register.cs
│ ├── Behaviors
│ │ └── ValidatorBehavior.cs
│ ├── LogsReadonly
│ │ ├── GetRoles.cs
│ │ ├── LogGetById.cs
│ │ └── LogGetPaged.cs
│ └── LogsWritable
│ │ ├── LogDeleteItem.cs
│ │ ├── LogPostItem.cs
│ │ └── LogPutItem.cs
│ ├── Middlewares
│ ├── ETagMiddleware.cs
│ └── ErrorHandle.cs
│ ├── Program.cs
│ ├── Startup.cs
│ ├── ViewModels
│ ├── AccountViewModels
│ │ ├── LoginViewModel.cs
│ │ ├── RegisterViewModel.cs
│ │ ├── RegisterViewModelValidator.cs
│ │ └── UserProfileViewModel.cs
│ └── LogViewModels
│ │ ├── LogCreateViewModel.cs
│ │ ├── LogUpdateViewModel.cs
│ │ └── LogViewModel.cs
│ ├── Views
│ ├── Authentication
│ │ └── Login.cshtml
│ ├── Shared
│ │ └── _Layout.cshtml
│ ├── _ViewImports.cshtml
│ └── _ViewStart.cshtml
│ ├── appsettings.Development.json
│ ├── appsettings.Production.json
│ ├── appsettings.json
│ ├── tempkey.jwk
│ └── tempkey.rsa
├── Calabonga.Chat.ConsoleClient
├── Calabonga.Chat.ConsoleClient.sln
└── Calabonga.Chat.ConsoleClient
│ ├── Calabonga.Chat.ConsoleClient.csproj
│ ├── MessageHelper.cs
│ ├── Program.cs
│ └── TokenHelper
│ ├── SecurityError.cs
│ ├── SecurityToken.cs
│ └── TokenLoader.cs
├── Calabonga.Chat.JavaScript
├── Calabonga.Chat.JavaScript.sln
└── Calabonga.Chat.JavaScript
│ ├── Calabonga.Chat.JavaScript.csproj
│ ├── Program.cs
│ ├── Startup.cs
│ ├── appsettings.Development.json
│ ├── appsettings.json
│ ├── libman.json
│ └── wwwroot
│ ├── Index.html
│ ├── app.js
│ ├── bootstrap
│ ├── css
│ │ └── bootstrap.min.css
│ └── js
│ │ └── bootstrap.min.js
│ └── microsoft-signalr
│ ├── signalr.js
│ └── signalr.min.js
├── Calabonga.Chat.WinFormClient
├── Calabonga.Chat.WinFormClient.sln
└── Calabonga.Chat.WinFormClient
│ ├── AppData.cs
│ ├── Calabonga.Chat.WinFormClient.csproj
│ ├── Form1.Designer.cs
│ ├── Form1.cs
│ ├── Form1.resx
│ ├── Program.cs
│ └── TokenHelper
│ ├── SecurityError.cs
│ ├── SecurityToken.cs
│ └── TokenLoader.cs
├── Calabonga.Chat.WpfClient
├── Calabonga.Chat.WpfClient.sln
└── Calabonga.Chat.WpfClient
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AssemblyInfo.cs
│ ├── Calabonga.Chat.WpfClient.csproj
│ ├── Converters
│ └── BoolToVisibilityConverter.cs
│ ├── TokenHelper
│ ├── SecurityError.cs
│ ├── SecurityToken.cs
│ └── TokenLoader.cs
│ ├── ViewModels
│ └── ShellViewModel.cs
│ └── Views
│ ├── Shell.xaml
│ └── Shell.xaml.cs
├── LICENSE
├── README.md
├── WpfClient.exe - Shortcut.lnk
├── start_AuthServer.cmd
├── start_ChatApiService_api.cmd
├── start_ConsoleClients_user1.cmd
├── start_ConsoleClients_user2.cmd
└── start_ConsoleClients_user3.cmd
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | custom: https://www.calabonga.net/site/thanks
2 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Data/ApplicationDbContext.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Chat.API.Data.Base;
2 | using Calabonga.Chat.API.Entities;
3 | using Microsoft.EntityFrameworkCore;
4 |
5 | namespace Calabonga.Chat.API.Data
6 | {
7 | ///
8 | /// Database for application
9 | ///
10 | public class ApplicationDbContext : DbContextBase, IApplicationDbContext
11 | {
12 | ///
13 | public ApplicationDbContext(DbContextOptions options) : base(options)
14 | {
15 | }
16 |
17 | #region System
18 |
19 | public DbSet Logs { get; set; }
20 |
21 | #endregion
22 | }
23 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Data/Calabonga.Chat.API.Data.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | enable
6 | 5.0
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | all
15 | runtime; build; native; contentfiles; analyzers; buildtransitive
16 |
17 |
18 |
19 | all
20 | runtime; build; native; contentfiles; analyzers; buildtransitive
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Data/DatabaseInitialization/DatabaseInitializer.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 | using System;
3 |
4 | namespace Calabonga.Chat.API.Data.DatabaseInitialization
5 | {
6 | ///
7 | /// Database Initializer
8 | ///
9 | public static class DatabaseInitializer
10 | {
11 | public static async void Seed(IServiceProvider serviceProvider)
12 | {
13 | using var scope = serviceProvider.CreateScope();
14 | await using var context = scope.ServiceProvider.GetService();
15 |
16 | // Should be uncomment when using UseSqlServer() settings or any other provider.
17 | // This is should not be used when UseInMemoryDatabase()
18 | // context.Database.Migrate();
19 |
20 | // TODO: Add your seed data here
21 |
22 | if (context.ChangeTracker.HasChanges())
23 | {
24 | await context.SaveChangesAsync();
25 | }
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Data/IApplicaitonDbContext.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Chat.API.Entities;
2 | using Microsoft.EntityFrameworkCore;
3 | using Microsoft.EntityFrameworkCore.ChangeTracking;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 |
6 | namespace Calabonga.Chat.API.Data
7 | {
8 | ///
9 | /// Abstraction for Database (EntityFramework)
10 | ///
11 | public interface IApplicationDbContext
12 | {
13 | #region System
14 |
15 | DbSet Logs { get; set; }
16 |
17 | DatabaseFacade Database { get; }
18 |
19 | ChangeTracker ChangeTracker { get; }
20 |
21 | DbSet Set() where TEntity : class;
22 |
23 | int SaveChanges();
24 |
25 | #endregion
26 | }
27 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Data/ModelConfigurations/Base/AuditableModelConfigurationBase.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.EntityFrameworkCore.Entities.Base;
2 | using Microsoft.EntityFrameworkCore;
3 | using Microsoft.EntityFrameworkCore.Metadata.Builders;
4 | using System;
5 |
6 | namespace Calabonga.Chat.API.Data.ModelConfigurations.Base
7 | {
8 | ///
9 | /// Audit-able Model Configuration base
10 | ///
11 | ///
12 | public abstract class AuditableModelConfigurationBase : IEntityTypeConfiguration where T : Auditable
13 | {
14 | public void Configure(EntityTypeBuilder builder)
15 | {
16 | builder.ToTable(TableName());
17 | builder.HasKey(x => x.Id);
18 | builder.Property(x => x.Id).IsRequired();
19 |
20 | // audit
21 | builder.Property(x => x.CreatedAt).IsRequired().HasConversion(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc)).IsRequired();
22 | builder.Property(x => x.CreatedBy).HasMaxLength(256).IsRequired();
23 | builder.Property(x => x.UpdatedAt).HasConversion(v => v.Value, v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
24 | builder.Property(x => x.UpdatedBy).HasMaxLength(256);
25 |
26 | AddBuilder(builder);
27 | }
28 |
29 | ///
30 | /// Add custom properties for your entity
31 | ///
32 | ///
33 | protected abstract void AddBuilder(EntityTypeBuilder builder);
34 |
35 | ///
36 | /// Table name
37 | ///
38 | ///
39 | protected abstract string TableName();
40 | }
41 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Data/ModelConfigurations/Base/IdentityModelConfigurationBase.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.EntityFrameworkCore.Entities.Base;
2 | using Microsoft.EntityFrameworkCore;
3 | using Microsoft.EntityFrameworkCore.Metadata.Builders;
4 |
5 | namespace Calabonga.Chat.API.Data.ModelConfigurations.Base
6 | {
7 | ///
8 | /// Audit-able Model Configuration base
9 | ///
10 | ///
11 | public abstract class IdentityModelConfigurationBase : IEntityTypeConfiguration where T : Identity
12 | {
13 | public void Configure(EntityTypeBuilder builder)
14 | {
15 | builder.ToTable(TableName());
16 | builder.HasKey(x => x.Id);
17 | builder.Property(x => x.Id).IsRequired();
18 |
19 | AddBuilder(builder);
20 | }
21 |
22 | ///
23 | /// Add custom properties for your entity
24 | ///
25 | ///
26 | protected abstract void AddBuilder(EntityTypeBuilder builder);
27 |
28 | ///
29 | /// Table name
30 | ///
31 | ///
32 | protected abstract string TableName();
33 | }
34 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Data/ModelConfigurations/LogModelConfiguration.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Chat.API.Data.ModelConfigurations.Base;
2 | using Calabonga.Chat.API.Entities;
3 | using Microsoft.EntityFrameworkCore.Metadata.Builders;
4 | using System;
5 |
6 | namespace Calabonga.Chat.API.Data.ModelConfigurations
7 | {
8 | ///
9 | /// Entity Type Configuration for Log entity
10 | ///
11 | public class LogModelConfiguration : IdentityModelConfigurationBase
12 | {
13 | protected override void AddBuilder(EntityTypeBuilder builder)
14 | {
15 | builder.Property(x => x.Logger).HasMaxLength(255).IsRequired();
16 | builder.Property(x => x.Level).HasMaxLength(50).IsRequired();
17 | builder.Property(x => x.Message).HasMaxLength(4000).IsRequired();
18 | builder.Property(x => x.CreatedAt).HasConversion(v => v, v => DateTime.SpecifyKind(v, DateTimeKind.Utc)).IsRequired();
19 | builder.Property(x => x.ThreadId).HasMaxLength(255);
20 | builder.Property(x => x.ExceptionMessage).HasMaxLength(2000);
21 | }
22 |
23 | protected override string TableName()
24 | {
25 | return "Logs";
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Entities/Calabonga.Chat.API.Entities.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | enable
6 | 5.0
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Entities/Core/AppData.Common.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Calabonga.Chat.API.Entities.Core
4 | {
5 | ///
6 | /// Static data container
7 | ///
8 | public static partial class AppData
9 | {
10 | ///
11 | /// Current service name
12 | ///
13 | public const string ServiceName = "Module";
14 |
15 | ///
16 | /// "SystemAdministrator"
17 | ///
18 | public const string SystemAdministratorRoleName = "Administrator";
19 |
20 | ///
21 | /// "BusinessOwner"
22 | ///
23 | public const string ManagerRoleName = "Manager";
24 |
25 | ///
26 | /// Roles
27 | ///
28 | public static IEnumerable Roles
29 | {
30 | get
31 | {
32 | yield return SystemAdministratorRoleName;
33 | yield return ManagerRoleName;
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Entities/Core/AppData.Messages.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Calabonga.Chat.API.Entities.Core
3 | {
4 | public static partial class AppData
5 | {
6 | ///
7 | /// Common messages
8 | ///
9 | public static class Messages
10 | {
11 |
12 | ///
13 | /// "Entity successfully deleted"
14 | ///
15 | public static string EntitySuccessfullyDeleted => "Entity successfully deleted";
16 |
17 | ///
18 | /// "Automatically generated by {0}"
19 | ///
20 | public static string ViewModelFactoryGenerationText => "Automatically generated by {0}";
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Entities/Core/EmailMessage.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Calabonga.Chat.API.Entities.Core
3 | {
4 | ///
5 | /// Mail Message to send
6 | ///
7 | public class EmailMessage : IEmailMessage
8 | {
9 |
10 | ///
11 | public EmailMessage()
12 | {
13 | Result = new SendEmailResult();
14 | }
15 |
16 | ///
17 | public string MailTo { get; set; }
18 |
19 | ///
20 | public string Subject { get; set; }
21 |
22 | ///
23 | public string Body { get; set; }
24 |
25 | ///
26 | /// Sent result info
27 | ///
28 | public SendEmailResult Result { get; }
29 |
30 | ///
31 | /// Use HTML in the Body
32 | ///
33 | public bool IsHtml { get; set; }
34 |
35 | ///
36 | public string MailFrom { get; set; }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Entities/Core/IMailMessage.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace Calabonga.Chat.API.Entities.Core
3 | {
4 | ///
5 | /// Mail message interface
6 | ///
7 | public interface IEmailMessage
8 | {
9 | ///
10 | /// Mail to
11 | ///
12 | string MailTo { get; set; }
13 |
14 | ///
15 | /// Mail from
16 | ///
17 | string MailFrom { get; set; }
18 |
19 | ///
20 | /// Subject or title of the message
21 | ///
22 | string Subject { get; set; }
23 |
24 | ///
25 | /// Message content
26 | ///
27 | string Body { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Entities/Core/SendEmailResult.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Calabonga.Chat.API.Entities.Core
4 | {
5 | ///
6 | /// MailKit send result
7 | ///
8 | public class SendEmailResult
9 | {
10 | ///
11 | /// Indicate mail sent
12 | ///
13 | public bool IsSent { get; set; }
14 |
15 | ///
16 | /// Indicate sending in process
17 | ///
18 | public bool IsInProcess { get; set; }
19 |
20 | ///
21 | /// Exception while sending
22 | ///
23 | public Exception Exception { get; set; }
24 | }
25 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Entities/Log.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.EntityFrameworkCore.Entities.Base;
2 | using System;
3 |
4 | namespace Calabonga.Chat.API.Entities
5 | {
6 | ///
7 | /// Logs
8 | ///
9 | public class Log : Identity
10 | {
11 | public DateTime CreatedAt { get; set; }
12 |
13 | public string Logger { get; set; }
14 |
15 | public string Level { get; set; }
16 |
17 | public string Message { get; set; }
18 |
19 | public string ThreadId { get; set; }
20 |
21 | public string ExceptionMessage { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/ConfigureServices/ConfigureServicesBase.cs:
--------------------------------------------------------------------------------
1 | using AutoMapper;
2 | using Calabonga.Chat.API.Data;
3 | using Calabonga.Chat.API.Web.Extensions;
4 | using Calabonga.Chat.API.Web.Infrastructure.Settings;
5 | using Calabonga.UnitOfWork;
6 | using Microsoft.AspNetCore.Mvc;
7 | using Microsoft.EntityFrameworkCore;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.DependencyInjection;
10 |
11 | namespace Calabonga.Chat.API.Web.AppStart.ConfigureServices
12 | {
13 | ///
14 | /// ASP.NET Core services registration and configurations
15 | ///
16 | public static class ConfigureServicesBase
17 | {
18 | ///
19 | /// ConfigureServices Services
20 | ///
21 | ///
22 | ///
23 | public static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
24 | {
25 | services.AddDbContextPool(config =>
26 | {
27 | // UseInMemoryDatabase - This for demo purposes only!
28 | // Should uninstall package "Microsoft.EntityFrameworkCore.InMemory" and install what you need.
29 | // For example: "Microsoft.EntityFrameworkCore.SqlServer"
30 | // uncomment line below to use UseSqlServer(). Don't forget setup connection string in appSettings.json
31 | config.UseInMemoryDatabase("DEMO_PURPOSES_ONLY");
32 | // config.UseSqlServer(configuration.GetConnectionString(nameof(ApplicationDbContext)));
33 | });
34 |
35 | services.AddAutoMapper(typeof(Startup));
36 | services.AddControllers();
37 | services.AddUnitOfWork();
38 | services.AddMemoryCache();
39 | services.AddRouting();
40 | services.Configure(options => { options.SuppressModelStateInvalidFilter = true; });
41 | services.AddOptions();
42 | services.Configure(configuration.GetSection(nameof(CurrentAppSettings)));
43 | services.Configure(options => options.UseRouteSlugify());
44 | services.AddLocalization();
45 | services.AddHttpContextAccessor();
46 | services.AddResponseCaching();
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/ConfigureServices/ConfigureServicesControllers.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 |
3 | namespace Calabonga.Chat.API.Web.AppStart.ConfigureServices
4 | {
5 | ///
6 | /// Configure controllers
7 | ///
8 | public static class ConfigureServicesControllers
9 | {
10 | ///
11 | /// Configure services
12 | ///
13 | ///
14 | public static void ConfigureServices(IServiceCollection services)
15 | {
16 | services.AddControllers();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/ConfigureServices/ConfigureServicesCors.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Configuration;
2 | using Microsoft.Extensions.DependencyInjection;
3 | using System.Linq;
4 |
5 | namespace Calabonga.Chat.API.Web.AppStart.ConfigureServices
6 | {
7 | ///
8 | /// Cors configurations
9 | ///
10 | public class ConfigureServicesCors
11 | {
12 | ///
13 | /// ConfigureServices
14 | ///
15 | ///
16 | ///
17 | public static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
18 | {
19 | var origins = configuration.GetSection("Cors")?.GetSection("Origins")?.Value?.Split(',');
20 | services.AddCors(options =>
21 | {
22 | options.AddPolicy("CorsPolicy", builder =>
23 | {
24 | builder.AllowAnyHeader();
25 | builder.AllowAnyMethod();
26 | if (origins != null && origins.Length > 0)
27 | {
28 | if (origins.Contains("*"))
29 | {
30 | builder.AllowAnyHeader();
31 | builder.AllowAnyMethod();
32 | builder.SetIsOriginAllowed(host => true);
33 | builder.AllowCredentials();
34 | }
35 | else
36 | {
37 | foreach (var origin in origins)
38 | {
39 | builder.WithOrigins(origin);
40 | }
41 | }
42 | }
43 | });
44 | });
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/ConfigureServices/ConfigureServicesMediator.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.AspNetCore.Controllers.Extensions;
2 | using Calabonga.Chat.API.Web.Mediator.Behaviors;
3 | using MediatR;
4 | using Microsoft.Extensions.DependencyInjection;
5 |
6 | namespace Calabonga.Chat.API.Web.AppStart.ConfigureServices
7 | {
8 | ///
9 | /// ASP.NET Core services registration and configurations
10 | ///
11 | public static class ConfigureServicesMediator
12 | {
13 | ///
14 | /// ConfigureServices Services
15 | ///
16 | ///
17 | public static void ConfigureServices(IServiceCollection services)
18 | {
19 | services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidatorBehavior<,>));
20 | services.AddCommandAndQueries(typeof(Startup).Assembly);
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/ConfigureServices/ConfigureServicesSignalR.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 |
3 | namespace Calabonga.Chat.API.Web.AppStart.ConfigureServices
4 | {
5 | ///
6 | /// ASP.NET Core services registration and configurations
7 | ///
8 | public static class ConfigureServicesSignalR
9 | {
10 | ///
11 | /// ConfigureServices Services
12 | ///
13 | ///
14 | public static void ConfigureServices(IServiceCollection services)
15 | {
16 | services.AddSignalR();
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/ConfigureServices/ConfigureServicesValidators.cs:
--------------------------------------------------------------------------------
1 | using FluentValidation;
2 | using Microsoft.Extensions.DependencyInjection;
3 |
4 | namespace Calabonga.Chat.API.Web.AppStart.ConfigureServices
5 | {
6 | ///
7 | /// ASP.NET Core services registration and configurations
8 | ///
9 | public static class ConfigureServicesValidators
10 | {
11 | ///
12 | /// ConfigureServices Services
13 | ///
14 | ///
15 | public static void ConfigureServices(IServiceCollection services)
16 | {
17 | services.AddValidatorsFromAssembly(typeof(Startup).Assembly);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/Configures/ConfigureCommon.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Chat.API.Web.AppStart.ConfigureServices;
2 | using Calabonga.Chat.API.Web.Infrastructure.Auth;
3 | using Calabonga.Chat.API.Web.Middlewares;
4 | using Microsoft.AspNetCore.Builder;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.AspNetCore.Http;
7 | using Microsoft.Extensions.DependencyInjection;
8 | using Microsoft.Extensions.Hosting;
9 |
10 | namespace Calabonga.Chat.API.Web.AppStart.Configures
11 | {
12 | ///
13 | /// Pipeline configuration
14 | ///
15 | public static class ConfigureCommon
16 | {
17 | ///
18 | /// Configure pipeline
19 | ///
20 | ///
21 | ///
22 | ///
23 | public static void Configure(IApplicationBuilder app, IWebHostEnvironment env, AutoMapper.IConfigurationProvider mapper)
24 | {
25 | if (env.IsDevelopment())
26 | {
27 | mapper.AssertConfigurationIsValid();
28 | app.UseDeveloperExceptionPage();
29 | }
30 | else
31 | {
32 | mapper.CompileMappings();
33 | }
34 |
35 | app.UseDefaultFiles();
36 | app.UseStaticFiles(new StaticFileOptions
37 | {
38 | OnPrepareResponse = ctx =>
39 | {
40 | ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=600");
41 | }
42 | });
43 |
44 | app.UseResponseCaching();
45 | app.UseETagger();
46 | app.UseMiddleware(typeof(ErrorHandlingMiddleware));
47 | app.UseSwagger();
48 | app.UseSwaggerUI(ConfigureServicesSwagger.SwaggerSettings);
49 |
50 | // Singleton setup for User Identity
51 | IdentityHelper.Instance.Configure(app.ApplicationServices.GetService()!);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/Configures/ConfigureEndpoints.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Chat.API.Web.Hubs;
2 | using Microsoft.AspNetCore.Builder;
3 |
4 | namespace Calabonga.Chat.API.Web.AppStart.Configures
5 | {
6 | ///
7 | /// Configure pipeline
8 | ///
9 | public static class ConfigureEndpoints
10 | {
11 | ///
12 | /// Configure Routing
13 | ///
14 | ///
15 | public static void Configure(IApplicationBuilder app)
16 | {
17 | app.UseRouting();
18 | app.UseCors("CorsPolicy");
19 | app.UseAuthentication();
20 | app.UseAuthorization();
21 | app.UseEndpoints(endpoints =>
22 | {
23 | endpoints.MapControllers();
24 | endpoints.MapHub("/chat");
25 | });
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/AppStart/SwaggerFilters/ApplySummariesOperationFilter.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc.Controllers;
2 | using Microsoft.OpenApi.Models;
3 | using Swashbuckle.AspNetCore.SwaggerGen;
4 |
5 | namespace Calabonga.Chat.API.Web.AppStart.SwaggerFilters
6 | {
7 | ///
8 | /// Swagger Method Info Generator from summary for
9 | ///
10 | public class ApplySummariesOperationFilter : IOperationFilter
11 | {
12 | ///
13 | public void Apply(OpenApiOperation operation, OperationFilterContext context)
14 | {
15 | var controllerActionDescriptor = context.ApiDescription.ActionDescriptor as ControllerActionDescriptor;
16 | if (controllerActionDescriptor == null)
17 | {
18 | return;
19 | }
20 |
21 | var actionName = controllerActionDescriptor.ActionName;
22 | if (actionName != "GetPaged")
23 | {
24 | return;
25 | }
26 |
27 | var resourceName = controllerActionDescriptor.ControllerName;
28 | operation.Summary = $"Returns paged list of the {resourceName} as IPagedList wrapped with OperationResult";
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Controllers/LogsReadonly2Controller.cs:
--------------------------------------------------------------------------------
1 | using AutoMapper;
2 | using Calabonga.Chat.API.Data;
3 | using Calabonga.Chat.API.Entities;
4 | using Calabonga.Chat.API.Web.Infrastructure.Settings;
5 | using Calabonga.Chat.API.Web.ViewModels.LogViewModels;
6 | using Calabonga.Microservices.Core;
7 | using Calabonga.Microservices.Core.QueryParams;
8 | using Calabonga.Microservices.Core.Validators;
9 | using Calabonga.UnitOfWork;
10 | using Calabonga.UnitOfWork.Controllers.Controllers;
11 | using Microsoft.AspNetCore.Authorization;
12 | using Microsoft.AspNetCore.Mvc;
13 | using Microsoft.Extensions.Options;
14 | using System.Security.Claims;
15 |
16 | namespace Calabonga.Chat.API.Web.Controllers
17 | {
18 | ///
19 | /// ReadOnlyController Demo
20 | ///
21 | [Route("api/[controller]")]
22 | [Authorize]
23 | public class LogsReadonly2Controller : ReadOnlyController
24 | {
25 | private readonly CurrentAppSettings _appSettings;
26 |
27 | ///
28 | public LogsReadonly2Controller(
29 | IOptions appSettings,
30 | IUnitOfWork unitOfWork,
31 | IMapper mapper)
32 | : base(unitOfWork, mapper)
33 | {
34 | _appSettings = appSettings.Value;
35 | }
36 |
37 | [HttpGet("user-roles")]
38 | [Authorize(Policy = "Logs:UserRoles:View")]
39 | public IActionResult Get()
40 | {
41 | //Get Roles for current user
42 | var roles = ClaimsHelper.GetValues((ClaimsIdentity)User.Identity, "role");
43 | return Ok($"Current user ({User.Identity.Name}) have following roles: {string.Join("|", roles)}");
44 | }
45 |
46 | ///
47 | protected override PermissionValidationResult ValidateQueryParams(PagedListQueryParams queryParams)
48 | {
49 | if (queryParams.PageSize <= 0)
50 | {
51 | queryParams.PageSize = _appSettings.PageSize;
52 | }
53 | return new PermissionValidationResult();
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Controllers/LogsReadonlyController.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Chat.API.Entities.Core;
2 | using Calabonga.Chat.API.Web.Mediator.LogsReadonly;
3 | using Calabonga.Microservices.Core.QueryParams;
4 | using MediatR;
5 | using Microsoft.AspNetCore.Authorization;
6 | using Microsoft.AspNetCore.Mvc;
7 | using System;
8 | using System.Threading.Tasks;
9 |
10 | namespace Calabonga.Chat.API.Web.Controllers
11 | {
12 | ///
13 | /// ReadOnlyController Demo
14 | ///
15 | [Route("api/[controller]")]
16 | [Authorize]
17 | public class LogsReadonlyController : ControllerBase
18 | {
19 | private readonly IMediator _mediator;
20 |
21 | public LogsReadonlyController(IMediator mediator)
22 | {
23 | _mediator = mediator;
24 | }
25 |
26 | [HttpGet("[action]")]
27 | [Authorize(Policy = "Logs:UserRoles:View", Roles = AppData.SystemAdministratorRoleName)]
28 | public async Task GetRoles()
29 | {
30 | //Get Roles for current user
31 | return Ok(await _mediator.Send(new GetRolesRequest(), HttpContext.RequestAborted));
32 | }
33 |
34 | [HttpGet("[action]/{id:guid}")]
35 | [ProducesResponseType(200)]
36 | public async Task GetById(Guid id)
37 | {
38 | return Ok(await _mediator.Send(new LogGetByIdRequest(id), HttpContext.RequestAborted));
39 | }
40 |
41 |
42 | [HttpGet("[action]")]
43 | [ProducesResponseType(200)]
44 | public async Task GetPaged([FromQuery] PagedListQueryParams queryParams)
45 | {
46 | return Ok(await _mediator.Send(new LogGetPagedRequest(queryParams), HttpContext.RequestAborted));
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Controllers/LogsWritable2Controller.cs:
--------------------------------------------------------------------------------
1 | using AutoMapper;
2 | using Calabonga.Chat.API.Data;
3 | using Calabonga.Chat.API.Entities;
4 | using Calabonga.Chat.API.Web.Infrastructure.Settings;
5 | using Calabonga.Chat.API.Web.ViewModels.LogViewModels;
6 | using Calabonga.Microservices.Core.QueryParams;
7 | using Calabonga.Microservices.Core.Validators;
8 | using Calabonga.OperationResults;
9 | using Calabonga.UnitOfWork;
10 | using Calabonga.UnitOfWork.Controllers.Controllers;
11 | using Calabonga.UnitOfWork.Controllers.Factories;
12 | using Microsoft.AspNetCore.Authorization;
13 | using Microsoft.AspNetCore.Mvc;
14 | using Microsoft.Extensions.Options;
15 | using System.Threading.Tasks;
16 |
17 | namespace Calabonga.Chat.API.Web.Controllers
18 | {
19 | ///
20 | /// WritableController Demo
21 | ///
22 | [Route("api/[controller]")]
23 | [Authorize]
24 | public class LogsWritable2Controller : WritableController
25 | {
26 | private readonly CurrentAppSettings _appSettings;
27 |
28 | ///
29 | public LogsWritable2Controller(
30 | IOptions appSettings,
31 | IEntityManagerFactory entityManagerFactory,
32 | IUnitOfWork unitOfWork,
33 | IMapper mapper)
34 | : base(entityManagerFactory, unitOfWork, mapper)
35 | {
36 | _appSettings = appSettings.Value;
37 | }
38 |
39 | ///
40 | [Authorize(Policy = "LogsWritable:GetCreateViewModelAsync:View")]
41 | public override Task>> GetViewmodelForCreation()
42 | {
43 | return base.GetViewmodelForCreation();
44 | }
45 |
46 | ///
47 | protected override PermissionValidationResult ValidateQueryParams(PagedListQueryParams queryParams)
48 | {
49 | if (queryParams.PageSize <= 0)
50 | {
51 | queryParams.PageSize = _appSettings.PageSize;
52 | }
53 | return new PermissionValidationResult();
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Controllers/LogsWritableController.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Chat.API.Web.Mediator.LogsReadonly;
2 | using Calabonga.Chat.API.Web.Mediator.LogsWritable;
3 | using Calabonga.Chat.API.Web.ViewModels.LogViewModels;
4 | using Calabonga.Microservices.Core.QueryParams;
5 | using MediatR;
6 | using Microsoft.AspNetCore.Authorization;
7 | using Microsoft.AspNetCore.Mvc;
8 | using System;
9 | using System.Threading.Tasks;
10 |
11 | namespace Calabonga.Chat.API.Web.Controllers
12 | {
13 | ///
14 | /// WritableController Demo
15 | ///
16 | [Route("api/[controller]")]
17 | [Authorize]
18 | public class LogsWritableController : ControllerBase
19 | {
20 | private readonly IMediator _mediator;
21 |
22 | public LogsWritableController(IMediator mediator)
23 | {
24 | _mediator = mediator;
25 | }
26 |
27 |
28 | [HttpGet("[action]/{id:guid}")]
29 | [ProducesResponseType(200)]
30 | public async Task GetById(Guid id)
31 | {
32 | return Ok(await _mediator.Send(new LogGetByIdRequest(id), HttpContext.RequestAborted));
33 | }
34 |
35 |
36 | [HttpGet("[action]")]
37 | [ProducesResponseType(200)]
38 | public async Task GetPaged([FromQuery] PagedListQueryParams queryParams)
39 | {
40 | return Ok(await _mediator.Send(new LogGetPagedRequest(queryParams), HttpContext.RequestAborted));
41 | }
42 |
43 | [HttpPost("[action]")]
44 | public async Task PostItem([FromBody] LogCreateViewModel model)
45 | {
46 | return Ok(await _mediator.Send(new LogPostItemRequest(model), HttpContext.RequestAborted));
47 | }
48 |
49 | [HttpPut("[action]")]
50 | public async Task PutItem([FromBody] LogUpdateViewModel model)
51 | {
52 | return Ok(await _mediator.Send(new LogPutItemRequest(model), HttpContext.RequestAborted));
53 | }
54 |
55 | [HttpDelete("[action]/{id:guid}")]
56 | public async Task DeleteItem(Guid id)
57 | {
58 | return Ok(await _mediator.Send(new LogDeleteItemRequest(id), HttpContext.RequestAborted));
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Extensions/ApplicationBuilderExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Mvc;
2 | using Microsoft.AspNetCore.Mvc.ApplicationModels;
3 | using Microsoft.AspNetCore.Routing;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using System.Text.RegularExpressions;
6 |
7 | namespace Calabonga.Chat.API.Web.Extensions
8 | {
9 | ///
10 | /// Extensions for application class
11 | ///
12 | public static class ApplicationBuilderExtensions
13 | {
14 | ///
15 | /// Use special route slugify for Pegasus routing
16 | ///
17 | ///
18 | public static void UseRouteSlugify(this MvcOptions options)
19 | {
20 | options.Conventions.Add(new RouteTokenTransformerConvention(new SlugifyParameterTransformer()));
21 | }
22 | }
23 |
24 | ///
25 | /// Special route naming convention
26 | ///
27 | public class SlugifyParameterTransformer : IOutboundParameterTransformer
28 | {
29 | ///
30 | public string TransformOutbound(object value)
31 | {
32 | return value == null
33 | ? null
34 | : Regex.Replace(value.ToString(), "([a-z])([A-Z])", "$1-$2").ToLower();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Extensions/AssemblyExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Reflection;
4 |
5 | namespace Calabonga.Chat.API.Web.Extensions
6 | {
7 | ///
8 | /// Assembly helpers
9 | ///
10 | public static class AssemblyExtensions
11 | {
12 | ///
13 | /// Returns types
14 | ///
15 | ///
16 | ///
17 | ///
18 | public static List GetTypesAssignableFrom(this Assembly assembly)
19 | {
20 | return assembly.GetTypesAssignableFrom(typeof(T));
21 | }
22 |
23 | private static List GetTypesAssignableFrom(this Assembly assembly, Type compareType)
24 | {
25 | var ret = new List();
26 | foreach (var type in assembly.DefinedTypes)
27 | {
28 | if (compareType.IsAssignableFrom(type) && compareType != type && !type.IsAbstract)
29 | {
30 | ret.Add(type);
31 | }
32 | }
33 | return ret;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Extensions/EntityValidatorExtensions.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.Microservices.Core.Validators;
2 | using System.Collections.Generic;
3 |
4 | namespace Calabonga.Chat.API.Web.Extensions
5 | {
6 | ///
7 | /// Entity Validator Extensions
8 | ///
9 | public static class EntityValidatorExtensions
10 | {
11 | ///
12 | /// Returns validator from validation results
13 | ///
14 | ///
15 | ///
16 | public static ValidationContext GetResult(this List source)
17 | {
18 | return new ValidationContext(source);
19 | }
20 |
21 | }
22 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Hubs/ChatConnection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Calabonga.Chat.API.Web.Hubs
4 | {
5 | ///
6 | /// User connection form one of the device (web)
7 | ///
8 | public class ChatConnection
9 | {
10 | ///
11 | /// Registered at time
12 | ///
13 | public DateTime ConnectedAt { get; set; }
14 |
15 | ///
16 | /// Connection Id from client
17 | ///
18 | public string ConnectionId { get; set; } = null!;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Hubs/ICommunicationHub.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 |
4 | namespace Calabonga.Chat.API.Web.Hubs
5 | {
6 | public interface ICommunicationHub
7 | {
8 | ///
9 | /// Send message
10 | ///
11 | ///
12 | ///
13 | ///
14 | Task SendMessageAsync(string userName, string message);
15 |
16 | ///
17 | /// Update user list
18 | ///
19 | ///
20 | Task UpdateUsersAsync(IEnumerable users);
21 | }
22 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Infrastructure/Attributes/SwaggerFormAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Calabonga.Chat.API.Web.Infrastructure.Attributes
4 | {
5 | ///
6 | /// Custom attribute for Swagger Upload Form
7 | ///
8 | [AttributeUsage(AttributeTargets.Method)]
9 | public sealed class SwaggerFormAttribute : Attribute
10 | {
11 | ///
12 | public SwaggerFormAttribute(string parameterName, string description, bool hasFileUpload = true)
13 | {
14 | ParameterName = parameterName;
15 | Description = description;
16 | HasFileUpload = hasFileUpload;
17 | }
18 |
19 | ///
20 | /// UploadFile enabled
21 | ///
22 | public bool HasFileUpload { get; }
23 |
24 | ///
25 | /// Name for the parameter
26 | ///
27 | public string ParameterName { get; }
28 |
29 | ///
30 | /// Small description
31 | ///
32 | public string Description { get; }
33 | }
34 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Infrastructure/Attributes/SwaggerGroupAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Calabonga.Chat.API.Web.Infrastructure.Attributes
4 | {
5 | ///
6 | /// Swagger controller group attribute
7 | ///
8 | ///
9 | [AttributeUsage(AttributeTargets.Class)]
10 | public class SwaggerGroupAttribute : Attribute
11 | {
12 | ///
13 | public SwaggerGroupAttribute(string groupName)
14 | {
15 | GroupName = groupName;
16 | }
17 |
18 | ///
19 | /// Group name
20 | ///
21 | public string GroupName { get; }
22 | }
23 | }
--------------------------------------------------------------------------------
/Calabonga.Chat.API/Calabonga.Chat.API/Calabonga.Chat.API.Web/Infrastructure/Attributes/ValidateModelStateAttribute.cs:
--------------------------------------------------------------------------------
1 | using Calabonga.OperationResults;
2 | using Microsoft.AspNetCore.Mvc;
3 | using Microsoft.AspNetCore.Mvc.Filters;
4 | using System.Linq;
5 |
6 | namespace Calabonga.Chat.API.Web.Infrastructure.Attributes
7 | {
8 | ///
9 | /// Custom validation handler for availability to whit OperationResult
10 | ///
11 | public class ValidateModelStateAttribute : ActionFilterAttribute
12 | {
13 | ///
14 | public override void OnActionExecuting(ActionExecutingContext context)
15 | {
16 | if (context.ModelState.IsValid)
17 | {
18 | return;
19 | }
20 |
21 | var operation = OperationResult.CreateResult