示例#1
0
        /// <summary>
        /// 缓存加载完毕开始获取数据
        /// </summary>
        internal void Start()
        {
            bool isStart = false;

            try
            {
                snapshot     = new Snapshot.Cache(Cache, false);
                snapshotSize = snapshot.NextSize();
                timeout      = Date.Now.AddTicks(timeoutTicks);
                if (snapshotSize != 0)
                {
                    step = CacheGetStep.Snapshot;
                    if (onCache.Callback(new CacheReturnParameter {
                        Getter = this
                    }))
                    {
                        isStart = true;
                    }
                }
                else
                {
                    step    = CacheGetStep.TcpQueue;
                    isStart = true;
                    GetQueue();
                }
            }
            finally
            {
                if (!isStart)
                {
                    error();
                    onCache.Callback(default(CacheReturnParameter));
                    Cache.NextGetter();
                }
            }
        }
示例#2
0
 /// <summary>
 /// 重建文件流
 /// </summary>
 /// <param name="cacheFile"></param>
 /// <returns></returns>
 internal ReturnType Start(FileStreamWriter cacheFile)
 {
     IsDisposed = 1;
     SubBuffer.PoolBufferFull buffer = default(SubBuffer.PoolBufferFull);
     try
     {
         snapshot = new Snapshot.Cache(cache, true);
         FileInfo file = new FileInfo(cacheFile.isSwitchFile ? Config.GetFileName : Config.GetSwitchFileName);
         FileName = file.FullName;
         if (file.Exists)
         {
             AutoCSer.IO.File.MoveBak(FileName);
         }
         fileStream = new FileStream(FileName, FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferPool.Size, FileOptions.None);
         create(ref buffer, 0);
         return(ReturnType.Success);
     }
     catch (Exception error)
     {
         cache.TcpServer.AddLog(error);
     }
     finally
     {
         buffer.Free();
         if (IsDisposed == 0)
         {
             Interlocked.Exchange(ref fileFlushSeconds, Config.FileFlushSeconds);
             AutoCSer.Threading.ThreadPool.TinyBackground.Start(writeCache);
         }
         else
         {
             cache.NextGetter();
             if (fileStream != null)
             {
                 fileStream.Dispose();
             }
         }
     }
     return(ReturnType.SnapshotFileStartError);
 }