This commit is contained in:
2020-01-27 22:47:47 +00:00
parent bb1a51af4a
commit 76e7d98319
7 changed files with 27 additions and 30 deletions

View File

@@ -211,7 +211,7 @@ namespace AyaNova.Api.Controllers
/// <param name="filename"></param>
/// <returns>Ok</returns>
[HttpPost("EraseDatabaseAndStartImport/{filename}")]
public ActionResult EraseDatabaseAndStartImport([FromRoute] string filename)
public async Task<IActionResult> EraseDatabaseAndStartImport([FromRoute] string filename)
{
//Open or opsOnly and user is opsadminfull
if (!serverState.IsOpenOrOpsOnly || (serverState.IsOpsOnly && !Authorized.HasAnyRole(HttpContext.Items, AuthorizationRoles.OpsAdminFull)))
@@ -259,7 +259,7 @@ namespace AyaNova.Api.Controllers
j.JobType = JobType.ImportV7Data;
//j.O wnerId = UserIdFromContext.Id(HttpContext.Items);
j.JobInfo = jobInfo.ToString();
JobsBiz.AddJobAsync(j, ct);
await JobsBiz.AddJobAsync(j, ct);
return Accepted(new { JobId = j.GId });//202 accepted
}

View File

@@ -124,7 +124,7 @@ namespace AyaNova.Api.Controllers
try
{
if (!biz.Put(o, inObj))
if (!biz.PutAsync(o, inObj))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}
@@ -189,7 +189,7 @@ namespace AyaNova.Api.Controllers
try
{
//patch and validate
if (!biz.Patch(o, objectPatch, concurrencyToken))
if (!biz.PatchAsync(o, objectPatch, concurrencyToken))
{
return BadRequest(new ApiErrorResponse(biz.Errors));
}

View File

@@ -16,7 +16,7 @@ namespace AyaNova.Biz
/// <summary>
/// Prime the database with manager account
/// </summary>
public static void PrimeManagerAccount(AyContext ct)
public static async Task PrimeManagerAccount(AyContext ct)
{
//get a db and logger
//ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("PrimeData");
@@ -31,8 +31,8 @@ namespace AyaNova.Biz
u.LocaleId = ServerBootConfig.AYANOVA_DEFAULT_LANGUAGE_ID;//Ensure primeLocales is called first
u.UserType = UserType.Administrator;
u.UserOptions = new UserOptions();
ct.User.Add(u);
ct.SaveChanges();
await ct.User.AddAsync(u);
await ct.SaveChangesAsync();
}

View File

@@ -64,18 +64,16 @@ namespace AyaNova.Biz
//FOR NOW NOT ASYNC so faking it at end of this method
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
JobsBiz.LogJobAsync(job.GId, $"Starting...", ct);
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
await JobsBiz.LogJobAsync(job.GId, $"Starting...", ct);
//Get the import filename from the jsondata
JObject jobData = JObject.Parse(job.JobInfo);
var seedLevel = (Seeder.SeedLevel)jobData["seedLevel"].Value<int>();
var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
Seeder.SeedDatabase(seedLevel, job.GId, timeZoneOffset);
JobsBiz.LogJobAsync(job.GId, "Finished.", ct);
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
//NO, BAD! Convert the logjob etc above to async
//await Task.CompletedTask;
await JobsBiz.LogJobAsync(job.GId, "Finished.", ct);
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
}

View File

@@ -809,7 +809,7 @@ namespace AyaNova.Biz
if (HasErrors)
{
//If there are any validation errors, log in joblog and move on
JobsBiz.LogJobAsync(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct);
await JobsBiz.LogJobAsync(jobId, $" -> import object \"{i.Name}\" source id {V7Id.ToString()} failed validation and was not imported: {GetErrorsAsString()} ", ct);
//This is a fundamental problem with the import as users are required for many things so bomb out entirely
//other things might be able to work around but this is too serious
@@ -907,8 +907,7 @@ namespace AyaNova.Biz
break;
}
//just to hide compiler warning for now
await Task.CompletedTask;
//this is the equivalent of returning void for a Task signature with nothing to return
return true;

View File

@@ -43,10 +43,10 @@ namespace AyaNova.Biz
//
//put
internal bool Put(UserOptions dbObj, UserOptions inObj)
internal async Task<bool> PutAsync(UserOptions dbObj, UserOptions inObj)
{
//Replace the db object with the PUT object
CopyObject.Copy(inObj, dbObj, "Id, UserId");
//Set "original" value of concurrency token to input token
@@ -57,14 +57,14 @@ namespace AyaNova.Biz
if (HasErrors)
return false;
ct.SaveChanges();
await ct.SaveChangesAsync();
//Log
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
return true;
}
//patch
internal bool Patch(UserOptions dbObj, JsonPatchDocument<UserOptions> objectPatch, uint concurrencyToken)
internal async Task<bool> PatchAsync(UserOptions dbObj, JsonPatchDocument<UserOptions> objectPatch, uint concurrencyToken)
{
//Validate Patch is allowed
if (!ValidateJsonPatch<UserOptions>.Validate(this, objectPatch, "UserId")) return false;
@@ -77,9 +77,9 @@ namespace AyaNova.Biz
if (HasErrors)
return false;
ct.SaveChanges();
await ct.SaveChangesAsync();
//Log
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.Id, AyaType.UserOptions, AyaEvent.Modified), ct);
return true;
}

View File

@@ -212,7 +212,7 @@ namespace AyaNova.Biz
//Determine if the object can be deleted, do the deletion tentatively
//Probably also in here deal with tags and associated search text etc
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
//NOT REQUIRED NOW BUT IF IN FUTURE ValidateCanDelete(dbObj);
if (HasErrors)
return false;
ct.Widget.Remove(dbObj);
@@ -290,7 +290,7 @@ namespace AyaNova.Biz
//validate custom fields
CustomFieldsValidator.Validate(this, FormCustomization, proposedObj.CustomFields);
}
}
@@ -329,13 +329,13 @@ namespace AyaNova.Biz
{
var sleepTime = 30 * 1000;
//Simulate a long running job here
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
await JobsBiz.LogJobAsync(job.GId, $"WidgetBiz::ProcessTestJob started, sleeping for {sleepTime} seconds...", ct);
//Uncomment this to test if the job prevents other routes from running
//result is NO it doesn't prevent other requests, so we are a-ok for now
await Task.Delay(sleepTime);
JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct);
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
await JobsBiz.LogJobAsync(job.GId, "WidgetBiz::ProcessTestJob done sleeping setting job to finished", ct);
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
}