diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-03-18 16:48:17 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-03-18 16:48:17 +0200 |
| commit | 19a6a9d026f3436afd9af7923db7ee6cbd861772 (patch) | |
| tree | b0841de3a13bfddd03ce9665f74e3f637517b1c9 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs | |
| parent | 18e15c056c25eccbd54f9f82c25630d900d2aa60 (diff) | |
| download | Tango-19a6a9d026f3436afd9af7923db7ee6cbd861772.tar.gz Tango-19a6a9d026f3436afd9af7923db7ee6cbd861772.zip | |
Job Runs, Action Logs - added async method to loading data.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs | 49 |
1 files changed, 24 insertions, 25 deletions
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<ActionLog>(); - 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); } - + /// <summary> /// New Database Query with search parameters. Initialization ActionLogs property. /// </summary> - 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 /// <summary> /// Update DifferenceObject on Selected item changed /// </summary> - 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 /// <summary> /// Initializes the selected action log difference. /// </summary> - 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; |
