Exemplo n.º 1
0
 public void btnUpload_Click(object sender, EventArgs e)
 {
     MediaDto mediaInfo = proxy.UploadRequest(String.Empty);
     var tcpBinding = new NetTcpBinding
         {
             Security =
                 {
                     Mode = SecurityMode.None,
                     Transport = {ClientCredentialType = TcpClientCredentialType.Windows},
                     Message = {ClientCredentialType = MessageCredentialType.Windows}
                 },
             ReliableSession = {Enabled = true}
         };
     var tcpAddress =
         new EndpointAddress("net.tcp://" + mediaInfo.Address + ":" + mediaInfo.Port + "/MediaService");
     mediaChannelFactory =
         new DuplexChannelFactory<IMediaContract>(new InstanceContext(new MediaServiceCallBack()), tcpBinding,
                                                  tcpAddress);
     mediaChannelFactory.Closing += delegate
         {
             mediaContract = null;
             mediaChannelFactory = null;
         };
     mediaContract = mediaChannelFactory.CreateChannel();
     mediaContract.SayHello("Upload test.");
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 private void Download()
 {
     while (!browseFinished)
     {
         Thread.Sleep(1000);
     }
     logger.Info("Begin to download...");
     foreach (var file in downloadFileList)
     {
         String relativePath = Path.Combine(syncPath, file.RelativePath);
         String filePath = Path.Combine(relativePath, file.Name);
         try
         {
             if (File.Exists(filePath))
             {
                 File.Delete(filePath);
             }
             if (!Directory.Exists(relativePath))
             {
                 Directory.CreateDirectory(relativePath);
             }
             writer = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write);
             foreach (var chunkId in file.ChunkList)
             {
                 var mediaInfo = proxy.DownloadRequest(chunkId);
                 if (mediaInfo == null)
                 {
                     logger.Info("There is no chunk on the media, id: {0}.", chunkId);
                     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}", chunkId);
                 mediaContract.DownloadChunk(chunkId);
                 mediaChannelFactory.Close();
             }
             writer.Close();
             writer = null;
         }
         catch (Exception e)
         {
             logger.Error("Failed to download the file, path: {0}.", e);
         }
     }
 }