This commit is contained in:
@@ -236,44 +236,52 @@ namespace AyaNova.Biz
|
|||||||
public long RefCount { get; set; }
|
public long RefCount { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Process bulk tag operation
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>true if object needs to be saved or false if no changes were made</returns>
|
||||||
|
internal static bool ProcessBulkTagOperation(List<string> tagCollection, string tag, string toTag, JobSubType subType)
|
||||||
|
{
|
||||||
|
switch (subType)
|
||||||
|
{
|
||||||
|
case JobSubType.TagAddAny:
|
||||||
|
case JobSubType.TagAdd:
|
||||||
|
if (!tagCollection.Contains(tag))
|
||||||
|
{
|
||||||
|
tagCollection.Add(tag);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
case JobSubType.TagRemoveAny:
|
||||||
|
case JobSubType.TagRemove:
|
||||||
|
return tagCollection.Remove(tag);
|
||||||
|
case JobSubType.TagReplaceAny:
|
||||||
|
case JobSubType.TagReplace:
|
||||||
|
int index = tagCollection.IndexOf(tag);
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
tagCollection[index] = toTag;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
throw new System.ArgumentOutOfRangeException($"ProcessBulkTagOperation -> Invalid job Subtype{subType}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion utilities
|
#endregion utilities
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Originally this whole object was just a simple utility class but was going to handle bulk tag jobs here so made it a full biz object
|
|
||||||
//keeping only in case I need to handle some job but in the end this could go back to a simple static utility class if it never pans out
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//JOB / OPERATIONS
|
//JOB / OPERATIONS
|
||||||
//
|
//
|
||||||
// public async Task HandleJobAsync(OpsJob job)
|
|
||||||
// {
|
|
||||||
// await Task.CompletedTask;
|
|
||||||
// switch (job.JobType)
|
|
||||||
// {
|
|
||||||
// // case JobType.BulkCoreBizObjectOperation:
|
|
||||||
// // await ProcessBulkJobAsync(job);
|
|
||||||
// // break;
|
|
||||||
// default:
|
|
||||||
// throw new System.ArgumentOutOfRangeException($"TagBiz.HandleJob-> Invalid job type{job.JobType.ToString()}");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
// private async Task ProcessBulkJobAsync(OpsJob job)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// //Simulate a long running job here
|
|
||||||
// await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
|
||||||
// await JobsBiz.LogJobAsync(job.GId, $"Tag::BulkJob started...", ct);
|
|
||||||
|
|
||||||
// //get XBiz for type specified
|
|
||||||
// //use XBiz to call get then update then save
|
|
||||||
// //ideally don't have a huge switch statement with identical code for each object
|
|
||||||
|
|
||||||
// await JobsBiz.LogJobAsync(job.GId, "Tag::BulkJob completed", ct);
|
|
||||||
// await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -584,69 +584,30 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||||
await JobsBiz.LogJobAsync(job.GId, $"Bulk job {job.SubType} started...", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"Bulk job {job.SubType} started...", ct);
|
||||||
|
|
||||||
List<long> idList = new List<long>();
|
List<long> idList = new List<long>();
|
||||||
long ProcessedObjectCount = 0;
|
long ChangedObjectCount = 0;
|
||||||
JObject jobData = JObject.Parse(job.JobInfo);
|
JObject jobData = JObject.Parse(job.JobInfo);
|
||||||
|
|
||||||
|
|
||||||
//TAGS?
|
|
||||||
string ToTag = null;
|
|
||||||
string Tag = null;
|
|
||||||
if (jobData.ContainsKey("tag"))
|
|
||||||
Tag = (string)jobData["tag"];
|
|
||||||
|
|
||||||
if (jobData.ContainsKey("toTag"))
|
|
||||||
ToTag = (string)jobData["toTag"];
|
|
||||||
|
|
||||||
if (jobData.ContainsKey("idList"))
|
if (jobData.ContainsKey("idList"))
|
||||||
{
|
|
||||||
idList = ((JArray)jobData["idList"]).ToObject<List<long>>();
|
idList = ((JArray)jobData["idList"]).ToObject<List<long>>();
|
||||||
// jobData["idList"].Value<List<long>>();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
idList = await ct.Widget.Select(m => m.Id).ToListAsync();
|
||||||
//we need to fetch a list of them all because ALL items was selected
|
|
||||||
//If they wanted to filter (say by Active=true) they can do that from a grid list mass op
|
|
||||||
idList = await ct.User.Select(m => m.Id).ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SaveIt = false;
|
bool SaveIt = false;
|
||||||
//Iterate the list fetching each in turn and sending to the processor to handle
|
|
||||||
foreach (long id in idList)
|
foreach (long id in idList)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SaveIt = false;
|
SaveIt = false;
|
||||||
//errors would pile up here if not cleared on each iteration
|
|
||||||
ClearErrors();
|
ClearErrors();
|
||||||
|
|
||||||
//Fetch
|
|
||||||
var o = await GetAsync(id, false);
|
var o = await GetAsync(id, false);
|
||||||
//call out processor for each item in turn
|
|
||||||
switch (job.SubType)
|
switch (job.SubType)
|
||||||
{
|
{
|
||||||
case JobSubType.TagAddAny:
|
case JobSubType.TagAddAny:
|
||||||
case JobSubType.TagAdd:
|
case JobSubType.TagAdd:
|
||||||
if (!o.Tags.Contains(Tag))
|
|
||||||
{
|
|
||||||
o.Tags.Add(Tag);
|
|
||||||
SaveIt = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case JobSubType.TagRemoveAny:
|
case JobSubType.TagRemoveAny:
|
||||||
case JobSubType.TagRemove:
|
case JobSubType.TagRemove:
|
||||||
SaveIt = o.Tags.Remove(Tag);
|
|
||||||
break;
|
|
||||||
case JobSubType.TagReplaceAny:
|
case JobSubType.TagReplaceAny:
|
||||||
case JobSubType.TagReplace:
|
case JobSubType.TagReplace:
|
||||||
int index = o.Tags.IndexOf(Tag);
|
SaveIt = TagBiz.ProcessBulkTagOperation(o.Tags, (string)jobData["tag"], jobData.ContainsKey("toTag") ? (string)jobData["toTag"] : null, job.SubType);
|
||||||
if (index != -1)
|
|
||||||
{
|
|
||||||
o.Tags[index] = ToTag;
|
|
||||||
SaveIt = true;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentOutOfRangeException($"ProcessBulkJob -> Invalid job Subtype{job.SubType}");
|
throw new System.ArgumentOutOfRangeException($"ProcessBulkJob -> Invalid job Subtype{job.SubType}");
|
||||||
@@ -660,14 +621,10 @@ namespace AyaNova.Biz
|
|||||||
if (u == null)
|
if (u == null)
|
||||||
await JobsBiz.LogJobAsync(job.GId, $"Error processing item {id}: {GetErrorsAsString()}", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"Error processing item {id}: {GetErrorsAsString()}", ct);
|
||||||
else
|
else
|
||||||
ProcessedObjectCount++;
|
ChangedObjectCount++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
ChangedObjectCount++;
|
||||||
|
|
||||||
ProcessedObjectCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -675,7 +632,7 @@ namespace AyaNova.Biz
|
|||||||
await JobsBiz.LogJobAsync(job.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
|
await JobsBiz.LogJobAsync(job.GId, ExceptionUtil.ExtractAllExceptionMessages(ex), ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await JobsBiz.LogJobAsync(job.GId, $"Bulk job {job.SubType} processed {ProcessedObjectCount} of {idList.Count}", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"Bulk job {job.SubType} changed {ChangedObjectCount} of {idList.Count}", ct);
|
||||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -325,86 +325,44 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||||
await JobsBiz.LogJobAsync(job.GId, $"Bulk job {job.SubType} started...", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"Bulk job {job.SubType} started...", ct);
|
||||||
|
|
||||||
List<long> idList = new List<long>();
|
List<long> idList = new List<long>();
|
||||||
long ProcessedObjectCount = 0;
|
long ProcessedObjectCount = 0;
|
||||||
JObject jobData = JObject.Parse(job.JobInfo);
|
JObject jobData = JObject.Parse(job.JobInfo);
|
||||||
|
|
||||||
|
|
||||||
//TAGS?
|
|
||||||
string ToTag = null;
|
|
||||||
string Tag = null;
|
|
||||||
if (jobData.ContainsKey("tag"))
|
|
||||||
Tag = (string)jobData["tag"];
|
|
||||||
|
|
||||||
if (jobData.ContainsKey("toTag"))
|
|
||||||
ToTag = (string)jobData["toTag"];
|
|
||||||
|
|
||||||
if (jobData.ContainsKey("idList"))
|
if (jobData.ContainsKey("idList"))
|
||||||
{
|
idList = ((JArray)jobData["idList"]).ToObject<List<long>>();
|
||||||
idList = ((JArray)jobData["idList"]).ToObject<List<long>>();
|
|
||||||
// jobData["idList"].Value<List<long>>();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
//we need to fetch a list of them all because ALL items was selected
|
|
||||||
//If they wanted to filter (say by Active=true) they can do that from a grid list mass op
|
|
||||||
idList = await ct.Widget.Select(m => m.Id).ToListAsync();
|
idList = await ct.Widget.Select(m => m.Id).ToListAsync();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SaveIt = false;
|
bool SaveIt = false;
|
||||||
//Iterate the list fetching each in turn and sending to the processor to handle
|
|
||||||
foreach (long id in idList)
|
foreach (long id in idList)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SaveIt = false;
|
SaveIt = false;
|
||||||
//errors would pile up here if not cleared on each iteration
|
|
||||||
ClearErrors();
|
ClearErrors();
|
||||||
|
var o = await GetAsync(id, false);
|
||||||
//Fetch
|
|
||||||
var o = (ICoreBizObjectModel)await GetAsync(id, false);
|
|
||||||
//call out processor for each item in turn
|
|
||||||
switch (job.SubType)
|
switch (job.SubType)
|
||||||
{
|
{
|
||||||
case JobSubType.TagAddAny:
|
case JobSubType.TagAddAny:
|
||||||
case JobSubType.TagAdd:
|
case JobSubType.TagAdd:
|
||||||
if (!o.Tags.Contains(Tag))
|
|
||||||
{
|
|
||||||
o.Tags.Add(Tag);
|
|
||||||
SaveIt = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case JobSubType.TagRemoveAny:
|
case JobSubType.TagRemoveAny:
|
||||||
case JobSubType.TagRemove:
|
case JobSubType.TagRemove:
|
||||||
SaveIt = o.Tags.Remove(Tag);
|
|
||||||
break;
|
|
||||||
case JobSubType.TagReplaceAny:
|
case JobSubType.TagReplaceAny:
|
||||||
case JobSubType.TagReplace:
|
case JobSubType.TagReplace:
|
||||||
int index = o.Tags.IndexOf(Tag);
|
SaveIt = TagBiz.ProcessBulkTagOperation(o.Tags, (string)jobData["tag"], jobData.ContainsKey("toTag") ? (string)jobData["toTag"] : null, job.SubType);
|
||||||
if (index != -1)
|
|
||||||
{
|
|
||||||
o.Tags[index] = ToTag;
|
|
||||||
SaveIt = true;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentOutOfRangeException($"ProcessBulkJob -> Invalid job Subtype{job.SubType}");
|
throw new System.ArgumentOutOfRangeException($"ProcessBulkJob -> Invalid job Subtype{job.SubType}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SaveIt)
|
if (SaveIt)
|
||||||
{
|
{
|
||||||
o = await PutAsync((Widget)o);
|
o = await PutAsync(o);
|
||||||
if (o == null)
|
if (o == null)
|
||||||
await JobsBiz.LogJobAsync(job.GId, $"Error processing item {id}: {GetErrorsAsString()}", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"Error processing item {id}: {GetErrorsAsString()}", ct);
|
||||||
else
|
else
|
||||||
ProcessedObjectCount++;
|
ProcessedObjectCount++;
|
||||||
}else{
|
|
||||||
|
|
||||||
ProcessedObjectCount++;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
ProcessedObjectCount++;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user