private unsafe int ConvertBlobToList(
TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity,
int timeStepCount, DateTime blobStartDate, Boolean applyLimits,
int nReqValues, DateTime reqStartDate, DateTime reqEndDate,
Byte[] blobData, ref List<TimeSeriesValue> dateValueList, int compressionCode)
{
int nValuesRead = 0;
if (timeStepUnit == TSDateCalculator.TimeStepUnitCode.Irregular)
{
// IRREGULAR TIME SERIES
// If we're not limiting the output list (i.e., we're returning every time step from
// the BLOB), then set the size of the intermediate array to match the size of the BLOB.
if (applyLimits == false)
nReqValues = timeStepCount;
// Allocate an array of date/value pairs that TSBlobCoder method will fill
TSDateValueStruct[] dateValueArray = new TSDateValueStruct[nReqValues];
// Method in the TSBlobCoder class does the real work
nValuesRead = TSBlobCoder.ConvertBlobToArrayIrregular(timeStepCount, applyLimits,
nReqValues, reqStartDate, reqEndDate,
blobData, dateValueArray, compressionCode);
// resize the array so that the List that we make from it will have exactly the right size
if(nValuesRead!=nReqValues)
Array.Resize<TSDateValueStruct>(ref dateValueArray, nValuesRead);
// Convert the array of date/value pairs into the List that will be used by the caller
dateValueList = dateValueArray
.Select(tsv => (TimeSeriesValue)tsv).ToList<TimeSeriesValue>();
}
else
{
// REGULAR TIME SERIES
// If we're not limiting the output list (i.e., we're returning every time step from
// the BLOB), then set the size of the intermediate array to match the size of the BLOB.
if (applyLimits == false)
nReqValues = timeStepCount;
// Allocate an array of values that TSBlobCoder method will fill
double[] valueArray = new double[nReqValues];
// Method in the TSBlobCoder class does the real work
nValuesRead = TSBlobCoder.ConvertBlobToArrayRegular(timeStepUnit, timeStepQuantity,
timeStepCount, blobStartDate, applyLimits,
nReqValues, reqStartDate, reqEndDate,
blobData, valueArray, compressionCode);
// Allocate an array to hold the time series' date values
DateTime[] dateArray = new DateTime[nValuesRead];
// Fill the array with the date values corresponding to the time steps defined
// for this time series in the database.
TSDateCalculator.FillDateArray(timeStepUnit, timeStepQuantity, nValuesRead, dateArray, reqStartDate);
// Allocate a List of date/value pairs that will be used by the caller
dateValueList = new List<TimeSeriesValue>(nValuesRead);
// Loop through all values, building the List of date/value pairs out of the
// primitive array of dates and primitive array of values.
int i;
for (i = 0; i < nValuesRead; i++)
{
dateValueList.Add(new TimeSeriesValue { Date = dateArray[i], Value = valueArray[i] });
}
nValuesRead = i;
}
return nValuesRead;
}