add support for Provider Base Controller and also resolve some refactoring issues ...
This commit is contained in:
@@ -0,0 +1,597 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using xCommons.Configurations;
|
||||||
|
using xCommons.Extensions;
|
||||||
|
using xCommons.Providers;
|
||||||
|
using xFileService.Interfaces;
|
||||||
|
using xFileService.Models.Dtos;
|
||||||
|
using xIdentityService.Controllers;
|
||||||
|
using xIdentityService.Interfaces;
|
||||||
|
using xModels.Dtos;
|
||||||
|
using XFileDto = xFileService.Models.Dtos.XFileDto;
|
||||||
|
|
||||||
|
namespace xFileService.Controllers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// a Controller base Class which implement based Actions to Provides File Provider Access ...
|
||||||
|
/// </summary>
|
||||||
|
public abstract class XFileServiceControllerBase : XIBaseProviderController, IXFileServiceControllerActions
|
||||||
|
{
|
||||||
|
//
|
||||||
|
#region Props ...
|
||||||
|
public IXFileProvider FileProvider { get; }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Constructor ...
|
||||||
|
protected XFileServiceControllerBase(
|
||||||
|
ILogger logger,
|
||||||
|
IXFileProvider fileProvider,
|
||||||
|
XAppConfiguration appConfiguration,
|
||||||
|
IXIdentityProvider identityProvider,
|
||||||
|
XValidationProvider validationProvider
|
||||||
|
) : base(
|
||||||
|
logger,
|
||||||
|
appConfiguration,
|
||||||
|
identityProvider,
|
||||||
|
validationProvider
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
FileProvider = fileProvider;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Tags ...
|
||||||
|
/// <summary>
|
||||||
|
/// Attach Tag to Specified Model ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("Tags/Attach")]
|
||||||
|
public async Task<ActionResult> TagAttach(
|
||||||
|
[FromQuery] string tag,
|
||||||
|
[FromQuery] Guid id
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// 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.TagAttach(
|
||||||
|
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>
|
||||||
|
[HttpGet("Tags/Detach")]
|
||||||
|
public async Task<ActionResult> TagDetach(
|
||||||
|
[FromQuery] string tag,
|
||||||
|
[FromQuery] Guid id
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// 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.TagDetach(
|
||||||
|
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>
|
||||||
|
[HttpGet("Tags/AttachMany")]
|
||||||
|
public async Task<ActionResult> TagsAttach(
|
||||||
|
[FromQuery] string tags,
|
||||||
|
[FromQuery] Guid id
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// 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.TagsAttach(
|
||||||
|
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>
|
||||||
|
[HttpGet("Tags/DetachMany")]
|
||||||
|
public async Task<ActionResult> TagsDetach(
|
||||||
|
[FromQuery] string tags,
|
||||||
|
[FromQuery] Guid id
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// 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.TagsDetach(
|
||||||
|
id: id,
|
||||||
|
tags: tagsList,
|
||||||
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
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 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 async Task<ActionResult<FileStreamResult>> 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 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 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("Upload")]
|
||||||
|
[RequestSizeLimit(966_367_641)]
|
||||||
|
public 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("Remove")]
|
||||||
|
public 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>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public 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>
|
||||||
|
/// <param name="ignoreSoftDeleteds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("All")]
|
||||||
|
public 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 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("Owned/Query")]
|
||||||
|
public 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 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 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,11 +62,13 @@ namespace xFileService.Interfaces
|
|||||||
/// <param name="tag"></param>
|
/// <param name="tag"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task TagAttach(
|
Task TagAttach(
|
||||||
string tag,
|
string tag,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -75,11 +77,13 @@ namespace xFileService.Interfaces
|
|||||||
/// <param name="tag"></param>
|
/// <param name="tag"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task TagDetach(
|
Task TagDetach(
|
||||||
string tag,
|
string tag,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -88,11 +92,13 @@ namespace xFileService.Interfaces
|
|||||||
/// <param name="tags"></param>
|
/// <param name="tags"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task TagsAttach(
|
Task TagsAttach(
|
||||||
IEnumerable<string> tags,
|
IEnumerable<string> tags,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -101,11 +107,13 @@ namespace xFileService.Interfaces
|
|||||||
/// <param name="tags"></param>
|
/// <param name="tags"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task TagsDetach(
|
Task TagsDetach(
|
||||||
IEnumerable<string> tags,
|
IEnumerable<string> tags,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -113,10 +121,12 @@ namespace xFileService.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task TagsDetach(
|
Task TagsDetach(
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -155,10 +165,12 @@ namespace xFileService.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<XFileDto>> Upload(
|
Task<IEnumerable<XFileDto>> Upload(
|
||||||
IFormFileCollection files,
|
IFormFileCollection files,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -166,10 +178,12 @@ namespace xFileService.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<Guid>> Remove(
|
Task<IEnumerable<Guid>> Remove(
|
||||||
string ids,
|
string ids,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -220,12 +234,14 @@ namespace xFileService.Interfaces
|
|||||||
/// <param name="forProvidedId"></param>
|
/// <param name="forProvidedId"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task AddReference<TKey>(
|
Task AddReference<TKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId,
|
TKey forProvidedId,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -235,12 +251,14 @@ namespace xFileService.Interfaces
|
|||||||
/// <param name="forProvidedId"></param>
|
/// <param name="forProvidedId"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task RemoveReference<TKey>(
|
Task RemoveReference<TKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId,
|
TKey forProvidedId,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -287,6 +305,17 @@ namespace xFileService.Interfaces
|
|||||||
XQuery 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>
|
/// <summary>
|
||||||
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
|
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -298,17 +327,32 @@ namespace xFileService.Interfaces
|
|||||||
XQuery query
|
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>
|
/// <summary>
|
||||||
/// Update an Entity values ...
|
/// Update an Entity values ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XFileDto> Update(
|
Task<XFileDto> Update(
|
||||||
Guid id,
|
Guid id,
|
||||||
XFileDto item,
|
XFileDto item,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -316,10 +360,12 @@ namespace xFileService.Interfaces
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<XFileDto> Remove(
|
Task<XFileDto> Remove(
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
);
|
);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
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="tag"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult> TagAttach(
|
||||||
|
string tag,
|
||||||
|
Guid id
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Detach Tag From Specified Model ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult> TagDetach(
|
||||||
|
string tag,
|
||||||
|
Guid id
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attach Tags to Specified Model ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tags"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult> TagsAttach(
|
||||||
|
string tags,
|
||||||
|
Guid id
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Detach Tags From Specified Model ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tags"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult> TagsDetach(
|
||||||
|
string tags,
|
||||||
|
Guid id
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Tools ...
|
||||||
|
/// <summary>
|
||||||
|
/// Stream Specified File ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult> Stream(Guid id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stream Specified File ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult<FileStreamResult>> Stream(string fileName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Download Specified File ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult> Download(Guid id);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Download Specified File ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult> Download(string fileName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Upload Files ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="files"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult<IEnumerable<XFileDto>>> Upload(
|
||||||
|
IFormFileCollection files
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove Specified Files ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult<IEnumerable<Guid>>> Remove(
|
||||||
|
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(
|
||||||
|
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(
|
||||||
|
XQuery query
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Owned Entities based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<ActionResult<XQueryResult<XFileDto>>> QueryOwned(
|
||||||
|
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(
|
||||||
|
Guid id
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
+242
-29
@@ -24,6 +24,7 @@ using System.IO;
|
|||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.AspNetCore.StaticFiles;
|
using Microsoft.AspNetCore.StaticFiles;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using xPushService.Constants;
|
||||||
|
|
||||||
namespace xFileService.Providers
|
namespace xFileService.Providers
|
||||||
{
|
{
|
||||||
@@ -217,11 +218,14 @@ namespace xFileService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tag"></param>
|
/// <param name="tag"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task TagAttach(
|
public async Task TagAttach(
|
||||||
string tag,
|
string tag,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -246,7 +250,12 @@ namespace xFileService.Providers
|
|||||||
//
|
//
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await TagProvider.Attach(tag, id);
|
//
|
||||||
|
await TagProvider.Attach(
|
||||||
|
tag,
|
||||||
|
id,
|
||||||
|
connectionId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
@@ -257,11 +266,14 @@ namespace xFileService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tag"></param>
|
/// <param name="tag"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task TagDetach(
|
public async Task TagDetach(
|
||||||
string tag,
|
string tag,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -285,7 +297,12 @@ namespace xFileService.Providers
|
|||||||
//
|
//
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await TagProvider.Detach(tag, id);
|
//
|
||||||
|
await TagProvider.Detach(
|
||||||
|
tag,
|
||||||
|
id,
|
||||||
|
connectionId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
@@ -296,11 +313,14 @@ namespace xFileService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tags"></param>
|
/// <param name="tags"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task TagsAttach(
|
public async Task TagsAttach(
|
||||||
IEnumerable<string> tags,
|
IEnumerable<string> tags,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -328,7 +348,13 @@ namespace xFileService.Providers
|
|||||||
//
|
//
|
||||||
foreach (var tag in tags)
|
foreach (var tag in tags)
|
||||||
{
|
{
|
||||||
await TagAttach(tag, id);
|
//
|
||||||
|
await TagAttach(
|
||||||
|
tag,
|
||||||
|
id,
|
||||||
|
userInfo,
|
||||||
|
connectionId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@@ -340,11 +366,14 @@ namespace xFileService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tags"></param>
|
/// <param name="tags"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task TagsDetach(
|
public async Task TagsDetach(
|
||||||
IEnumerable<string> tags,
|
IEnumerable<string> tags,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -372,7 +401,13 @@ namespace xFileService.Providers
|
|||||||
//
|
//
|
||||||
foreach (var tag in tags)
|
foreach (var tag in tags)
|
||||||
{
|
{
|
||||||
await TagDetach(tag, id);
|
//
|
||||||
|
await TagDetach(
|
||||||
|
tag,
|
||||||
|
id,
|
||||||
|
userInfo,
|
||||||
|
connectionId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@@ -383,10 +418,13 @@ namespace xFileService.Providers
|
|||||||
/// Detach all Attached Tags for Specified File ...
|
/// Detach all Attached Tags for Specified File ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task TagsDetach(
|
public async Task TagsDetach(
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -573,10 +611,12 @@ namespace xFileService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="files"></param>
|
/// <param name="files"></param>
|
||||||
/// <param name="userId"></param>
|
/// <param name="userId"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<XFileDto>> Upload(
|
public async Task<IEnumerable<XFileDto>> Upload(
|
||||||
IFormFileCollection files,
|
IFormFileCollection files,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -631,6 +671,14 @@ namespace xFileService.Providers
|
|||||||
//
|
//
|
||||||
if (!entity.IsNullOrDefault())
|
if (!entity.IsNullOrDefault())
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XBaseEntityHubAction.Add.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(camelCase: true),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
entities.Add(entity);
|
entities.Add(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -649,10 +697,13 @@ namespace xFileService.Providers
|
|||||||
/// Remove Specified Files ...
|
/// Remove Specified Files ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ids"></param>
|
/// <param name="ids"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<IEnumerable<Guid>> Remove(
|
public async Task<IEnumerable<Guid>> Remove(
|
||||||
string ids,
|
string ids,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -733,8 +784,15 @@ namespace xFileService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
// Remove File Entty ...
|
// Remove File Entty ...
|
||||||
await FileRepository.RemoveAsync(model.Id);
|
var entity = await FileRepository.RemoveAsync(model.Id);
|
||||||
result.Add(model.Id);
|
result.Add(model.Id);
|
||||||
|
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(camelCase: true),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -744,7 +802,10 @@ namespace xFileService.Providers
|
|||||||
//
|
//
|
||||||
foreach (var id in result)
|
foreach (var id in result)
|
||||||
{
|
{
|
||||||
await TagsDetach(id);
|
//
|
||||||
|
// Here we send Null Connection ID for Preventing Update Push ...
|
||||||
|
// since we Remove Entity ...
|
||||||
|
await TagsDetach(id, userInfo, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -971,7 +1032,7 @@ namespace xFileService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
var identifier = GetIdentifier(
|
var identifier = GetIdentifier(
|
||||||
providedFor: providedFor,
|
providedFor: providedFor,
|
||||||
forProvidedId: forProvidedId
|
forProvidedId: forProvidedId
|
||||||
);
|
);
|
||||||
var result =
|
var result =
|
||||||
@@ -990,12 +1051,14 @@ namespace xFileService.Providers
|
|||||||
/// <param name="forProvidedId"></param>
|
/// <param name="forProvidedId"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task AddReference<TKey>(
|
public async Task AddReference<TKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId,
|
TKey forProvidedId,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1015,7 +1078,7 @@ namespace xFileService.Providers
|
|||||||
// Check Has Reference or not ...
|
// Check Has Reference or not ...
|
||||||
isValid = await IsProvidedFor(
|
isValid = await IsProvidedFor(
|
||||||
providedFor: providedFor,
|
providedFor: providedFor,
|
||||||
forProvidedId: forProvidedId,
|
forProvidedId: forProvidedId,
|
||||||
id: id
|
id: id
|
||||||
);
|
);
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
@@ -1050,7 +1113,8 @@ namespace xFileService.Providers
|
|||||||
dto = await Update(
|
dto = await Update(
|
||||||
id: dto.Id,
|
id: dto.Id,
|
||||||
item: dto,
|
item: dto,
|
||||||
userInfo: userInfo
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId
|
||||||
);
|
);
|
||||||
isValid = !dto.IsNullOrDefault();
|
isValid = !dto.IsNullOrDefault();
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
@@ -1067,12 +1131,14 @@ namespace xFileService.Providers
|
|||||||
/// <param name="forProvidedId"></param>
|
/// <param name="forProvidedId"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task RemoveReference<TKey>(
|
public async Task RemoveReference<TKey>(
|
||||||
string providedFor,
|
string providedFor,
|
||||||
TKey forProvidedId,
|
TKey forProvidedId,
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1119,7 +1185,7 @@ namespace xFileService.Providers
|
|||||||
|
|
||||||
//
|
//
|
||||||
var identifier = GetIdentifier(
|
var identifier = GetIdentifier(
|
||||||
providedFor: providedFor,
|
providedFor: providedFor,
|
||||||
forProvidedId: forProvidedId
|
forProvidedId: forProvidedId
|
||||||
);
|
);
|
||||||
dto.References = dto.References
|
dto.References = dto.References
|
||||||
@@ -1128,7 +1194,8 @@ namespace xFileService.Providers
|
|||||||
dto = await Update(
|
dto = await Update(
|
||||||
id: dto.Id,
|
id: dto.Id,
|
||||||
item: dto,
|
item: dto,
|
||||||
userInfo: userInfo
|
userInfo: userInfo,
|
||||||
|
connectionId: connectionId
|
||||||
);
|
);
|
||||||
isValid = !dto.IsNullOrDefault();
|
isValid = !dto.IsNullOrDefault();
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
@@ -1159,14 +1226,14 @@ namespace xFileService.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var entitiy = await FileRepository.GetAsync(id);
|
var entity = await FileRepository.GetAsync(id);
|
||||||
if (entitiy.IsNullOrDefault())
|
if (entity.IsNullOrDefault())
|
||||||
{
|
{
|
||||||
XException.NotFound.Throw();
|
XException.NotFound.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var result = await ToDto(entitiy);
|
var result = await ToDto(entity);
|
||||||
if (result.IsNullOrDefault())
|
if (result.IsNullOrDefault())
|
||||||
{
|
{
|
||||||
XException.ActionFailed.Throw();
|
XException.ActionFailed.Throw();
|
||||||
@@ -1267,6 +1334,37 @@ namespace xFileService.Providers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// retrieve Owned Entities based on XQuery Pagination structure ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="userInfo"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XFileDto>> QueryOwned(
|
||||||
|
XQuery query,
|
||||||
|
XUserClaimsInfoDto userInfo = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid = !userInfo.IsNullOrDefault();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create Where Clause ...
|
||||||
|
Expression<Func<XFile, bool>> whereClause = e => e.OwnerId == userInfo.UserId;
|
||||||
|
var result = await ConditionalQuery(
|
||||||
|
query: query,
|
||||||
|
whereClause: whereClause
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
|
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1295,17 +1393,60 @@ namespace xFileService.Providers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
public async Task<XQueryResult<XFileDto>> ConditionalQueryOwned(
|
||||||
|
Expression<Func<XFile, bool>> whereClause,
|
||||||
|
XQuery query,
|
||||||
|
XUserClaimsInfoDto userInfo = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid = !whereClause.IsNull() &&
|
||||||
|
!userInfo.IsNullOrDefault();
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
XException.InvalidArgs.Throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Compile Where Clause ...
|
||||||
|
var whereFunc = whereClause.Compile();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create new Where Clause ...
|
||||||
|
Expression<Func<XFile, bool>> condition =
|
||||||
|
e => whereFunc(e) && e.OwnerId == userInfo.UserId;
|
||||||
|
|
||||||
|
//
|
||||||
|
var result = await ConditionalQuery(
|
||||||
|
query: query,
|
||||||
|
whereClause: condition
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update an Entity values ...
|
/// Update an Entity values ...
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XFileDto> Update(
|
public async Task<XFileDto> Update(
|
||||||
Guid id,
|
Guid id,
|
||||||
XFileDto item,
|
XFileDto item,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1320,7 +1461,7 @@ namespace xFileService.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check Entitiy Exists and Retrieve it ...
|
// Check entity Exists and Retrieve it ...
|
||||||
isValid = await IsExists(id);
|
isValid = await IsExists(id);
|
||||||
if (!isValid)
|
if (!isValid)
|
||||||
{
|
{
|
||||||
@@ -1375,6 +1516,17 @@ namespace xFileService.Providers
|
|||||||
// Converts to Dto ...
|
// Converts to Dto ...
|
||||||
var result = await ToDto(entity);
|
var result = await ToDto(entity);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (!result.IsNullOrDefault())
|
||||||
|
{
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XBaseEntityHubAction.Update.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(camelCase: true),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1384,10 +1536,12 @@ namespace xFileService.Providers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <param name="userInfo"></param>
|
/// <param name="userInfo"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<XFileDto> Remove(
|
public async Task<XFileDto> Remove(
|
||||||
Guid id,
|
Guid id,
|
||||||
XUserClaimsInfoDto userInfo = null
|
XUserClaimsInfoDto userInfo = null,
|
||||||
|
string connectionId = null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -1428,14 +1582,14 @@ namespace xFileService.Providers
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
var entitiy = await FileRepository.RemoveAsync(id);
|
var entity = await FileRepository.RemoveAsync(id);
|
||||||
if (entitiy.IsNullOrDefault())
|
if (entity.IsNullOrDefault())
|
||||||
{
|
{
|
||||||
XException.ActionFailed.Throw();
|
XException.ActionFailed.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
result = await ToDto(entitiy);
|
result = await ToDto(entity);
|
||||||
if (result.IsNullOrDefault())
|
if (result.IsNullOrDefault())
|
||||||
{
|
{
|
||||||
XException.ActionFailed.Throw();
|
XException.ActionFailed.Throw();
|
||||||
@@ -1445,6 +1599,13 @@ namespace xFileService.Providers
|
|||||||
// Removing Tags ...
|
// Removing Tags ...
|
||||||
await TagProvider.RemoveTagsFor(result.Id);
|
await TagProvider.RemoveTagsFor(result.Id);
|
||||||
|
|
||||||
|
//
|
||||||
|
await SendPush(
|
||||||
|
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
||||||
|
payLoad: entity.ToJSON(camelCase: true),
|
||||||
|
connectionId: connectionId
|
||||||
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1470,5 +1631,57 @@ namespace xFileService.Providers
|
|||||||
return await FileRepository.IsExistsAsync(id);
|
return await FileRepository.IsExistsAsync(id);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Hub Actions ...
|
||||||
|
/// <summary>
|
||||||
|
/// Send Custom Push Message ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action"></param>
|
||||||
|
/// <param name="payLoad"></param>
|
||||||
|
/// <param name="connectionId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task SendPush(
|
||||||
|
string action,
|
||||||
|
string payLoad,
|
||||||
|
string connectionId = null
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
var actions = new List<string>
|
||||||
|
{
|
||||||
|
XBaseEntityHubAction.Add.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.Update.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.Delete.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.AddMany.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
||||||
|
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate ...
|
||||||
|
var isValid =
|
||||||
|
!Hub.IsNull() &&
|
||||||
|
!action.IsNullOrEmpty() &&
|
||||||
|
actions.Contains(action);
|
||||||
|
if (!isValid)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
var clients = Hub.Clients.All;
|
||||||
|
if (!connectionId.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
clients = Hub.Clients.AllExcept(connectionId);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await clients.SendAsync(action, payLoad, connectionId);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user