public void Test(Boolean inBulk, Boolean doParam) { // Create dummy time series that we can write to the database var valList = new List <double[]>(); for (int i = 0; i < nIter; i++) { var iterList = new List <double>(); for (int t = 0; t < nVals; t++) { iterList.Add(1.5 * t + i + 0.33); } valList.Add(iterList.ToArray()); } if (inBulk) { var traceObjects = new List <ITimeSeriesTrace>(); for (int i = 0; i < nIter; i++) { ITimeSeriesTrace traceObject = new TSTrace { TraceNumber = 1 }; // Convert the array of double values into a byte array...a BLOB traceObject.ValueBlob = TSBlobCoder.ConvertArrayToBlobRegular (valList[i], TSBlobCoder.currentCompressionCode, traceObject); traceObjects.Add(traceObject); } WriteBulkTraces(traceObjects); } else if (doParam) { // reference: http://stackoverflow.com/questions/2449827/pros-and-cons-of-using-sqlcommand-prepare-in-c // this does appear to be faster!! SqlCommand cmd = new SqlCommand("INSERT INTO " + TableName + "(TimeSeries_Id, TraceNumber, ValueBlob, Checksum) " + "VALUES (@TimeSeries_Id, @TraceNumber, @ValueBlob, @Checksum)", Connx); cmd.Parameters.Add("@TimeSeries_Id", SqlDbType.Int); cmd.Parameters.Add("@TraceNumber", SqlDbType.Int); cmd.Parameters.Add("@ValueBlob", SqlDbType.VarBinary, -1); cmd.Parameters.Add("@Checksum", SqlDbType.Binary, 16); cmd.Prepare(); SqlCommand selectCmd = new SqlCommand("SELECT TraceNumber, Checksum from " + TableName + " where TimeSeries_Id=@TimeSeries_Id order by TraceNumber", Connx); selectCmd.Parameters.Add("@TimeSeries_Id", SqlDbType.Int); selectCmd.Prepare(); SqlCommand updateCmd = new SqlCommand("UPDATE " + "OutputTimeSeries" + " SET Checksum=@Checksum WHERE Id=@Id", Connx); updateCmd.Parameters.Add("@Checksum", SqlDbType.Binary, 16); updateCmd.Parameters.Add("@Id", SqlDbType.Int); updateCmd.Prepare(); for (int i = 0; i < nIter; i++) { ITimeSeriesTrace traceObject = new TSTrace { TraceNumber = 1 }; // Convert the array of double values into a byte array...a BLOB traceObject.ValueBlob = TSBlobCoder.ConvertArrayToBlobRegular (valList[i], TSBlobCoder.currentCompressionCode, traceObject); WriteOneTraceParam(i + 1, traceObject, cmd); // update the checksum in the parameters table UpdateParametersChecksum(i + 1, selectCmd, updateCmd); } } else { for (int i = 0; i < nIter; i++) { ITimeSeriesTrace traceObject = new TSTrace { TraceNumber = 1 }; // Convert the array of double values into a byte array...a BLOB traceObject.ValueBlob = TSBlobCoder.ConvertArrayToBlobRegular (valList[i], TSBlobCoder.currentCompressionCode, traceObject); WriteOneTrace(traceObject); } } }
// Note--this test class was created primarily b/c we wanted to individually test the different // compression methods. Hence, we have created the test methods below. The class TSBlobCoder // certainly deserves full test coverage, but that can be developed later. In the meantime, // it is generally expected that TSBlobCoder has adequate test coverage via TSLibraryTest. #region Test Methods for ConvertBlobToListAll() and ConvertListToBlob() // 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, int compressionCode) { TSLibrary tsLib = new TSLibrary(); var traceObject = new TSTrace { TraceNumber = 1, TimeStepCount = inList.Count, EndDate = inList.Last().Date }; if (timeStepUnit == TSDateCalculator.TimeStepUnitCode.Irregular) { var inArray = inList.Select(v => (TSDateValueStruct)v).ToArray(); var outArray = new TSDateValueStruct[inList.Count]; byte[] blobData = TSBlobCoder.ConvertArrayToBlobIrregular(inArray, compressionCode, traceObject); int ret = TSBlobCoder.ConvertBlobToArrayIrregular(inList.Count, false, 0, blobStartDate, blobStartDate, blobData, outArray, 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(inArray.Length, outArray.Length); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outArray[i].Date != inArray[i].Date || outArray[i].Value != inArray[i].Value) { AreEqual = false; } } Assert.IsTrue(AreEqual); } else { var inArray = inList.Select(v => v.Value).ToArray(); var outArray = new Double[inList.Count]; byte[] blobData = TSBlobCoder.ConvertArrayToBlobRegular(inArray, compressionCode, traceObject); int ret = TSBlobCoder.ConvertBlobToArrayRegular(timeStepUnit, timeStepQuantity, inList.Count, blobStartDate, false, 0, blobStartDate, blobStartDate, blobData, outArray, 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(inArray.Length, outArray.Length); // now check each item in the two lists Boolean AreEqual = true; for (int i = 0; i < ret; i++) { if (outArray[i] != inArray[i]) { AreEqual = false; } } Assert.IsTrue(AreEqual); } }