diff --git a/Extensions/xFileServiceExtensions.cs b/Extensions/xFileServiceExtensions.cs
index 6ea5897..66e692c 100644
--- a/Extensions/xFileServiceExtensions.cs
+++ b/Extensions/xFileServiceExtensions.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using xCommons.Extensions;
using xFileService.Models.Dtos;
using xFileService.Models.Entities;
@@ -11,7 +12,7 @@ namespace xFileService.Extensions
///
///
///
- public static XFileDto ToXFileDto(this XFile source)
+ public static XFileDto ToDto(this XFile source)
{
//
XFileDto result = null;
@@ -21,25 +22,54 @@ namespace xFileService.Extensions
{
//
result = new XFileDto();
- result = result.UpdateData(source);
-
- //
- // result = new XFileDto
- // {
- // Id = source.Id,
- // Type = source.Type,
- // OwnerId = source.OwnerId,
- // Name = source.Name,
- // Path = source.Path,
- // Thumb = source.Thumb,
- // ThumbPath = source.ThumbPath,
- // UploadedOn = source.UploadedOn,
- // FileName = source.FileName
- // };
+ result = result.UpdateData(
+ updateWith: source,
+ propertyBlackList: new List
+ {
+ nameof(XFileDto.Owner),
+ nameof(XFile.Deleted),
+ nameof(XFile.References),
+ }
+ );
}
//
return result;
}
+
+ ///
+ /// Converts a Dto to Entity Representation ...
+ /// Ignore ID Property ...
+ ///
+ ///
+ ///
+ public static XFile FromDto(this XFileDto source)
+ {
+ //
+ var result = new XFile();
+
+ //
+ if (!source.IsNull())
+ {
+ //
+ result = result.UpdateData(
+ updateWith: source,
+ propertyBlackList: new List
+ {
+ nameof(XFile.Deleted),
+ nameof(XFile.References),
+ }
+ );
+
+ //
+ if (!source.References.IsNull() && source.References.HasChild()) {
+ result.References = source.References.ToListString();
+ }
+ }
+
+ //
+ return result;
+
+ }
}
}
\ No newline at end of file
diff --git a/Interfaces/IXBaseFileProvider.cs b/Interfaces/IXBaseFileProvider.cs
new file mode 100644
index 0000000..a88c7b7
--- /dev/null
+++ b/Interfaces/IXBaseFileProvider.cs
@@ -0,0 +1,211 @@
+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 XFileDto = xFileService.Models.Dtos.XFileDto;
+
+// using xModels.Dtos;
+using xTagService.Interfaces;
+
+namespace xFileService.Interfaces
+{
+ public interface IXBaseFileProvider
+ {
+ //
+ #region Props ...
+ ///
+ /// Specified Provider ...
+ ///
+ string ProvideFor { get; }
+
+ ///
+ /// Specified Provider Repositroy ...
+ ///
+ IXFileProvider Provider { get; }
+
+ ///
+ /// Tag Provider for Specified File ...
+ ///
+ ///
+ IXBaseTagProvider TagProvider { get; }
+ #endregion
+
+ //
+ #region Helper ...
+ ///
+ /// Get Specified Identifier ...
+ ///
+ ///
+ ///
+ string GetIdentifier(TKey forProvidedId);
+ #endregion
+
+ //
+ #region Implementation ...
+ ///
+ /// Stream Specified File ...
+ ///
+ ///
+ ///
+ Task Stream(Guid id);
+
+ ///
+ /// Stream Specified File ...
+ ///
+ ///
+ ///
+ Task Stream(string fileName);
+
+
+ ///
+ /// Download Specified File ...
+ ///
+ ///
+ ///
+ Task Download(Guid id);
+
+ ///
+ /// Download Specified File ...
+ ///
+ ///
+ ///
+ Task Download(string fileName);
+
+ ///
+ /// Upload Files ...
+ ///
+ ///
+ ///
+ ///
+ Task> Upload(
+ IFormFileCollection files,
+ XUserClaimsInfoDto userInfo = null
+ );
+
+ ///
+ /// Remove Specified Files ...
+ ///
+ ///
+ ///
+ ///
+ Task> Remove(
+ string ids,
+ XUserClaimsInfoDto userInfo = null
+ );
+
+ ///
+ /// Retrieve Specified File Streaming Info ...
+ ///
+ ///
+ ///
+ Task GetFileDescriptor(Guid id);
+
+ ///
+ /// Retrieve Specified File Streaming Info ...
+ ///
+ ///
+ ///
+ Task GetFileDescriptor(string fileName);
+ #endregion
+
+ //
+ #region Data Model ...
+ ///
+ /// Get Specified File Model ...
+ ///
+ ///
+ ///
+ ///
+ Task Get(
+ Guid id
+ );
+
+ ///
+ /// Get All Exists File Models ...
+ ///
+ ///
+ ///
+ Task> GetAll();
+
+ ///
+ /// find an Entity by providing a Conditional Expression ...
+ ///
+ ///
+ Task FindOne(Expression> whereClause);
+
+ ///
+ /// find a collection of Entities by proving a Conditional Expression ...
+ ///
+ ///
+ ///
+ Task> FindMany(
+ Expression> whereClause
+ );
+
+ ///
+ /// retrieve Entities based on XQuery Pagination structure ...
+ ///
+ ///
+ ///
+ Task> Query(
+ XQuery query
+ );
+
+ ///
+ /// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
+ ///
+ ///
+ ///
+ ///
+ Task> ConditionalQuery(
+ Expression> whereClause,
+ XQuery query
+ );
+
+ ///
+ /// Update an Entity values ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ Task Update(
+ Guid id,
+ XFileDto item,
+ XUserClaimsInfoDto userInfo = null
+ );
+
+ ///
+ /// remove an Entity ...
+ ///
+ ///
+ ///
+ ///
+ Task Remove(
+ Guid id,
+ XUserClaimsInfoDto userInfo = null
+ );
+
+ ///
+ /// count all exists Entities ...
+ ///
+ ///
+ Task Count();
+
+ ///
+ /// Check an Entity exists or not ...
+ ///
+ ///
+ ///
+ Task IsExists(
+ Guid id
+ );
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/Interfaces/IXFileProvider.cs b/Interfaces/IXFileProvider.cs
index d6fe1b5..cc3f315 100644
--- a/Interfaces/IXFileProvider.cs
+++ b/Interfaces/IXFileProvider.cs
@@ -29,6 +29,30 @@ namespace xFileService.Interfaces
XDataServiceConfiguration DataSercviceConfiguration { get; }
#endregion
+ //
+ #region Helpers ...
+ ///
+ /// Converts an Entity to Dto ...
+ ///
+ ///
+ ///
+ Task ToDto(XFile model);
+
+ ///
+ /// Convert a List of Entities to Dto ...
+ ///
+ ///
+ ///
+ Task> ToDtoList(IEnumerable list);
+
+ ///
+ /// Converts an Entity Query Result to Dto ...
+ ///
+ ///
+ ///
+ Task> ToDtoQueryResult(XQueryResult queryResult);
+ #endregion
+
//
#region Tools ...
///
@@ -189,29 +213,5 @@ namespace xFileService.Interfaces
Guid id
);
#endregion
-
- //
- #region Helpers ...
- ///
- /// Converts an Entity to Dto ...
- ///
- ///
- ///
- Task ToXFileDto(XFile model);
-
- ///
- /// Convert a List of Entities to Dto ...
- ///
- ///
- ///
- Task> ToXDtoList(IEnumerable list);
-
- ///
- /// Converts an Entity Query Result to Dto ...
- ///
- ///
- ///
- Task> ToXDtoQueryResult(XQueryResult queryResult);
- #endregion
}
}
\ No newline at end of file
diff --git a/Models/Dtos/XFileDto.cs b/Models/Dtos/XFileDto.cs
index de112ef..bdc8355 100644
--- a/Models/Dtos/XFileDto.cs
+++ b/Models/Dtos/XFileDto.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using xCommons.Constants;
using xModels.Base;
using xModels.Dtos;
@@ -19,5 +20,7 @@ namespace xFileService.Models.Dtos
public string OwnerId { get; set; }
public XPersonDto Owner { get; set; }
+
+ public IList References = new List();
}
}
\ No newline at end of file
diff --git a/Models/Entities/XFile.cs b/Models/Entities/XFile.cs
index 5ca1dbd..2822ce1 100644
--- a/Models/Entities/XFile.cs
+++ b/Models/Entities/XFile.cs
@@ -64,5 +64,12 @@ namespace xFileService.Models.Entities
///
///
public string FileName { get; set; }
+
+ ///
+ /// Comma Separated List Which Provides Pointer to Specified
+ /// Model for Describe ...
+ ///
+ ///
+ public string References { get; set; }
}
}
\ No newline at end of file
diff --git a/Providers/XBaseFileProvider.cs b/Providers/XBaseFileProvider.cs
new file mode 100644
index 0000000..0b2bfd2
--- /dev/null
+++ b/Providers/XBaseFileProvider.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using xFileService.Interfaces;
+using xTagService.Interfaces;
+
+namespace xFileService.Providers
+{
+ public class XBaseFileProvider : IXBaseFileProvider
+ {
+ //
+ #region Props ...
+ ///
+ /// Specified Provider ...
+ ///
+ public string ProvideFor { get; }
+
+ ///
+ /// Specified Provider Repositroy ...
+ ///
+ public IXFileProvider Provider { get; }
+
+ ///
+ /// Tag Provider for Specified File ...
+ ///
+ ///
+ public IXBaseTagProvider TagProvider { get; }
+ #endregion
+
+
+ }
+}
\ No newline at end of file
diff --git a/Providers/XFileProvider.cs b/Providers/XFileProvider.cs
index 97ba421..681d3fe 100644
--- a/Providers/XFileProvider.cs
+++ b/Providers/XFileProvider.cs
@@ -57,6 +57,106 @@ namespace xFileService.Providers
}
#endregion
+ //
+ #region Helpers ...
+ ///
+ /// Converts an Entity to Dto ...
+ ///
+ ///
+ ///
+ public async Task ToDto(XFile model)
+ {
+ //
+ XFileDto result = null;
+
+ //
+ if (!model.IsNullOrDefault())
+ {
+ //
+ result = model.ToDto();
+
+ //
+ // Prepare Inner API Providers Device Dto ...
+ var device = IdentityProvider.GetDevice();
+ var userInfo = await IdentityProvider.GetUserInfo(
+ device: device,
+ userSelectByParam: model.OwnerId
+ );
+ if (userInfo.IsNullOrDefault())
+ {
+ XException.NotFound.Throw();
+ }
+
+ //
+ result.Owner = userInfo.ToXPersonDto();
+ }
+
+ //
+ return result;
+ }
+
+ ///
+ /// Convert a List of Entities to Dto ...
+ ///
+ ///
+ ///
+ public async Task> ToDtoList(IEnumerable list)
+ {
+ //
+ var result = new List();
+
+ //
+ if (!list.IsNull() && list.HasChild())
+ {
+ //
+ foreach (var item in list)
+ {
+ //
+ var dto = await ToDto(item);
+ if (!dto.IsNullOrDefault())
+ {
+ result.Add(dto);
+ }
+ }
+ }
+
+ //
+ return result;
+ }
+
+ ///
+ /// Converts an Entity Query Result to Dto ...
+ ///
+ ///
+ ///
+ public async Task> ToDtoQueryResult(XQueryResult queryResult)
+ {
+ //
+ var result = new XQueryResult();
+
+ //
+ if (!queryResult.IsNullOrDefault())
+ {
+ //
+ result.Page = queryResult.Page;
+ result.PageSize = queryResult.PageSize;
+ result.TotalItems = queryResult.TotalItems;
+ result.TotalPages = queryResult.TotalPages;
+ result.TotalFilteredItems = queryResult.TotalFilteredItems;
+ result.TotalFilteredPages = queryResult.TotalFilteredPages;
+
+ //
+ if (!queryResult.Items.IsNull() && queryResult.Items.HasChild())
+ {
+ result.Items = await ToDtoList(queryResult.Items);
+ }
+ }
+
+ //
+ return result;
+ }
+ #endregion
+
//
#region Tools ...
///
@@ -280,7 +380,7 @@ namespace xFileService.Providers
//
// Preparing Result ...
- var result = await ToXDtoList(entities);
+ var result = await ToDtoList(entities);
//
return result;
@@ -569,7 +669,7 @@ namespace xFileService.Providers
}
//
- var result = await ToXFileDto(entitiy);
+ var result = await ToDto(entitiy);
if (result.IsNullOrDefault())
{
XException.ActionFailed.Throw();
@@ -594,7 +694,7 @@ namespace xFileService.Providers
if (!entities.IsNull() && entities.HasChild())
{
//
- result = (await ToXDtoList(entities))
+ result = (await ToDtoList(entities))
.ToList();
}
@@ -615,7 +715,7 @@ namespace xFileService.Providers
var entity = await FileRepository.FindOneAsync(whereClause);
if (!entity.IsNullOrDefault())
{
- result = await ToXFileDto(entity);
+ result = await ToDto(entity);
}
//
@@ -639,7 +739,7 @@ namespace xFileService.Providers
if (!entities.IsNull() && entities.HasChild())
{
//
- result = (await ToXDtoList(entities))
+ result = (await ToDtoList(entities))
.ToList();
}
@@ -663,7 +763,7 @@ namespace xFileService.Providers
var queryResult = await FileRepository.QueryAsync(query);
if (!queryResult.IsNullOrDefault())
{
- result = await ToXDtoQueryResult(queryResult);
+ result = await ToDtoQueryResult(queryResult);
}
//
@@ -691,7 +791,7 @@ namespace xFileService.Providers
);
if (!queryResult.IsNullOrDefault())
{
- result = await ToXDtoQueryResult(queryResult);
+ result = await ToDtoQueryResult(queryResult);
}
//
@@ -771,7 +871,7 @@ namespace xFileService.Providers
}
//
- var result = await ToXFileDto(entity);
+ var result = await ToDto(entity);
//
return result;
@@ -832,7 +932,7 @@ namespace xFileService.Providers
}
//
- result = await ToXFileDto(entitiy);
+ result = await ToDto(entitiy);
if (result.IsNullOrDefault())
{
XException.ActionFailed.Throw();
@@ -863,105 +963,5 @@ namespace xFileService.Providers
return await FileRepository.IsExistsAsync(id);
}
#endregion
-
- //
- #region Helpers ...
- ///
- /// Converts an Entity to Dto ...
- ///
- ///
- ///
- public async Task ToXFileDto(XFile model)
- {
- //
- XFileDto result = null;
-
- //
- if (!model.IsNullOrDefault())
- {
- //
- result = model.ToXFileDto();
-
- //
- // Prepare Inner API Providers Device Dto ...
- var device = IdentityProvider.GetDevice();
- var userInfo = await IdentityProvider.GetUserInfo(
- device: device,
- userSelectByParam: model.OwnerId
- );
- if (userInfo.IsNullOrDefault())
- {
- XException.NotFound.Throw();
- }
-
- //
- result.Owner = userInfo.ToXPersonDto();
- }
-
- //
- return result;
- }
-
- ///
- /// Convert a List of Entities to Dto ...
- ///
- ///
- ///
- public async Task> ToXDtoList(IEnumerable list)
- {
- //
- var result = new List();
-
- //
- if (!list.IsNull() && list.HasChild())
- {
- //
- foreach (var item in list)
- {
- //
- var dto = await ToXFileDto(item);
- if (!dto.IsNullOrDefault())
- {
- result.Add(dto);
- }
- }
- }
-
- //
- return result;
- }
-
- ///
- /// Converts an Entity Query Result to Dto ...
- ///
- ///
- ///
- public async Task> ToXDtoQueryResult(XQueryResult queryResult)
- {
- //
- var result = new XQueryResult();
-
- //
- if (!queryResult.IsNullOrDefault())
- {
- //
- result.Page = queryResult.Page;
- result.PageSize = queryResult.PageSize;
- result.TotalItems = queryResult.TotalItems;
- result.TotalPages = queryResult.TotalPages;
- result.TotalFilteredItems = queryResult.TotalFilteredItems;
- result.TotalFilteredPages = queryResult.TotalFilteredPages;
-
- //
- if (!queryResult.Items.IsNull() && queryResult.Items.HasChild())
- {
- result.Items = await ToXDtoList(queryResult.Items);
- }
- }
-
- //
- return result;
- }
- #endregion
}
}
\ No newline at end of file