Exemplo n.º 1
0
        // 打开Index文件
        private void OpenIndexFile(Delegate_getTempFileName procGetTempFileName = null)
        {
            if (m_streamSmall == null)
            {

                if (string.IsNullOrEmpty(m_strSmallFileName) == true)
                {
                    // 2016/4/5
                    // 优先使用临时的函数 创建临时文件
                    if (procGetTempFileName != null)
                        m_strSmallFileName = procGetTempFileName();

                    if (string.IsNullOrEmpty(m_strSmallFileName) == true)
                        m_strSmallFileName = this.GetTempFileName();
                }
                // 创建index文件的时候,可以给出角色暗示,以便取有特色的物理文件名

                m_streamSmall = File.Open(m_strSmallFileName,
                    FileMode.OpenOrCreate,
                    FileAccess.ReadWrite,
                    FileShare.ReadWrite);  // 2007/12/26
            }

            bDirty = false;
            // m_streamSmall的非空就表明它处于Open状态
        }
Exemplo n.º 2
0
        // 创建Index
        // parameters:
        //	strIndexFileName	如果==null,表示自动分配临时文件
        public void CreateIndexFile(string strIndexFileName,
            Delegate_getTempFileName procGetTempFileName = null)
        {
            int nLength;

            RemoveIndexFile();

            if (strIndexFileName != null)
                this.m_strSmallFileName = strIndexFileName;

            OpenIndexFile(procGetTempFileName);

            m_streamBig.Seek(0, SeekOrigin.Begin);
            m_streamSmall.Seek(0, SeekOrigin.End);

            int i = 0;
            long lPosition = 0;
            for (i = 0; ; i++)
            {
                //长度字节数组
                byte[] bufferLength = new byte[4];
                int n = m_streamBig.Read(bufferLength, 0, 4);
                if (n < 4)   //表示文件到尾
                    break;

                nLength = System.BitConverter.ToInt32(bufferLength, 0);
                if (nLength < 0)  //删除项
                {
                    nLength = (int)GetRealValue(nLength);
                    goto CONTINUE;
                }

                byte[] bufferOffset = new byte[8];
                bufferOffset = System.BitConverter.GetBytes((long)lPosition);
                Debug.Assert(bufferOffset.Length == 8, "");
                m_streamSmall.Write(bufferOffset, 0, 8);

            CONTINUE:

                m_streamBig.Seek(nLength, SeekOrigin.Current);
                lPosition += (4 + nLength);
            }
        }
Exemplo n.º 3
0
 // 排序
 public void Sort(Delegate_getTempFileName procGetTempFileName = null)
 {
     // 加写锁
     this.m_lock.AcquireWriterLock(m_nLockTimeout);
     try
     {
         if (string.IsNullOrEmpty(this.m_strSmallFileName) == false)
             CreateIndexFile(this.m_strSmallFileName, procGetTempFileName);
         else
             CreateIndexFile(null, procGetTempFileName);
         QuickSort();
     }
     finally
     {
         this.m_lock.ReleaseWriterLock();
     }
 }
Exemplo n.º 4
0
 // 确保创建了索引
 public void EnsureCreateIndex(Delegate_getTempFileName procGetTempFileName = null)
 {
     if (this.m_streamSmall == null)
     {
         this.CreateIndexFile(null, procGetTempFileName);
     }
     else
     {
         // Debug时可以校验一下index文件尺寸和Count的关系是否正确
     }
 }
Exemplo n.º 5
0
        // 打开
        // bInitialIndex	初始化index文件,并打开。
        public void Open(bool bInitialIndex,
            Delegate_getTempFileName procGetTempFileName = null)
        {
            // 加写锁
            this.m_lock.AcquireWriterLock(m_nLockTimeout);
            try
            {
                if (m_streamBig == null)
                {
                    // 2016/4/5
                    // 优先使用临时的函数 创建临时文件
                    if (procGetTempFileName != null)
                        m_strBigFileName = procGetTempFileName();

                    if (string.IsNullOrEmpty(m_strBigFileName) == true)
                        m_strBigFileName = this.GetTempFileName();	// 创建临时文件可以用delegate处理

                    m_streamBig = File.Open(m_strBigFileName,
                        FileMode.OpenOrCreate);

                    /*
                    m_streamBig = File.Open(m_strBigFileName,
                        FileMode.OpenOrCreate, 
                        FileAccess.ReadWrite,
                        FileShare.ReadWrite);  // 2007/12/26
                     * */
                }

                if (bInitialIndex == true)
                {
                    string strSaveSmallFileName = "";
                    if (this.m_strSmallFileName != "")
                        strSaveSmallFileName = m_strSmallFileName;

                    RemoveIndexFile();

                    if (strSaveSmallFileName != "")
                        m_strSmallFileName = strSaveSmallFileName;

                    OpenIndexFile(procGetTempFileName);
                }

            }
            finally
            {
                this.m_lock.ReleaseWriterLock();
            }
        }