public bool DownFile(CustomFileInfo currentDownFile) { lock (obj) { if (down != null) { down.Invoke(currentDownFile); return true; } return false; } }
public IAsyncResult BeginUploadFile(CustomFileInfo currentUploadFile, AsyncCallback ra, object state) { throw new NotImplementedException(); }
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); } }
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(); } }
public bool DownFile(CustomFileInfo currentDownFile) { MessageBox.Show("DownFile success!"); return true; }