From 19a6a9d026f3436afd9af7923db7ee6cbd861772 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 18 Mar 2020 16:48:17 +0200 Subject: Job Runs, Action Logs - added async method to loading data. --- .../ViewModels/MainViewVM.cs | 49 +++++++++++----------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index c1bf63ce4..50ec7f7a5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -110,7 +110,7 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels IsLoading = false; ActionLogs = new ObservableCollection(); - SearchCommand = new RelayCommand(GetActionLogs, () => IsFree); + SearchCommand = new RelayCommand(async () => await GetActionLogs(), () => IsFree); CopyRelateObjectIDCommand = new RelayCommand(CopyRelateObjectID); CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard, () => SelectedActionLog != null && SelectedActionLog.DifferenceObject != null); DateTime now = DateTime.Now; @@ -159,11 +159,11 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels DataObject data = new DataObject(SelectedActionLog.RelatedObjectGuid); System.Windows.Clipboard.SetDataObject(data); } - + /// /// New Database Query with search parameters. Initialization ActionLogs property. /// - private void GetActionLogs() + private async Task GetActionLogs() { IsLoading = true; string filter = SearchFilter?.ToLower(); @@ -182,22 +182,31 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels DateTime endUtc = new DateTime(EndSelectedDate.Date.Ticks + offsetTime.Ticks, DateTimeKind.Utc); Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); - + var db_ActionLogs = db.ActionLogs.Where(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) .Select(x => new { - x.ID,x.Guid,x.UserGuid, x.LastUpdated,x.Type,x.RelatedObjectName, x.RelatedObjectGuid,x.Message + x.ID, + x.Guid, + x.UserGuid, + x.LastUpdated, + x.Type, + x.RelatedObjectName, + x.RelatedObjectGuid, + x.Message }); + int[] actionTypes = SelectedActionLogTypes.SynchedSource.ToArray().Select(x => (int)x).ToArray(); - if(actionTypes.Length > 0) + if (actionTypes.Length > 0) { db_ActionLogs = db_ActionLogs.Where(x => actionTypes.Contains(x.Type)); } - var runs = db_ActionLogs.ToList() - .Select(x => new ActionLog() + var runs_db = await db_ActionLogs.ToListAsync(); + var runs = runs_db.Select(x => new ActionLog() { - ID = x.ID,Guid = x.Guid, + ID = x.ID, + Guid = x.Guid, UserGuid = x.UserGuid, LastUpdated = x.LastUpdated, Type = x.Type, @@ -206,6 +215,7 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels Message = x.Message, User = _allUsers.SingleOrDefault(y => y.Guid == x.UserGuid) }); + if (!String.IsNullOrEmpty(filter)) { runs = runs.Where(x => x.ID.ToString().ToLower().StartsWith(filter) || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) @@ -213,17 +223,6 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))); } ActionLogs = runs.ToObservableCollection(); - - //ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) - // .WithUsers() - // .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) - // .Query(y => y.Where - // (x => filter == null || - // (x.ID.ToString().ToLower().StartsWith(filter) - // || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) - // || (x.RelatedObjectGuid != null && x.RelatedObjectGuid.ToLower().StartsWith(filter)) - // || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) - // .BuildAsync(); } } catch (Exception ex) @@ -242,13 +241,13 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels /// /// Update DifferenceObject on Selected item changed /// - private void SelectedItemChanged() + private async void SelectedItemChanged() { if (SelectedActionLog == null) return; - if(SelectedActionLog.Difference==null) + if (SelectedActionLog.Difference == null) { - InitSelectedActionLogDifference(); + await InitSelectedActionLogDifference(); } DifferenceObject = SelectedActionLog.DifferenceObject; } @@ -256,14 +255,14 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels /// /// Initializes the selected action log difference. /// - public void InitSelectedActionLogDifference() + public async Task InitSelectedActionLogDifference() { IsLoading = true; try { using (var db = ObservablesContext.CreateDefault()) { - var difference = db.ActionLogs.SingleOrDefault(x => x.Guid.Equals(SelectedActionLog.Guid)); + var difference = await db.ActionLogs.SingleOrDefaultAsync(x => x.Guid.Equals(SelectedActionLog.Guid)); if (difference != null) { SelectedActionLog.DifferenceObject = difference.DifferenceObject; -- cgit v1.3.1