Click here to Skip to main content
15,894,405 members
Articles / Programming Languages / C# 4.0

Grandiose projects 5. Audio support

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
3 Feb 2012CPOL8 min read 23.2K   2K   8  
Audio support for grandiose projects
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

using System.Runtime.Serialization;

using CategoryTheory;


using DiagramUI;


using DataPerformer;

using DataPerformer.Interfaces;

using DataSetService;


namespace DataTableSelection
{
    /// <summary>
    /// Series obtained from data set
    /// </summary>
    [Serializable()]
    public class DataTableSeries : Series, IPostSetArrow, IDataSetConsumer, INamedCoordinates
    {

        #region Fields

        /// <summary>
        /// X - coordinate measure name
        /// </summary>
        new protected string x = "";

        /// <summary>
        /// X - coordinate measure name
        /// </summary>
        new protected string y = "";

        /// <summary>
        /// Data set
        /// </summary>
        protected DataSet dataSet;

        /// <summary>
        /// Data set factory
        /// </summary>
        protected IDataSetFactory factory;

        #endregion

        #region Constructors

        /// <summary>
        /// Default constructor
        /// </summary>
        public DataTableSeries()
        {
        }



        /// <summary>
        /// Deserialization constructor
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        protected DataTableSeries(SerializationInfo info, StreamingContext context)
        {
            x = info.GetValue("X", typeof(string)) as string;
            y = info.GetValue("Y", typeof(string)) as string;
        }


        #endregion

        #region Overriden Members

        /// <summary>
        /// ISerializable interface implementation
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("X", x, typeof(string));
            info.AddValue("Y", y, typeof(string));
        }

        #endregion

        #region IPostSetArrow Members

        void IPostSetArrow.PostSetArrow()
        {
            Set();
            Post();
        }

        #endregion

        #region IDataSetConsumer Members

        void IDataSetConsumer.Add(DataSet dataSet)
        {
            if (this.dataSet != null & dataSet != null)
            {
                throw new Exception("Data set already exists");
            }
            this.dataSet = dataSet;
        }

        void IDataSetConsumer.Remove(DataSet dataSet)
        {
            this.dataSet = null;
        }

        IDataSetFactory IDataSetConsumer.Factory
        {
            get
            {
                return factory;
            }
            set
            {
                factory = value;
            }
        }

        #endregion

        #region INamedCoordinates Members

        IList<string> INamedCoordinates.GetNames(string coordinateName)
        {
            return Names;
        }

        string INamedCoordinates.X
        {
            get
            {
                return x;
            }
        }

        string INamedCoordinates.Y
        {
            get
            {
                return y;
            }
        }

        /// <summary>
        /// Sets parameters
        /// </summary>
        /// <param name="x"> X measure column name</param>
        /// <param name="y"> Y measure column name</param>
        void INamedCoordinates.Set(string x, string y)
        {
            this.x = x;
            this.y = y;
            Set();
        }

        void INamedCoordinates.Update()
        {
        }


        #endregion
 

        #region Specific Members

        /// <summary>
        /// X measure column name
        /// </summary>
        new public string X
        {
            get { return x; }
        }

        /// <summary>
        /// Y measure column name
        /// </summary>
        new public string Y
        {
            get { return y; }
        }

        /// <summary>
        /// Names of columns
        /// </summary>
        public List<string> Names
        {
            get
            {
                if (dataSet == null)
                {
                    return null;
                }
                return DataSetSelection.GetDoubleNames(dataSet);
            }
        }

        /// <summary>
        /// Sets parameters
        /// </summary>
        /// <param name="x"> X measure column name</param>
        /// <param name="y"> Y measure column name</param>
        public void Set(string x, string y)
        {
            this.x = x;
            this.y = y;
            Set();
        }

        /// <summary>
        /// Sets all parameters
        /// </summary>
        protected void Set()
        {
            points = new List<double[]>();
            if (dataSet != null)
            {
                DataTable table = dataSet.Tables[0];
                DataColumn cx = DataSetSelection.SelectColumn(x, dataSet);
                DataColumn cy = DataSetSelection.SelectColumn(y, dataSet);
                foreach (DataRow row in table.Rows)
                {
                    object ox = row[cx];
                    if (ox is DBNull)
                    {
                        continue;
                    }
                    object oy = row[cy];
                    if (oy is DBNull)
                    {
                        continue;
                    }
                    points.Add(new double[] { Convert(ox), Convert(oy) });
                }
            }
        }

        double Convert(object o)
        {
            if (o is DateTime)
            {
                DateTime dt = (DateTime)o;
                return dt.ToOADate();
            }
            return (double)o;
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Russian Federation Russian Federation
Ph. D. Petr Ivankov worked as scientific researcher at Russian Mission Control Centre since 1978 up to 2000. Now he is engaged by Aviation training simulators http://dinamika-avia.com/ . His additional interests are:

1) Noncommutative geometry

http://front.math.ucdavis.edu/author/P.Ivankov

2) Literary work (Russian only)

http://zhurnal.lib.ru/editors/3/3d_m/

3) Scientific articles
http://arxiv.org/find/all/1/au:+Ivankov_Petr/0/1/0/all/0/1

Comments and Discussions