Compare commits

...
10 Commits
Author SHA1 Message Date
saherelm 19ef6aa887 cleanup Dependencies ... 2026-07-30 15:58:43 +03:30
saherelm 9c101a63eb refactor and add using constants instead of hard coded strings ... 2026-07-30 14:26:51 +03:30
saherelm 651fde1cd8 last ... 2026-07-26 21:19:22 +03:30
saherelm 12b9b6326f last ... 2026-06-12 23:42:38 +03:30
saherelm 8674c2ace1 Update Lang Version to 12 ... 2026-06-12 02:10:57 +03:30
saherelm 943275d24c last ... 2026-05-31 07:35:43 +03:30
saherelm b99f0de912 last ... 2026-05-28 19:15:31 +03:30
saherelm 6101d25a7b last ... 2026-05-28 16:16:44 +03:30
saherelm db03b59cc8 kast ... 2026-05-28 11:39:34 +03:30
saherelm a4c0f9a181 last ... 2026-05-28 07:32:46 +03:30
50 changed files with 2115 additions and 3506 deletions
@@ -0,0 +1,17 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using xDataService.Providers;
using xFileService.Constants;
using xFileService.Models.Entities;
namespace xFileService.Configurations.Entities
{
public class XFileEntityConfiguration : XBaseEntityTypeConfiguration<XFile, Guid>
{
public override void Configure(EntityTypeBuilder<XFile> builder)
{
builder.ToTable(XFileServiceConstants.XFileTable);
}
}
}
+33
View File
@@ -0,0 +1,33 @@
using xFileService.Models.Entities;
namespace xFileService.Constants
{
public struct XFileServiceConstants
{
//
// Service Extensions Log Tag ...
public const string XFileServiceDILogTag = "XFileService";
//
// Table Mapping Identifiers ...
public const string XFileTable = "Files";
//
// GraphQL Collection Mappings ...
public const string XFileSingleName = "file";
public const string XFileCollectionName = "files";
//
// Hubs ...
public const string XFileDtoHub = "fileDto";
public const string XFileEntityHub = "fileEntity";
//
// Custome Constants ...
public const string XFileTagProvided = nameof(XFile);
//
// EF Repositories Helper Extensions ...
public const string GetXFileEFRepositoryDescriptor = "GetXFileEFRepositoryDescriptor";
}
}
+485
View File
@@ -0,0 +1,485 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xDataService.Models;
using xExceptions.Constants;
using xFileService.Interfaces;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xFileService.Providers.Dtos;
using xIdentityService.Interfaces;
using xTagService.Controllers;
namespace xFileService.Controllers
{
public abstract class XFileProviderControllerBase : XBaseProvidedHasTagControllerBase<XFile, XFileDto, Guid, XFileDtoHub>, IXFileProviderController
{
private readonly IXFileProvider provider;
protected XFileProviderControllerBase(
ILogger<XFileProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXFileProvider provider,
IXFileTagProvided tagProvided,
Func<IQueryable<XFile>, IOrderedQueryable<XFile>> defaultOrderBuilder = null,
Func<IQueryable<XFile>, IIncludableQueryable<XFile, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
tagProvided,
defaultOrderBuilder,
defaultIncludeBuilder
)
{
this.provider = provider;
}
//
#region Tools ...
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{id}/Stream/ById")]
public virtual async Task<ActionResult> Stream(
[FromRoute] Guid id,
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider.Stream(
id: id,
cancellationToken: cancellationToken
);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{name}/Stream/ByName")]
public virtual async Task<ActionResult> Stream(
[FromRoute] string name,
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider.Stream(
name: name,
cancellationToken: cancellationToken
);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{id}/Download/ById")]
public virtual async Task<ActionResult> Download(
[FromRoute] Guid id,
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider.Download(
id: id,
cancellationToken: cancellationToken
);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{name}/Download/ByName")]
public virtual async Task<ActionResult> Download(
string name,
CancellationToken cancellationToken = default
)
{
//
try
{
//
var result = await provider.Download(
name: name,
cancellationToken: cancellationToken
);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Upload Files ...
/// </summary>
/// <param name="files"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Upload")]
[RequestSizeLimit(966_367_641)]
public virtual async Task<ActionResult<IEnumerable<XFileDto>>> Upload(
[FromForm] IFormFileCollection files,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
//
var result = await provider.Upload(
files: files,
userInfo: userInfo,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Remove Specified Files ...
/// </summary>
/// <param name="ids"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpDelete("")]
public virtual async Task<ActionResult<IEnumerable<Guid>>> Remove(
[FromQuery] string ids,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
//
var result = await provider.Remove(
ids: ids,
userInfo: userInfo,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
//
#region Reference ...
/// <summary>
/// Check an Item Has Reference to Specified ProvideFor and Specified forProvidedId ...
/// </summary>
/// <param name="id"></param>
/// <param name="providedFor"></param>
/// <param name="forProvidedId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{id}/Reference/IsProvidedFor")]
public virtual async Task<ActionResult<bool>> IsProvidedFor(
[FromRoute] Guid id,
[FromQuery] string providedFor,
[FromQuery] object forProvidedId,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
if (!ModelState.IsValid)
{
XException.InvalidArgs.Throw();
}
await ValidationProvider
.GroupValidationBuilder()
.AddNotNull(id)
.AddNotEmpty(providedFor)
.AddNotNull(forProvidedId)
.ValidateGroupAsync();
//
var result = await provider.IsProvidedFor(
id: id,
providedFor: providedFor,
forProvidedId: forProvidedId,
cancellationToken: cancellationToken
);
//
return Ok(result);
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Add a Reference to Item for Specified ProvideFor and Specified forProvidedId ...
/// </summary>
/// <param name="id"></param>
/// <param name="providedFor"></param>
/// <param name="forProvidedId"></param>
/// <param name="forIndex"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("{id}/Reference")]
public virtual async Task<ActionResult> AddReference(
[FromRoute] Guid id,
[FromQuery] string providedFor,
[FromQuery] object forProvidedId,
[FromQuery] int forIndex = 0,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
if (!ModelState.IsValid)
{
XException.InvalidArgs.Throw();
}
await ValidationProvider
.GroupValidationBuilder()
.AddNotNull(id)
.AddNotEmpty(providedFor)
.AddNotNull(forProvidedId)
.ValidateGroupAsync();
//
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
//
await provider.AddReference(
id: id,
forIndex: forIndex,
userInfo: userInfo,
providedFor: providedFor,
connectionId: connectionId,
forProvidedId: forProvidedId,
cancellationToken: cancellationToken
);
//
return Ok();
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Remove a Reference from Item for Specified ProvideFor and Specified forProvidedId ...
/// </summary>
/// <param name="id"></param>
/// <param name="providedFor"></param>
/// <param name="forProvidedId"></param>
/// <param name="forIndex"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpDelete("{id}/Reference")]
public virtual async Task<ActionResult> RemoveReference(
[FromRoute] Guid id,
[FromQuery] string providedFor,
[FromQuery] object forProvidedId,
[FromQuery] int forIndex = 0,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
if (!ModelState.IsValid)
{
XException.InvalidArgs.Throw();
}
await ValidationProvider
.GroupValidationBuilder()
.AddNotNull(id)
.AddNotEmpty(providedFor)
.AddNotNull(forProvidedId)
.ValidateGroupAsync();
//
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
//
await provider.RemoveReference(
id: id,
forIndex: forIndex,
userInfo: userInfo,
providedFor: providedFor,
connectionId: connectionId,
forProvidedId: forProvidedId,
cancellationToken: cancellationToken
);
//
return Ok();
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve References of Specified Itemfor providedFor ...
/// </summary>
/// <param name="id"></param>
/// <param name="providedFor"></param>
/// <param name="cancellationToken"></param>
/// <typeparam name="TReferenceKey"></typeparam>
/// <returns></returns>
[HttpGet("{id}/References")]
public virtual async Task<ActionResult<IEnumerable<XReference<string>>>> GetReferences(
[FromRoute] Guid id,
[FromQuery] string providedFor,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
if (!ModelState.IsValid)
{
XException.InvalidArgs.Throw();
}
await ValidationProvider
.GroupValidationBuilder()
.AddNotNull(id)
.AddNotEmpty(providedFor)
.ValidateGroupAsync();
//
var result = await provider.GetReferences(
id: id,
providedFor: providedFor,
cancellationToken: cancellationToken
);
//
return Ok(result.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
}
}
@@ -0,0 +1,33 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Providers;
using xDataService.Controllers;
using xDataService.Interfaces;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.Controllers
{
public abstract class XFileRepositoryControllerBase : XBaseRepositoryController<XFile, Guid>, IXBaseRepositoryController<XFile, Guid>
{
protected XFileRepositoryControllerBase(
ILogger<XFileRepositoryControllerBase> logger,
XAppConfiguration appConfiguration,
XValidationProvider validationProvider,
IXFileRepository repository,
Func<IQueryable<XFile>, IOrderedQueryable<XFile>> defaultOrderBuilder = null,
Func<IQueryable<XFile>, IIncludableQueryable<XFile, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
validationProvider,
repository,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
@@ -0,0 +1,37 @@
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Providers;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
using xFileService.Providers.Entities;
using xIdentityService.Interfaces;
using xPushService.Controllers;
using xPushService.Interfaces;
namespace xFileService.Controllers
{
public abstract class XFileRepositoryProviderControllerBase : XBaseRepositoryProviderController<XFile, Guid, XFileEntityHub>, IXBaseRepositoryProviderController<XFile, Guid, XFileEntityHub>
{
protected XFileRepositoryProviderControllerBase(
ILogger<XFileRepositoryProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXFileRepositoryProvider provider,
Func<IQueryable<XFile>, IOrderedQueryable<XFile>> defaultOrderBuilder = null,
Func<IQueryable<XFile>, IIncludableQueryable<XFile, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
+17 -606
View File
@@ -1,623 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xFileService.Interfaces;
using xIdentityService.Controllers;
using xIdentityService.Interfaces;
using xModels.Dtos;
using XFileDto = xFileService.Models.Dtos.XFileDto;
using xDataService.Controllers;
using xDataService.Interfaces;
using xFileService.Interfaces.Dtos;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
namespace xFileService.Controllers
{
/// <summary>
/// a Controller base Class which implement based Actions to Provides File Provider Access ...
/// </summary>
public abstract class XFileServiceControllerBase : XIBaseProviderController, IXFileServiceControllerActions
public abstract class XFileServiceControllerBase : XBaseServiceController<XFile, XFileDto, Guid>, IXBaseServiceController<XFile, XFileDto, Guid>
{
//
#region Props ...
public IXFileProvider FileProvider { get; }
#endregion
//
#region Constructor ...
protected XFileServiceControllerBase(
ILogger logger,
IXFileProvider fileProvider,
ILogger<XFileServiceControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider
XValidationProvider validationProvider,
IXFileRepositoryService repositoryService,
Func<IQueryable<XFile>, IOrderedQueryable<XFile>> defaultOrderBuilder = null,
Func<IQueryable<XFile>, IIncludableQueryable<XFile, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider
validationProvider,
repositoryService,
defaultOrderBuilder,
defaultIncludeBuilder
)
{
//
FileProvider = fileProvider;
}
#endregion
//
#region Tags ...
/// <summary>
/// Attach Tag to Specified Model ...
/// </summary>
/// <param name="id"></param>
/// <param name="tag"></param>
/// <returns></returns>
[HttpPost("{id}/Tags/Attach")]
public virtual async Task<ActionResult> AttachTag(
[FromRoute] Guid id,
[FromQuery] string tag
)
{
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
await FileProvider.AttachTag(
id: id,
tag: tag,
userInfo: userInfo,
connectionId: connectionId
);
//
return Ok();
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Detach Tag From Specified Model ...
/// </summary>
/// <param name="tag"></param>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id}/Tags/Detach")]
public virtual async Task<ActionResult> DetachTag(
[FromRoute] Guid id,
[FromQuery] string tag
)
{
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
await FileProvider.DetachTag(
id: id,
tag: tag,
userInfo: userInfo,
connectionId: connectionId
);
//
return Ok();
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Attach Tags to Specified Model ...
/// </summary>
/// <param name="tags"></param>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost("{id}/Tags/AttachMany")]
public virtual async Task<ActionResult> AttachTags(
[FromRoute] Guid id,
[FromQuery] string tags
)
{
//
// Do ...
try
{
//
var tagsList = tags.ParseListString<string>();
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
await FileProvider.AttachTags(
id: id,
tags: tagsList,
userInfo: userInfo,
connectionId: connectionId
);
//
return Ok();
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Detach Tags From Specified Model ...
/// </summary>
/// <param name="tags"></param>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id}/Tags/DetachMany")]
public virtual async Task<ActionResult> DetachTags(
[FromRoute] Guid id,
[FromQuery] string tags
)
{
//
// Do ...
try
{
//
var tagsList = tags.ParseListString<string>();
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
await FileProvider.DetachTags(
id: id,
tags: tagsList,
userInfo: userInfo,
connectionId: connectionId
);
//
return Ok();
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Retrieve Tags of Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/Tags")]
public virtual async Task<ActionResult<IEnumerable<string>>> GetTags(
[FromRoute] Guid id
)
{
//
// Do ...
try
{
//
var result = await FileProvider.GetTags(id);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
//
#region Tools ...
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/Stream/ById")]
public virtual async Task<ActionResult> Stream(
[FromRoute] Guid id
)
{
//
// Do ...
try
{
//
var result = await FileProvider.Stream(id);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{name}/Stream/ByName")]
public virtual async Task<ActionResult> Stream(
[FromRoute] string name
)
{
//
// Do ...
try
{
//
var result = await FileProvider.Stream(name);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/Download/ById")]
public virtual async Task<ActionResult> Download(
[FromRoute] Guid id
)
{
//
// Do ...
try
{
//
var result = await FileProvider.Download(id);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
[HttpGet("{name}/Download/ByName")]
public virtual async Task<ActionResult> Download(
[FromRoute] string name
)
{
//
// Do ...
try
{
//
var result = await FileProvider.Download(name);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Upload Files ...
/// </summary>
/// <param name="files"></param>
/// <returns></returns>
[HttpPost("")]
[RequestSizeLimit(966_367_641)]
public virtual async Task<ActionResult<IEnumerable<XFileDto>>> Upload(
[FromForm] IFormFileCollection files
)
{
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
var result = await FileProvider.Upload(
files: files,
userInfo: userInfo,
connectionId: connectionId
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Remove Specified Files ...
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
/// [HttpDelete("Remove")]
[HttpDelete("")]
public virtual async Task<ActionResult<IEnumerable<Guid>>> Remove(
[FromQuery] string ids
) {
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
var result = await FileProvider.Remove(
ids: ids,
userInfo: userInfo,
connectionId: connectionId
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
//
#region Model ...
/// <summary>
/// Get Specified File Model ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public virtual async Task<ActionResult<XFileDto>> Get(
[FromRoute] Guid id
) {
//
// Do ...
try
{
//
var result = await FileProvider.Get(id);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Get All Exists File Models ...
/// </summary>
/// <returns></returns>
[HttpGet("All")]
public virtual async Task<ActionResult<IEnumerable<XFileDto>>> GetAll() {
//
// Do ...
try
{
//
var result = await FileProvider.GetAll();
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// retrieve Entities based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet("Query")]
public virtual async Task<ActionResult<XQueryResult<XFileDto>>> Query(
[FromQuery] XQuery query
) {
//
// Do ...
try
{
//
var result = await FileProvider.Query(query);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// retrieve Owned Entities based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
[HttpGet("Query/Owned")]
public virtual async Task<ActionResult<XQueryResult<XFileDto>>> QueryOwned(
[FromQuery] XQuery query
) {
//
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
//
var result = await FileProvider.QueryOwned(
query: query,
userInfo: userInfo
);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// count all exists Entities ...
/// </summary>
/// <returns></returns>
[HttpGet("Count")]
public virtual async Task<ActionResult<int>> Count() {
//
// Do ...
try
{
//
var result = await FileProvider.Count();
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
/// <summary>
/// Check an Entity exists or not ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}/IsExists")]
public virtual async Task<ActionResult<bool>> IsExists(
[FromRoute] Guid id
) {
//
// Do ...
try
{
//
var result = await FileProvider.IsExists(id);
//
return Ok(result
.ToDynamicObject());
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
#endregion
{ }
}
}
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Providers;
using xFileService.Interfaces.Dtos;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xFileService.Providers.Dtos;
using xIdentityService.Interfaces;
using xPushService.Controllers;
using xPushService.Interfaces;
namespace xFileService.Controllers
{
public abstract class XFileServiceProviderControllerBase : XBaseServiceProviderController<XFile, XFileDto, Guid, XFileDtoHub>, IXBaseServiceProviderController<XFile, XFileDto, Guid, XFileDtoHub>
{
protected XFileServiceProviderControllerBase(
ILogger<XFileServiceProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXFileServiceProvider provider,
Func<IQueryable<XFile>, IOrderedQueryable<XFile>> defaultOrderBuilder = null,
Func<IQueryable<XFile>, IIncludableQueryable<XFile, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
+148 -31
View File
@@ -1,12 +1,23 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using xCommons.Extensions;
using xCommons.Helpers;
using xDataService.Constants;
using xDataService.Db;
using xDataService.DI;
using xDataService.Models;
using xExceptions.Constants;
using xFileService.Interfaces;
using xPushService.DI;
using xPushService.Helpers;
using xFileService.Helpers;
using xFileService.Interfaces.Dtos;
using xFileService.Interfaces.Entities;
using xFileService.Providers.Dtos;
using xFileService.Providers.Entities;
using xFileService.Interfaces;
using xFileService.Providers;
using xStorageService.Interfaces;
using xTagService.Interfaces;
using xFileService.Constants;
namespace xFileService.DI
{
@@ -16,25 +27,87 @@ namespace xFileService.DI
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="config"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXFileService(
this IServiceCollection services,
ServiceLifetime lifeTime
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
AddFileService(
contextType: null,
services: services,
lifeTime: lifeTime,
repositoryType: repositoryType
);
}
/// <summary>
/// Register Service ...
/// </summary>
/// <typeparam name="TContext"></typeparam>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXFileService<TContext>(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
where TContext : XDbContext
{
AddFileService(
services: services,
lifeTime: lifeTime,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
/// <summary>
/// Use XFileService Middleware ...
/// </summary>
/// <param name="app"></param>
/// <param name="isDevelopmentEnvironment"></param>
public static void UseXFileService(
this IApplicationBuilder app,
bool isDevelopmentEnvironment = false
)
{
//
AddFileService(
services,
lifeTime
#region Using XFile Hubs ...
//
var pushHelper = new XPushServiceHelper();
//
pushHelper.AddHub<XFileDtoHub>(XFileServiceConstants.XFileDtoHub);
pushHelper.AddHub<XFileEntityHub>(XFileServiceConstants.XFileEntityHub);
//
app.UseXPushService(pushHelper);
#endregion
//
// Using XFile Repository Descriptor ...
if (!descriptor.IsNull())
{
//
app.UseXRepository(
descriptor: descriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment
);
}
}
//
#region Private ...
private static XRepositoryDescriptor descriptor = null;
/// <summary>
/// a LogTag for Service ...
/// </summary>
private static string XLogTag = "XFileService";
private static string XLogTag = XFileServiceConstants.XFileServiceDILogTag;
/// <summary>
/// print a log in Console ...
@@ -49,10 +122,14 @@ namespace xFileService.DI
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="contextType"></param>
/// <param name="lifeTime"></param>
private static void AddFileService(
IServiceCollection services,
ServiceLifetime lifeTime
XRepositoryType repositoryType,
Type contextType = null,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
@@ -64,7 +141,7 @@ namespace xFileService.DI
if (!isServicesExists)
{
//
Log("AddFileService failed, services not provided ...");
Log("Service Registration failed, services not provided ...");
throw exception;
}
@@ -74,45 +151,85 @@ namespace xFileService.DI
if (!isLifetimeExists)
{
//
Log("AddFileService failed, lifetime not provided ...");
Log("Service Registration failed, lifetime not provided ...");
throw exception;
}
//
// Check Dependencies Exists ...
var isDependenciesPassed = !services
.GetRegisteredService<IXStorageProvider>()
.IsNull() &&
!services.GetRegisteredService<IXTagProvider>().IsNull();
if (!isDependenciesPassed)
// Validate Repository Type ...
var isRepositoryTypeValid =
(repositoryType == XRepositoryType.EF &&
!contextType.IsNull()) ||
((repositoryType == XRepositoryType.Mongo ||
repositoryType == XRepositoryType.InMemory) &&
contextType.IsNull());
if (!isRepositoryTypeValid)
{
//
Log("AddFileService failed due Dependencies Issues, IXTagProvider, IXStorageProvider not provided ...");
Log("Service Registration failed, Invalid Repository Type and Context Type ...");
throw exception;
}
//
// Check Repository Exists ...
var isRepositoryExists = !services
.GetRegisteredService<IXFileRepository>()
.IsNull();
if (!isRepositoryExists)
// Maske Instance of Repository Descriptor
// Based on Provided Type ...
switch (repositoryType)
{
//
Log("AddFileService failed, IXFileRepository not provided ...");
throw exception;
case XRepositoryType.EF:
//
descriptor = typeof(XFileServiceHelper)
.InvokeGenericMethod<XRepositoryDescriptor>(
args: null,
runtimeType: contextType,
methodName: XFileServiceConstants.GetXFileEFRepositoryDescriptor
);
break;
//
case XRepositoryType.Mongo:
descriptor = XFileServiceHelper.GetXFileMongoRepositoryDescriptor();
break;
//
case XRepositoryType.InMemory:
descriptor = XFileServiceHelper.GetXFileInMemoryRepositoryDescriptor();
break;
}
//
// Register Tag Provider for Files ...
services.Add(new ServiceDescriptor(typeof(IXFileTagProvider), typeof(XFileTagProvider), lifeTime));
// Register XFile Repository Descriptor ...
services.AddXRepository(
lifeTime: lifeTime,
descriptor: descriptor
);
//
// Register Main Provider ...
services.Add(new ServiceDescriptor(typeof(IXFileProvider), typeof(XFileProvider), lifeTime));
// Register Dto Services ...
services.Add(
new ServiceDescriptor(typeof(IXFileServiceProvider), typeof(XFileServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXFileRepositoryService), typeof(XFileRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXFileRepositoryProvider), typeof(XFileRepositoryProvider), lifeTime)
);
//
Log("AddFileService Succeed ...");
// Register Additional Service ...
services.Add(
new ServiceDescriptor(typeof(IXFileTagProvider), typeof(XFileTagProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXFileTagProvided), typeof(XFileTagProvided), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXFileProvider), typeof(XFileProvider), lifeTime)
);
//
Log("Service Regitration Succeed ...");
}
#endregion
}
-9
View File
@@ -1,9 +0,0 @@
using xDataService.Events;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.DataHelper.Events
{
public class XFileEvents : XBaseRepositoryEvents<XFile>, IXFileEvents
{ }
}
+149
View File
@@ -0,0 +1,149 @@
using System.Collections.Generic;
using System.Linq;
using xCommons.Extensions;
using xDataService.Extensions;
using xDataService.Models;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
namespace xFileService.Extensions
{
public static class XModelExtensions
{
/// <summary>
/// Extract References of a Model ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IList<XReference<string>> GetReferences(
this XFile source
)
{
//
var result = new List<XReference<string>>();
//
if (
!source.IsNullOrDefault() &&
!source.References.IsNullOrEmpty()
)
{
//
result = source.References
.ParseXReferenceList<string>()
.ToList();
}
//
return result;
}
/// <summary>
/// Extract References of a Model ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static IList<XReference<string>> GetReferences(
this XFileDto source
)
{
//
var result = new List<XReference<string>>();
//
if (
!source.IsNullOrDefault() &&
!source.References.IsNullOrEmpty()
)
{
//
result = source.References
.ParseXReferenceList<string>()
.ToList();
}
//
return result;
}
/// <summary>
/// Update a Model's References by Providing References List ...
/// </summary>
/// <param name="source"></param>
/// <param name="references"></param>
/// <param name="forceClean"></param>
/// <returns></returns>
public static XFile UpdateReferences(
this XFile source,
IList<XReference<string>> references,
bool forceClean = true
)
{
//
XFile result = source;
//
if (!source.IsNullOrDefault())
{
//
result = source;
//
if (forceClean)
{
result.References = string.Empty;
}
//
if (!references.IsNull() &&
references.HasChild())
{
result.References = references.ToXReferenceString();
}
}
//
return result;
}
/// <summary>
/// Update a Model's References by Providing References List ...
/// </summary>
/// <param name="source"></param>
/// <param name="references"></param>
/// <param name="forceClean"></param>
/// <returns></returns>
public static XFileDto UpdateReferences(
this XFileDto source,
IList<XReference<string>> references,
bool forceClean = true
)
{
//
XFileDto result = source;
//
if (!source.IsNullOrDefault())
{
//
result = source;
//
if (forceClean)
{
result.References = string.Empty;
}
//
if (!references.IsNull() &&
references.HasChild())
{
result.References = references.ToXReferenceString();
}
}
//
return result;
}
}
}
-85
View File
@@ -1,85 +0,0 @@
using System.Collections.Generic;
using xCommons.Extensions;
using xDataService.Extensions;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
namespace xFileService.Extensions
{
public static class xFileServiceExtensions
{
/// <summary>
/// Map Global Properties From XFile to XFile Dto ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XFileDto ToDto(this XFile source)
{
//
XFileDto result = null;
//
if (!source.IsNullOrDefault())
{
//
result = new XFileDto();
result = result.UpdateData(
updateWith: source,
propertyBlackList: new List<string>
{
nameof(XFileDto.Owner),
nameof(XFile.Deleted),
nameof(XFile.References),
}
);
//
// Preparing List ...
if (!source.References.IsNullOrEmpty())
{
result.References = source.References.ParseXReferenceList<string>();
}
}
//
return result;
}
/// <summary>
/// Converts a Dto to Entity Representation ...
/// Ignore ID Property ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static XFile FromDto(this XFileDto source)
{
//
var result = new XFile();
//
if (!source.IsNull())
{
//
result = result.UpdateData(
updateWith: source,
propertyBlackList: new List<string>
{
nameof(XFile.Deleted),
nameof(XFile.References),
}
);
//
if (!source.References.IsNull() && source.References.HasChild())
{
result.References = source.References.ToXReferenceString();
}
}
//
return result;
}
}
}
View File
+280
View File
@@ -0,0 +1,280 @@
using System;
using GraphQL.Types;
using xDataService.Db;
using xDataService.Models;
using xDataService.Providers;
using xFileService.Interfaces;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
using xFileService.Providers.Entities;
using xFileService.Providers.GraphQL;
namespace xFileService.Helpers
{
public static class XFileServiceHelper
{
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileEFRepository<TContext>,
TContext
> GetXFileEFRepositoryDescriptor<TContext>()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileEFRepository<TContext>,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileEFRepository<TContext>,
TContext,
IXFileSeeder,
TSeederImplementation
> GetXFileEFRepositoryDescriptor<TContext, TSeederImplementation>()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder<XFile, Guid>
{
//
var result = new XEFRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileEFRepository<TContext>,
TContext,
IXFileSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileMongoRepository
> GetXFileMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileMongoRepository,
IXFileSeeder,
TSeederImplementation
> GetXFileMongoRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XFile, Guid>
{
//
var result = new XMongoRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileMongoRepository,
IXFileSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileInMemoryRepository
> GetXFileInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileInMemoryRepository,
IXFileSeeder,
TSeederImplementation
> GetXFileInMemoryRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XFile, Guid>
{
//
var result = new XInMemoryRepositoryDescriptor<
XFile,
Guid,
IXFileKeyGenerator,
XFileKeyGenerator,
IXFileRepositoryEvents,
XFileRepositoryEvents,
XFileGraphType,
GuidGraphType,
XFileGraphQuery,
IXFileGraphQLTypeHelper,
XFileGraphQLTypeHelper,
XFileGraphSchema,
IXFileRepository,
XFileInMemoryRepository,
IXFileSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
}
}
-16
View File
@@ -1,16 +0,0 @@
using System;
using Microsoft.Extensions.Logging;
using xFileService.Models.Entities;
using xPushService.Base;
namespace xFileService.Hubs
{
public class XFileEntityHub : XBaseEntityHub<XFile, Guid>
{
//
#region Constructor ...
public XFileEntityHub(ILogger<XBaseHub> logger) : base(logger)
{ }
#endregion
}
}
+10
View File
@@ -0,0 +1,10 @@
using System;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xPushService.Interfaces;
namespace xFileService.Interfaces.Dtos
{
public interface IXFileDtoHub : IXBaseDtoHub<XFile, XFileDto, Guid>
{ }
}
@@ -0,0 +1,10 @@
using System;
using xDataService.Interfaces;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
namespace xFileService.Interfaces.Dtos
{
public interface IXFileRepositoryService : IXBaseRepositoryService<XFile, XFileDto, Guid>
{ }
}
+11
View File
@@ -0,0 +1,11 @@
using System;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xFileService.Providers.Dtos;
using xPushService.Interfaces;
namespace xFileService.Interfaces.Dtos
{
public interface IXFileServiceProvider : IXBaseDtoProvider<XFile, XFileDto, Guid, XFileDtoHub>
{ }
}
+9
View File
@@ -0,0 +1,9 @@
using System;
using xFileService.Models.Entities;
using xPushService.Interfaces;
namespace xFileService.Interfaces.Entities
{
public interface IXFileEntityHub : IXBaseEntityHub<XFile, Guid>
{ }
}
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xFileService.Models.Entities;
namespace xFileService.Interfaces.Entities
{
public interface IXFileKeyGenerator : IXKeyGenerator<XFile, Guid>
{ }
}
@@ -3,6 +3,6 @@ using xFileService.Models.Entities;
namespace xFileService.Interfaces.Entities
{
public interface IXFileEvents : IXBaseRepositoryEvents<XFile>
public interface IXFileRepositoryEvents : IXBaseRepositoryEvents<XFile>
{ }
}
@@ -0,0 +1,10 @@
using System;
using xFileService.Models.Entities;
using xFileService.Providers.Entities;
using xPushService.Interfaces;
namespace xFileService.Interfaces.Entities
{
public interface IXFileRepositoryProvider : IXBaseEntityProvider<XFile, Guid, XFileEntityHub>
{ }
}
+9
View File
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xFileService.Models.Entities;
namespace xFileService.Interfaces.Entities
{
public interface IXFileSeeder : IXBaseDbSeeder<XFile, Guid>
{ }
}
-87
View File
@@ -1,87 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using xFileService.Models.Dtos;
using xIdentityModels.Models;
using xIdentityService.Interfaces;
using XFileDto = xFileService.Models.Dtos.XFileDto;
namespace xFileService.Interfaces
{
/// <summary>
/// Implementing XBaseFileProvider ...
/// </summary>
/// <typeparam name="TKey"></typeparam>
public interface IXBaseFileProvider<TKey> : IXIdentityBaseReferencedProvider<XFileDto, TKey>
{
//
#region Props ...
/// <summary>
/// Specified Provider Repositroy ...
/// </summary>
IXFileProvider FileProvider { get; }
#endregion
//
#region Tools ...
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<FileStreamResult> Stream(Guid id);
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
Task<FileStreamResult> Stream(string fileName);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<PhysicalFileResult> Download(Guid id);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
Task<PhysicalFileResult> Download(string fileName);
/// <summary>
/// Upload Files ...
/// </summary>
/// <param name="forProvidedId"></param>
/// <param name="files"></param>
/// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
Task<IEnumerable<XFileDto>> Upload(
TKey forProvidedId,
IFormFileCollection files,
string connectionId = null,
XUserClaimsInfoDto userInfo = null
);
/// <summary>
/// Retrieve Specified File Streaming Info ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<XFileStreamDescriptorDto> GetFileDescriptor(Guid id);
/// <summary>
/// Retrieve Specified File Streaming Info ...
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
Task<XFileStreamDescriptorDto> GetFileDescriptor(string fileName);
#endregion
}
}
+41 -322
View File
@@ -1,171 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using xDataService.Configuration;
using xFileService.Hubs;
using xFileService.Interfaces.Entities;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xFileService.Providers.Dtos;
using xIdentityModels.Models;
using xIdentityService.Interfaces;
using xModels.Dtos;
using xStorageService.Interfaces;
using XFileDto = xFileService.Models.Dtos.XFileDto;
using xTagService.Interfaces;
namespace xFileService.Interfaces
{
public interface IXFileProvider
public interface IXFileProvider : IXBaseProvidedHasTag<XFile, XFileDto, Guid, XFileDtoHub>, IXBaseReferenced<XFile, Guid>
{
//
#region Props ...
IXFileTagProvider TagProvider { get; }
IHubContext<XFileEntityHub> Hub { get; }
IXFileRepository FileRepository { get; }
IXStorageProvider StorageProvider { get; }
IXIdentityProvider IdentityProvider { get; }
XDataServiceConfiguration DataSercviceConfiguration { get; }
#endregion
//
#region Helpers ...
/// <summary>
/// Converts an Entity to Dto ...
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
Task<XFileDto> ToDto(XFile model);
/// <summary>
/// Convert a List of Entities to Dto ...
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
Task<IEnumerable<XFileDto>> ToDtoList(IEnumerable<XFile> list);
/// <summary>
/// Converts an Entity Query Result to Dto ...
/// </summary>
/// <param name="queryResult"></param>
/// <returns></returns>
Task<XQueryResult<XFileDto>> ToDtoQueryResult(XQueryResult<XFile> queryResult);
#endregion
//
#region Tags ...
/// <summary>
/// Attach Tag to Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="tag"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task AttachTag(
Guid id,
string tag,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// Detach Tag fro Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="tag"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task DetachTag(
Guid id,
string tag,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// Attach Tags for Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="tags"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task AttachTags(
Guid id,
IEnumerable<string> tags,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// Detach Tags for Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="tags"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task DetachTags(
Guid id,
IEnumerable<string> tags,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// Detach all Attached Tags for Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task DetachTags(
Guid id,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// Get Specified Model's Tag ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<IEnumerable<string>> GetTags(Guid id);
#endregion
//
#region Tools ...
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<FileStreamResult> Stream(Guid id);
Task<FileStreamResult> Stream(
Guid id,
CancellationToken cancellationToken = default
);
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="fileName"></param>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<FileStreamResult> Stream(string fileName);
Task<FileStreamResult> Stream(
string name,
CancellationToken cancellationToken = default
);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<PhysicalFileResult> Download(Guid id);
Task<PhysicalFileResult> Download(
Guid id,
CancellationToken cancellationToken = default
);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="fileName"></param>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<PhysicalFileResult> Download(string fileName);
Task<PhysicalFileResult> Download(
string name,
CancellationToken cancellationToken = default
);
/// <summary>
/// Upload Files ...
@@ -173,11 +67,13 @@ namespace xFileService.Interfaces
/// <param name="files"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XFileDto>> Upload(
IFormFileCollection files,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
@@ -186,212 +82,35 @@ namespace xFileService.Interfaces
/// <param name="ids"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<Guid>> Remove(
string ids,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve Specified File Streaming Info ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XFileStreamDescriptorDto> GetFileDescriptor(Guid id);
Task<XFileStreamDescriptorDto> GetFileDescriptor(
Guid id,
CancellationToken cancellationToken = default
);
/// <summary>
/// Retrieve Specified File Streaming Info ...
/// </summary>
/// <param name="fileName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XFileStreamDescriptorDto> GetFileDescriptor(string fileName);
#endregion
//
#region Reference ...
/// <summary>
/// Get Reference Identifier for Specified Provider and Specified File ...
/// </summary>
/// <param name="providedFor"></param>
/// <param name="forProvidedId"></param>
/// <returns></returns>
string GetIdentifier<TKey>(
string providedFor,
TKey forProvidedId
);
/// <summary>
/// Check Specified File has Refernce to Provider ...
/// </summary>
/// <param name="providedFor"></param>
/// <param name="forProvidedId"></param>
/// <param name="id"></param>
/// <returns></returns>
Task<bool> IsProvidedFor<TKey>(
string providedFor,
TKey forProvidedId,
Guid id
);
/// <summary>
/// Add Specified Reference to Specified File ...
/// </summary>
/// <param name="providedFor"></param>
/// <param name="forProvidedId"></param>
/// <param name="id"></param>
/// <param name="forIndex"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task AddReference<TKey>(
string providedFor,
TKey forProvidedId,
Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// Remove Specified Reference from Specified File ...
/// </summary>
/// <param name="providedFor"></param>
/// <param name="forProvidedId"></param>
/// <param name="id"></param>
/// <param name="forIndex"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task RemoveReference<TKey>(
string providedFor,
TKey forProvidedId,
Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
#endregion
//
#region Data Model ...
/// <summary>
/// Get Specified File Model ...
/// </summary>
/// <param name="id"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<XFileDto> Get(
Guid id
);
/// <summary>
/// Get All Exists File Models ...
/// </summary>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<IEnumerable<XFileDto>> GetAll();
/// <summary>
/// find an Entity by providing a Conditional Expression ...
/// </summary>
/// <param name="whereClause"></param>
Task<XFileDto> FindOne(Expression<Func<XFile, bool>> whereClause);
/// <summary>
/// find a collection of Entities by proving a Conditional Expression ...
/// </summary>
/// <param name="whereClause"></param>
/// <returns></returns>
Task<IEnumerable<XFileDto>> FindMany(
Expression<Func<XFile, bool>> whereClause
);
/// <summary>
/// retrieve Entities based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<XQueryResult<XFileDto>> Query(
XQuery query
);
/// <summary>
/// retrieve Owned Entities based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
Task<XQueryResult<XFileDto>> QueryOwned(
XQuery query,
XUserClaimsInfoDto userInfo = null
);
/// <summary>
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
/// </summary>
/// <param name="whereClause"></param>
/// <param name="query"></param>
/// <returns></returns>
Task<XQueryResult<XFileDto>> ConditionalQuery(
Expression<Func<XFile, bool>> whereClause,
XQuery query
);
/// <summary>
/// retrieve Owned Entities based on XQuery Pagination structure by providing a Conditional Expression ...
/// </summary>
/// <param name="whereClause"></param>
/// <param name="query"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
Task<XQueryResult<XFileDto>> ConditionalQueryOwned(
Expression<Func<XFile, bool>> whereClause,
XQuery query,
XUserClaimsInfoDto userInfo = null
);
/// <summary>
/// Update an Entity values ...
/// </summary>
/// <param name="id"></param>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XFileDto> Update(
Guid id,
XFileDto item,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// remove an Entity ...
/// </summary>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XFileDto> Remove(
Guid id,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
/// <summary>
/// count all exists Entities ...
/// </summary>
/// <returns></returns>
Task<int> Count();
/// <summary>
/// Check an Entity exists or not ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<bool> IsExists(
Guid id
Task<XFileStreamDescriptorDto> GetFileDescriptor(
string fileName,
CancellationToken cancellationToken = default
);
#endregion
}
+95
View File
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xFileService.Providers.Dtos;
using xIdentityService.Interfaces;
using xTagService.Interfaces;
namespace xFileService.Interfaces
{
public interface IXFileProviderController : IXBaseProvidedHasTagController<XFile, XFileDto, Guid, XFileDtoHub>, IXBaseReferencedController<XFile, Guid>
{
//
#region Tools ...
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{id}/Stream/ById")]
Task<ActionResult> Stream(
[FromRoute] Guid id,
CancellationToken cancellationToken = default
);
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{name}/Stream/ByName")]
Task<ActionResult> Stream(
[FromRoute] string name,
CancellationToken cancellationToken = default
);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{id}/Download/ById")]
Task<ActionResult> Download(
[FromRoute] Guid id,
CancellationToken cancellationToken = default
);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpGet("{name}/Download/ByName")]
Task<ActionResult> Download(
string name,
CancellationToken cancellationToken = default
);
/// <summary>
/// Upload Files ...
/// </summary>
/// <param name="files"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Upload")]
[RequestSizeLimit(966_367_641)]
Task<ActionResult<IEnumerable<XFileDto>>> Upload(
[FromForm] IFormFileCollection files,
CancellationToken cancellationToken = default
);
/// <summary>
/// Remove Specified Files ...
/// </summary>
/// <param name="ids"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpDelete("")]
Task<ActionResult<IEnumerable<Guid>>> Remove(
[FromQuery] string ids,
CancellationToken cancellationToken = default
);
#endregion
}
}
@@ -1,181 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using xFileService.Models.Dtos;
using xModels.Dtos;
using XFileDto = xFileService.Models.Dtos.XFileDto;
namespace xFileService.Interfaces
{
public interface IXFileServiceControllerActions
{
//
#region Tags ...
/// <summary>
/// Attach Tag to Specified Model ...
/// </summary>
/// <param name="id"></param>
/// <param name="tag"></param>
/// <returns></returns>
Task<ActionResult> AttachTag(
[FromRoute] Guid id,
[FromQuery] string tag
);
/// <summary>
/// Detach Tag From Specified Model ...
/// </summary>
/// <param name="tag"></param>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult> DetachTag(
[FromRoute] Guid id,
[FromQuery] string tag
);
/// <summary>
/// Attach Tags to Specified Model ...
/// </summary>
/// <param name="tags"></param>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult> AttachTags(
[FromRoute] Guid id,
[FromQuery] string tags
);
/// <summary>
/// Detach Tags From Specified Model ...
/// </summary>
/// <param name="tags"></param>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult> DetachTags(
[FromRoute] Guid id,
[FromQuery] string tags
);
/// <summary>
/// Retrieve Tags of Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<string>>> GetTags(
[FromRoute] Guid id
);
#endregion
//
#region Tools ...
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult> Stream(
[FromRoute] Guid id
);
/// <summary>
/// Stream Specified File ...
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
Task<ActionResult> Stream(
[FromRoute] string fileName
);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult> Download(
[FromRoute] Guid id
);
/// <summary>
/// Download Specified File ...
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
Task<ActionResult> Download(
[FromRoute] string name
);
/// <summary>
/// Upload Files ...
/// </summary>
/// <param name="files"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<XFileDto>>> Upload(
[FromForm] IFormFileCollection files
);
/// <summary>
/// Remove Specified Files ...
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<Guid>>> Remove(
[FromQuery] string ids
);
#endregion
//
#region Model ...
/// <summary>
/// Get Specified File Model ...
/// </summary>
/// <param name="id"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<ActionResult<XFileDto>> Get(
[FromRoute] Guid id
);
/// <summary>
/// Get All Exists File Models ...
/// </summary>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<ActionResult<IEnumerable<XFileDto>>> GetAll();
/// <summary>
/// retrieve Entities based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<ActionResult<XQueryResult<XFileDto>>> Query(
[FromQuery] XQuery query
);
/// <summary>
/// retrieve Owned Entities based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
Task<ActionResult<XQueryResult<XFileDto>>> QueryOwned(
[FromQuery] XQuery query
);
/// <summary>
/// count all exists Entities ...
/// </summary>
/// <returns></returns>
Task<ActionResult<int>> Count();
/// <summary>
/// Check an Entity exists or not ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<ActionResult<bool>> IsExists(
[FromRoute] Guid id
);
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
using System;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xFileService.Providers.Dtos;
using xTagService.Interfaces;
namespace xFileService.Interfaces
{
public interface IXFileTagProvided : IXTagProvided<XFile, XFileDto, Guid, XFileDtoHub>
{ }
}
+2 -6
View File
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using xCommons.Constants;
using xDataService.Models;
using xModels.Base;
using xModels.Dtos;
namespace xFileService.Models.Dtos
{
public class XFileDto : XBaseDto
public class XFileDto : XBaseGuidIDEntityDto
{
public Guid Id { get; set; }
public XFileType Type { get; set; }
public string Name { get; set; }
public string Thumb { get; set; }
@@ -22,6 +18,6 @@ namespace xFileService.Models.Dtos
public string OwnerId { get; set; }
public XPersonDto Owner { get; set; }
public IList<XReference<string>> References = new List<XReference<string>>();
public string References { get; set; }
}
}
+17
View File
@@ -0,0 +1,17 @@
using System;
using Microsoft.Extensions.Logging;
using xFileService.Interfaces.Dtos;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xPushService.Base;
namespace xFileService.Providers.Dtos
{
public class XFileDtoHub : XBaseDtoHub<XFile, XFileDto, Guid>, IXFileDtoHub
{
public XFileDtoHub(
ILogger<XFileDtoHub> logger
) : base(logger)
{ }
}
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using AutoMapper;
using xDataService.Providers;
using xFileService.Interfaces.Dtos;
using xFileService.Interfaces.Entities;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
namespace xFileService.Providers.Dtos
{
public class XFileRepositoryService : XBaseRepositoryService<XFile, XFileDto, Guid>, IXFileRepositoryService
{
public XFileRepositoryService(
IXFileRepository repository,
IEnumerable<Profile> mapperProfiles = null
) : base(
repository,
mapperProfiles
)
{ }
}
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using Microsoft.AspNetCore.SignalR;
using xDataService.Configuration;
using xFileService.Interfaces.Dtos;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xIdentityService.Interfaces;
using xPushService.Base;
namespace xFileService.Providers.Dtos
{
public class XFileServiceProvider : XBaseDtoProvider<XFile, XFileDto, Guid, XFileDtoHub>, IXFileServiceProvider
{
public XFileServiceProvider(
IHubContext<XFileDtoHub> hub,
XDataServiceConfiguration dataConfiguration,
IXFileRepositoryService service,
IXIdentityProvider identityProvider = null
) : base(
hub,
dataConfiguration,
service,
identityProvider
)
{ }
}
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using xDataService.Configuration;
using xDataService.Db;
using xDataService.Interfaces;
using xDataService.Providers;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.Providers.Entities
{
public class XFileEFRepository<TContext> : XBaseEFRepository<XFile, Guid, TContext>, IXFileRepository
where TContext : XDbContext
{
public XFileEFRepository(
IXUnitOfWorks<TContext> unitOfWorks,
XDataServiceConfiguration configuration,
IXFileKeyGenerator keyGenerator = null,
IXFileRepositoryEvents baseRepositoryEvents = null
) : base(
unitOfWorks,
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
+16
View File
@@ -0,0 +1,16 @@
using System;
using Microsoft.Extensions.Logging;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
using xPushService.Base;
namespace xFileService.Providers.Entities
{
public class XFileEntityHub : XBaseEntityHub<XFile, Guid>, IXFileEntityHub
{
public XFileEntityHub(
ILogger<XFileEntityHub> logger
) : base(logger)
{ }
}
}
@@ -0,0 +1,22 @@
using System;
using xDataService.Configuration;
using xDataService.Providers;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.Providers.Entities
{
public class XFileInMemoryRepository : XBaseInMemoryRepository<XFile, Guid>, IXFileRepository
{
public XFileInMemoryRepository(
XDataServiceConfiguration configuration,
IXFileKeyGenerator keyGenerator = null,
IXFileRepositoryEvents baseRepositoryEvents = null
) : base(
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
+9
View File
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.Providers.Entities
{
public class XFileKeyGenerator : XGuidKeyGenerator<XFile>, IXFileKeyGenerator
{ }
}
@@ -0,0 +1,26 @@
using System;
using xDataService.Configuration;
using xDataService.Providers;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.Providers.Entities
{
public class XFileMongoRepository : XBaseMongoRepository<XFile, Guid>, IXFileRepository
{
public XFileMongoRepository(
XDataBaseConfiguration dbConfiguration,
XDataServiceConfiguration configuration,
string collectionName = null,
IXFileKeyGenerator keyGenerator = null,
IXFileRepositoryEvents baseRepositoryEvents = null
) : base(
dbConfiguration,
configuration,
collectionName,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.Providers.Entities
{
public class XFileRepositoryEvents : XBaseRepositoryEvents<XFile>, IXFileRepositoryEvents
{ }
}
@@ -0,0 +1,26 @@
using System;
using Microsoft.AspNetCore.SignalR;
using xDataService.Configuration;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
using xIdentityService.Interfaces;
using xPushService.Base;
namespace xFileService.Providers.Entities
{
public class XFileRepositoryProvider : XBaseEntityProvider<XFile, Guid, XFileEntityHub>, IXFileRepositoryProvider
{
public XFileRepositoryProvider(
IHubContext<XFileEntityHub> hub,
IXFileRepository repository,
XDataServiceConfiguration dataConfiguration,
IXIdentityProvider identityProvider = null
) : base(
hub,
repository,
dataConfiguration,
identityProvider
)
{ }
}
}
+24
View File
@@ -0,0 +1,24 @@
using System;
using xDataService.Configuration;
using xDataService.Providers;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.Providers.Entities
{
public abstract class XFileSeederBase : XBaseDbSeeder<XFile, Guid>, IXFileSeeder
{
protected XFileSeederBase(
string entity,
string database,
IXFileRepository repository,
XDataServiceConfiguration dataServiceConfiguration
) : base(
entity,
database,
repository,
dataServiceConfiguration
)
{ }
}
}
@@ -1,10 +1,11 @@
using System;
using xDataService.Configuration;
using xDataService.GraphQL;
using xFileService.Constants;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.DataHelper.GraphQL
namespace xFileService.Providers.GraphQL
{
public class XFileGraphQLTypeHelper : XBaseGraphQLTypeHelper<XFile, Guid>, IXFileGraphQLTypeHelper
{
@@ -15,12 +16,12 @@ namespace xFileService.DataHelper.GraphQL
public override string GetInQueryCollectionName()
{
return "files";
return XFileServiceConstants.XFileCollectionName;
}
public override string GetInQuerySingleName()
{
return "file";
return XFileServiceConstants.XFileSingleName;
}
}
}
@@ -5,7 +5,7 @@ using xDataService.GraphQL;
using xFileService.Interfaces.Entities;
using xFileService.Models.Entities;
namespace xFileService.DataHelper.GraphQL
namespace xFileService.Providers.GraphQL
{
public class XFileGraphQuery : XBaseGraphQLQuery<XFile, Guid, XFileGraphType, GuidGraphType>
{
@@ -1,7 +1,7 @@
using System;
using GraphQL.Types;
namespace xFileService.DataHelper.GraphQL
namespace xFileService.Providers.GraphQL
{
public class XFileGraphSchema : Schema
{
@@ -9,5 +9,6 @@ namespace xFileService.DataHelper.GraphQL
{
Query = (XFileGraphQuery)services.GetService(typeof(XFileGraphQuery));
}
}
}
@@ -2,20 +2,21 @@ using System;
using xDataService.GraphQL;
using xFileService.Models.Entities;
namespace xFileService.DataHelper.GraphQL
namespace xFileService.Providers.GraphQL
{
public class XFileGraphType : XBaseGraphObjectType<XFile, Guid>
{
public XFileGraphType() : base()
{
Field(x => x.Type);
Field(x => x.OwnerId);
Field(x => x.Name);
Field(x => x.Path);
Field(x => x.Thumb);
Field(x => x.OwnerId);
Field(x => x.FileName);
Field(x => x.ThumbPath);
Field(x => x.UploadedOn);
Field(x => x.FileName);
Field(x => x.References);
}
}
}
File diff suppressed because it is too large Load Diff
+35
View File
@@ -0,0 +1,35 @@
using System;
using Microsoft.EntityFrameworkCore;
using xDataService.Interfaces;
using xDataService.Providers;
using xFileService.Configurations.Entities;
using xFileService.Models.Entities;
namespace xFileService.Providers
{
public class XFileEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XFileEntityRegisterar()
: base(nameof(XFileEntityRegisterar))
{
//
// Add XFile Entity ...
AddEntity<XFile, Guid>();
}
/// <summary>
/// Configure Entities ...
/// </summary>
/// <param name="modelBuilder"></param>
public override void ConfigureEntities(ModelBuilder modelBuilder)
{
//
// Configure Entity Using Provided ...
modelBuilder
.ApplyConfigurationsFromAssembly(typeof(XFileEntityConfiguration).Assembly);
//
base.ConfigureEntities(modelBuilder);
}
}
}
+273 -1088
View File
File diff suppressed because it is too large Load Diff
+56
View File
@@ -0,0 +1,56 @@
using System;
using xCommons.Extensions;
using xFileService.Interfaces;
using xFileService.Interfaces.Dtos;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xFileService.Providers.Dtos;
using xIdentityModels.Models;
using xTagService.Interfaces;
using xTagService.Providers;
namespace xFileService.Providers
{
public class XFileTagProvided : XBaseTagProvided<XFile, XFileDto, Guid, XFileDtoHub>, IXFileTagProvided
{
public XFileTagProvided(
IXFileTagProvider tagProvider,
IXFileServiceProvider provider
) : base(
provider: provider,
tagProvider: tagProvider,
permittedRoles: new string[] { "admin" }
)
{ }
public override bool IsOwned(
XFileDto item,
XUserClaimsInfoDto userInfo
)
{
//
var result =
!item.IsNullOrDefault() &&
!userInfo.IsNullOrDefault() &&
item.OwnerId == userInfo.UserId;
//
return result;
}
public override bool IsOwned(
XFile item,
XUserClaimsInfoDto userInfo
)
{
//
var result =
!item.IsNullOrDefault() &&
!userInfo.IsNullOrDefault() &&
item.OwnerId == userInfo.UserId;
//
return result;
}
}
}
+5 -5
View File
@@ -1,7 +1,7 @@
using System;
using xFileService.Constants;
using xFileService.Interfaces;
using xFileService.Models.Entities;
using xTagService.Interfaces;
using xTagService.Interfaces.Dtos;
using xTagService.Providers;
namespace xFileService.Providers
@@ -9,10 +9,10 @@ namespace xFileService.Providers
public class XFileTagProvider : XBaseTagProvider<Guid>, IXFileTagProvider
{
public XFileTagProvider(
IXTagProvider tagProvider
IXTagServiceProvider tagProvider
) : base(
providedFor: nameof(XFile),
tagProvider: tagProvider
tagProvider: tagProvider,
providedFor: XFileServiceConstants.XFileTagProvided
)
{ }
}
+2 -1
View File
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- <add key="megan" value="https://hub.megan.ir/nuget/index.json" /> -->
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" />
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" disableTLSCertificateValidation="true" />
</packageSources>
</configuration>
+13 -12
View File
@@ -2,11 +2,13 @@
<!-- Runtime Definition -->
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>xDashboard.xFileService</PackageId>
<Version>1.0.0</Version>
<LangVersion>12.0</LangVersion>
<Authors>Hadi Khazaee Asl</Authors>
<Company>SaherElm IT Center</Company>
<PackageId>xDashboard.xFileService</PackageId>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>
it is a Part of xDashboard on SaherElm IT Center which provides all Files Related Futures ...
</Description>
@@ -17,28 +19,27 @@
<!-- Icon Handling -->
<ItemGroup>
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true" PackagePath="\icon.png" />
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true"
PackagePath="\icon.png" />
</ItemGroup>
<!-- Local Modules -->
<ItemGroup>
<!-- <PackageReference Include="xDashboard.xTagService" Version="1.0.0" /> -->
<!-- <PackageReference Include="xDashboard.xDataService" Version="1.0.0" /> -->
<!-- <PackageReference Include="xDashboard.xStringService" Version="1.0.0" /> -->
<!-- <PackageReference Include="xDashboard.xStorageService" Version="1.0.0" /> -->
<!-- <PackageReference Include="xDashboard.xIdentityService" Version="1.0.0" /> -->
</ItemGroup>
<!-- Local Dependencies -->
<ItemGroup>
<ProjectReference Include="../xTagService/xTagService.csproj" />
<ProjectReference Include="../xPushService/xPushService.csproj" />
<ProjectReference Include="../xIdentityService/xIdentityService.csproj" />
<ProjectReference Include="../xDataService/xDataService.csproj" />
<ProjectReference Include="../xStorageService/xStorageService.csproj" />
<!--
<ProjectReference Include="../xStringService/xStringService.csproj" />
-->
</ItemGroup>
<!-- For XML Documentation Support -->
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
</Project>