This commit is contained in:
@@ -259,7 +259,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
j.JobType = JobType.ImportV7Data;
|
j.JobType = JobType.ImportV7Data;
|
||||||
//j.O wnerId = UserIdFromContext.Id(HttpContext.Items);
|
//j.O wnerId = UserIdFromContext.Id(HttpContext.Items);
|
||||||
j.JobInfo = jobInfo.ToString();
|
j.JobInfo = jobInfo.ToString();
|
||||||
JobsBiz.AddJob(j, ct);
|
JobsBiz.AddJobAsync(j, ct);
|
||||||
return Accepted(new { JobId = j.GId });//202 accepted
|
return Accepted(new { JobId = j.GId });//202 accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
return BadRequest(new ApiErrorResponse(ModelState));
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AyaNova.Util.DbUtil.DBIsEmpty(ct, log))
|
if (!AyaNova.Util.DbUtil.DBIsEmptyAsync(ct, log))
|
||||||
{
|
{
|
||||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Only an empty AyaNova database can request a trial key. Erase the database to proceed with a new trial."));
|
return BadRequest(new ApiErrorResponse(ApiErrorCode.INVALID_OPERATION, null, "Only an empty AyaNova database can request a trial key. Erase the database to proceed with a new trial."));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
j.JobType = JobType.SeedTestData;
|
j.JobType = JobType.SeedTestData;
|
||||||
j.Exclusive = true;//don't run other jobs, this will erase the db
|
j.Exclusive = true;//don't run other jobs, this will erase the db
|
||||||
j.JobInfo = o.ToString();
|
j.JobInfo = o.ToString();
|
||||||
JobsBiz.AddJob(j, ct);
|
JobsBiz.AddJobAsync(j, ct);
|
||||||
|
|
||||||
//Log
|
//Log
|
||||||
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.TrialSeeder, AyaEvent.Created, size), ct);
|
EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.TrialSeeder, AyaEvent.Created, size), ct);
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
OpsJob j = new OpsJob();
|
OpsJob j = new OpsJob();
|
||||||
j.Name = "TestWidgetJob";
|
j.Name = "TestWidgetJob";
|
||||||
j.JobType = JobType.TestWidgetJob;
|
j.JobType = JobType.TestWidgetJob;
|
||||||
JobsBiz.AddJob(j, ct);
|
JobsBiz.AddJobAsync(j, ct);
|
||||||
return Accepted(new { JobId = j.GId });//202 accepted
|
return Accepted(new { JobId = j.GId });//202 accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ namespace AyaNova
|
|||||||
|
|
||||||
//Check database integrity
|
//Check database integrity
|
||||||
_newLog.LogDebug("BOOT: db integrity check");
|
_newLog.LogDebug("BOOT: db integrity check");
|
||||||
DbUtil.CheckFingerPrint(AySchema.EXPECTED_COLUMN_COUNT, AySchema.EXPECTED_INDEX_COUNT, _newLog);
|
DbUtil.CheckFingerPrintAsync(AySchema.EXPECTED_COLUMN_COUNT, AySchema.EXPECTED_INDEX_COUNT, _newLog);
|
||||||
|
|
||||||
//Initialize license
|
//Initialize license
|
||||||
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog);
|
AyaNova.Core.License.InitializeAsync(apiServerState, dbContext, _newLog);
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ namespace AyaNova.Biz
|
|||||||
//basically any error condition during job processing should throw up an exception if it can't be handled
|
//basically any error condition during job processing should throw up an exception if it can't be handled
|
||||||
List<ImportAyaNova7MapItem> importMap = new List<ImportAyaNova7MapItem>();
|
List<ImportAyaNova7MapItem> importMap = new List<ImportAyaNova7MapItem>();
|
||||||
|
|
||||||
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Running, ct);
|
||||||
JobsBiz.LogJobAsync(job.GId, $"ImportAyaNova7 starting", ct);
|
await JobsBiz.LogJobAsync(job.GId, $"ImportAyaNova7 starting", ct);
|
||||||
|
|
||||||
//Get the import filename from the jsondata
|
//Get the import filename from the jsondata
|
||||||
JObject jobData = JObject.Parse(job.JobInfo);
|
JObject jobData = JObject.Parse(job.JobInfo);
|
||||||
@@ -81,8 +81,8 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//Erase all the data except for the license, schema and the manager user
|
//Erase all the data except for the license, schema and the manager user
|
||||||
Microsoft.Extensions.Logging.ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("ImportAyaNova7");
|
Microsoft.Extensions.Logging.ILogger log = AyaNova.Util.ApplicationLogging.CreateLogger("ImportAyaNova7");
|
||||||
JobsBiz.LogJobAsync(job.GId, "ImportAyaNova7 - Erasing data from database", ct);
|
await JobsBiz.LogJobAsync(job.GId, "ImportAyaNova7 - Erasing data from database", ct);
|
||||||
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImporting(log);
|
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
|
||||||
|
|
||||||
|
|
||||||
//get the contents of the archive
|
//get the contents of the archive
|
||||||
@@ -105,42 +105,42 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
//IMPORT UNIT MODEL CATEGORIES AS TAGS
|
//IMPORT UNIT MODEL CATEGORIES AS TAGS
|
||||||
TagLists.Add("UnitModelCategory", new Dictionary<Guid, string>());
|
TagLists.Add("UnitModelCategory", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.UnitModelCategory", job.GId, TagLists["UnitModelCategory"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.UnitModelCategory", job.GId, TagLists["UnitModelCategory"], importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT Unit service type AS TAGS
|
//IMPORT Unit service type AS TAGS
|
||||||
TagLists.Add("UnitServiceType", new Dictionary<Guid, string>());
|
TagLists.Add("UnitServiceType", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.UnitServiceType", job.GId, TagLists["UnitServiceType"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.UnitServiceType", job.GId, TagLists["UnitServiceType"], importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT Workorder Item Type AS TAGS
|
//IMPORT Workorder Item Type AS TAGS
|
||||||
TagLists.Add("WorkorderItemType", new Dictionary<Guid, string>());
|
TagLists.Add("WorkorderItemType", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.WorkorderItemType", job.GId, TagLists["WorkorderItemType"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.WorkorderItemType", job.GId, TagLists["WorkorderItemType"], importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT Client group AS TAGS
|
//IMPORT Client group AS TAGS
|
||||||
TagLists.Add("ClientGroup", new Dictionary<Guid, string>());
|
TagLists.Add("ClientGroup", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.ClientGroup", job.GId, TagLists["ClientGroup"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.ClientGroup", job.GId, TagLists["ClientGroup"], importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT Workorder category AS TAGS
|
//IMPORT Workorder category AS TAGS
|
||||||
TagLists.Add("WorkorderCategory", new Dictionary<Guid, string>());
|
TagLists.Add("WorkorderCategory", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.WorkorderCategory", job.GId, TagLists["WorkorderCategory"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.WorkorderCategory", job.GId, TagLists["WorkorderCategory"], importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT Part Category AS TAGS
|
//IMPORT Part Category AS TAGS
|
||||||
TagLists.Add("PartCategory", new Dictionary<Guid, string>());
|
TagLists.Add("PartCategory", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.PartCategory", job.GId, TagLists["PartCategory"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.PartCategory", job.GId, TagLists["PartCategory"], importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT Dispatch zones AS TAGS
|
//IMPORT Dispatch zones AS TAGS
|
||||||
TagLists.Add("DispatchZone", new Dictionary<Guid, string>());
|
TagLists.Add("DispatchZone", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.DispatchZone", job.GId, TagLists["DispatchZone"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.DispatchZone", job.GId, TagLists["DispatchZone"], importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT Scheduleable User Groups AS TAGS
|
//IMPORT Scheduleable User Groups AS TAGS
|
||||||
TagLists.Add("ScheduleableUserGroup", new Dictionary<Guid, string>());
|
TagLists.Add("ScheduleableUserGroup", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.ScheduleableUserGroup", job.GId, TagLists["ScheduleableUserGroup"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.ScheduleableUserGroup", job.GId, TagLists["ScheduleableUserGroup"], importFileName, zipEntries);
|
||||||
|
|
||||||
//Now can set users to correct tag for scheduleable user group
|
//Now can set users to correct tag for scheduleable user group
|
||||||
// await ImportTagList("GZTW.AyaNova.BLL.ScheduleableUserGroup", "scheduleableusergrouptags", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
|
// await ImportTagList("GZTW.AyaNova.BLL.ScheduleableUserGroup", "scheduleableusergrouptags", AyaType.Tag, job.GId, importMap, importFileName, zipEntries);
|
||||||
|
|
||||||
//IMPORT REGIONS AS TAGS
|
//IMPORT REGIONS AS TAGS
|
||||||
TagLists.Add("Region", new Dictionary<Guid, string>());
|
TagLists.Add("Region", new Dictionary<Guid, string>());
|
||||||
ImportTagList("GZTW.AyaNova.BLL.Region", job.GId, TagLists["Region"], importFileName, zipEntries);
|
await ImportTagListAsync("GZTW.AyaNova.BLL.Region", job.GId, TagLists["Region"], importFileName, zipEntries);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -173,8 +173,8 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
//----------------
|
//----------------
|
||||||
JobsBiz.LogJobAsync(job.GId, "ImportAyaNova7 finished", ct);
|
await JobsBiz.LogJobAsync(job.GId, "ImportAyaNova7 finished", ct);
|
||||||
JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
await JobsBiz.UpdateJobStatusAsync(job.GId, JobStatus.Completed, ct);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -204,11 +204,11 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (importTask != "main")
|
if (importTask != "main")
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Starting import sub-task {importTask} of {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Starting import sub-task {importTask} of {entryStartsWith} objects", ct);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Starting import of {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Starting import of {entryStartsWith} objects", ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
|
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
|
||||||
@@ -235,11 +235,11 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (importTask != "main")
|
if (importTask != "main")
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Successfully ran import subtask {importTask} on {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Successfully ran import subtask {importTask} on {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Successfully imported {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Successfully imported {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,11 +247,11 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
if (importTask != "main")
|
if (importTask != "main")
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Failed to run import subtask {importTask} on {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Failed to run import subtask {importTask} on {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Did not import {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Did not import {notImportCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,14 +260,14 @@ namespace AyaNova.Biz
|
|||||||
//Other job handlers here...
|
//Other job handlers here...
|
||||||
|
|
||||||
|
|
||||||
private void ImportTagList(string entryStartsWith, Guid jobId, Dictionary<Guid, string> tagDictionary, string importFileName, List<string> zipEntries)
|
private async Task ImportTagListAsync(string entryStartsWith, Guid jobId, Dictionary<Guid, string> tagDictionary, string importFileName, List<string> zipEntries)
|
||||||
{
|
{
|
||||||
var zipObjectList = zipEntries.Where(m => m.StartsWith(entryStartsWith)).ToList();
|
var zipObjectList = zipEntries.Where(m => m.StartsWith(entryStartsWith)).ToList();
|
||||||
long importCount = 0;
|
long importCount = 0;
|
||||||
|
|
||||||
if (zipObjectList.Count > 0)
|
if (zipObjectList.Count > 0)
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Starting import to TAGS of {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Starting import to TAGS of {entryStartsWith} objects", ct);
|
||||||
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
|
var jList = FileUtil.ZipGetUtilityArchiveEntriesAsJsonObjects(zipObjectList, importFileName);
|
||||||
|
|
||||||
foreach (JObject j in jList)
|
foreach (JObject j in jList)
|
||||||
@@ -327,7 +327,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
if (importCount > 0)
|
if (importCount > 0)
|
||||||
{
|
{
|
||||||
JobsBiz.LogJobAsync(jobId, $"Successfully imported as TAGS {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
await JobsBiz.LogJobAsync(jobId, $"Successfully imported as TAGS {importCount.ToString()} of {zipObjectList.Count.ToString()} {entryStartsWith} objects", ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,11 +140,11 @@ namespace AyaNova.Biz
|
|||||||
/// <param name="newJob"></param>
|
/// <param name="newJob"></param>
|
||||||
/// <param name="ct"></param>
|
/// <param name="ct"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal static OpsJob AddJob(OpsJob newJob, AyContext ct)
|
internal static async Task<OpsJob> AddJobAsync(OpsJob newJob, AyContext ct)
|
||||||
{
|
{
|
||||||
//TODO: Does this need to create an event so we know which user created the job?
|
//TODO: Does this need to create an event so we know which user created the job?
|
||||||
ct.OpsJob.Add(newJob);
|
await ct.OpsJob.AddAsync(newJob);
|
||||||
ct.SaveChanges();
|
await ct.SaveChangesAsync();
|
||||||
return newJob;
|
return newJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
//Get a count of important tables in db
|
//Get a count of important tables in db
|
||||||
List<string> allTableNames = DbUtil.GetAllTablenames();
|
List<string> allTableNames = DbUtil.GetAllTablenamesAsync();
|
||||||
|
|
||||||
//Skip some tables as they are internal and / or only ever have one record
|
//Skip some tables as they are internal and / or only ever have one record
|
||||||
List<string> skipTableNames = new List<string>();
|
List<string> skipTableNames = new List<string>();
|
||||||
@@ -76,7 +76,7 @@ namespace AyaNova.Biz
|
|||||||
if (!skipTableNames.Contains(table))
|
if (!skipTableNames.Contains(table))
|
||||||
{
|
{
|
||||||
var tags = new MetricTags("TableTagKey", table);
|
var tags = new MetricTags("TableTagKey", table);
|
||||||
metrics.Measure.Gauge.SetValue(MetricsRegistry.DBRecordsGauge, tags, DbUtil.CountOfRecords(table));
|
metrics.Measure.Gauge.SetValue(MetricsRegistry.DBRecordsGauge, tags, DbUtil.CountOfRecordsAsync(table));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using AyaNova.Models;
|
using AyaNova.Models;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
namespace AyaNova.Util
|
namespace AyaNova.Util
|
||||||
@@ -251,7 +252,7 @@ namespace AyaNova.Util
|
|||||||
// Erase all user entered data from the db
|
// Erase all user entered data from the db
|
||||||
// This is called by seeder for trial seeding purposes
|
// This is called by seeder for trial seeding purposes
|
||||||
//
|
//
|
||||||
internal static void EmptyBizDataFromDatabaseForSeedingOrImporting(ILogger _log)
|
internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -265,14 +266,14 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
||||||
{
|
{
|
||||||
conn.Open();
|
await conn.OpenAsync();
|
||||||
|
|
||||||
//Delete from user options table first
|
//Delete from user options table first
|
||||||
using (var cmd = new Npgsql.NpgsqlCommand())
|
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||||
{
|
{
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandText = "delete from \"auseroptions\" where UserId <> 1;";
|
cmd.CommandText = "delete from \"auseroptions\" where UserId <> 1;";
|
||||||
cmd.ExecuteNonQuery();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete from users table
|
//Delete from users table
|
||||||
@@ -280,20 +281,20 @@ namespace AyaNova.Util
|
|||||||
{
|
{
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandText = "delete from \"auser\" where id <> 1;";
|
cmd.CommandText = "delete from \"auser\" where id <> 1;";
|
||||||
cmd.ExecuteNonQuery();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
//REMOVE ALL DATA with few exceptions of manager user, license, schema tables
|
//REMOVE ALL DATA with few exceptions of manager user, license, schema tables
|
||||||
//and job logs because this is called by job code
|
//and job logs because this is called by job code
|
||||||
EraseTable("afileattachment", conn);
|
EraseTableAsync("afileattachment", conn);
|
||||||
EraseTable("awidget", conn);
|
EraseTableAsync("awidget", conn);
|
||||||
EraseTable("aevent", conn);
|
EraseTableAsync("aevent", conn);
|
||||||
EraseTable("adatalistfilter", conn);
|
EraseTableAsync("adatalistfilter", conn);
|
||||||
EraseTable("adatalisttemplate", conn);
|
EraseTableAsync("adatalisttemplate", conn);
|
||||||
EraseTable("aformcustom", conn);
|
EraseTableAsync("aformcustom", conn);
|
||||||
EraseTable("asearchkey", conn);
|
EraseTableAsync("asearchkey", conn);
|
||||||
EraseTable("asearchdictionary", conn);
|
EraseTableAsync("asearchdictionary", conn);
|
||||||
EraseTable("atag", conn);
|
EraseTableAsync("atag", conn);
|
||||||
|
|
||||||
conn.Close();
|
conn.Close();
|
||||||
}
|
}
|
||||||
@@ -309,13 +310,13 @@ namespace AyaNova.Util
|
|||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
// Erase all data from the table specified
|
// Erase all data from the table specified
|
||||||
//
|
//
|
||||||
private static void EraseTable(string sTable, Npgsql.NpgsqlConnection conn)
|
private static async Task EraseTableAsync(string sTable, Npgsql.NpgsqlConnection conn)
|
||||||
{
|
{
|
||||||
using (var cmd = new Npgsql.NpgsqlCommand())
|
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||||
{
|
{
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandText = "TRUNCATE \"" + sTable + "\" RESTART IDENTITY CASCADE;";
|
cmd.CommandText = "TRUNCATE \"" + sTable + "\" RESTART IDENTITY CASCADE;";
|
||||||
cmd.ExecuteNonQuery();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +325,7 @@ namespace AyaNova.Util
|
|||||||
// Check if DB is empty
|
// Check if DB is empty
|
||||||
// CALLED BY LICENSE CONTROLLER AND LICENSE.CS FOR TRIAL Request check
|
// CALLED BY LICENSE CONTROLLER AND LICENSE.CS FOR TRIAL Request check
|
||||||
// Also called by Import
|
// Also called by Import
|
||||||
internal static bool DBIsEmpty(AyContext ctx, ILogger _log)
|
internal static bool DBIsEmpty(AyContext ct, ILogger _log)
|
||||||
{
|
{
|
||||||
//TODO: This needs to be way more thorough, only the main tables though, no need to get crazy with it
|
//TODO: This needs to be way more thorough, only the main tables though, no need to get crazy with it
|
||||||
//just stuff that would be shitty to have to re-enter
|
//just stuff that would be shitty to have to re-enter
|
||||||
@@ -332,7 +333,7 @@ namespace AyaNova.Util
|
|||||||
_log.LogDebug("DB empty check");
|
_log.LogDebug("DB empty check");
|
||||||
|
|
||||||
//An empty db contains only one User
|
//An empty db contains only one User
|
||||||
if (ctx.User.Count() > 1) return false;
|
if (ct.User.Count() > 1) return false;
|
||||||
|
|
||||||
//No clients
|
//No clients
|
||||||
//if(ctx.Client.Count()>0) return false;
|
//if(ctx.Client.Count()>0) return false;
|
||||||
@@ -354,7 +355,7 @@ namespace AyaNova.Util
|
|||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
// Ensure the db is not modified
|
// Ensure the db is not modified
|
||||||
//
|
//
|
||||||
internal static void CheckFingerPrint(long ExpectedColumns, long ExpectedIndexes, ILogger _log)
|
internal static async Task CheckFingerPrintAsync(long ExpectedColumns, long ExpectedIndexes, ILogger _log)
|
||||||
{
|
{
|
||||||
_log.LogDebug("Checking DB integrity");
|
_log.LogDebug("Checking DB integrity");
|
||||||
|
|
||||||
@@ -363,19 +364,19 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
||||||
{
|
{
|
||||||
conn.Open();
|
await conn.OpenAsync();
|
||||||
|
|
||||||
using (var command = conn.CreateCommand())
|
using (var command = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
//Count all columns in all our tables
|
//Count all columns in all our tables
|
||||||
command.CommandText = "SELECT count(*) FROM information_schema.columns where table_schema='public'";
|
command.CommandText = "SELECT count(*) FROM information_schema.columns where table_schema='public'";
|
||||||
|
|
||||||
using (var result = command.ExecuteReader())
|
using (var result = await command.ExecuteReaderAsync())
|
||||||
{
|
{
|
||||||
if (result.HasRows)
|
if (result.HasRows)
|
||||||
{
|
{
|
||||||
//check the values
|
//check the values
|
||||||
result.Read();
|
await result.ReadAsync();
|
||||||
actualColumns = result.GetInt64(0);
|
actualColumns = result.GetInt64(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -393,12 +394,12 @@ namespace AyaNova.Util
|
|||||||
//Count all indexes in all our tables
|
//Count all indexes in all our tables
|
||||||
command.CommandText = "select Count(*) from pg_indexes where schemaname='public'";
|
command.CommandText = "select Count(*) from pg_indexes where schemaname='public'";
|
||||||
|
|
||||||
using (var result = command.ExecuteReader())
|
using (var result = await command.ExecuteReaderAsync())
|
||||||
{
|
{
|
||||||
if (result.HasRows)
|
if (result.HasRows)
|
||||||
{
|
{
|
||||||
//check the values
|
//check the values
|
||||||
result.Read();
|
await result.ReadAsync();
|
||||||
actualIndexes = result.GetInt64(0);
|
actualIndexes = result.GetInt64(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -409,7 +410,7 @@ namespace AyaNova.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conn.Close();
|
await conn.CloseAsync();
|
||||||
|
|
||||||
if (ExpectedColumns != actualColumns || ExpectedIndexes != actualIndexes)
|
if (ExpectedColumns != actualColumns || ExpectedIndexes != actualIndexes)
|
||||||
{
|
{
|
||||||
@@ -426,27 +427,27 @@ namespace AyaNova.Util
|
|||||||
// Used for metrics
|
// Used for metrics
|
||||||
//
|
//
|
||||||
///
|
///
|
||||||
internal static long CountOfRecords(string TableName)
|
internal static async Task<long> CountOfRecordsAsync(string TableName)
|
||||||
{
|
{
|
||||||
long ret = 0;
|
long ret = 0;
|
||||||
|
|
||||||
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
using (var conn = new Npgsql.NpgsqlConnection(_dbConnectionString))
|
||||||
{
|
{
|
||||||
conn.Open();
|
await conn.OpenAsync();
|
||||||
|
|
||||||
using (var command = conn.CreateCommand())
|
using (var command = conn.CreateCommand())
|
||||||
{
|
{
|
||||||
command.CommandText = $"SELECT count(*) FROM {TableName}";
|
command.CommandText = $"SELECT count(*) FROM {TableName}";
|
||||||
using (var result = command.ExecuteReader())
|
using (var result = await command.ExecuteReaderAsync())
|
||||||
{
|
{
|
||||||
if (result.HasRows)
|
if (result.HasRows)
|
||||||
{
|
{
|
||||||
result.Read();
|
await result.ReadAsync();
|
||||||
ret = result.GetInt64(0);
|
ret = result.GetInt64(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conn.Close();
|
await conn.CloseAsync();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -456,7 +457,7 @@ namespace AyaNova.Util
|
|||||||
// Returns all table names that are ours in current schema
|
// Returns all table names that are ours in current schema
|
||||||
//
|
//
|
||||||
///
|
///
|
||||||
internal static List<string> GetAllTablenames()
|
internal static async Task<List<string>> GetAllTablenamesAsync()
|
||||||
{
|
{
|
||||||
|
|
||||||
List<string> ret = new List<string>();
|
List<string> ret = new List<string>();
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ namespace AyaNova.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Can't install a trial into a non-empty db
|
//Can't install a trial into a non-empty db
|
||||||
if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmpty(ct, log))
|
if (ParsedNewKey.TrialLicense && !DbUtil.DBIsEmptyAsync(ct, log))
|
||||||
{
|
{
|
||||||
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
|
throw new ApplicationException("E1020 - Can't install a trial key into a non empty AyaNova database. Erase the database first.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace AyaNova.Util
|
|||||||
apiServerState.SetOpsOnly("Seeding database");
|
apiServerState.SetOpsOnly("Seeding database");
|
||||||
|
|
||||||
//Erase all the data except for the license, schema and the manager user
|
//Erase all the data except for the license, schema and the manager user
|
||||||
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImporting(log);
|
DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
|
||||||
|
|
||||||
|
|
||||||
//Set the time zone of the manager account
|
//Set the time zone of the manager account
|
||||||
|
|||||||
Reference in New Issue
Block a user