Refactor Providing Mechanism ...

This commit is contained in:
2025-12-17 14:44:55 +03:30
parent 0b033ab1b9
commit 228e2e4eca
6 changed files with 635 additions and 498 deletions
+12 -2
View File
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using xCommons.Extensions;
using xDataService.Extensions;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
@@ -31,6 +32,14 @@ namespace xFileService.Extensions
nameof(XFile.References),
}
);
//
// Preparing List ...
if (!source.References.IsNullOrEmpty())
{
result.References = source.References.ParseXReferenceList<string>();
}
}
//
@@ -62,8 +71,9 @@ namespace xFileService.Extensions
);
//
if (!source.References.IsNull() && source.References.HasChild()) {
result.References = source.References.ToListString();
if (!source.References.IsNull() && source.References.HasChild())
{
result.References = source.References.ToXReferenceString();
}
}
+14 -131
View File
@@ -1,45 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xIdentityModels.Models;
using xModels.Dtos;
using xIdentityService.Interfaces;
using XFileDto = xFileService.Models.Dtos.XFileDto;
// using xModels.Dtos;
using xTagService.Interfaces;
namespace xFileService.Interfaces
{
public interface IXBaseFileProvider<TKey>
/// <summary>
/// Implementing XBaseFileProvider ...
/// </summary>
/// <typeparam name="TKey"></typeparam>
public interface IXBaseFileProvider<TKey> : IXIdentityBaseReferencedProvider<XFileDto, TKey>
{
//
#region Props ...
/// <summary>
/// Specified Provider ...
/// </summary>
string ProvidedFor { get; }
/// <summary>
/// Specified Provider Repositroy ...
/// </summary>
IXFileProvider Provider { get; }
IXFileProvider FileProvider { get; }
#endregion
//
#region Helper ...
/// <summary>
/// Get Specified Identifier ...
/// </summary>
/// <param name="forProvidedId"></param>
/// <returns></returns>
string GetIdentifier(TKey forProvidedId);
#endregion
//
#region Tools ...
/// <summary>
@@ -56,7 +40,6 @@ namespace xFileService.Interfaces
/// <returns></returns>
Task<FileStreamResult> Stream(string fileName);
/// <summary>
/// Download Specified File ...
/// </summary>
@@ -76,14 +59,14 @@ namespace xFileService.Interfaces
/// </summary>
/// <param name="forProvidedId"></param>
/// <param name="files"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
Task<IEnumerable<XFileDto>> Upload(
TKey forProvidedId,
IFormFileCollection files,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
string connectionId = null,
XUserClaimsInfoDto userInfo = null
);
/// <summary>
@@ -91,14 +74,14 @@ namespace xFileService.Interfaces
/// </summary>
/// <param name="forProvidedId"></param>
/// <param name="ids"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
Task<IEnumerable<Guid>> Remove(
Task<IEnumerable<Guid>> RemoveFile(
TKey forProvidedId,
string ids = null,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
string connectionId = null,
XUserClaimsInfoDto userInfo = null
);
/// <summary>
@@ -115,105 +98,5 @@ namespace xFileService.Interfaces
/// <returns></returns>
Task<XFileStreamDescriptorDto> GetFileDescriptor(string fileName);
#endregion
//
#region Data Model ...
/// <summary>
/// Get Specified File Model ...
/// </summary>
/// <param name="id"></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>
/// Get All Exists File Models ...
/// </summary>
/// <param name="forProvidedId"></param>
/// <returns></returns>
Task<IEnumerable<XFileDto>> GetAllFor(TKey forProvidedId);
/// <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 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>
/// Update an Entity values ...
/// </summary>
/// <param name="id"></param>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
Task<XFileDto> Update(
Guid id,
XFileDto item,
XUserClaimsInfoDto userInfo = null
);
/// <summary>
/// remove an Entity ...
/// </summary>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
Task<XFileDto> Remove(
Guid id,
XUserClaimsInfoDto userInfo = 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
);
#endregion
}
}
+4
View File
@@ -240,6 +240,7 @@ namespace xFileService.Interfaces
/// <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>
@@ -247,6 +248,7 @@ namespace xFileService.Interfaces
string providedFor,
TKey forProvidedId,
Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
@@ -257,6 +259,7 @@ namespace xFileService.Interfaces
/// <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>
@@ -264,6 +267,7 @@ namespace xFileService.Interfaces
string providedFor,
TKey forProvidedId,
Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
);
+4 -3
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using xCommons.Constants;
using xDataService.Models;
using xModels.Base;
using xModels.Dtos;
@@ -9,7 +10,7 @@ namespace xFileService.Models.Dtos
public class XFileDto : XBaseDto
{
public Guid Id { get; set; }
public XFileType Type { get; set; }
public string Name { get; set; }
public string Thumb { get; set; }
@@ -20,7 +21,7 @@ namespace xFileService.Models.Dtos
public string OwnerId { get; set; }
public XPersonDto Owner { get; set; }
public IList<string> References = new List<string>();
public IList<XReference<string>> References = new List<XReference<string>>();
}
}
File diff suppressed because it is too large Load Diff
+39 -28
View File
@@ -25,6 +25,7 @@ using Microsoft.Extensions.FileProviders;
using Microsoft.AspNetCore.StaticFiles;
using System.Linq;
using xPushService.Constants;
using xDataService.Models;
namespace xFileService.Providers
{
@@ -251,10 +252,10 @@ namespace xFileService.Providers
try
{
//
await TagProvider.Attach(
tag,
id,
connectionId
await TagProvider.AddReference(
tag: tag,
providedForId: id,
connectionId: connectionId
);
}
catch { }
@@ -298,10 +299,10 @@ namespace xFileService.Providers
try
{
//
await TagProvider.Detach(
tag,
id,
connectionId
await TagProvider.RemoveReference(
tag: tag,
providedForId: id,
connectionId: connectionId
);
}
catch { }
@@ -447,7 +448,10 @@ namespace xFileService.Providers
try
{
//
var tags = await TagProvider.RemoveTagsFor(id);
await TagProvider.RemoveReferences(
providedForId: id,
connectionId: connectionId
);
}
catch { }
}
@@ -464,7 +468,7 @@ namespace xFileService.Providers
// Validate ...
var isValid = !id.IsNull() &&
!id.IsDefaultGuid();
if (!isValid)
if (!isValid)
{
XException.InvalidArgs.Throw();
}
@@ -478,7 +482,7 @@ namespace xFileService.Providers
}
//
var tags = await TagProvider.GetTags(id);
var tags = await TagProvider.GetAllReferences(id);
//
var result = new List<string>();
@@ -492,7 +496,7 @@ namespace xFileService.Providers
//
return result;
}
}
#endregion
//
@@ -847,8 +851,8 @@ namespace xFileService.Providers
// Here we send Null Connection ID for Preventing Update Push ...
// since we Remove Entity ...
await DetachTags(
id: id,
userInfo: userInfo,
id: id,
userInfo: userInfo,
connectionId: null
);
}
@@ -1076,14 +1080,11 @@ namespace xFileService.Providers
}
//
var identifier = GetIdentifier(
providedFor: providedFor,
forProvidedId: forProvidedId
);
var result =
dto.References.IsNull() &&
dto.References.HasChild() &&
dto.References.Any(r => r.ToNormalString() == identifier.ToNormalString());
dto.References.Any(r => r.ProvidedFor == providedFor &&
r.ReferencedTo == $"{forProvidedId}");
//
return result;
@@ -1095,6 +1096,7 @@ namespace xFileService.Providers
/// <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>
@@ -1102,6 +1104,7 @@ namespace xFileService.Providers
string providedFor,
TKey forProvidedId,
Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
)
@@ -1148,16 +1151,18 @@ namespace xFileService.Providers
}
//
var identifier = GetIdentifier(
providedFor: providedFor,
forProvidedId: forProvidedId
);
dto.References.Add(identifier);
var reference = new XReference<string>
{
Index = forIndex,
ProvidedFor = providedFor,
ReferencedTo = $"{forProvidedId}"
};
dto.References.Add(reference);
//
dto = await Update(
id: dto.Id,
item: dto,
id: dto.Id,
userInfo: userInfo,
connectionId: connectionId
);
@@ -1175,6 +1180,7 @@ namespace xFileService.Providers
/// <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>
@@ -1182,6 +1188,7 @@ namespace xFileService.Providers
string providedFor,
TKey forProvidedId,
Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null,
string connectionId = null
)
@@ -1234,11 +1241,15 @@ namespace xFileService.Providers
forProvidedId: forProvidedId
);
dto.References = dto.References
.Where(r => r.ToNormalString() != identifier.ToNormalString())
.Where(r =>
r.Index != forIndex &&
r.ProvidedFor != providedFor &&
r.ReferencedTo != $"{forProvidedId}"
)
.ToList();
dto = await Update(
id: dto.Id,
item: dto,
id: dto.Id,
userInfo: userInfo,
connectionId: connectionId
);
@@ -1642,7 +1653,7 @@ namespace xFileService.Providers
//
// Removing Tags ...
await TagProvider.RemoveTagsFor(result.Id);
await TagProvider.RemoveReferences(result.Id);
//
await SendPush(