aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2020-03-18 16:48:17 +0200
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2020-03-18 16:48:17 +0200
commit19a6a9d026f3436afd9af7923db7ee6cbd861772 (patch)
treeb0841de3a13bfddd03ce9665f74e3f637517b1c9 /Software/Visual_Studio/MachineStudio/Modules
parent18e15c056c25eccbd54f9f82c25630d900d2aa60 (diff)
downloadTango-19a6a9d026f3436afd9af7923db7ee6cbd861772.tar.gz
Tango-19a6a9d026f3436afd9af7923db7ee6cbd861772.zip
Job Runs, Action Logs - added async method to loading data.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs49
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml5
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs70
3 files changed, 64 insertions, 60 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;
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml
index 05aad0574..b077f6088 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml
@@ -82,8 +82,9 @@
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel Margin="2">
- <CheckBox VerticalAlignment="Center" DockPanel.Dock="Left" IsChecked="{Binding IsSelected}" />
- <TextBlock Margin="5 0 0 0" VerticalAlignment="Center" Text="{Binding Data,Converter={StaticResource EnumToDescriptionConverter}}"></TextBlock>
+ <CheckBox VerticalAlignment="Center" DockPanel.Dock="Left" IsChecked="{Binding IsSelected}" >
+ <TextBlock Margin="5 0 0 0" VerticalAlignment="Center" Text="{Binding Data,Converter={StaticResource EnumToDescriptionConverter}}"></TextBlock>
+ </CheckBox>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
index b0c4975ee..3aa93cd3e 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs
@@ -323,49 +323,51 @@ namespace Tango.MachineStudio.Statistics.ViewModels
TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59);
DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime;
string jobName = SelectedJob == null ? "" : SelectedJob.Name;
-
-
- var db_JobRuns = db.JobRuns.Where(x=> x.StartDate <= DbFunctions.TruncateTime(endUtc) && x.StartDate >= DbFunctions.TruncateTime(startUtc.Date))
+
+
+ var db_JobRuns = db.JobRuns.Where(x => x.StartDate <= DbFunctions.TruncateTime(endUtc) && x.StartDate >= DbFunctions.TruncateTime(startUtc.Date))
.Select(x => new
- {
- x.ID,
- x.ActualStartDate,
- x.EndDate,
- x.EndPosition,
- x.GradientResolutionCm,
- x.Guid,
- x.HeatingStartDate,
- x.IsGradient,
- x.JobGuid,
- x.JobLength,
- x.JobName,
- x.JobSource,
- x.MachineGuid,
- x.RmlGuid,
- x.StartDate,
- x.Status,
- x.UploadingStartDate,
- x.UserGuid,
- x.LiquidQuantityString,
- });
+ {
+ x.ID,
+ x.ActualStartDate,
+ x.EndDate,
+ x.EndPosition,
+ x.GradientResolutionCm,
+ x.Guid,
+ x.HeatingStartDate,
+ x.IsGradient,
+ x.JobGuid,
+ x.JobLength,
+ x.JobName,
+ x.JobSource,
+ x.MachineGuid,
+ x.RmlGuid,
+ x.StartDate,
+ x.Status,
+ x.UploadingStartDate,
+ x.UserGuid,
+ x.LiquidQuantityString,
+ });
+
+
var machineIDs = new HashSet<string>(SelectedMachines.SynchedSource.ToList().Select(p => p.Guid));
- if(machineIDs.Count > 0)
+ if (machineIDs.Count > 0)
{
db_JobRuns = db_JobRuns.Where(x => machineIDs.Contains(x.MachineGuid));
}
int[] jobRunSourceArr = JobRunSelectedSources.SynchedSource.Select(x => (int)x).ToArray();
- if(jobRunSourceArr.Length > 0)
+ if (jobRunSourceArr.Length > 0)
{
db_JobRuns = db_JobRuns.Where(x => jobRunSourceArr.Contains(x.JobSource));
}
int[] jobRunStatusArr = JobRunSelectedStatuses.SynchedSource.Select(x => (int)x).ToArray();
- if(jobRunStatusArr.Length > 0)
+ if (jobRunStatusArr.Length > 0)
{
db_JobRuns = db_JobRuns.Where(x => jobRunStatusArr.Contains(x.Status));
}
bool[] isGradientArr = IsGradientSelection.SynchedSource.Select(x => (bool)x).ToArray();
- if(isGradientArr.Length > 0)
+ if (isGradientArr.Length > 0)
{
db_JobRuns = db_JobRuns.Where(x => isGradientArr.Contains(x.IsGradient));
}
@@ -374,13 +376,15 @@ namespace Tango.MachineStudio.Statistics.ViewModels
{
db_JobRuns = db_JobRuns.Where(x => rmlGuids.Contains(x.RmlGuid));
}
- if(!String.IsNullOrEmpty(jobName))
+ if (!String.IsNullOrEmpty(jobName))
{
db_JobRuns = db_JobRuns.Where(x => x.JobName.ToLower().StartsWith(jobName.ToLower()));
}
-
- List<JobRun> runs = db_JobRuns.ToList()
- .Where(x => (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))
+
+ var runs_db = await db_JobRuns.ToListAsync(); //Execute actual query.
+
+
+ List<JobRun> runs = runs_db.Where(x => (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))
.Select(x => new JobRun()
{
ID = x.ID,
@@ -473,7 +477,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels
var selection = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.EndDate != null && z.JobRun.ActualStartDate != null);
double val = 0d;
double average = 0d;
- if (selection != null && selection.Count<JobRunModel>() > 0)
+ if (selection != null && selection.Count<JobRunModel>() > 0)
{
val = selection.Sum(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalHours);
average = selection.Average(x => (x.JobRun.EndDate - x.JobRun.ActualStartDate).Value.TotalMilliseconds);