コード例 #1
0
ファイル: ChunkQueue.cs プロジェクト: GQHero/TinyStorage
 public void PutFreeBlock(ChunkInfo freeBlock)
 {
     lock (blockQueue)
     {
         blockQueue.Insert(0, freeBlock);
         freeCount++;
         //logger.Info("Chunk queue freee count: {0}, work count: {1}, total count: {2}.", freeCount, workingCount, freeCount + workingCount);
     }
     freeBlockSemaphore.Release();
 }
コード例 #2
0
 public bool DownChunk(ChunkInfo chunkInfo)
 {
     try
     {
         if (downloadChunk != null)
         {
             downloadChunk(chunkInfo);
             return true;
         }
         return false;
     }
     catch (Exception e)
     {
         logger.Error("Error occurred when writing data, info: {0}.", e);
         return false;
     }
 }
コード例 #3
0
ファイル: MediaService.cs プロジェクト: GQHero/TinyStorage
        public void DownloadChunk(string chunkId)
        {
            var callback = OperationContext.Current.GetCallbackChannel<IMediaCallBack>();
            var result = MediaIndexOperator.GetIndexDatabaseHelper()
                .ExecuteReader<ChunkPathMap>(
                String.Format(Constants.MediaQueryChunk, chunkId),
                new Dictionary<string, object>());
            if (result.Count <= 0)
            {
                logger.Error("There is no chunk on media, chunk id: {0}.", chunkId);
                throw new Exception(String.Format("No chunk: {0}", chunkId));
            }
            var reader = new FileStream(Path.Combine(result[0].Path, chunkId),
                FileMode.Open, FileAccess.Read);
            var chunk = new ChunkInfo()
                {
                    Id = chunkId,

                    Buffer = new byte[Constants.MaxChunkSize]
                };
            chunk.BufferLength = reader.Read(chunk.Buffer, 0, Constants.MaxChunkSize);
            callback.DownChunk(chunk);
        }
コード例 #4
0
ファイル: ChunkQueue.cs プロジェクト: GQHero/TinyStorage
 public void PutWorkingBlock(ChunkInfo block)
 {
     lock (blockQueue)
     {
         blockQueue.Add(block);
         WorkingCount++;
         //logger.Info("Chunk queue freee count: {0}, work count: {1}, total count: {2}.", freeCount, workingCount, freeCount + workingCount);
     }
     workingBlockSemaphore.Release();
 }
コード例 #5
0
ファイル: MediaService.cs プロジェクト: GQHero/TinyStorage
 public void UploadChunk(ChunkInfo chunkInfo)
 {
     try
     {
         var fs = new FileStream(MediaConfiguration.StoragePath
             + "\\" + chunkInfo.StrongChecksum,
             FileMode.OpenOrCreate, FileAccess.Write);
         fs.BeginWrite(
             chunkInfo.Buffer, 0,
             chunkInfo.BufferLength,
             delegate(IAsyncResult ra)
             {
                 try
                 {
                     fs.EndWrite(ra);
                     fs.Close();
                     fs.Dispose();
                     fs = null;
                     MediaIndexOperator.GetIndexDatabaseHelper()
                         .ExecuteNonQuery(new List<ChunkPathMap>
                         {
                             new ChunkPathMap
                             {
                                 ChunkId = chunkInfo.Id,
                                 Path = MediaConfiguration.StoragePath
                             }
                         });
                 }
                 catch (Exception e)
                 {
                     logger.Error("Error occurred when uploading chunk, " +
                                  "details: {0}.", e);
                 }
             }, null);
     }
     catch (Exception e)
     {
         logger.Error("Error occurred when writing file, details: {0}.",
             e);
     }
     finally
     {
         MediaConfiguration.MediaControl.MediaControlProxy
             .CompleteSession(MediaConfiguration.CurrrentMedia.Id);
     }
 }
コード例 #6
0
ファイル: FmLogin.cs プロジェクト: GQHero/TinyStorage
 public bool DownChunk(ChunkInfo chunkInfo)
 {
     throw new NotImplementedException();
 }
コード例 #7
0
ファイル: TTTD.cs プロジェクト: GQHero/TinyStorage
 private void CalculateCheckSumAndInQueue(ChunkInfo chunk)
 {
     chunk.WeakChecksum = AlderChecksum.GetAdler32Checksum(chunk.Buffer, chunk.Buffer.Length).ToString(CultureInfo.InvariantCulture);
     chunk.Id = chunk.StrongChecksum = HashCodeHelper.ToHashCode(chunk.Buffer, "MD5");
     chunkQueue.PutWorkingBlock(chunk);
 }
コード例 #8
0
ファイル: TTTD.cs プロジェクト: GQHero/TinyStorage
 public void PutFreeChunkInQueue(ChunkInfo chunk)
 {
     chunkQueue.PutFreeBlock(chunk);
 }
コード例 #9
0
ファイル: MySync.cs プロジェクト: GQHero/TinyStorage
 private void UploadChunk(ChunkInfo chunk)
 {
     var mediaInfo = proxy.UploadRequest(chunk.Id);
     if (mediaInfo == null)
     {
         logger.Info("There is the same chunk on the media, id: {0}.", chunk.Id);
         return;
     }
     var tcpAddress =
         new EndpointAddress("net.tcp://" + mediaInfo.Address + ":" + mediaInfo.Port + "/MediaService");
     mediaChannelFactory = new DuplexChannelFactory<IMediaContract>(mediaInstanceContext, tcpBinding, tcpAddress);
     mediaChannelFactory.Closing += delegate
     {
         mediaContract = null;
         mediaChannelFactory = null;
         //logger.Debug("Media channel factory is closing...");
     };
     mediaContract = mediaChannelFactory.CreateChannel();
     logger.Debug("Uploading chunking to server, id: {0}, length: {1}.", chunk.Id, chunk.BufferLength);
     mediaContract.UploadChunk(chunk);
     mediaChannelFactory.Close();
     //writeStream.Write(chunk.Buffer, 0, chunk.BufferLength);
 }
コード例 #10
0
ファイル: MySync.cs プロジェクト: GQHero/TinyStorage
 private void DownloadChunk(ChunkInfo info)
 {
     writer.Write(info.Buffer, 0, info.BufferLength);
 }