Exemplo n.º 1
0
 public bool DownFile(CustomFileInfo currentDownFile)
 {
     lock (obj)
     {
         if (down != null)
         {
             down.Invoke(currentDownFile);
             return true;
         }
         return false;
     }
 }
Exemplo n.º 2
0
 public IAsyncResult BeginUploadFile(CustomFileInfo currentUploadFile, AsyncCallback ra, object state)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
 public void UploadFile(CustomFileInfo currentUploadFile)
 {
     try
     {
         logger.Info("Begin to writer file...");
         if (!Directory.Exists(MediaConfiguration.StoragePath))
         {
             Directory.CreateDirectory(MediaConfiguration.StoragePath);
         }
         var fs = new FileStream(MediaConfiguration.StoragePath + "\\" + currentUploadFile.FileName,
                             FileMode.OpenOrCreate, FileAccess.Write);
         fs.Seek(currentUploadFile.CurrentOffset, SeekOrigin.Begin);
         fs.BeginWrite(
             currentUploadFile.CurrentData, 0,
             currentUploadFile.CurrentLen,
             delegate(IAsyncResult ra)
             {
                 fs.EndWrite(ra);
                 fs.Close();
                 fs.Dispose();
             }, null);
     }
     catch (Exception e)
     {
         logger.Error("Error occurred when writing file, details: {0}.", e);
     }
 }
Exemplo n.º 4
0
        private void DownFileCallBack(IAsyncResult ra)
        {
            var customFile = (CustomFile)ra.AsyncState;
            int currentLen = customFile.FileStream.EndRead(ra);

            if (currentLen != 0)
            {
                var customFileInfo = new CustomFileInfo();
                customFileInfo.CurrentData = customFile.CurrentByte;
                customFileInfo.CurrentOffset = customFile.FileStream.Position - currentLen;
                customFileInfo.FileLength = customFile.FileStream.Length;
                customFileInfo.CurrentLen = currentLen;
                customFileInfo.FileName = customFile.FileName;
                if (customFile.ClientCallBack != null && customFile.ClientCallBack.DownFile(customFileInfo))
                {
                    customFile.FileStream.BeginRead(customFile.CurrentByte, 0, customFile.MaxLength, DownFileCallBack,
                                                    customFile);
                }
                else
                {
                    customFile.FileStream.Close();
                    customFile.FileStream.Dispose();
                }
            }
            else
            {
                customFile.FileStream.Close();
                customFile.FileStream.Dispose();
            }
        }
Exemplo n.º 5
0
 public bool DownFile(CustomFileInfo currentDownFile)
 {
     MessageBox.Show("DownFile success!");
     return true;
 }