265 lines
9.1 KiB
C#
265 lines
9.1 KiB
C#
// Copyright (c) 2020 LG Electronics Inc.
|
|
// SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using Aurora.Api;
|
|
using Microsoft.Win32;
|
|
using Aurora;
|
|
using Aurora.View;
|
|
|
|
namespace AuroraUIComponent.Views
|
|
{
|
|
public class TactTimeViewModel : NotifyPropertyChangedBase
|
|
{
|
|
private readonly Logger _log;
|
|
public ObservableCollection<string> Files1 { get; set; }
|
|
public string FilePath1 { get; set; }
|
|
public ObservableCollection<string> Files2 { get; set; }
|
|
public string FilePath2 { get; set; }
|
|
private List<LogItemCase> statDataOri = new List<LogItemCase>();
|
|
public ObservableCollection<LogItemCase> StatData { get; set; } = new ObservableCollection<LogItemCase>();
|
|
|
|
private LogItemCase selStatData;
|
|
public LogItemCase SelStatData { get => selStatData; set {
|
|
SetProperty(ref selStatData, value);
|
|
UserVM?.UpdateData(value);
|
|
}
|
|
}
|
|
|
|
private TactData _tactData = new TactData();
|
|
public IUser<LogItemCase> UserVM { get; set; }
|
|
|
|
public TactTimeViewModel(IAuroraEnvironment env)
|
|
{
|
|
_log = new Logger("TactTimeView");
|
|
Files1 = new ObservableCollection<string>();
|
|
Files2 = new ObservableCollection<string>();
|
|
|
|
|
|
ICmdAddLogFiles_1 = new DelegateCommand(AddLogFiles1);
|
|
ICmdAddLogFiles_2 = new DelegateCommand(AddLogFiles2);
|
|
CmdClearTable = new DelegateCommand(ClearTable);
|
|
CmdStart = new DelegateCommand(Start);
|
|
CmdClear = new DelegateCommand(Clear);
|
|
CmdFilter = new DelegateCommand(Filter);
|
|
//
|
|
}
|
|
|
|
private void Filter(object obj)
|
|
{
|
|
if (string.IsNullOrEmpty(SeqFileter) == false) {
|
|
var lowStr = SeqFileter.ToLower();
|
|
StatData = new ObservableCollection<LogItemCase>(statDataOri.Where(x => x.Name.ToLower().Contains(lowStr)));
|
|
} else {
|
|
StatData = new ObservableCollection<LogItemCase>(statDataOri);
|
|
}
|
|
NotifyPropertyChanged("StatData");
|
|
}
|
|
|
|
private void Clear(object obj)
|
|
{
|
|
_tactData.ClearTable();
|
|
UpdateUI();
|
|
}
|
|
|
|
private async void Start(object obj)
|
|
{
|
|
await Task.Run(() => {
|
|
try
|
|
{
|
|
if (SelectTact1)
|
|
{
|
|
DateTime? st = null;
|
|
DateTime? et = null;
|
|
if (UseStartTime1) { st = StartTime1; }
|
|
if (UseEndTime1) { et = EndTime1; }
|
|
if (IsFromTact1)
|
|
{
|
|
StartFromTact(true, st, et);
|
|
}
|
|
else
|
|
{
|
|
StartFromFile(true, st, et);
|
|
}
|
|
}
|
|
if (selectTact2)
|
|
{
|
|
DateTime? st = null;
|
|
DateTime? et = null;
|
|
if (UseStartTime2) { st = StartTime2; }
|
|
if (UseEndTime2) { et = EndTime2; }
|
|
if (IsFromTact2)
|
|
{
|
|
StartFromTact(false, st, et);
|
|
}
|
|
else
|
|
{
|
|
StartFromFile(false, st, et);
|
|
}
|
|
}
|
|
UpdateUI();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_log.E(ex.Message);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void StartFromFile(bool isFirst, DateTime? st, DateTime? et)
|
|
{
|
|
if (isFirst)
|
|
{
|
|
_tactData.Start(Files1.ToList(), FilePath1, SearchStr, Min1, CaseType.Case1, st, et);
|
|
}
|
|
else
|
|
{
|
|
_tactData.Start(Files2.ToList(), FilePath2, SearchStr, Min2, CaseType.Case2, st, et);
|
|
}
|
|
}
|
|
|
|
private void StartFromTact(bool isFirst, DateTime? st, DateTime? et)
|
|
{
|
|
|
|
}
|
|
|
|
private void ClearTable(object obj)
|
|
{
|
|
_tactData.ClearTable();
|
|
UpdateUI();
|
|
}
|
|
|
|
private void UpdateUI()
|
|
{
|
|
statDataOri = _tactData.GetLogItems();
|
|
StatData = new ObservableCollection<LogItemCase>(statDataOri);
|
|
NotifyPropertyChanged("StatData");
|
|
|
|
StartTime1 = _tactData.StartTime1;
|
|
EndTime1 = _tactData.EndTime1;
|
|
StartTime2 = _tactData.StartTime2;
|
|
EndTime2 = _tactData.EndTime2;
|
|
}
|
|
|
|
private void AddLogFiles1(object obj)
|
|
{
|
|
AddFile(true);
|
|
}
|
|
private void AddLogFiles2(object obj)
|
|
{
|
|
AddFile(false);
|
|
}
|
|
|
|
private void AddFile(bool IsFirst)
|
|
{
|
|
FileDialog fd = new OpenFileDialog()
|
|
{
|
|
Multiselect = true,
|
|
};
|
|
var res = fd.ShowDialog(Application.Current.MainWindow);
|
|
if (res == true && fd.FileNames.Length != 0)
|
|
{
|
|
if (IsFirst)
|
|
{
|
|
FilePath1 = Path.GetDirectoryName(fd.FileNames.First());
|
|
Files1.Clear();
|
|
foreach (var fName in fd.FileNames)
|
|
{
|
|
Files1.Add(Path.GetFileName(fName));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FilePath2 = Path.GetDirectoryName(fd.FileNames.First());
|
|
Files2.Clear();
|
|
foreach (var fName in fd.FileNames)
|
|
{
|
|
Files2.Add(Path.GetFileName(fName));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
internal void KeyDown(Key key)
|
|
{
|
|
Filter(null);
|
|
}
|
|
|
|
public ICommand ICmdAddLogFiles_1 { get; }
|
|
public ICommand ICmdAddLogFiles_2 { get; }
|
|
public ICommand CmdClearTable { get; }
|
|
public ICommand CmdStart { get; }
|
|
public ICommand CmdClear { get; }
|
|
public ICommand CmdFilter { get; }
|
|
//
|
|
|
|
|
|
private bool selectTact1 = true;
|
|
public bool SelectTact1 { get => selectTact1; set => SetProperty(ref selectTact1, value); }
|
|
private double min1;
|
|
public double Min1 { get => min1; set => SetProperty(ref min1, value); }
|
|
|
|
private double max1;
|
|
public double Max1 { get => max1; set => SetProperty(ref max1, value); }
|
|
|
|
private bool selectTact2 = true;
|
|
public bool SelectTact2 { get => selectTact2; set => SetProperty(ref selectTact2, value); }
|
|
|
|
private double min2;
|
|
public double Min2 { get => min2; set => SetProperty(ref min2, value); }
|
|
|
|
private double max2;
|
|
public double Max2 { get => max2; set => SetProperty(ref max2, value); }
|
|
|
|
private string searchStr = "\\[END\\]";
|
|
|
|
public string SearchStr { get => searchStr; set => SetProperty(ref searchStr, value); }
|
|
|
|
private bool isFromTact1 = true;
|
|
public bool IsFromTact1 { get => isFromTact1; set => SetProperty(ref isFromTact1, value); }
|
|
|
|
private bool isFromFile1;
|
|
public bool IsFromFile1 { get => isFromFile1; set => SetProperty(ref isFromFile1, value); }
|
|
|
|
private bool isFromTact2 = true;
|
|
public bool IsFromTact2 { get => isFromTact2; set => SetProperty(ref isFromTact2, value); }
|
|
|
|
private bool isFromFile2;
|
|
public bool IsFromFile2 { get => isFromFile2; set => SetProperty(ref isFromFile2, value); }
|
|
|
|
private DateTime startTime1;
|
|
public DateTime StartTime1 { get => startTime1; set => SetProperty(ref startTime1, value); }
|
|
private DateTime startTime2;
|
|
public DateTime StartTime2 { get => startTime2; set => SetProperty(ref startTime2, value); }
|
|
|
|
private DateTime endTime1;
|
|
public DateTime EndTime1 { get => endTime1; set => SetProperty(ref endTime1, value); }
|
|
private DateTime endTime2;
|
|
public DateTime EndTime2 { get => startTime2; set => SetProperty(ref startTime2, value); }
|
|
|
|
private bool useStartTime1;
|
|
public bool UseStartTime1 { get => useStartTime1; set => SetProperty(ref useStartTime1, value); }
|
|
private bool useEndTime1;
|
|
public bool UseEndTime1 { get => useEndTime1; set => SetProperty(ref useEndTime1, value); }
|
|
private bool useStartTime2;
|
|
public bool UseStartTime2 { get => useStartTime2; set => SetProperty(ref useStartTime2, value); }
|
|
private bool useEndTime2;
|
|
public bool UseEndTime2 { get => useEndTime2; set => SetProperty(ref useEndTime2, value); }
|
|
|
|
private string seqFileter;
|
|
public string SeqFileter { get => seqFileter; set => SetProperty(ref seqFileter, value); }
|
|
}
|
|
|
|
public interface IUser<T>
|
|
{
|
|
void UpdateData(T data);
|
|
}
|
|
}
|