ConvertListToBlobWithChecksum() public method

This method converts a List of TimeSeriesValue objects into a BLOB (byte array) of time series values and computes a checksum from the BLOB. This method assigns the new values of the ValueBlob, Checksum, EndDate, and TimeStepCount to the object given in the traceObject parameter. The TraceNumber property of the traceObject parameter must be set before calling this method. The entire List is converted into the BLOB--i.e., the method does not take any parameters for limiting the size of the List that is created. This method will throw exceptions if the meta-parameters that are passed in are not consistent with the List of TimeSeriesValue objects.
public ConvertListToBlobWithChecksum ( TSDateCalculator timeStepUnit, short timeStepQuantity, int timeStepCount, System.DateTime blobStartDate, System.DateTime blobEndDate, List dateValueList, ITimeSeriesTrace traceObject, int &compressionCode ) : byte[]
timeStepUnit TSDateCalculator TSDateCalculator.TimeStepUnitCode value for /// Minute, Hour, Day, Week, Month, Year, or Irregular
timeStepQuantity short The number of the given unit that defines the time step. /// For instance, if the time step is 6 hours long, then this value is 6.
timeStepCount int The number of time steps stored in the BLOB
blobStartDate System.DateTime Date of the first time step in the BLOB
blobEndDate System.DateTime Date of the last time step in the BLOB
dateValueList List A List of TimeSeriesValue objects that will be converted to a BLOB
traceObject ITimeSeriesTrace an object which contains the a TraceNumber property that is used to /// compute the checksum. The computed BLOB and checksum are both saved to the appropriate properties /// of this object.
compressionCode int a generation number that indicates what compression technique to use
return byte[]
        public List<ITimeSeriesTrace> Get3TracesRegular(
                    TSDateCalculator.TimeStepUnitCode u1, short q1, int c1,
                    DateTime sDate1, out DateTime eDate1,
                    Boolean shouldPerturb = false,
                    int perturbTraceIndex = 0, int perturbStep = 0, 
                    double perturbVal = 0, double perturbMinutes = 0)
        {
            eDate1 = DateTime.Now;  // dummy
            TSLibrary tsLib = new TSLibrary();
            List<ITimeSeriesTrace> traceList = new List<ITimeSeriesTrace>();
            int compressionCode;

            for (int t = 0; t < 3; t++)
            {
                TSTrace trace1 = new TSTrace { TraceNumber = t + 1 };
                List<TimeSeriesValue> tsValues = new List<TimeSeriesValue>();
                DateTime curDate = sDate1;
                Double curVal = 20;
                for (int i = 0; i < c1; i++)
                {
                    tsValues.Add(new TimeSeriesValue { Date = curDate, Value = curVal });
                    curDate = tsLib.IncrementDate(curDate, u1, q1, 1);
                    curVal = curVal + i / (t + 1);
                }
                // make a perturbation if called for
                if (shouldPerturb && t==perturbTraceIndex)
                {
                    tsValues[perturbStep].Value += perturbVal;
                    tsValues[perturbStep].Date = tsValues[perturbStep].Date.AddMinutes(perturbMinutes);
                }
                eDate1 = tsValues.Last().Date;
                tsLib.ConvertListToBlobWithChecksum(
                        u1, q1, c1,
                        sDate1, eDate1, tsValues, trace1, out compressionCode);

                traceList.Add(trace1);
            }
            return traceList;
        }
        public void ConvertListToBlobWithChecksum_Err4()
        {
            TSLibrary tsLib = new TSLibrary();
            TSTrace traceObject = new TSTrace { TraceNumber = 1 };
            int compressionCode;

            try
            {
                byte[] blobData = tsLib.ConvertListToBlobWithChecksum(
                        TSDateCalculator.TimeStepUnitCode.Irregular, 0,
                        IrregList1.Count, IrregList1.First().Date, IrregList1.Last().Date.AddDays(2),
                        IrregList1, traceObject, out compressionCode);
                Assert.Fail("Should have thrown exception");
            }
            catch (TSLibraryException e)
            {
                Assert.AreEqual(ErrCode.Enum.Checksum_Improper_EndDate, e.ErrCode);
            }
        }
        public void ConvertListToBlobWithChecksum_Err0()
        {
            TSLibrary tsLib = new TSLibrary();
            TSTrace traceObject = new TSTrace { TraceNumber = 1 };
            int compressionCode;

            try
            {
                byte[] blobData = tsLib.ConvertListToBlobWithChecksum(
                        TSDateCalculator.TimeStepUnitCode.Irregular, 0,
                        IrregList1.Count, IrregList1.First().Date, IrregList1.Last().Date,
                        IrregList1, traceObject, out compressionCode);
                Assert.IsTrue(true);
            }
            catch (TSLibraryException)
            {
                Assert.Fail("Should not throw any exceptions");
            }
        }
        // the maximum number of time steps to put into the series
        // The series of tests below is for ConvertBlobToListLimited and ConvertListToBlob.
        // The tests take advantage of the fact that the methods are designed so that
        // the series that is put into the BLOB must be identical to the series that
        // comes out of the BLOB.
        // This method is re-used by the actual test methods that follow.
        public void ConvertBlobLimited(List<TimeSeriesValue> inList,
                TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity,
                DateTime blobStartDate,
                int nCutStart,          // the number of time steps that the test will truncate from the start of the series
                int nCutEnd,            // the number of time steps that the test will truncate from the end of the series
                int nMax)
        {
            TSLibrary tsLib = new TSLibrary();
            List<TimeSeriesValue> outList = new List<TimeSeriesValue>();
            int compressionCode;

            byte[] blobData = tsLib.ConvertListToBlobWithChecksum(timeStepUnit, timeStepQuantity,
                                inList.Count, inList.First().Date, inList.Last().Date, inList,
                                new TSTrace { TraceNumber = 1 }, out compressionCode);

            int ret = tsLib.ConvertBlobToListLimited(timeStepUnit, timeStepQuantity,
                            inList.Count, blobStartDate,
                            nMax, inList[nCutStart].Date, inList[inList.Count - nCutEnd - 1].Date,
                            blobData, ref outList, compressionCode);

            // The return value of the function must match the number of items in the original list
            Assert.AreEqual(ret, Math.Min(nMax, inList.Count - nCutStart - nCutEnd));
            // the count in both lists must match
            Assert.AreEqual(outList.Count, Math.Min(nMax, inList.Count - nCutStart - nCutEnd));

            // now check each item in the two lists
            Boolean AreEqual = true;
            for (int i = 0; i < ret; i++)
            {
                if (outList[i].ValueEquals(inList[i + nCutStart]) == false)
                    AreEqual = false;
            }

            Assert.IsTrue(AreEqual);
        }
        // The series of tests below is for ConvertBlobToListAll and ConvertListToBlob.
        // The tests take advantage of the fact that the methods are designed so that
        // the series that is put into the BLOB must be identical to the series that
        // comes out of the BLOB.
        // This method is re-used by the actual test methods that follow.
        public void ConvertBlobAll(List<TimeSeriesValue> inList,
                TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity,
                DateTime blobStartDate)
        {
            TSLibrary tsLib = new TSLibrary();
            List<TimeSeriesValue> outList = new List<TimeSeriesValue>();
            int compressionCode;

            byte[] blobData = tsLib.ConvertListToBlobWithChecksum(timeStepUnit, timeStepQuantity,
                                inList.Count, inList.First().Date, inList.Last().Date, inList,
                                new TSTrace { TraceNumber=1 }, out compressionCode);

            int ret = tsLib.ConvertBlobToListAll(timeStepUnit, timeStepQuantity,
                            inList.Count, blobStartDate, blobData, ref outList, compressionCode);

            // The return value of the function must match the number of items in the original list
            Assert.AreEqual(ret, inList.Count);
            // the count in both lists must match
            Assert.AreEqual(outList.Count, inList.Count);

            // now check each item in the two lists
            Boolean AreEqual = true;
            for (int i = 0; i < ret; i++)
            {
                if (outList[i].ValueEquals(inList[i]) == false)
                    AreEqual = false;
            }

            Assert.IsTrue(AreEqual);
        }
        // The series of tests below is for ConvertListToBlobWithChecksum()
        //
        // This method is reused by the actual test methods that follow
        public Boolean ComputeTestChecksums(
                TSDateCalculator.TimeStepUnitCode u1, short q1, List<TimeSeriesValue> list1, ITimeSeriesTrace trace1,
                TSDateCalculator.TimeStepUnitCode u2, short q2, List<TimeSeriesValue> list2, ITimeSeriesTrace trace2)
        {
            TSLibrary tsLib = new TSLibrary();
            int compressionCode;

            tsLib.ConvertListToBlobWithChecksum(
                u1, q1, list1.Count,
                list1[0].Date, list1[list1.Count - 1].Date, list1, trace1, out compressionCode);

            tsLib.ConvertListToBlobWithChecksum(
                u2, q2, list2.Count,
                list2[0].Date, list2[list2.Count - 1].Date, list2, trace2, out compressionCode);

            Assert.IsTrue(trace1.Checksum.Length == 16);
            Assert.IsTrue(trace2.Checksum.Length == 16);

            for (int i = 0; i < trace2.Checksum.Length; i++)
                if (trace1.Checksum[i] != trace2.Checksum[i])
                    return false;

            return true;
        }