/// <summary> /// serialize a Quantler tick file filter /// </summary> /// <param name="tff"></param> /// <returns></returns> public static string Serialize(TickFileFilter tff) { // save everything as xml StringWriter fs; try { XmlSerializer xs = new XmlSerializer(typeof(TickFileFilter)); fs = new StringWriter(); xs.Serialize(fs, tff); fs.Close(); } catch (FileNotFoundException) { return(string.Empty); } catch (Exception) { return(string.Empty); } if (fs == null) { return(""); } return(fs.GetStringBuilder().ToString()); }
/// <summary> /// save tickfilefilter to a file /// </summary> /// <param name="filename"></param> /// <returns></returns> public static TickFileFilter FromFile(string filename) { StreamReader sr = new StreamReader(filename); string msg = sr.ReadToEnd(); TickFileFilter tff = Deserialize(msg); return(tff); }
/// <summary> /// restore a filter from a file /// </summary> /// <param name="tff"></param> /// <param name="filename"></param> /// <returns></returns> public static bool ToFile(TickFileFilter tff, string filename) { try { StreamWriter sw = new StreamWriter(filename, false) { AutoFlush = true }; sw.WriteLine(Serialize(tff)); sw.Close(); } catch (Exception) { return(false); } return(true); }
/// <summary> /// take a serialized tickfilefilter and convert back to an object /// </summary> /// <param name="msg"></param> /// <returns></returns> public static TickFileFilter Deserialize(string msg) { TickFileFilter tf = null; try { // prepare serializer XmlSerializer xs = new XmlSerializer(typeof(TickFileFilter)); // read in message var fs = new StringReader(msg); // deserialize message tf = (TickFileFilter)xs.Deserialize(fs); // close serializer fs.Close(); } catch (FileNotFoundException) { } catch (Exception) { // ignored } return(tf); }