示例#1
0
 static void SetVo(
     object[] vo,
     int voi,
     object value)
 {
     VoArray.SetVo(vo, voi, value);
     return;
 }
示例#2
0
        /// <summary>
        /// Binary serialize a single Mobius data type object
        /// </summary>
        /// <param name="mdtObject"></param>
        /// <returns></returns>

        public static MobiusDataType DeserializeBinarySingle(
            byte[] ba)
        {
            if (ba == null)
            {
                return(null);
            }

            MemoryStream ms = new MemoryStream(ba);
            BinaryReader br = new BinaryReader(ms);

            object         obj = VoArray.ReadBinaryItem(br);
            MobiusDataType mdt = obj as MobiusDataType;

            br.Close();
            return(mdt);
        }
示例#3
0
        /// <summary>
        /// Read in all of the rows that have been cached
        /// </summary>
        /// <returns></returns>

        public List <object[]> ReadCachedRows()
        {
            AssertMx.IsTrue(File.Exists(CacheFilePath), "CacheFilePath doesn't exist");
            FileStream   fs = File.Open(CacheFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader br = new BinaryReader(fs);

            List <object[]> cachedRows = new List <object[]>();           // in-memory buffer list of rows

            for (int ri = 0; ri < RowsWrittenToCache; ri++)
            {
                object[] vo = VoArray.ReadBinaryVoArray(br, VoaLength);
                cachedRows.Add(vo);
            }

            br.Close();             // close reader and the underlying stream

            return(cachedRows);
        }
示例#4
0
/// <summary>
/// Binary serialize a single Mobius data type object
/// </summary>
/// <param name="mdtObject"></param>
/// <returns></returns>

        public static byte[] SerializeBinarySingle(
            MobiusDataType mdtObject)
        {
            if (mdtObject == null)
            {
                return(new byte[0]);
            }

            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            VoArray.WriteBinaryItem(mdtObject, bw);

            bw.Flush();
            byte[] ba = new byte[ms.Length];
            ms.Seek(0, 0);
            ms.Read(ba, 0, (int)ms.Length);
            bw.Close();

            return(ba);
        }
示例#5
0
        /// <summary>
        /// Try to get the row at the given index from the buffer or cache
        /// </summary>
        /// <param name="ri"></param>
        /// <returns></returns>
        ///
        public object[] GetRow(
            int ri)
        {
            object[] vo = null;

            if (ri < 0 || ri >= TotalRowCount)
            {
                string msg = string.Format("Row {0} not in cache or buffer (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count);
                throw new InvalidDataException(msg);
            }

            // See if in buffer

            if (ri >= RowsWrittenToCache)
            {
                vo = (object[])RowBuffer[ri - RowsWrittenToCache];

                if (DebugCaching)
                {
                    DebugLog.Message(string.Format("Row: {0} in Buffer (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count));
                }

                return(vo);
            }

            // Get from cache

            if (ri < CacheReaderPosition + 1)             // if already read past this then close current cursor
            {
                CloseCacheReader();
            }

            if (CacheReader == null)             // need to open reader?
            {
                AssertMx.IsNotNull(CacheWriter, "CacheWriter");
                AssertMx.IsTrue(File.Exists(CacheFilePath), "CacheFilePath doesn't exist");

                FileStream fs = File.Open(CacheFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                CacheReader         = new BinaryReader(fs);
                CacheReaderPosition = -1;

                if (DebugCaching)
                {
                    DebugLog.Message("Opening cache reader");
                }
            }

            while (CacheReaderPosition + 1 <= ri)             // read rows until we get the one we want
            {
                vo = VoArray.ReadBinaryVoArray(CacheReader, VoaLength);
                CacheReaderPosition++;
            }

            CacheReaderPosition = ri;

            if (DebugCaching)
            {
                DebugLog.Message(string.Format("Row: {0} in Cache (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count));
            }

            return(vo);
        }
示例#6
0
        /// <summary>
        /// Move rows to cache file if caching is turned on and RowBuffer contains the threshhold number of rows
        /// </summary>
        /// <returns></returns>

        public int MoveRowsToCacheAsAppropriate()
        {
            int rowsCached = 0, rowsRemoved = 0, rowsAffected = 0;

            lock (this)
            {
                Stopwatch sw = Stopwatch.StartNew();

                if (RowBuffer.Count == 0)
                {
                    return(0);
                }

                if (!WriteCache && !RemoveRows)
                {
                    return(0);                                            // leave as is
                }
// Write rows to cache if caching is turned on

                if (WriteCache)
                {
                    if (RowBuffer.Count < MininumRowsRequiredForCaching)
                    {
                        return(0);                                                                     // not time to cache yet
                    }
                    if (RowsWrittenToCache == 0)
                    {
                        CacheFilePath = TempFile.GetTempFileName(ServicesDirs.TempDir, "voa", true);                         // Note that we want the temp dir to be local to the current machine
                        CacheWriter   = new BinaryWriter(File.Open(CacheFilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite));
                    }

                    byte[] ba = VoArray.SerializeBinaryVoArrayListToByteArray(RowBuffer, includeListHeader: false);
                    CacheWriter.Write(ba);
                    CacheWriter.Flush();

                    rowsCached          = rowsAffected = RowBuffer.Count;
                    RowsWrittenToCache += rowsCached;
                }

// Remove all rows from Rows if rows purging is turned on

                if (RemoveRows)
                {
                    if (WriteCache && RowBuffer.Count < MininumRowsRequiredForCaching)
                    {
                        return(0);                                                                                   // not time to remove rows yet if caching
                    }
                    rowsRemoved = rowsAffected = RowBuffer.Count;
                    RowBuffer.Clear();

                    RowsRemovedFromList += rowsRemoved;
                }

                if (DebugCaching)
                {
                    string msg = String.Format("Rows added to cache: {0} , rows removed from buffer: {1}, total rows removed: {2} (cacheSize: {3}, bufferSize: {4}",
                                               rowsCached, rowsRemoved, RowsRemovedFromList, RowsWrittenToCache, RowBuffer.Count);
                    DebugLog.StopwatchMessage(msg, sw);
                }

                return(rowsAffected);
            }             // end of lock
        }