示例#1
0
        /// <summary>
        /// Construct a Waveform by reading an XML file.
        /// </summary>
        /// <param name="filename">The name of the file to read.</param>
        /// <returns>The new WaveForm instance.</returns>
        public static Waveform FromXMLFile(string filename)
        {
            FileStream file = new FileStream(filename,
                                             FileMode.Open, FileAccess.Read);

            using (file)
            {
                Waveform newwave = (Waveform)serializer.Deserialize(file);
                newwave.Profile.filename = filename;
                newwave.Profile.parent   = newwave;

                int seq = newwave.FirstIndex;
                foreach (Point point in newwave.Point)
                {
                    if (point.seq != seq)
                    {
                        throw new InvalidDataException(
                                  "The waveform data points are not contiguous.");
                    }
                    seq++;
                    point.Parent = newwave;
                }
                newwave.InitSeries();
                return(newwave);
            }
        }
示例#2
0
        /// <summary>
        /// Replace a template token.
        /// </summary>
        /// <param name="token">The token string.</param>
        /// <param name="waveform">
        /// The waveform from which data should be taken.
        /// </param>
        /// <returns>The replacement text.</returns>
        protected override string ReplaceToken(string token, Waveform waveform)
        {
            string result = base.ReplaceToken(token, waveform);

            if (result != null)
            {
                return(result);
            }
            if (token != "DataLines")
            {
                return(null);
            }
            result = "";
            int column = 0;

            foreach (Point point in waveform.Point)
            {
                result += point.val + ";";
                if (++column == 10)
                {
                    column  = 0;
                    result += "\n";
                }
                else
                {
                    result += "\t";
                }
            }
            return(result);
        }
示例#3
0
 /// <summary>Replace a template token.</summary>
 /// <param name="token">The token string.</param>
 /// <param name="waveform">
 /// The waveform from which data should be taken.
 /// </param>
 /// <returns>The replacement text.</returns>
 protected virtual string ReplaceToken(string token, Waveform waveform)
 {
     if (token == "TemplateProfile")
     {
         return(Replace(Properties.Resources.TemplateProfile, waveform));
     }
     return(PropertyExtractor.Extract(token, waveform));
 }
示例#4
0
        /// <summary>Save a waveform to a file.</summary>
        /// <param name="waveform">The waveform to save.</param>
        /// <param name="filename">The name of the file to save to.</param>
        public virtual void Save(Waveform waveform, string filename)
        {
            FileStream stream = new FileStream(filename,
                                               FileMode.Create, FileAccess.Write);
            StreamWriter writer = new StreamWriter(stream);

            using (stream)
                using (writer)
                    Save(waveform, writer);
            waveform.Profile.filename = filename;
        }
示例#5
0
        /// <summary>
        /// Save a waveform to a stream.
        /// </summary>
        /// <param name="waveform">The waveform to save.</param>
        /// <param name="writer">The stream writer to write to.</param>
        public override void Save(Waveform waveform, StreamWriter writer)
        {
            writer.WriteLine(
                "Series index" + Delimiter + "Time" + Delimiter + "Voltage");

            foreach (Point p in waveform.Point)
            {
                writer.WriteLine(
                    p.seq + Delimiter +
                    p.TimeDouble + Delimiter +
                    p.val);
            }
        }
示例#6
0
        /// <summary>Replace a template token.</summary>
        /// <param name="token">The token string.</param>
        /// <param name="waveform">
        /// The waveform from which data should be taken.
        /// </param>
        /// <returns>The replacement text.</returns>
        protected override string ReplaceToken(string token, Waveform waveform)
        {
            string result = base.ReplaceToken(token, waveform);

            if (result != null)
            {
                return(result);
            }
            if (token != "DataLines")
            {
                return(null);
            }
            return(string.Join(Environment.NewLine,
                               Array.ConvertAll(waveform.Point, p =>
                                                p.val.ToString(CultureInfo.InvariantCulture))));
        }
示例#7
0
        /// <summary>Save a waveform to a file.</summary>
        /// <param name="waveform">The waveform to save.</param>
        /// <param name="filename">The name of the file to save to.</param>
        public override void Save(Waveform waveform, string filename)
        {
            // Write an internal XLS template resource to the file first.
            WriteTemplate(filename);

            // Use the Jet OLE DB facility to connect to the XLS file as a
            // database.
            OleDbConnectionStringBuilder connbuilder =
                new OleDbConnectionStringBuilder();

            connbuilder.DataSource = filename;
            connbuilder.Provider   = "Microsoft.Jet.OLEDB.4.0";
            connbuilder.Add("Extended Properties", "Excel 8.0");

            OleDbConnection conn = new OleDbConnection(connbuilder.ConnectionString);

            using (conn)
            {
                try { conn.Open(); }
                catch (InvalidOperationException e)
                {
                    if (Is64BitProcess)
                    {
                        throw new ApplicationException(
                                  "Excel export currently will not work because " +
                                  "this is a 64-bit process.", e);
                    }
                    throw;
                }

                DataContext context = new DataContext(conn);
                using (context)
                {
                    Table <Profile> tprofile = context.GetTable <Profile>();
                    tprofile.InsertOnSubmit(waveform.Profile);

                    Table <Point> tpoint = context.GetTable <Point>();
                    tpoint.InsertAllOnSubmit(waveform.Point);

                    context.SubmitChanges();
                }
                conn.Close();
            }
        }
示例#8
0
 /// <summary>Save a waveform to a stream.</summary>
 /// <param name="waveform">The waveform to save.</param>
 /// <param name="writer">The stream writer to write to.</param>
 public virtual void Save(Waveform waveform, StreamWriter writer)
 {
     throw new NotImplementedException();
 }
示例#9
0
        /// <summary>Save a waveform to a file.</summary>
        /// <param name="waveform">The waveform to save.</param>
        /// <param name="filename">The name of the file to save to.</param>
        public override void Save(Waveform waveform, string filename)
        {
            Bitmap bitmap = WaveformToBitmap(waveform);

            bitmap.Save(filename, format);
        }
示例#10
0
 /// <summary>
 /// Save a waveform to a stream.
 /// </summary>
 /// <param name="waveform">The waveform to save.</param>
 /// <param name="writer">The stream writer to write to.</param>
 public override void Save(Waveform waveform, StreamWriter writer)
 {
     waveform.ToXMLStream(writer);
 }
示例#11
0
        /// <summary>
        /// Save a waveform to a stream.
        /// </summary>
        /// <param name="waveform">The waveform to save.</param>
        /// <param name="writer">The stream writer to write to.</param>
        public override void Save(Waveform waveform, StreamWriter writer)
        {
            string newtext = Replace(Template, waveform);

            writer.Write(newtext);
        }
示例#12
0
 /// <summary>
 /// Replace {tokens} in a template string with data from a waveform.
 /// </summary>
 /// <param name="text">The template string.</param>
 /// <param name="waveform">
 /// The waveform from which properties will be acquired.
 /// </param>
 /// <returns>The template string, with {tokens} replaced.</returns>
 protected string Replace(string text, Waveform waveform)
 {
     return(parser.Replace(text, match =>
                           ReplaceToken(match.Groups["property"].Value, waveform)
                           ));
 }