protected void RaiseDiskFull(FileDataInfo currentFile) { if (DiskFull != null) { DiskFull(currentFile); } }
public override void CopyFile(FileDataInfo file) { CurrentFile = file; Reader = file.GetStreamToRead(); Writer = file.GetStreamToWrite(FileMode.Create); var writer1 = new BinaryWriter(Writer); readBytes = 0; FileBytesTransferred = 0; unsafe { do { //Dinamic bufferSize. Dynamic buffer size. readBytes = Reader.Read(buffer, 0, (int)(file.Size > BufferSize ? BufferSize : file.Size)); writer1.Write(buffer, 0, readBytes); //Status FileBytesTransferred += readBytes; TotalBytesTransferred += readBytes; } while (readBytes > 0); } Reader.Close(); Reader.Dispose(); Writer.Flush(); Writer.Close(); Writer.Dispose(); }
/// <summary> /// 上传大视频,分段上传 /// </summary> /// <param name="articleVideo"></param> /// <returns></returns> public ActionResult UploadArticleVideo(HttpPostedFileBase articleVideo) { string fileDataJson = Request.Params["fileDataJson"];//文件信息json HttpPostedFileBase file = Request.Files["file"]; FileDataInfo fileData = JsonHelper.DeserializeJsonToObject <FileDataInfo>(fileDataJson); //文件信息实体 string tempPath = IOHelper.GetMapPath("/upload/article/video/tempFile/"); //临时保存路径 string filePath = IOHelper.GetMapPath("/upload/article/video/source/"); //保存路径 string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(fileData.fileName); //最终保存路劲 string ZSFilePath = filePath + newFileName; string tempFilePath = tempPath + fileData.fileName;//临时保存路径 bool result = false; CommonHelper.SaveFileToServer(tempFilePath, ZSFilePath, fileData, file, ref result); if (result) { AddLog(WorkContext.UserName, "上传成功" + ":" + ZSFilePath + "", "上传2g以下视频"); } return(Content(newFileName)); }
protected FileNotFoundOption RaiseFileNotFound(NeathCopyHandle copyHandle, FileDataInfo CurrentFile) { if (FileNotFound != null) { return(FileNotFound(copyHandle, CurrentFile)); } return(FileNotFoundOption.Cancel); }
protected TransferErrorOption RaiseTransferError(NeathCopyHandle copyHandle, FileDataInfo CurrentFile, string error) { if (TransferError != null) { return(TransferError(copyHandle, CurrentFile, error)); } return(TransferErrorOption.SkipCurrentFile); }
void DoNothing(FileDataInfo currentFile) { //if is not readonly if ((currentFile.FileAttributes & Delimon.Win32.IO.FileAttributes.ReadOnly) == 0) { SetAttributes(currentFile); } SetAccessTimes(currentFile); }
public override void CopyFile(FileDataInfo file) { CurrentFile = file; finish = false; producerFinish = false; FileBytesTransferred = 0; Task.Factory.StartNew(() => Producer_ReadBytes(file)); Task.Factory.StartNew(() => Consumer_WriteBytes(file)); while (!finish) { } }
public static FileDataInfo GetFileDataFromBase64String(string inputData) { FileDataInfo result = new FileDataInfo(); var regex = new Regex("data:([a-zA-Z0-9]+/[a-zA-Z0-9-.+]+).*"); var match = regex.Match(inputData); if (match.Groups.Count > 1) { result.FileType = match.Groups[1].Value; result.Extension = result.FileType.Split('/')[1]; } return(result); }
public override void CopyFile(FileDataInfo file) { CurrentFile = file; var driverInfo = new System.IO.DriveInfo(Delimon.Win32.IO.Path.GetPathRoot(file.DestinyPath)); string tmp_file = ""; using (Reader = file.GetStreamToRead()) { if (file.DestinyPath.Length > 248) { //Create the file in short name tmp_file = Delimon.Win32.IO.Path.Combine(file.DestinyDirectoryPath, "tmp_a19"); using (Writer = new FileStream(tmp_file, FileMode.Create, FileAccess.Write)) { //if (driverInfo.DriveType == DriveType.Removable) //{ // ExecuteCopySafe(driverInfo, file); //} //else ExecuteCopy(driverInfo, file); ExecuteCopy(driverInfo, file); } //Move the file to it's original destinyPath if (Delimon.Win32.IO.File.Exists(file.DestinyPath)) { Delimon.Win32.IO.File.Delete(file.DestinyPath); } Delimon.Win32.IO.File.Move(tmp_file, file.DestinyPath); } else { using (Writer = file.GetStreamToWrite(FileMode.Create)) { //if (driverInfo.DriveType == DriveType.Removable && driverInfo.DriveFormat=="FAT32") //{ // ExecuteCopySafe(driverInfo, file); //} //else ExecuteCopy(driverInfo, file); ExecuteCopy(driverInfo, file); } } } }
private void ExecuteCopy(System.IO.DriveInfo driverInfo, FileDataInfo file) { if (driverInfo.TotalFreeSpace < file.Size) { ReleaseResources(); throw new NotEnoughSpaceException(string.Format("{0} ({1})", driverInfo.VolumeLabel, driverInfo.Name)); } Writer.SetLength(Reader.Length); readBytes = 0; FileBytesTransferred = 0; while ((readBytes = Reader.Read(buffer, 0, BufferSize)) > 0) { // Request the lock, and block until it is obtained. Monitor.Enter(Writer); //If operation was cancelled, them the writer has been released //and this statement produce: The Thread has been aborted exception. //Them capture the exception and terminate the current file copy process. try { Writer.Write(buffer, 0, readBytes); //Status FileBytesTransferred += readBytes; TotalBytesTransferred += readBytes; } catch (Exception ex) { return; //MessageBox.Show(ex.Message + " in FileCopier.Copy"); } // Ensure that the lock is released. Monitor.Exit(Writer); } CurrentFile = null; }
void Producer_ReadBytes(FileDataInfo file) { int length = 0; var reader = file.GetStreamToRead(); while (reader.Position < reader.Length) { if (queve.Count < buffersListCapacity) { lock (thisobject) { buffer = new byte[BufferSize]; length = reader.Read(buffer, 0, BufferSize); queve.Enqueue(new Buffer_Length(buffer, length)); } } } producerFinish = true; }
/// <summary> /// Delete the file thats was copied. /// </summary> /// <param name="currentFile"></param> void DeleteFile(FileDataInfo currentFile) { SetAttributes(currentFile); SetAccessTimes(currentFile); #region Delete the file after copy finished try { //Delete the copied file Alphaleonis.Win32.Filesystem.File.Delete(CurrentFile.FullName); } catch (IOException ex) { throw new IOException(string.Format("The File: {0} cold not been moved. {1}", CurrentFile.FullName, ex.Message)); } #endregion }
private void AddFileInfo(FileDataInfo info) { string str, strEnd; string[] strings = _fileIO.ReadAllLines(info.FilePath, false); int index = 1; int count = strings.Length; str = "Adding Method [" + info.Method + "]"; Console.WriteLine(str); str = "Adding File [" + info.FilePath + "] Count=" + count.ToString(); Console.WriteLine(str); if (count > 0) { AddString(" public static List<string> " + info.Method + "()"); AddString(" {"); AddString(" List<string> strings = new List<string>"); AddString(" {"); foreach (string s in strings) { if (index < count) { strEnd = ","; } else { strEnd = ""; } str = AdjustSlashs(s); str = AdjustQuotes(str); AddString(" " + Quote(str) + strEnd); } AddString(" };"); AddString(""); AddString(" return strings;"); AddString(" }"); } }
public void MoveDown(IEnumerable <FileDataInfo> files) { try { Monitor.Enter(Files); if (files.Count() == 0) { return; } int index = Files.IndexOf(files.First()); //Nothing to move if (files.Count() == Files.Count - index) { return; } FileDataInfo aux = null; foreach (var f in files.Reverse()) { index = Files.IndexOf(f); if (index < Files.Count - 1) { aux = Files[index + 1]; Files[index + 1] = f; Files[index] = aux; } } Monitor.Exit(Files); } catch (Exception ex) { MessageBox.Show(Error.GetErrorLogInLine(ex.Message, "NeathCopyEngine", "FilesList", "MoveDown")); } }
public override void CopyFile(FileDataInfo file) { CurrentFile = file; fileName = Delimon.Win32.IO.Path.GetPathRoot(file.DestinyPath); driverInfo = new Alphaleonis.Win32.Filesystem.DriveInfo(fileName); using (Reader = file.GetStreamToRead()) { using (Writer = file.GetStreamToWrite(FileMode.Create)) { //if (driverInfo.DriveType == DriveType.Removable && driverInfo.DriveFormat=="FAT32") //{ // ExecuteCopySafe(driverInfo, file); //} //else ExecuteCopy(driverInfo, file); ExecuteCopy(driverInfo, file); } //} } }
void Consumer_WriteBytes(FileDataInfo file) { Buffer_Length bl; var writer = file.GetStreamToWrite(FileMode.Create); while (!(queve.Count == 0 && producerFinish)) { if (queve.Count > 0) { lock (thisobject) { bl = queve.Dequeue(); } writer.Write(bl.buffer, 0, bl.length); FileBytesTransferred += bl.length; TotalBytesTransferred += bl.length; } } finish = true; }
public void MoveUp(IEnumerable <FileDataInfo> files) { try { Monitor.Enter(Files); if (files.Count() == 0) { return; } int index = 0; FileDataInfo aux = null; foreach (var f in files) { index = Files.IndexOf(f); if (index > 0) { if (Files[index - 1].CopyState != CopyState.Waiting) { Monitor.Exit(this); return; } aux = Files[index - 1]; Files[index - 1] = f; Files[index] = aux; } } Monitor.Exit(Files); } catch (Exception ex) { MessageBox.Show(Error.GetErrorLogInLine(ex.Message, "NeathCopyEngine", "FilesList", "MoveUp")); } }
public override void CopyFile(FileDataInfo file) { CurrentFile = file; Reader = file.GetStreamToRead(); using (Writer = file.GetStreamToWrite(FileMode.Create)) { readBytes = 0; FileBytesTransferred = 0; while ((readBytes = Reader.Read(buffer, 0, BufferSize)) > 0) { Writer.SetLength(Writer.Length + readBytes); Writer.Write(buffer, 0, readBytes); //Status FileBytesTransferred += readBytes; TotalBytesTransferred += readBytes; } } Reader.Dispose(); }
/// <summary> /// Initialize a file for download /// </summary> /// <returns>Token that is used to get file chunks</returns> public FileDataInfo GetFileStart(Guid tenantId, string container, string fileName) { Guid token; try { var retval = new FileDataInfo(); using (var fm = new FileManager()) { var info = fm.GetFileInfo(tenantId, container, fileName); if (info == null) { return(retval); } token = Guid.NewGuid(); _fileDownloadCache.TryAdd(token, new FilePartCache { DecryptStream = fm.GetFile(tenantId, container, fileName), Size = info.Size, }); retval.Token = token; retval.Size = info.Size; retval.CreatedTime = info.FileCreatedTime; retval.ModifiedTime = info.FileModifiedTime; return(retval); } } catch (Exception ex) { Logger.LogError(ex); throw; } }
protected virtual void ExecuteCopy(Alphaleonis.Win32.Filesystem.DriveInfo driverInfo, FileDataInfo file) { if (driverInfo.TotalFreeSpace < file.Size) { ReleaseResources(); throw new NotEnoughSpaceException(string.Format("{0} ({1})", driverInfo.VolumeLabel, driverInfo.Name)); } Writer.SetLength(Reader.Length); readBytes = 0; FileBytesTransferred = 0; executeCopyException = null; try { while ((readBytes = Reader.Read(buffer, 0, BufferSize)) > 0) { Writer.Write(buffer, 0, readBytes); //Status FileBytesTransferred += readBytes; TotalBytesTransferred += readBytes; } } catch (Exception ex) { executeCopyException = ex; } finally { ReleaseResources(); CurrentFile = null; if (executeCopyException != null) { throw executeCopyException; } } }
protected override void ExecuteCopy(Alphaleonis.Win32.Filesystem.DriveInfo driverInfo, FileDataInfo file) { buffer = new byte[CalculateBufferSize(file.Size)]; base.ExecuteCopy(driverInfo, file); }
/// <summary> /// Copy the specific sourceFile to destinyPath new location. /// </summary> /// <param name="sourceName"></param> /// <param name="destinyPath"></param> public abstract void CopyFile(FileDataInfo file);
public FileDataModel() { FileData = new FileDataInfo(); }
public ActionResult FileUpload() { string fileDataJson = Request.Params["fileDataJson"]; //文件信息json FileDataInfo fileData = JsonHelper.DeserializeJsonToObject <FileDataInfo>(fileDataJson); //文件信息实体 fileInfoList.Add(fileData); HttpPostedFileBase file = Request.Files["file"]; string tempPath = IOHelper.GetMapPath("/upload/TempFile/"); //临时保存路径 string filePath = IOHelper.GetMapPath("/upload/Files/"); //保存路径 string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + Path.GetExtension(fileData.fileName); //最终保存路劲 string ZSFilePath = filePath + filename; string tempFilePath = tempPath + fileData.fileName; //临时保存路径 if (!System.IO.File.Exists(tempFilePath)) //如果文件不存在则保存一个 { if (fileData.fileSize == fileData.fileEnd) { file.SaveAs(ZSFilePath); } else { IsFileInUse(tempFilePath); file.SaveAs(tempFilePath); } return(Content("{\"result\":\"True\",\"msg\":\"\"}")); } #region 开始保存文件到服务器 try { IsFileInUse(tempFilePath); using (FileStream fStream = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { //偏移指针 fStream.Seek(fileData.fileStart, SeekOrigin.Begin); //从客户端的请求中获取文件流 using (BinaryReader bReader = new BinaryReader(file.InputStream)) { long upLoadLength = file.InputStream.Length; //文件的长度 byte[] data = new byte[upLoadLength]; bReader.Read(data, 0, (int)upLoadLength); //读取上传文件 fStream.Write(data, 0, (int)upLoadLength); //将读取的文件写入服务器 bReader.Dispose(); bReader.Close(); } fStream.Dispose(); fStream.Close(); } } catch (Exception) { System.IO.FileInfo fileInfo = new FileInfo(tempFilePath); fileInfo.Delete();//删除源文件 throw; } #endregion //转移文件 if (fileData.fileSize == fileData.fileEnd)//判断文件大小是不是等于文件结束大小 { System.IO.FileInfo fileInfo = new FileInfo(tempFilePath); fileInfo.CopyTo(ZSFilePath); //另存为正式目录 fileInfo.Delete(); //删除源文件 } return(Content(filename)); }
/// <summary> /// Opens a file stream to the file specified in the path argument. /// </summary> /// <param name="path">Path to file to open. Must begin with \\?\ for local paths or \\?\UNC\ for network paths.</param> /// <param name="mode">Specifies how the file is opened or if existing data in the file is retained.</param> /// <param name="access">Specifies type of access to the file, read, write or both.</param> /// <param name="share">Specifies share access capabilities of subsequent open calls to this file.</param> /// <returns>A FileStream to the file specified in the path argument.</returns> public static System.IO.FileStream Open(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, FileDataInfo filedi) { System.IO.FileStream result = null; SafeFileHandle fileHandle = CreateFile(path, getAccessFromAccess(access), getShareFromShare(share), IntPtr.Zero, getDispositionFromMode(mode), 0, IntPtr.Zero); int lastWin32Error = Marshal.GetLastWin32Error(); if (fileHandle.IsInvalid) { throw new System.ComponentModel.Win32Exception(lastWin32Error); } result = new System.IO.FileStream(fileHandle, access); if (mode == System.IO.FileMode.Append) { result.Seek(0, System.IO.SeekOrigin.End); } return(result); }
public void OverwriteAllDifferent(bool fastMove) { if (Alphaleonis.Win32.Filesystem.File.Exists(CurrentFile.DestinyPath) && !FileDataInfo.Md5Check(CurrentFile.FullName, CurrentFile.DestinyPath)) { OverwriteCurrentFile(fastMove); } else { SkipCurrentFile(fastMove); } FileCollisionAction = OverwriteAllDifferent; }
protected override void ExecuteCopy(Alphaleonis.Win32.Filesystem.DriveInfo driverInfo, FileDataInfo file) { CurrentFile = null; }
public int AddFieldData(string FondsNumber, string FileNumber, FileDataInfo Info, string nodeid = "", string dept = "") { var user = int.Parse(base.User.Identity.Name); return(_IFileDataService.AddFieldData(FondsNumber, FileNumber, user, Info, nodeid, dept)); }
protected CopyRoutineResult CopyRoutine(FilesList files, bool fastMove) { //System.IO.DirectoryInfo sysDirInfo = null; //FileAttributes sysAtt; //Alphaleonis.Win32.Filesystem.DirectoryInfo di = null; //FileAttributes att; for (; DiscoverdList.Index < DiscoverdList.Count; DiscoverdList.Index++) { try { if (State == CopyHandleState.Canceled) { return(CopyRoutineResult.Canceled); } //Get the file to copy. if (DiscoverdList.Count == 0 || DiscoverdList.Index >= DiscoverdList.Count) { return(CopyRoutineResult.Error); } CurrentFile = DiscoverdList.Files[DiscoverdList.Index]; CurrentFile.CopyState = CopyState.Processing; //Create the Directories. try { //di = new Alphaleonis.Win32.Filesystem.DirectoryInfo(Alphaleonis.Win32.Filesystem.Path.GetDirectoryName(CurrentFile.FullName)); //att = di.Attributes; LongPath.Directory.CreateDirectoriesInPath(CurrentFile.DestinyDirectoryPath); //di=new Alphaleonis.Win32.Filesystem.DirectoryInfo(CurrentFile.DestinyDirectoryPath); //di.Attributes = att; } catch (Exception) { } finally { //This is a copy actions wich deals with file collisions. FileCollisionAction.Invoke(fastMove); //If the File was Processed succefully============================= //Set the currentFile copy state as Copied. CurrentFile.CopyState = affeterOperationState; //Status. CopiedsFiles++; } } catch (Exception ex) { opt = ErrorsCheck(ex); if (opt == AffterErrorAction.Cancel) { return(CopyRoutineResult.Canceled); } else if (opt == AffterErrorAction.Try) { //Try to process the same file DiscoverdList.Index--; FileCopier.TotalBytesTransferred -= FileCopier.FileBytesTransferred; FileCopier.FileBytesTransferred = 0; } else if (!(ex is ThreadAbortException)) { CurrentFile.CopyState = CopyState.Error; } } } return(CopyRoutineResult.Ok); }
private void InitializeFileInfos() { // Get root project path for following locations string projectPath = GetRootProjectPath(); // Expected Blazor files // Minimun _Host.cshtml for blazor FileDataInfo info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinBlazor\Min_Host.cshtml", Method = "Min_Host_CSHtml_File" }; _fileInfos.Add(info); // Minimun NavMenu.Razor for blazor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinBlazor\MinNavMenu.Razor", Method = "MinNavMenu_Razor_File" }; _fileInfos.Add(info); // Minimun Min.Razor for blazor wasm info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinBlazor\MinMin.Razor", Method = "MinMin_Razor_File" }; _fileInfos.Add(info); // Expected Blazor Wasm files // Minimun _Host.cshtml for blazor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinWasm\WasmIndex.html", Method = "Min_Wasm_Index_Html_File" }; _fileInfos.Add(info); // Minimun NavMenu.Razor for blazor wasm info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinWasm\WasmNavMenu.Razor", Method = "Min_Wasm_NavMenu_Razor_File" }; _fileInfos.Add(info); // Minimun Wasm.Razor for blazor wasm info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinWasm\Wasm.Razor", Method = "Wasm_Razor_File" }; _fileInfos.Add(info); // Expected Blazor Wasm PWA files // Minimun index.html for blazor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinWasmPWA\WasmPWAIndex.html", Method = "Min_Wasm_PWA_Index_Html_File" }; _fileInfos.Add(info); // Minimun NavMenu.Razor for blazor wasm info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinWasmPWA\WasmPWANavMenu.Razor", Method = "Min_Wasm_PWA_NavMenu_Razor_File" }; _fileInfos.Add(info); // Minimun Wasm.Razor for blazor wasm info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinWasmPWA\WasmPWA.Razor", Method = "Wasm_PWA_Razor_File" }; _fileInfos.Add(info); // Expected _Layout.cshtml files // Minimun _Layout.cshtml for blazor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinRazor\Razor_Layout.cshtml", Method = "Min_Razor_Layout_CSHtml_File" }; _fileInfos.Add(info); // Minimun NavMenu.Razor for blazor wasm info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinRazor\WasmPWANavMenu.Razor", Method = "Min_Wasm_PWA_NavMenu_Razor_File" }; _fileInfos.Add(info); // Minimun Razor.CSHtml for Razor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinRazor\Razor.cshtml", Method = "MIN_Razor_CSHtml_File" }; _fileInfos.Add(info); // Minimun Razor.CSHtml.cs for Razor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinRazor\Razor.cshtml.cs", Method = "MIN_Razor_CSHtml_CS_File" }; _fileInfos.Add(info); // Minimun Razor_Layout.CSHtml for Razor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinRazor\Razor_Razor_Layout.cshtml", Method = "MIN_Razor_Razor_Layout_CSHtml_File" }; _fileInfos.Add(info); // Minimun _Layout.CSHtml for Razor info = new FileDataInfo { FilePath = projectPath + @"\VSBootstrapImporter.Tests\MinRazor\Razor_Layout.cshtml", Method = "MIN_Razor_Layout_CSHtml_File" }; _fileInfos.Add(info); Console.WriteLine("Initialize " + _fileInfos.Count.ToString() + " files"); }