Esempio n. 1
0
 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();
 }
Esempio n. 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;
     }
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 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);
     }
 }
Esempio n. 6
0
 public bool DownChunk(ChunkInfo chunkInfo)
 {
     throw new NotImplementedException();
 }
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 public void PutFreeChunkInQueue(ChunkInfo chunk)
 {
     chunkQueue.PutFreeBlock(chunk);
 }
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
 private void DownloadChunk(ChunkInfo info)
 {
     writer.Write(info.Buffer, 0, info.BufferLength);
 }