public static void Do()
        {
            List<DateValuePair> lDVPs = new List<DateValuePair>();
            lDVPs.AddRange(new DateValuePair[]
            {
                new DateValuePair() { Value = 100.0D, Date = DateTime.Parse("2014-01-01 17:00:00") },
                new DateValuePair() { Value = 50.0D, Date = DateTime.Parse("2014-01-01 17:00:01") },
                new DateValuePair() { Value = 0.0D, Date = DateTime.Parse("2014-01-01 17:00:02") },
                new DateValuePair() { Value = 180.0D, Date = DateTime.Parse("2014-01-01 17:00:02.5") }
            });

            StreamNormalizer sn = new StreamNormalizer(new TimeSpan(0, 0, 1));

            foreach (DateValuePair dvp in lDVPs)
            {
                List<DateValuePair> lOutput = sn.Push(dvp);

                for (int i = 0; i < lOutput.Count; i++)
                {
                    System.Console.WriteLine("{0:S} - {1:N2}", lOutput[i].Date.ToString(), lOutput[i].Value);
                }
            }

            DateValuePair dvpLast = sn.Finish();
            if (dvpLast != null)
                System.Console.WriteLine("*Last {0:S} - {1:N2}", dvpLast.Date.ToString(), dvpLast.Value);
        }
Пример #2
0
        public static System.Collections.IEnumerable TimeNormalize(SqlString statement, SqlInt32 days, SqlInt32 hours, SqlInt32 minutes, SqlInt32 seconds, SqlInt32 milliseconds)
        {
            using (SqlConnection conn = new SqlConnection("context connection = true"))
            {
                conn.Open();
                List<DateValuePair> lDVPs = new List<DateValuePair>();

                StreamNormalizer sn = new StreamNormalizer(new TimeSpan(
                    days.Value, hours.Value, minutes.Value, seconds.Value, milliseconds.Value));

                using (SqlCommand cmd = new SqlCommand(statement.Value, conn))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (!(reader[0] is DateTime))
                                throw new ArgumentException("Field 0 must be a " + typeof(DateTime).FullName + ". It is " + reader[0].GetType().FullName + " instead.");

                            DateValuePair dvp = new DateValuePair { Date = reader.GetDateTime(0) };
                            object oVal = reader[1];

                            try
                            {
                                if (oVal is Int32)
                                    dvp.Value = (int)oVal;
                                else if (oVal is double)
                                    dvp.Value = (double)oVal;
                                else
                                    dvp.Value = Decimal.ToDouble((Decimal)oVal);
                            }
                            catch (Exception exce)
                            {
                                throw new ArgumentException("Field 1 must be a numeric value. It is " + oVal.GetType().FullName + " instead. (Internal exception: " + exce.Message + ").");
                            }

                            lDVPs.AddRange(sn.Push(dvp));
                        }
                    }
                }

                DateValuePair dvpFinish = sn.Finish();

                if (dvpFinish != null)
                    lDVPs.Add(dvpFinish);

                return lDVPs;
            }
        }
Пример #3
0
        public static System.Collections.IEnumerable TimeNormalize_TestType(SqlString statement, SqlInt32 days, SqlInt32 hours, SqlInt32 minutes, SqlInt32 seconds, SqlInt32 milliseconds)
        {
            using (SqlConnection conn = new SqlConnection("context connection = true"))
            {
                conn.Open();
                List<string> lDVPs = new List<string>();

                StreamNormalizer sn = new StreamNormalizer(new TimeSpan(
                    days.Value, hours.Value, minutes.Value, seconds.Value, milliseconds.Value));

                using (SqlCommand cmd = new SqlCommand(statement.Value, conn))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            lDVPs.Add(reader[0].GetType().FullName + " - " + reader[1].GetType().FullName);
                        }
                    }
                }

                return lDVPs;
            }
        }