Exemplo n.º 1
0
        /// <summary>
        /// Fills the index & byte buffers with new data from the database.
        /// </summary>
        public void Populate(long newStartingTicks)
        {
            populating = true;

            // Use a lock to prevent overwriting startingTick during an override operation
            lock ( populatingLockObj )
            {
#if TIMING
                long startTimer = DateTime.Now.Ticks;
#endif

                // Try to avoid expensive database operatons (both of them)
                if (populateOverride)  // RETURN and leave populate as true
                {
                    return;
                }

                // load the indexes from the database
                streamOutOfData = DBHelper.LoadIndices(indices, newStartingTicks, streamID, buffer.Buffer.Length, out indexCount);
                currentIndex    = 0;

                // if there are indicies, load the raw byte data for them
                if (indexCount > 0)
                {
                    // Try to avoid expensive database operatons
                    if (populateOverride)  // RETURN and leave populate as true
                    {
                        return;
                    }

                    this.startingTick = indices[0].timestamp;
                    this.endingTick   = indices[indexCount - 1].timestamp;

                    DBHelper.LoadBuffer(streamID, indices[0].start, indices[indexCount - 1].end, ref buffer);

                    Trace.WriteLine(String.Format(CultureInfo.InvariantCulture,
                                                  "Loaded buffer (ID: {0}) with: {1} sec, {2} bytes, {3} frames",
                                                  streamID, ((double)(endingTick - startingTick) / 10000000.0),
                                                  (indices[indexCount - 1].end - indices[0].start + 1), indexCount));
                }
                else
                {
                    // Populate these two variables with some meaningful data
                    this.startingTick = newStartingTicks;
                    this.endingTick   = newStartingTicks;
                }

#if TIMING
                long takenTime = DateTime.Now.Ticks - startTimer;
                Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "TIMING: Load buffer took {0} ms",
                                              (takenTime / Constants.TicksPerMs)));
#endif

                populating = false;
            }
        }