/// <summary> /// 打开文件获取操作堆栈信息 /// </summary> /// <param name="filename"></param> /// <returns></returns> public static PeakHelper GetPeekHelper(string filename) { PeakHelper ph = new PeakHelper(); if (DoOpen(filename, null, ph, null)) { return(ph); } return(null); }
/// <summary> /// 保存数据 /// </summary> /// <param name="filename"></param> /// <param name="dh"></param> /// <param name="ph"></param> /// <returns></returns> //private static bool DoSave(string filename, DataHelper dh, PeekHelper ph) //{ // return DoSave(filename, dh, ph, null); //} /// <summary> /// 保存数据 /// </summary> /// <param name="filename"></param> /// <param name="dh"></param> /// <param name="ph"></param> /// <returns></returns> private static bool DoSave(string filename, DataHelper dh, PeakHelper ph, DetectPeakParameter dpp) { try { if (dh == null || ph == null) { return(false); } IFileReadWrite file = ReadWriteFactory.CreateFileInstance(SerialType.Binary); try { file.OpenFile(filename, FileOpenFlag.Create); List <MemoryStream> mlst = new List <MemoryStream>(); MemoryStream ms = new MemoryStream(); //save points dh.Serialize(ref ms); mlst.Add(ms); file.WriteContent(mlst, 0); //save peaks mlst.Clear(); ms = new MemoryStream(); ph.SerializePeaks(ref ms); mlst.Add(ms); file.WriteContent(mlst, 1); //save operates //mlst.Clear(); //ms = new MemoryStream(); //ph.SerializeOperates(ref ms); //mlst.Add(ms); //file.WriteContent(mlst, 2); //save Detect Peak Parameter mlst.Clear(); ms = new MemoryStream(); dpp.Serialize(ref ms); mlst.Add(ms); file.WriteContent(mlst, 2); } finally { file.CloseFile(); } return(true); } catch (Exception ex) { LogHelper.WriteError(ex); return(false); } }
/// <summary> /// 打开数据 /// </summary> /// <param name="filename"></param> /// <returns></returns> private static bool DoOpen(string filename, DataHelper dh, PeakHelper ph, DetectPeakParameter dpp) { try { //if (dh == null || ph == null) return false; if (!File.Exists(filename)) { return(false); } IFileReadWrite file = ReadWriteFactory.CreateFileInstance(SerialType.Binary); try { file.OpenFile(filename, FileOpenFlag.Open); List <MemoryStream> mlst = new List <MemoryStream>(); //open points if (dh != null && file.ReadContent(0, out mlst)) { dh.Deserialize(mlst[0]); } mlst = new List <MemoryStream>(); //open peaks if (ph != null && file.ReadContent(1, out mlst)) { ph.DeserializePeaks(mlst[0]); } mlst = new List <MemoryStream>(); ////open operates //if (ph != null && file.ReadContent(2, out mlst)) // ph.DeserializeOperates(mlst[0]); //open Detect Peak Parameter if (dpp != null && file.ReadContent(2, out mlst)) { dpp.Deserialize(mlst[0]); } return(true); } finally { file.CloseFile(); } } catch (Exception ex) { LogHelper.WriteError(ex); return(false); } }
/// <summary> /// 获取谱图图形数据 /// </summary> /// <param name="filename">图谱文件名</param> /// <returns></returns> public static PeakAndPointList GetGraphData(string filename) { try { //open points DataHelper dh = new DataHelper(); //open peaks PeakHelper ph = new PeakHelper(); DoOpen(filename, dh, ph, null); PeakAndPointList lst = new PeakAndPointList(); lst.PeakList = ph.Peaks; lst.PointList = dh.List; return(lst); } catch (Exception ex) { LogHelper.WriteError(ex); return(null); } }
/// <summary> /// 清除所有引用 /// </summary> public void FlushRef() { try { _peakhelper = null; _peakcheckor = null; _datahelper = null; if (_cancelpeaklist != null) { _cancelpeaklist.Clear(); } _cancelpeaklist = null; if (_graphcolors != null) { _graphcolors.Clear(); } _graphcolors = null; } catch (Exception ex) { LogHelper.WriteError(ex); } }
/// <summary> /// 保存峰数据 /// </summary> /// <param name="filename"></param> /// <param name="lst"></param> /// <returns></returns> public static bool SetGraphData(string filename, List <Peak> lst) { try { //open points DataHelper dh = new DataHelper(); //open peaks PeakHelper ph = new PeakHelper(); //open detectpeakparameter DetectPeakParameter dpp = new DetectPeakParameter(); if (!DoOpen(filename, dh, ph, dpp)) { return(false); } ph.Peaks.Clear(); ph.Peaks.AddRange(lst); return(DoSave(filename, dh, ph, dpp)); } catch (Exception ex) { LogHelper.WriteError(ex); return(false); } }