Esempio n. 1
0
        public int ReadDatesValues(
            int connectionNumber, sbyte *pParamTableName, sbyte *pTraceTableName,
            int id, int traceNumber, int nReqValues,
            ref TSDateValueStruct[] dateValueArray, DateTime reqStartDate, DateTime reqEndDate)
        {
            try
            {
                // Convert from simple character byte array to .Net String object
                String paramTableName = new String(pParamTableName);
                String traceTableName = new String(pTraceTableName);
                // Get the connection that we'll pass along.
                var connx = TSLib.GetConnectionContainerFromId(connectionNumber);
                // Construct new TS object with SqlConnection object and table name
                TS ts = new TS(connx, paramTableName, traceTableName);

                int nValuesRead = 0;
                // Read the parameters of the time series so that we'll know if it's regular or irregular
                if (!ts.IsInitialized)
                {
                    ts.Initialize(id);
                }

                // The operations will differ for regular and irregular time series
                if (ts.TimeStepUnit == TSDateCalculator.TimeStepUnitCode.Irregular)
                {
                    // IRREGULAR TIME SERIES

                    // Read the date/value array from the database
                    nValuesRead = ts.ReadValuesIrregular(id, traceNumber, nReqValues, dateValueArray,
                                                         reqStartDate, reqEndDate);
                }
                else
                {
                    // REGULAR TIME SERIES

                    // Allocate an array to hold the time series' data values
                    double[] valueArray = new double[nReqValues];
                    // Read the data values from the database
                    nValuesRead = ts.ReadValuesRegular(id, traceNumber, nReqValues, valueArray,
                                                       reqStartDate, reqEndDate);
                    // 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.
                    ts.FillDateArray(id, nValuesRead, dateArray, reqStartDate);
                    // Loop through all values, filling the array of date/value pairs from the
                    // primitive array of dates and primitive array of values.
                    int i;
                    for (i = 0; i < nValuesRead; i++)
                    {
                        dateValueArray[i].Date  = dateArray[i];
                        dateValueArray[i].Value = valueArray[i];
                        // So far we have ignored the requested end date.  However, at this
                        // stage we won't make the list any longer than was requested by the caller.
                        if (dateValueArray[i].Date >= reqEndDate)
                        {
                            i++;
                            break;
                        }
                    }
                    nValuesRead = i;
                }
                return(nValuesRead);
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
                return(0);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// This method copies into this TSImport object:
 ///      the parameters of the time series
 ///      the checksum for the entire time series
 ///      the ID of the database record for the time series.
 /// </summary>
 /// <param name="tsp">The TS object that values will be copied from</param>
 public void RecordFromTS(TS ts)
 {
     Id = ts.Id;
     RecordFromTSParameters(ts.TSParameters);
     Checksum = ts.Checksum;
 }