using System; using System.Collections.Generic; using System.Linq; using System.Text; using Aitex.UI.Charting.ViewModel; using DataAnalysisControl.Core; using Aitex.DataAnalysis.Core; namespace Aitex.UI.Charting.Model { [Serializable] public class DataItem { public string DataName { get; set; } //public bool IsPreLoaded { get; set; } public List TimeStamp { get; set; } public List RawData { get; set; } } [Serializable] public class ArchivedFile { public string ChamId { get; set; } public string Description { get; set; } public string WaferDisplayIndex { get; set; } public DateTime BeginTime { get; set; } public DateTime EndTime { get; set; } public Dictionary Datas { get; set; } public Dictionary> AliasList { get; set; } //public Dictionary EventList { get; set; } public List> RecipeSteps { get; set; } } public class ArchievedFileDataSource : BaseViewModel, IDataSource { public ArchievedFileDataSource(string fileName) { try { _archieved = ObjectSerializer.DeserializeObjectFromBinaryFile(fileName); System.IO.FileInfo fi = new System.IO.FileInfo(fileName); Title = fi.Name; //填充Datas数据集 Datas = new Dictionary(); foreach (var item in _archieved.Datas) { Datas.Add(item.Key, new DataItem() { DataName = item.Key, TimeStamp = new List(), RawData = new List() }); } //填充recipe信息 List recipeInfo = new List(); if (_archieved.RecipeSteps != null) { foreach (var item in _archieved.RecipeSteps) { recipeInfo.Add(new RecipeSyncPoint() { StepTime = item.Key, StepName = item.Value });// Tuple(item.Key, item.Value)); } } if (recipeInfo.Count == 0) { recipeInfo.Add(new RecipeSyncPoint() { StepTime = DateTime.MinValue, StepName = "NULL" }); } RecipeSteps = recipeInfo; SyncPoint = RecipeSteps[0]; TimeMove = new TimeSpan(0); } catch (Exception ex) { CONTEXT.WriteLog(ex); } } ArchivedFile _archieved; public ArchivedFile ArchivedFile { get { return _archieved; } } public Dictionary Datas { get; set; } public string Title { get; set; } public string ChamberName { get { return _archieved.ChamId; } set { ; } } public string WaferDisplayIndex { get { return _archieved!=null?_archieved.WaferDisplayIndex:null; } set { ; } } public string Description { get { return _archieved.Description; } set { ; } } public DateTime BeginTime { get { return _archieved.BeginTime; } set { ; } } public DateTime EndTime { get { return _archieved.EndTime; } set { ; } } public List RecipeSteps { get; set; } public bool GetData(string dataName, DateTime beginTime, DateTime endTime, out DataItem returnDataItem) { returnDataItem = new DataItem() { DataName = dataName, TimeStamp = new List(), RawData = new List() }; if (!_archieved.Datas.Keys.Contains(dataName)) return false; var data = _archieved.Datas[dataName]; int beginIndex = int.MaxValue; int endIndex = int.MinValue; for (int i = 0; i < data.TimeStamp.Count - 1; i++) { if (data.TimeStamp[i] >= beginTime) { beginIndex = i; break; } } for (int i = data.TimeStamp.Count - 1; i>=0 ; i--) { if (endTime >= data.TimeStamp[i]) { endIndex = i; break; } } if (beginIndex <= endIndex && beginIndex >= 0 && endIndex <= data.TimeStamp.Count - 1) { for (int i = beginIndex; i <= endIndex; i++) { returnDataItem.TimeStamp.Add(data.TimeStamp[i]); returnDataItem.RawData.Add(data.RawData[i]); } } return true; } /// /// get specific datas from archieved files /// /// /// /// /// /// public bool GetData(List dataNames, DateTime beginTime, DateTime endTime, out List returnDataItems) { returnDataItems = new List(); DataItem di; foreach (var dataName in dataNames) { if (GetData(dataName, beginTime, endTime, out di)) returnDataItems.Add(di); else { returnDataItems = new List(); return false; } } return true; } public void Dispose() { if (Datas != null) Datas.Clear(); Datas = null; if (_archieved != null && _archieved.Datas != null) _archieved.Datas.Clear(); _archieved = null; } public TimeSpan TimeMove { get; set; } private RecipeSyncPoint _syncPoint; public RecipeSyncPoint SyncPoint { get { return _syncPoint; } set { if (value != _syncPoint) { CommonViewModel.Instance.SyncSourceTime(Title, value.StepTime, value.StepName); _syncPoint = value; InvokePropertyChanged("SyncPoint"); } } } } }