| | |
| | | using Plugin.SeqEditor.Util; |
| | | using System.Collections.ObjectModel; |
| | | using System.IO; |
| | | using System.Runtime.InteropServices; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | using System.Windows.Data; |
| | |
| | | |
| | | private Engine engine; |
| | | private SequenceFile sequenceFile; |
| | | |
| | | public Dictionary<string, SequenceFile> cacheFiles = new Dictionary<string, SequenceFile>(); |
| | | |
| | | private bool isLoaded; |
| | | private ILog log; |
| | | public SeqEditor control { get; private set; } |
| | |
| | | |
| | | private HashSet<string> edits = new HashSet<string>(); |
| | | public Dictionary<Sequence, ObservableCollection<StepUI>> sequenceCache { get; private set; } = new(); |
| | | |
| | | private HashSet<string> indexType = new HashSet<string> { |
| | | StepTypeStr.PassFailTest, |
| | | StepTypeStr.NumericLimitTest, |
| | | StepTypeStr.NI_MultipleNumericLimitTest, |
| | | StepTypeStr.StringValueTest, |
| | | StepTypeStr.NI_Wait, |
| | | StepTypeStr.Action |
| | | }; |
| | | |
| | | public SeqEditorViewModel(SeqEditor control, ILog log) |
| | | { |
| | |
| | | { |
| | | engine.ReleaseSequenceFileEx(sequenceFile); |
| | | } |
| | | foreach (var file in cacheFiles.Values) |
| | | { |
| | | engine.ReleaseSequenceFileEx(file); |
| | | } |
| | | engine.ShutDown(true); |
| | | // 不加延时会弹窗md |
| | | System.Threading.Thread.Sleep(2500); |
| | | //System.Threading.Thread.Sleep(2500); |
| | | } |
| | | } |
| | | |
| | | private ObservableCollection<StepUI> LoadSteps(Sequence seq, string group = null) |
| | | { |
| | | if (sequenceCache.ContainsKey(seq)) |
| | | { |
| | | return sequenceCache[seq]; |
| | | } |
| | | //if (sequenceCache.ContainsKey(seq)) |
| | | //{ |
| | | // return sequenceCache[seq]; |
| | | //} |
| | | |
| | | //setupSteps.Clear(); |
| | | //var steps = new ObservableCollection<StepUI>(); |
| | | //int num = seq.GetNumSteps(StepGroups.StepGroup_Setup); |
| | |
| | | return steps; |
| | | } |
| | | |
| | | private int indexCache = 0; |
| | | |
| | | private StepUI Convert2StepUI(int index, Step step, Sequence sequence, string group) |
| | | { |
| | | var ui = new StepUI(step, sequence); |
| | |
| | | } |
| | | ui.Children = LoadSteps(sunSequence, group); |
| | | } |
| | | else |
| | | { |
| | | string seqName = po.GetValString("SeqName", 0); |
| | | if (!Path.IsPathRooted(sfPath)) |
| | | { |
| | | sfPath = Path.Combine(Path.GetDirectoryName(CurrentFilePath), sfPath); |
| | | } |
| | | SequenceFile diffSequence = null; |
| | | try |
| | | { |
| | | if (cacheFiles.ContainsKey(sfPath)) |
| | | { |
| | | diffSequence = cacheFiles[sfPath]; |
| | | } |
| | | else if (File.Exists(sfPath)) |
| | | { |
| | | diffSequence = engine.GetSequenceFileEx(sfPath); |
| | | cacheFiles[sfPath] = diffSequence; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Warn("Read Diff SubSequence Failed.", ex); |
| | | } |
| | | if (diffSequence != null) |
| | | { |
| | | Sequence sunSequence = diffSequence.GetSequenceByName(seqName); |
| | | ui.Children = LoadSteps(sunSequence, group); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | } |
| | | if (CurrentSeqUI != null) |
| | | { |
| | |
| | | { |
| | | sequenceFile?.Save(CurrentFilePath); |
| | | CurrentSeqUI.IsChanged = false; |
| | | foreach (var key in cacheFiles.Keys) |
| | | { |
| | | cacheFiles[key]?.Save(key); |
| | | } |
| | | ToastHelper.Success(LangUtil.Get("App.SaveSuccess")); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | { |
| | | sequenceFile.Save(sfd.FileName); |
| | | CurrentFilePath = sfd.FileName; |
| | | foreach (var key in cacheFiles.Keys) |
| | | { |
| | | cacheFiles[key]?.Save(key); |
| | | } |
| | | ToastHelper.Success(LangUtil.Get("App.SaveSuccess")); |
| | | CurrentSeqUI.IsChanged = false; |
| | | } |
| | |
| | | if (engine != null && sequenceFile != null) |
| | | { |
| | | engine.ReleaseSequenceFileEx(sequenceFile); |
| | | foreach (var file in cacheFiles.Values) |
| | | { |
| | | engine.ReleaseSequenceFileEx(file); |
| | | } |
| | | sequenceFile = null; |
| | | } |
| | | |
| | | cacheFiles.Clear(); |
| | | setupSteps.Clear(); |
| | | mainSteps.Clear(); |
| | | cleanupSteps.Clear(); |
| | |
| | | } |
| | | var newUI = new StepUI(newStep, targetSequence); |
| | | |
| | | |
| | | |
| | | targetSequence.InsertStep(newStep, index + 1, group); |
| | | ObservableCollection<StepUI> datasource = sequenceCache[targetSequence]; |
| | | int uiIndex = datasource.IndexOf(CurrentStepUI); |
| | |
| | | // var items = parentItem.Items; |
| | | // int innerIndex = items.IndexOf(TreeItemData); |
| | | |
| | | |
| | | |
| | | // items.Insert(innerIndex + 1, newItem); |
| | | // TreeItemDataCollection.ResetSubItems(items); |
| | | //} |
| | |
| | | |
| | | public void RefreshData() |
| | | { |
| | | indexCache = 0; |
| | | sequenceCache.Clear(); |
| | | AllSteps = LoadSteps(CurrentSeqUI.sequence); |
| | | foreach (var file in cacheFiles.Values) |
| | | { |
| | | try |
| | | { |
| | | engine.ReleaseSequenceFileEx(file); |
| | | Marshal.ReleaseComObject(file); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("RefreshData Release Last CacheFile Failed.", ex); |
| | | } |
| | | } |
| | | var converter = control.Resources["treeNumber"] as RowNumberConverter; |
| | | converter.Reset(); |
| | | var temp = LoadSteps(CurrentSeqUI.sequence); |
| | | SetIndex(temp); |
| | | AllSteps = temp; |
| | | } |
| | | |
| | | void SetIndex(IEnumerable<StepUI> datas) |
| | | { |
| | | foreach (var data in datas) |
| | | { |
| | | if (indexType.Contains(data.Type)) |
| | | { |
| | | data.CustomIndex = ++indexCache; |
| | | } |
| | | if (data.Children != null && data.Children.Count > 0) |
| | | { |
| | | SetIndex(data.Children); |
| | | } |
| | | } |
| | | } |
| | | |
| | | partial void OnAllStepsChanged(ObservableCollection<StepUI> data) |