예제 #1
0
        /// <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());
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 /// <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);
 }
예제 #4
0
        /// <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);
        }