add support for Provider Base Controller and also resolve some refactoring issues ...
This commit is contained in:
+242
-29
@@ -24,6 +24,7 @@ using System.IO;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using System.Linq;
|
||||
using xPushService.Constants;
|
||||
|
||||
namespace xFileService.Providers
|
||||
{
|
||||
@@ -217,11 +218,14 @@ namespace xFileService.Providers
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagAttach(
|
||||
string tag,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -246,7 +250,12 @@ namespace xFileService.Providers
|
||||
//
|
||||
try
|
||||
{
|
||||
await TagProvider.Attach(tag, id);
|
||||
//
|
||||
await TagProvider.Attach(
|
||||
tag,
|
||||
id,
|
||||
connectionId
|
||||
);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -257,11 +266,14 @@ namespace xFileService.Providers
|
||||
/// </summary>
|
||||
/// <param name="tag"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagDetach(
|
||||
string tag,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -285,7 +297,12 @@ namespace xFileService.Providers
|
||||
//
|
||||
try
|
||||
{
|
||||
await TagProvider.Detach(tag, id);
|
||||
//
|
||||
await TagProvider.Detach(
|
||||
tag,
|
||||
id,
|
||||
connectionId
|
||||
);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -296,11 +313,14 @@ namespace xFileService.Providers
|
||||
/// </summary>
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsAttach(
|
||||
IEnumerable<string> tags,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -328,7 +348,13 @@ namespace xFileService.Providers
|
||||
//
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
await TagAttach(tag, id);
|
||||
//
|
||||
await TagAttach(
|
||||
tag,
|
||||
id,
|
||||
userInfo,
|
||||
connectionId
|
||||
);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
@@ -340,11 +366,14 @@ namespace xFileService.Providers
|
||||
/// </summary>
|
||||
/// <param name="tags"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsDetach(
|
||||
IEnumerable<string> tags,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -372,7 +401,13 @@ namespace xFileService.Providers
|
||||
//
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
await TagDetach(tag, id);
|
||||
//
|
||||
await TagDetach(
|
||||
tag,
|
||||
id,
|
||||
userInfo,
|
||||
connectionId
|
||||
);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
@@ -383,10 +418,13 @@ namespace xFileService.Providers
|
||||
/// Detach all Attached Tags for Specified File ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task TagsDetach(
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -573,10 +611,12 @@ namespace xFileService.Providers
|
||||
/// </summary>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<XFileDto>> Upload(
|
||||
IFormFileCollection files,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -631,6 +671,14 @@ namespace xFileService.Providers
|
||||
//
|
||||
if (!entity.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
action: XBaseEntityHubAction.Add.GetStringValue(),
|
||||
payLoad: entity.ToJSON(camelCase: true),
|
||||
connectionId: connectionId
|
||||
);
|
||||
|
||||
//
|
||||
entities.Add(entity);
|
||||
}
|
||||
}
|
||||
@@ -649,10 +697,13 @@ namespace xFileService.Providers
|
||||
/// Remove Specified Files ...
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IEnumerable<Guid>> Remove(
|
||||
string ids,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -733,8 +784,15 @@ namespace xFileService.Providers
|
||||
|
||||
//
|
||||
// Remove File Entty ...
|
||||
await FileRepository.RemoveAsync(model.Id);
|
||||
var entity = await FileRepository.RemoveAsync(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)
|
||||
{
|
||||
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(
|
||||
providedFor: providedFor,
|
||||
providedFor: providedFor,
|
||||
forProvidedId: forProvidedId
|
||||
);
|
||||
var result =
|
||||
@@ -990,12 +1051,14 @@ namespace xFileService.Providers
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task AddReference<TKey>(
|
||||
string providedFor,
|
||||
TKey forProvidedId,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1015,7 +1078,7 @@ namespace xFileService.Providers
|
||||
// Check Has Reference or not ...
|
||||
isValid = await IsProvidedFor(
|
||||
providedFor: providedFor,
|
||||
forProvidedId: forProvidedId,
|
||||
forProvidedId: forProvidedId,
|
||||
id: id
|
||||
);
|
||||
if (!isValid)
|
||||
@@ -1050,7 +1113,8 @@ namespace xFileService.Providers
|
||||
dto = await Update(
|
||||
id: dto.Id,
|
||||
item: dto,
|
||||
userInfo: userInfo
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId
|
||||
);
|
||||
isValid = !dto.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
@@ -1067,12 +1131,14 @@ namespace xFileService.Providers
|
||||
/// <param name="forProvidedId"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task RemoveReference<TKey>(
|
||||
string providedFor,
|
||||
TKey forProvidedId,
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1119,7 +1185,7 @@ namespace xFileService.Providers
|
||||
|
||||
//
|
||||
var identifier = GetIdentifier(
|
||||
providedFor: providedFor,
|
||||
providedFor: providedFor,
|
||||
forProvidedId: forProvidedId
|
||||
);
|
||||
dto.References = dto.References
|
||||
@@ -1128,7 +1194,8 @@ namespace xFileService.Providers
|
||||
dto = await Update(
|
||||
id: dto.Id,
|
||||
item: dto,
|
||||
userInfo: userInfo
|
||||
userInfo: userInfo,
|
||||
connectionId: connectionId
|
||||
);
|
||||
isValid = !dto.IsNullOrDefault();
|
||||
if (!isValid)
|
||||
@@ -1159,14 +1226,14 @@ namespace xFileService.Providers
|
||||
}
|
||||
|
||||
//
|
||||
var entitiy = await FileRepository.GetAsync(id);
|
||||
if (entitiy.IsNullOrDefault())
|
||||
var entity = await FileRepository.GetAsync(id);
|
||||
if (entity.IsNullOrDefault())
|
||||
{
|
||||
XException.NotFound.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var result = await ToDto(entitiy);
|
||||
var result = await ToDto(entity);
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
@@ -1267,6 +1334,37 @@ namespace xFileService.Providers
|
||||
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>
|
||||
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
@@ -1295,17 +1393,60 @@ namespace xFileService.Providers
|
||||
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>
|
||||
/// Update an Entity values ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XFileDto> Update(
|
||||
Guid id,
|
||||
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);
|
||||
if (!isValid)
|
||||
{
|
||||
@@ -1375,6 +1516,17 @@ namespace xFileService.Providers
|
||||
// Converts to Dto ...
|
||||
var result = await ToDto(entity);
|
||||
|
||||
//
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await SendPush(
|
||||
action: XBaseEntityHubAction.Update.GetStringValue(),
|
||||
payLoad: entity.ToJSON(camelCase: true),
|
||||
connectionId: connectionId
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -1384,10 +1536,12 @@ namespace xFileService.Providers
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
/// <param name="connectionId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<XFileDto> Remove(
|
||||
Guid id,
|
||||
XUserClaimsInfoDto userInfo = null
|
||||
XUserClaimsInfoDto userInfo = null,
|
||||
string connectionId = null
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -1428,14 +1582,14 @@ namespace xFileService.Providers
|
||||
}
|
||||
|
||||
//
|
||||
var entitiy = await FileRepository.RemoveAsync(id);
|
||||
if (entitiy.IsNullOrDefault())
|
||||
var entity = await FileRepository.RemoveAsync(id);
|
||||
if (entity.IsNullOrDefault())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
result = await ToDto(entitiy);
|
||||
result = await ToDto(entity);
|
||||
if (result.IsNullOrDefault())
|
||||
{
|
||||
XException.ActionFailed.Throw();
|
||||
@@ -1445,6 +1599,13 @@ namespace xFileService.Providers
|
||||
// Removing Tags ...
|
||||
await TagProvider.RemoveTagsFor(result.Id);
|
||||
|
||||
//
|
||||
await SendPush(
|
||||
action: XBaseEntityHubAction.Delete.GetStringValue(),
|
||||
payLoad: entity.ToJSON(camelCase: true),
|
||||
connectionId: connectionId
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -1470,5 +1631,57 @@ namespace xFileService.Providers
|
||||
return await FileRepository.IsExistsAsync(id);
|
||||
}
|
||||
#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