Initial Commit of Workspace ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,322 @@
|
||||
# xPushService
|
||||
|
||||
it is a Part of xDashboard Projects on SaherElm IT Center which provides:
|
||||
|
||||
- all requirements to Implement Realtime Communications in a **xDashboard** based Project.
|
||||
|
||||
this module has following dependencies:
|
||||
|
||||
- xModels
|
||||
- xCommons
|
||||
- xDataService
|
||||
- xIdentityService
|
||||
|
||||
all tools which provides realtime communications features in this module constructed based on SignalR library.
|
||||
|
||||
for configure and use this Module refer to DI.XDIHelperExtension.cs file.
|
||||
|
||||
## Implementation
|
||||
|
||||
### Hub
|
||||
|
||||
it is a High Level Communication Endpoint which allow Bi-Directional Communications (Server => Client and Client => Server) using Realtime Connections. which introduced using **SignalR**.
|
||||
|
||||
#### XBaseHub
|
||||
|
||||
all Supported Hubs in **xDashboard** must inherit from this based abstract class, which provides base requirement which used in all Hubs.
|
||||
|
||||
#### XBaseWebRTCHub
|
||||
|
||||
a base abstract class which provides all requirements to establish WebRTC based Communications which called Signalling.
|
||||
|
||||
if you want to Implement WebRTC based Hubs for Audio/Vide/... establish connections. you have to extens from this base abstraction class.
|
||||
|
||||
#### XBaseEntityHub
|
||||
|
||||
an abstract class which Provides all requirements to Implement Entity Manipulations Notifications in your Projects.
|
||||
|
||||
```C#
|
||||
public class XTestEntityHub : XBaseEntityHub<XTest, Guid>, IXTestEntityHub
|
||||
{
|
||||
public XTestEntityHub(ILogger<XBaseHub> logger) : base(logger)
|
||||
{ }
|
||||
}
|
||||
```
|
||||
|
||||
#### XBaseDtoHub
|
||||
|
||||
an abstract class which Provides all requirements to Implement Dto Manipulations Notifications in your Projects.
|
||||
|
||||
```C#
|
||||
public class XTestDtoHub : XBaseDtoHub<XTest, XTestDto, Guid>, IXTestDtoHub
|
||||
{
|
||||
public XTestDtoHub(ILogger<XTestDtoHub> logger) : base(logger)
|
||||
{ }
|
||||
}
|
||||
```
|
||||
|
||||
### Provider
|
||||
|
||||
a Provider is a Service which has access to Hub or Hubs for Realtime Communications in other words Push Notification Enabled Service.
|
||||
|
||||
#### XBaseEntityProvider
|
||||
|
||||
an abstract class which has Repository based Data Manipulation Implemented actions, which used EntityHub for Notifying Entity Changes.
|
||||
|
||||
```C#
|
||||
public class XTestRepositoryProvider : XBaseEntityProvider<XTest, Guid, XTestEntityHub>, IXTestRepositoryProvider
|
||||
{
|
||||
public XTestRepositoryProvider(
|
||||
IXTestRepository repository,
|
||||
IHubContext<XTestEntityHub> hub,
|
||||
XDataServiceConfiguration dataConfiguration,
|
||||
IXIdentityProvider identityProvider = null
|
||||
) : base(
|
||||
hub: hub,
|
||||
repository: repository,
|
||||
identityProvider: identityProvider,
|
||||
dataConfiguration: dataConfiguration
|
||||
)
|
||||
{ }
|
||||
}
|
||||
```
|
||||
|
||||
#### XBaseDtoProvider
|
||||
|
||||
an abstract class which has Service based Data Manipulation Implemented actions, which used DtoHub for Notifying Dto Changes.
|
||||
|
||||
```C#
|
||||
public class XTestServiceProvider : XBaseDtoProvider<XTest, XTestDto, Guid, XTestDtoHub>, IXTestServiceProvider
|
||||
{
|
||||
public XTestServiceProvider(
|
||||
IHubContext<XTestDtoHub> hub,
|
||||
IXTestRepositoryService service,
|
||||
XDataServiceConfiguration dataConfiguration,
|
||||
IXIdentityProvider identityProvider = null
|
||||
) : base(
|
||||
hub: hub,
|
||||
service: service,
|
||||
identityProvider: identityProvider,
|
||||
dataConfiguration: dataConfiguration
|
||||
)
|
||||
{ }
|
||||
}
|
||||
```
|
||||
|
||||
#### XBaseRepositoryProviderController
|
||||
|
||||
an abstract Controller class which has Identity Enabled Services for Authorization and Authentication based Endpoint Providing and also has all default Entity based Provider Service Actions implementation for using in Projects.
|
||||
|
||||
```C#
|
||||
public class XTestRepositoryProviderController : XBaseRepositoryProviderController<XTest, Guid, XTestEntityHub>, IXBaseRepositoryProviderController<XTest, Guid, XTestEntityHub>
|
||||
{
|
||||
public XTestRepositoryProviderController(
|
||||
ILogger<XTestRepositoryProviderController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXTestRepositoryProvider provider,
|
||||
Func<IQueryable<XTest>, IOrderedQueryable<XTest>> defaultOrderBuilder,
|
||||
Func<IQueryable<XTest>, IIncludableQueryable<XTest, object>> defaultIncludeBuilder
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
provider,
|
||||
defaultOrderBuilder,
|
||||
defaultIncludeBuilder
|
||||
)
|
||||
{ }
|
||||
}
|
||||
```
|
||||
|
||||
#### XBaseServiceProviderController
|
||||
|
||||
an abstract Controller class which has Identity Enabled Services for Authorization and Authentication based Endpoint Providing and also has all default Dto based Provider Service Actions implementation for using in Projects.
|
||||
|
||||
```C#
|
||||
public class XTestServiceProviderController : XBaseServiceProviderController<XTest, XTestDto, Guid, XTestDtoHub>, IXBaseServiceProviderController<XTest, XTestDto, Guid, XTestDtoHub>
|
||||
{
|
||||
public XTestServiceProviderController(
|
||||
ILogger<XTestServiceProviderController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider,
|
||||
IXTestServiceProvider provider,
|
||||
Func<IQueryable<XTest>, IOrderedQueryable<XTest>> defaultOrderBuilder,
|
||||
Func<IQueryable<XTest>, IIncludableQueryable<XTest, object>> defaultIncludeBuilder
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider,
|
||||
provider,
|
||||
defaultOrderBuilder,
|
||||
defaultIncludeBuilder
|
||||
)
|
||||
{ }
|
||||
}
|
||||
```
|
||||
|
||||
### Register PushService
|
||||
|
||||
after preparation of all requirements, final steps is Register DataService.there are two main step:
|
||||
|
||||
- **DI Registration**: in this phase, all requirements for Enabling Push Notifications Registered in DI Container.
|
||||
- **Middleware Usage**: in this phase, all registered Hubs enabled using it's Provided routes and then accessible through their Paths.
|
||||
|
||||
#### Configure Service
|
||||
|
||||
this service Configured using this Configuration Model:
|
||||
|
||||
```C#
|
||||
public partial class XPushServiceConfiguration {
|
||||
/// <summary>
|
||||
/// Base route of WebSocket Server ...
|
||||
/// </summary>
|
||||
/// <value>string</value>
|
||||
public string BaseRoute { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// determines log level of signalR ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public object ConnectionLogLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// when client disconnected it's automatically try to reconnect, this
|
||||
/// determines max number of try to connect ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int PushConnectionMaxRetry { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// add support for message protocol ...
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public bool AddSupportMessageProtocol { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// the delay between two connection try ..
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int PushConnectionReconnectDelay { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
you can directly instanced this class and fill it and use it in Service Registration phase for Configuring Service. or Configure Service using App Setting Filling like this:
|
||||
|
||||
```json
|
||||
...
|
||||
"PushServiceConfiguration": {
|
||||
"BaseRoute": "hubs",
|
||||
"AddSupportMessageProtocol": true
|
||||
},
|
||||
...
|
||||
```
|
||||
|
||||
for Register Service and see different Methods:
|
||||
|
||||
```C#
|
||||
...
|
||||
/// <summary>
|
||||
/// Register Module Provided Service on DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="config"></param>
|
||||
public static void AddXPushService(
|
||||
this IServiceCollection services,
|
||||
IConfiguration config,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Register Module Provided Service on DI
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="config"></param>
|
||||
public static void AddXPushService(
|
||||
this IServiceCollection services,
|
||||
XPushServiceConfiguration config,
|
||||
ServiceLifetime lifeTime = ServiceLifetime.Scoped
|
||||
);
|
||||
...
|
||||
```
|
||||
|
||||
and for enable Hubs Middle wares you Have to Introduce your Hubs through an Instance of xPushServiceHelper class and provides it to Middleware Registrations:
|
||||
|
||||
```C#
|
||||
/// <summary>
|
||||
/// Use Module Middlewares on Application Builder
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <param name="helper"></param>
|
||||
public static void UseXPushService(
|
||||
this IApplicationBuilder app,
|
||||
XPushServiceHelper helper
|
||||
);
|
||||
```
|
||||
|
||||
full Service Registration:
|
||||
|
||||
```C#
|
||||
public class Startup
|
||||
{
|
||||
//
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
...
|
||||
Configuration = configuration;
|
||||
...
|
||||
}
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
...
|
||||
//
|
||||
// Push Service ...
|
||||
services.AddXPushService(
|
||||
config: configuration,
|
||||
lifeTime: ServiceLifetime.Scoped
|
||||
);
|
||||
|
||||
//
|
||||
// Register Provider Services ...
|
||||
// since Hubs required Identity Provider, you Have to Register IdentityService as Requirements ...
|
||||
// a Provider Service, Provides Repository (Entity) or Service (Dto) based
|
||||
// Data Manipulation Actions by Supporting Hub Contexts Events ...
|
||||
services.AddScoped<IXTestServiceProvider, XTestServiceProvider>();
|
||||
services.AddScoped<IXTestRepositoryProvider, XTestRepositoryProvider>();
|
||||
...
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
...
|
||||
//
|
||||
// Instance Service Helper ...
|
||||
var pushHelper = new XPushServiceHelper();
|
||||
|
||||
//
|
||||
// Introduce Hubs and their Child paths ...
|
||||
pushHelper.AddHub<XTestDtoHub>("testDto");
|
||||
pushHelper.AddHub<XTestEntityHub>("testEntity");
|
||||
|
||||
//
|
||||
// Use Push Service Middlewares ...
|
||||
app.UseXPushService(pushHelper);
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Maintainer
|
||||
|
||||
Hadi Khazaee asl
|
||||
|
||||
[https://www.saherelm.ir](https://www.saherelm.ir)
|
||||
|
||||
[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com)
|
||||
Binary file not shown.
@@ -0,0 +1,658 @@
|
||||
# xStringService
|
||||
|
||||
it is a Part of xDashboard on SaherElm IT Center which provides:
|
||||
|
||||
- all requirements to Implement String Resource Features in a **xDashboard** based Project.
|
||||
|
||||
this module has following dependencies :
|
||||
|
||||
- xDataService
|
||||
- xPushService
|
||||
- xIdentityService
|
||||
|
||||
for configure and use this Module refer to DI.XDIHelperExtension.cs file.
|
||||
|
||||
## String Resource
|
||||
|
||||
an string resource is a Key/Value based structure which used in Multi Language Applications for accessing Translated of Spcified Values by Key, in Specified Languages.
|
||||
this architecture is very useful for implementing other services in an Application. such as Terms and Conditions.
|
||||
|
||||
## Data Persists
|
||||
|
||||
all of Provided features of this Module is works based on Data Persistance. so data models is Very Important.
|
||||
in this section all Data models explained.
|
||||
|
||||
data manipulation done using **xDataService** provided Features.
|
||||
|
||||
- **XString**: an Entity Model for Mapping to Tables.
|
||||
- **XStringDto**: a Data Transfer Object for Representing a Data Model.
|
||||
- **XStringEntityConfiguration**: a Configuration file for XString Entity.
|
||||
- **XStringEntityHub**: a Hub Implementation for XString Entity Model.
|
||||
- **XStringDtoHub**: a Hub Implementation for XStringDto Model.
|
||||
- **XStringEntityRegisterar**: an Implementation class for Dynamically Register XString Entity in a DbContext.
|
||||
- **IXStringRepositoryEvents**: an Interface for Repository Events Describing of XString Entity.
|
||||
- **XStringRepositoryEvents**: an Implementation for Repository Events of XString Entity.
|
||||
- **IXStringKeyGenerator**: an Interface for Describing Key Generator Actions for XString Entity.
|
||||
- **XStringKeyGenerator**: an Implementation for Describing Key Generator Actions for XString Entity.
|
||||
- **IXStringRepository**: an Interface for Describing XString Repository Actions.
|
||||
- **XStringEFRepository**: an Implementation of EF Core based XString Repository Actions.
|
||||
- **XStringMongoRepository**: an Implementation of MongoDb based XString Repository Actions.
|
||||
- **XStringMongoRepository**: an Implementation of MongoDb based XString Repository Actions.
|
||||
- **XStringInMemoryRepository**: an Implementation of InMemory based XString Repository Actions.
|
||||
- **IXStringSeeder**: an Interface for Describe XString DbSeeder actions.
|
||||
- **XStringSeederBase**: an abstraction of Implementation of XString DbSeeder actions.
|
||||
- **IXStringRepositoryProvider**: an Interface for Describing XString Repository Provider (using Hubs) actions.
|
||||
- **XStringRepositoryProvider**: an Implementation of XString Repository Provider (using Hubs) actions.
|
||||
- **IXStringRepositoryService**: an Interface for Describing XString Repository Service Actions (using XStringDto).
|
||||
- **XStringRepositoryService**: an Implementation of XString Repository Service Actions (using XStringDto).
|
||||
- **IXStringServiceProvider**: an Interface for Describing XString Repository Service Actions Provider (using Hubs and XStringDto).
|
||||
- **XStringServiceProvider**: an Implementation of XString Repository Service Actions Provider (using Hubs and XStringDto).
|
||||
- **XStringGraphType**: introduce XString Data model for GraphQL using.
|
||||
- **XStringGraphQuery**: introduce Repositry Implementation of XString model actions as Query Actions for GraphQL using.
|
||||
- **XStringGraphSchema**: introduce XString Query Schema for GraphQL using.
|
||||
- **IXStringGraphQLTypeHelper**: an Interface for Describing XString GraphQL Type Helper Provided Actions.
|
||||
- **IXStringGraphQLTypeHelper**: an Implementation of XString GraphQL Type Helper Provided Actions.
|
||||
|
||||
data presistance almost is a Down Layer works which handled using Service it self.
|
||||
but in some Used cases of Applications Business Logics, for Manipulating resources you can use above Registered Services by Injecting them.
|
||||
|
||||
## Providers
|
||||
|
||||
this module actually used to act as a base Provider for implementing Features based on it.
|
||||
for this purpose, provides some Features which described in this section.
|
||||
|
||||
### String Resource Provider
|
||||
|
||||
some services used XString model for Provide Specially Concept's of Actions. for example Terms and Conditions Services use XString Persisted Resource for Specified Purpose.
|
||||
|
||||
this Module provides some sort of tools for this purpose. which described in this section.
|
||||
|
||||
#### Data Transfer Models
|
||||
|
||||
this service used some Data Transfer Models for Data Providing. which Described in this section.
|
||||
|
||||
```C#
|
||||
public class XLocaleResourceDto : XBaseDto
|
||||
{
|
||||
public string Language { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class XResourceDto : XBaseDto
|
||||
{
|
||||
public string Resource { get; set; }
|
||||
public IEnumerable<XLocaleResourceDto> Locales { get; set; } = new HashSet<XLocaleResourceDto>();
|
||||
}
|
||||
```
|
||||
|
||||
#### IXBaseStringResourceProvider
|
||||
|
||||
an interface for Describe Provided Actions of Resource based Service.
|
||||
|
||||
```C#
|
||||
/// <summary>
|
||||
/// a Base Class for Handling Resources Based on Specified Types on
|
||||
/// String Resources Use ...
|
||||
/// such as:
|
||||
/// - Terms and Conditions;
|
||||
/// - Contents;
|
||||
/// - News;
|
||||
/// - etc ...
|
||||
/// </summary>
|
||||
public interface IXBaseStringResourceProvider
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
string Prefix { get; }
|
||||
IXStringServiceProvider Provider { get; }
|
||||
XAppConfiguration AppConfiguration { get; }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Prepare Resource Title by Given Data ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <returns></returns>
|
||||
string GetResourceTitle(string suffix);
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Locales ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="locales"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XStringDto>> Add(
|
||||
string suffix,
|
||||
IEnumerable<XLocaleResourceDto> locales,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Specified Locals ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="locales"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<XStringDto>> AddOrUpdate(
|
||||
string resource,
|
||||
IEnumerable<XLocaleResourceDto> locales,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get Specified Locale ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XLocaleResourceDto> GetLocale(
|
||||
string suffix,
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XResourceDto> AddResource(
|
||||
string suffix,
|
||||
XResourceDto item,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Get Resources of Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<XResourceDto> GetResource(
|
||||
string suffix,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Suffix Resources ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task Remove(
|
||||
string suffix,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task Remove(
|
||||
string resource,
|
||||
string language,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
);
|
||||
#endregion
|
||||
}
|
||||
```
|
||||
|
||||
#### XBaseStringResourceProvider
|
||||
|
||||
an implementation of Provided Actions of Resource based Service.
|
||||
|
||||
```C#
|
||||
/// <summary>
|
||||
/// a Base Class for Handling Resources Based on Specified Types on
|
||||
/// String Resources Use ...
|
||||
/// such as:
|
||||
/// - Terms and Conditions;
|
||||
/// - Contents;
|
||||
/// - News;
|
||||
/// - etc ...
|
||||
/// </summary>
|
||||
public abstract class XBaseStringResourceProvider : IXBaseStringResourceProvider
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
public string Prefix { get; }
|
||||
public IXStringServiceProvider Provider { get; }
|
||||
public XAppConfiguration AppConfiguration { get; }
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor ...
|
||||
public XBaseStringResourceProvider(
|
||||
string prefix,
|
||||
IXStringServiceProvider provider,
|
||||
XAppConfiguration appConfiguration
|
||||
)
|
||||
{
|
||||
//
|
||||
Prefix = prefix;
|
||||
Provider = provider;
|
||||
AppConfiguration = appConfiguration;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
/// <summary>
|
||||
/// Prepare Resource Title by Given Data ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <returns></returns>
|
||||
public string GetResourceTitle(string suffix)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (suffix.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = $"{Prefix}_${suffix}";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Locales ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="locales"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XStringDto>> Add(
|
||||
string suffix,
|
||||
IEnumerable<XLocaleResourceDto> locales,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
var has =
|
||||
locales.HasChild() &&
|
||||
!suffix.IsNullOrEmpty();
|
||||
if (!has)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Resource ID ...
|
||||
string resourceID = GetResourceTitle(suffix);
|
||||
var result = await locales.SelectAsync(async l =>
|
||||
{
|
||||
//
|
||||
// Normalize Language ...
|
||||
if (l.Language.IsNullOrEmpty())
|
||||
{
|
||||
l.Language = AppConfiguration.DefaultLanguage;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Model for Add ...
|
||||
var model = new XStringDto
|
||||
{
|
||||
Language = l.Language,
|
||||
TranslatedValue = l.Value,
|
||||
ResourceTitle = resourceID,
|
||||
};
|
||||
model = await Provider.AddAsync(
|
||||
item: model,
|
||||
saveChanges: true,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
return model;
|
||||
});
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Or Update Specified Locals ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="locales"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XStringDto>> AddOrUpdate(
|
||||
string resource,
|
||||
IEnumerable<XLocaleResourceDto> locales,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
bool isValid =
|
||||
locales.HasChild() &&
|
||||
!resource.IsNullOrEmpty() &&
|
||||
locales.All(l => !l.Value.IsNullOrEmpty() && !l.Language.IsNullOrEmpty());
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Resource ...
|
||||
isValid = resource.Contains(Prefix);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await locales.SelectAsync(async l =>
|
||||
await Provider.AddOrUpdateByLocaleResource(
|
||||
item: l,
|
||||
resource: resource,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
)
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Specified Locale ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XLocaleResourceDto> GetLocale(
|
||||
string suffix,
|
||||
string language = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Normalize ...
|
||||
if (language.IsNullOrEmpty())
|
||||
{
|
||||
language = AppConfiguration.DefaultLanguage;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (suffix.IsNullOrEmpty() || language.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Resource Title ...
|
||||
string resource = GetResourceTitle(suffix);
|
||||
|
||||
//
|
||||
// Check Resource Exists ...
|
||||
var isExists = await Provider.IsResourceExists(
|
||||
resource: resource,
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!isExists)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve and Validate Dto Model ...
|
||||
var model = await Provider.Get(
|
||||
resource: resource,
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (model.IsNullOrDefault())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Result ...
|
||||
var result = model
|
||||
.ToXLocaleResourceDto();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XResourceDto> AddResource(
|
||||
string suffix,
|
||||
XResourceDto item,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (suffix.IsNullOrEmpty() ||
|
||||
item.IsNull() ||
|
||||
!item.Locales.HasChild() ||
|
||||
!item.Locales.All(l => !l.Value.IsNullOrEmpty()))
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Resource ID ...
|
||||
var addedLocals = await Add(
|
||||
suffix: suffix,
|
||||
locales: item.Locales,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!addedLocals.HasChild())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await GetResource(
|
||||
suffix: suffix,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Resources of Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XResourceDto> GetResource(
|
||||
string suffix,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (suffix.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare Resource ID ...
|
||||
string resourceID = GetResourceTitle(suffix);
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
var result = await Provider.GetResource(
|
||||
resource: resourceID,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Suffix Resources ...
|
||||
/// </summary>
|
||||
/// <param name="suffix"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Remove(
|
||||
string suffix,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (suffix.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var resourceID = GetResourceTitle(suffix);
|
||||
await Provider.RemoveResource(
|
||||
resource: resourceID,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove Specified Resource ...
|
||||
/// </summary>
|
||||
/// <param name="resource"></param>
|
||||
/// <param name="language"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Remove(
|
||||
string resource,
|
||||
string language,
|
||||
string connectionId = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
bool isValid =
|
||||
!resource.IsNullOrEmpty() &&
|
||||
!language.IsNullOrEmpty();
|
||||
if (!isValid)
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check resource ID Contains Prefix ...
|
||||
isValid = resource.Contains(Prefix);
|
||||
if (!isValid)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Check Exists ...
|
||||
var isExists = await Provider.IsResourceExists(
|
||||
resource: resource,
|
||||
language: language,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!isExists)
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Remove Resource ...
|
||||
await Provider.Remove(
|
||||
resource: resource,
|
||||
language: language,
|
||||
connectionId: connectionId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
```
|
||||
|
||||
## Implementation
|
||||
|
||||
you have to follow these steps for using this Module.
|
||||
|
||||
- **DI Registration**: in this phase, all Provided Services Registered in DI.
|
||||
- **Middleware Usage**: in this phase, Service Middlewares Use to Handle Features.
|
||||
|
||||
```C#
|
||||
public class Startup
|
||||
{
|
||||
//
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
...
|
||||
//
|
||||
// Register String Service ...
|
||||
services.AddXStringService<XApiDbContext>(
|
||||
lifeTime: lifeTime,
|
||||
repositoryType: xDataService.Constants.XRepositoryType.EF
|
||||
);
|
||||
...
|
||||
}
|
||||
|
||||
//
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
...
|
||||
//
|
||||
// Using String Service ...
|
||||
app.UseXStringService(
|
||||
isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
);
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Maintainer
|
||||
|
||||
Hadi Khazaee asl
|
||||
|
||||
[https://www.saherelm.ir](https://www.saherelm.ir)
|
||||
|
||||
[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com)
|
||||
Binary file not shown.
@@ -0,0 +1,116 @@
|
||||
# xTermsAndConditionsService
|
||||
|
||||
it is a Part of xDashboard on SaherElm IT Center which provides Terms and Conditions Management Futures ...
|
||||
|
||||
its depends on:
|
||||
|
||||
- **xStringService**
|
||||
|
||||
## Providers
|
||||
|
||||
in this module all requirements tools for manage Terms and Conditions Integrated and Provided.
|
||||
|
||||
- **IXTermsAndComditionsProvider**: an Interface for Describe Provided Actions for Terms and Conditions Management.
|
||||
- **XTermsAndComditionsProvider**: an Implementation of Provided Actions for Terms and Conditions Management.
|
||||
- **XTermsHub**: a Hub Implementation for Notifing Terms Changes to Connected Clients.
|
||||
- **IXTermsAndComditionsController**: an Interface for Describe base Terms and Conditions Management Controller Actions.
|
||||
- **XTermsAndComditionsControllerBase**: an Abstract Base Implementation of base Terms and Conditions Management Controller Actions.
|
||||
|
||||
## Implementation
|
||||
|
||||
you have to follow these steps for using this Module.
|
||||
|
||||
### Configure Service
|
||||
|
||||
all of Requirements for Terms and Conditions must be Configured using appSettings and provided by IConfiguration to Modules.
|
||||
|
||||
fo using Service you Have to Configure the Service in you appSettings.json file.
|
||||
|
||||
this configurations mapped to **XTermsAndConditionsServiceConfiguration** class.
|
||||
|
||||
```C#
|
||||
/// <summary>
|
||||
/// Terms and Conditions Configuration ...
|
||||
/// </summary>
|
||||
public class XTermsAndConditionsServiceConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Terms And Conditions Resource Title in XString Table ...
|
||||
/// </summary>
|
||||
public string ResourceTitle { get; set; } = "terms_and_conditions";
|
||||
|
||||
/// <summary>
|
||||
/// Seeding Mode for Terms and Conditions ...
|
||||
/// </summary>
|
||||
public XDbSeedingMode SeedingMode { get; set; } = XDbSeedingMode.AddIfNotExists;
|
||||
|
||||
/// <summary>
|
||||
/// Default Terms and Conditions for Add to Databse on App Startup ...
|
||||
/// </summary>
|
||||
public List<XStringDto> TermsAndConditions { get; set; } = null;
|
||||
}
|
||||
```
|
||||
|
||||
a sample Configuration must like this:
|
||||
|
||||
```json
|
||||
{
|
||||
...
|
||||
"TermsAndConditionsService": {
|
||||
"ResourceTitle": "terms_and_conditions",
|
||||
"SeedingMode": "AddIfNotExists",
|
||||
"TermsAndConditions": [
|
||||
{
|
||||
"Language": "fa-IR",
|
||||
"TranslatedValue": "شرایط و ضوابط ثبت نام در سامانه"
|
||||
}
|
||||
]
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### Register Service
|
||||
|
||||
after preparation of all requirements, final steps is Register Service.
|
||||
|
||||
there are two main step:
|
||||
|
||||
- **DI Registration**: in this phase, all Provided Services Registered in DI.
|
||||
- **Middleware Usage**: in this phase, if any Terms and Conditions Provided in Configuration, Seeded in Data Persist System using Provided Services.
|
||||
|
||||
```C#
|
||||
public class Startup
|
||||
{
|
||||
//
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
...
|
||||
//
|
||||
// Register Terms and Conditions Service ...
|
||||
services.AddXTermsConditionsService(
|
||||
lifeTime: lifeTime,
|
||||
configuration: configuration
|
||||
);
|
||||
...
|
||||
}
|
||||
|
||||
//
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
...
|
||||
//
|
||||
// Using Terms and Conditions Service ...
|
||||
app.UseXTermsAndConditionsService();
|
||||
...
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Maintainer
|
||||
|
||||
Hadi Khazaee asl
|
||||
|
||||
[https://www.saherelm.ir](https://www.saherelm.ir)
|
||||
|
||||
[hadi_khazaee_asl@yahoo.com](mailto:hadi_khazaee_asl@yahoo.com)
|
||||
Binary file not shown.
Reference in New Issue
Block a user