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 System.Collections.Generic;
using xCommons.Extensions; using xCommons.Extensions;
using xDataService.Extensions;
using xFileService.Models.Dtos; using xFileService.Models.Dtos;
using xFileService.Models.Entities; using xFileService.Models.Entities;
@@ -31,6 +32,14 @@ namespace xFileService.Extensions
nameof(XFile.References), 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()) { if (!source.References.IsNull() && source.References.HasChild())
result.References = source.References.ToListString(); {
result.References = source.References.ToXReferenceString();
} }
} }
+14 -131
View File
@@ -1,45 +1,29 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using xFileService.Models.Dtos; using xFileService.Models.Dtos;
using xFileService.Models.Entities;
using xIdentityModels.Models; using xIdentityModels.Models;
using xModels.Dtos; using xIdentityService.Interfaces;
using XFileDto = xFileService.Models.Dtos.XFileDto; using XFileDto = xFileService.Models.Dtos.XFileDto;
// using xModels.Dtos;
using xTagService.Interfaces;
namespace xFileService.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 ... #region Props ...
/// <summary>
/// Specified Provider ...
/// </summary>
string ProvidedFor { get; }
/// <summary> /// <summary>
/// Specified Provider Repositroy ... /// Specified Provider Repositroy ...
/// </summary> /// </summary>
IXFileProvider Provider { get; } IXFileProvider FileProvider { get; }
#endregion #endregion
//
#region Helper ...
/// <summary>
/// Get Specified Identifier ...
/// </summary>
/// <param name="forProvidedId"></param>
/// <returns></returns>
string GetIdentifier(TKey forProvidedId);
#endregion
// //
#region Tools ... #region Tools ...
/// <summary> /// <summary>
@@ -56,7 +40,6 @@ namespace xFileService.Interfaces
/// <returns></returns> /// <returns></returns>
Task<FileStreamResult> Stream(string fileName); Task<FileStreamResult> Stream(string fileName);
/// <summary> /// <summary>
/// Download Specified File ... /// Download Specified File ...
/// </summary> /// </summary>
@@ -76,14 +59,14 @@ namespace xFileService.Interfaces
/// </summary> /// </summary>
/// <param name="forProvidedId"></param> /// <param name="forProvidedId"></param>
/// <param name="files"></param> /// <param name="files"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<XFileDto>> Upload( Task<IEnumerable<XFileDto>> Upload(
TKey forProvidedId, TKey forProvidedId,
IFormFileCollection files, IFormFileCollection files,
XUserClaimsInfoDto userInfo = null, string connectionId = null,
string connectionId = null XUserClaimsInfoDto userInfo = null
); );
/// <summary> /// <summary>
@@ -91,14 +74,14 @@ namespace xFileService.Interfaces
/// </summary> /// </summary>
/// <param name="forProvidedId"></param> /// <param name="forProvidedId"></param>
/// <param name="ids"></param> /// <param name="ids"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<Guid>> Remove( Task<IEnumerable<Guid>> RemoveFile(
TKey forProvidedId, TKey forProvidedId,
string ids = null, string ids = null,
XUserClaimsInfoDto userInfo = null, string connectionId = null,
string connectionId = null XUserClaimsInfoDto userInfo = null
); );
/// <summary> /// <summary>
@@ -115,105 +98,5 @@ namespace xFileService.Interfaces
/// <returns></returns> /// <returns></returns>
Task<XFileStreamDescriptorDto> GetFileDescriptor(string fileName); Task<XFileStreamDescriptorDto> GetFileDescriptor(string fileName);
#endregion #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="providedFor"></param>
/// <param name="forProvidedId"></param> /// <param name="forProvidedId"></param>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="forIndex"></param>
/// <param name="userInfo"></param> /// <param name="userInfo"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <returns></returns> /// <returns></returns>
@@ -247,6 +248,7 @@ namespace xFileService.Interfaces
string providedFor, string providedFor,
TKey forProvidedId, TKey forProvidedId,
Guid id, Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null, XUserClaimsInfoDto userInfo = null,
string connectionId = null string connectionId = null
); );
@@ -257,6 +259,7 @@ namespace xFileService.Interfaces
/// <param name="providedFor"></param> /// <param name="providedFor"></param>
/// <param name="forProvidedId"></param> /// <param name="forProvidedId"></param>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="forIndex"></param>
/// <param name="userInfo"></param> /// <param name="userInfo"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <returns></returns> /// <returns></returns>
@@ -264,6 +267,7 @@ namespace xFileService.Interfaces
string providedFor, string providedFor,
TKey forProvidedId, TKey forProvidedId,
Guid id, Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null, XUserClaimsInfoDto userInfo = null,
string connectionId = null string connectionId = null
); );
+4 -3
View File
@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using xCommons.Constants; using xCommons.Constants;
using xDataService.Models;
using xModels.Base; using xModels.Base;
using xModels.Dtos; using xModels.Dtos;
@@ -9,7 +10,7 @@ namespace xFileService.Models.Dtos
public class XFileDto : XBaseDto public class XFileDto : XBaseDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public XFileType Type { get; set; } public XFileType Type { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Thumb { get; set; } public string Thumb { get; set; }
@@ -20,7 +21,7 @@ namespace xFileService.Models.Dtos
public string OwnerId { get; set; } public string OwnerId { get; set; }
public XPersonDto Owner { 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 Microsoft.AspNetCore.StaticFiles;
using System.Linq; using System.Linq;
using xPushService.Constants; using xPushService.Constants;
using xDataService.Models;
namespace xFileService.Providers namespace xFileService.Providers
{ {
@@ -251,10 +252,10 @@ namespace xFileService.Providers
try try
{ {
// //
await TagProvider.Attach( await TagProvider.AddReference(
tag, tag: tag,
id, providedForId: id,
connectionId connectionId: connectionId
); );
} }
catch { } catch { }
@@ -298,10 +299,10 @@ namespace xFileService.Providers
try try
{ {
// //
await TagProvider.Detach( await TagProvider.RemoveReference(
tag, tag: tag,
id, providedForId: id,
connectionId connectionId: connectionId
); );
} }
catch { } catch { }
@@ -447,7 +448,10 @@ namespace xFileService.Providers
try try
{ {
// //
var tags = await TagProvider.RemoveTagsFor(id); await TagProvider.RemoveReferences(
providedForId: id,
connectionId: connectionId
);
} }
catch { } catch { }
} }
@@ -464,7 +468,7 @@ namespace xFileService.Providers
// Validate ... // Validate ...
var isValid = !id.IsNull() && var isValid = !id.IsNull() &&
!id.IsDefaultGuid(); !id.IsDefaultGuid();
if (!isValid) if (!isValid)
{ {
XException.InvalidArgs.Throw(); 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>(); var result = new List<string>();
@@ -492,7 +496,7 @@ namespace xFileService.Providers
// //
return result; return result;
} }
#endregion #endregion
// //
@@ -847,8 +851,8 @@ namespace xFileService.Providers
// Here we send Null Connection ID for Preventing Update Push ... // Here we send Null Connection ID for Preventing Update Push ...
// since we Remove Entity ... // since we Remove Entity ...
await DetachTags( await DetachTags(
id: id, id: id,
userInfo: userInfo, userInfo: userInfo,
connectionId: null connectionId: null
); );
} }
@@ -1076,14 +1080,11 @@ namespace xFileService.Providers
} }
// //
var identifier = GetIdentifier(
providedFor: providedFor,
forProvidedId: forProvidedId
);
var result = var result =
dto.References.IsNull() && dto.References.IsNull() &&
dto.References.HasChild() && dto.References.HasChild() &&
dto.References.Any(r => r.ToNormalString() == identifier.ToNormalString()); dto.References.Any(r => r.ProvidedFor == providedFor &&
r.ReferencedTo == $"{forProvidedId}");
// //
return result; return result;
@@ -1095,6 +1096,7 @@ namespace xFileService.Providers
/// <param name="providedFor"></param> /// <param name="providedFor"></param>
/// <param name="forProvidedId"></param> /// <param name="forProvidedId"></param>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="forIndex"></param>
/// <param name="userInfo"></param> /// <param name="userInfo"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <returns></returns> /// <returns></returns>
@@ -1102,6 +1104,7 @@ namespace xFileService.Providers
string providedFor, string providedFor,
TKey forProvidedId, TKey forProvidedId,
Guid id, Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null, XUserClaimsInfoDto userInfo = null,
string connectionId = null string connectionId = null
) )
@@ -1148,16 +1151,18 @@ namespace xFileService.Providers
} }
// //
var identifier = GetIdentifier( var reference = new XReference<string>
providedFor: providedFor, {
forProvidedId: forProvidedId Index = forIndex,
); ProvidedFor = providedFor,
dto.References.Add(identifier); ReferencedTo = $"{forProvidedId}"
};
dto.References.Add(reference);
// //
dto = await Update( dto = await Update(
id: dto.Id,
item: dto, item: dto,
id: dto.Id,
userInfo: userInfo, userInfo: userInfo,
connectionId: connectionId connectionId: connectionId
); );
@@ -1175,6 +1180,7 @@ namespace xFileService.Providers
/// <param name="providedFor"></param> /// <param name="providedFor"></param>
/// <param name="forProvidedId"></param> /// <param name="forProvidedId"></param>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="forIndex"></param>
/// <param name="userInfo"></param> /// <param name="userInfo"></param>
/// <param name="connectionId"></param> /// <param name="connectionId"></param>
/// <returns></returns> /// <returns></returns>
@@ -1182,6 +1188,7 @@ namespace xFileService.Providers
string providedFor, string providedFor,
TKey forProvidedId, TKey forProvidedId,
Guid id, Guid id,
int forIndex = 0,
XUserClaimsInfoDto userInfo = null, XUserClaimsInfoDto userInfo = null,
string connectionId = null string connectionId = null
) )
@@ -1234,11 +1241,15 @@ namespace xFileService.Providers
forProvidedId: forProvidedId forProvidedId: forProvidedId
); );
dto.References = dto.References dto.References = dto.References
.Where(r => r.ToNormalString() != identifier.ToNormalString()) .Where(r =>
r.Index != forIndex &&
r.ProvidedFor != providedFor &&
r.ReferencedTo != $"{forProvidedId}"
)
.ToList(); .ToList();
dto = await Update( dto = await Update(
id: dto.Id,
item: dto, item: dto,
id: dto.Id,
userInfo: userInfo, userInfo: userInfo,
connectionId: connectionId connectionId: connectionId
); );
@@ -1642,7 +1653,7 @@ namespace xFileService.Providers
// //
// Removing Tags ... // Removing Tags ...
await TagProvider.RemoveTagsFor(result.Id); await TagProvider.RemoveReferences(result.Id);
// //
await SendPush( await SendPush(