private void getXLContent(FileSpecs fs) { //TODO: try blocks for error handling Excel.Application xlApp = new Excel.Application(); Excel.Worksheet wkSht = xlApp.Workbooks.Open(fs.Path).Worksheets[1]; Excel.Range ur = wkSht.UsedRange; int columnEnd = ur.Columns.Count + 1; int rowEnd = ur.Rows.Count + 1; //Console.WriteLine("columEnd: " + columnEnd); //Console.WriteLine("rowEnd: " + rowEnd); Excel.Range end = wkSht.Cells[rowEnd, columnEnd]; ur = wkSht.Range["A1", end]; List <string> line = new List <string>(); fd = new FileData(fs.Name); for (int row = 1; row < ur.Rows.Count; row++) { line = new List <string>(); for (int col = 1; col < ur.Columns.Count; col++) { //Console.WriteLine("Row: " + row); //Console.WriteLine("Col: " + col); line.Add(Convert.ToString( (wkSht.Cells[row, col] as Excel.Range).Value2 )); //Console.WriteLine("Add: " + line[col - 1]); } fd.Add(line); } xlApp.Quit(); }
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (headers == null) { throw new ArgumentNullException(nameof(headers)); } // Generate a new filename for every new blob var fileName = Guid.NewGuid().ToString(); var blob = _blobContainer.GetBlockBlobReference(fileName); if (headers.ContentType != null) { blob.Properties.ContentType = headers.ContentType.MediaType; } FileData.Add(new MultipartFileData(headers, blob.Name)); return(blob.OpenWrite()); }
/// <inheritdoc /> public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (MultipartFormDataStreamProviderHelper.IsFileContent(parent, headers)) { RemoteStreamInfo remoteStreamInfo = GetRemoteStream(parent, headers); if (remoteStreamInfo == null) { throw Error.InvalidOperation( Properties.Resources.RemoteStreamInfoCannotBeNull, "GetRemoteStream", GetType().Name ); } FileData.Add( new MultipartRemoteFileData( headers, remoteStreamInfo.Location, remoteStreamInfo.FileName ) ); return(remoteStreamInfo.RemoteStream); } return(new MemoryStream()); }
public static FileData createData(string name) { FileData fd = new FileData(name); List <string> t1, t2; t1 = new List <string>(); t2 = new List <string>(); t1.Add("User1"); t1.Add("Last1"); t2.Add("User2"); t2.Add("Last2"); fd.Add(t1); fd.Add(t2); return(fd); }
public override Stream GetStream(HttpContentHeaders headers) { if (!IsValidUpload(headers)) { throw new Exception("Not a valid upload, check file extension(s)."); } string fileName = GetFileName(headers.ContentDisposition); FileData.Add(new MultipartFileData(headers, fileName)); string contentType = headers.ContentType?.MediaType; return(_storageProvider.Create(_path, fileName, contentType)); }
private Stream GetStream(HttpContentHeaders headers) { string fileName = GetFileName(headers.ContentDisposition); bool hasFileName = !string.IsNullOrEmpty(fileName); Stream stream = hasFileName ? _uploadStream.GetStream(headers, fileName) : new MemoryStream(); _isFormData.Add(!hasFileName); if (hasFileName) { FileData.Add(new MultipartFileData(headers, fileName)); } return(stream); }
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (!InMemory || headers.ContentDisposition == null || string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName)) { return(base.GetStream(parent, headers)); } var data = new CustomMultipartFileData(headers, GetLocalFileName(headers)) { MemoryStream = new MemoryStream() }; FileData.Add(data); CustomFileData.Add(data); return(data.MemoryStream); }
private void spliteData() { FolderData.Clear(); FileData.Clear(); foreach (UserFileModel file in Data) { if (file.is_folder) { FolderData.Add(file); } else { FileData.Add(file); Debug.WriteLine("file", file.file_name); } } }
/// <summary> /// Gets the stream instance to which the message body part is written. /// </summary> /// <param name="parent">The HTTP content that contains this body part.</param> /// <param name="headers">Header fields describing the body part.</param> /// <returns>The <see cref="Stream"/> instance where the message body part is written.</returns> public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (headers == null) { throw new ArgumentNullException("headers"); } var filename = GetLocalFileName(headers); var fullpath = Path.Combine(RootPath, filename); var data = new MultipartFileData(headers, fullpath); FileData.Add(data); var stream_wrapper = FileWrapper.Create(fullpath, BufferSize, FileOptions.Asynchronous); return(stream_wrapper.StreamInstance); }
private void getCSVContent(FileSpecs fs) { string[] fileContent; List <string> fileRow; FileData fd = new FileData(fs.Name); int row, col = 0; fileContent = System.IO.File.ReadAllLines(fs.Path); row = fileContent.Length; if (row > 0) { col = fileContent[0].Split(',').Length; } for (int r = 0; r < row; r++) { fileRow = fileContent[r].Split(',').ToList <string>(); fd.Add(fileRow); } }
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { Stream stream = null; ContentDispositionHeaderValue contentDisposition = headers.ContentDisposition; if (contentDisposition != null) { if (!String.IsNullOrEmpty(contentDisposition.FileName)) { FileData.Add(new MultipartFileData(headers, contentDisposition.FileName)); // Can be replaced with any stream the user want. e.g. Azure Blob Storage Stream. stream = new MemoryStream(); } else { stream = base.GetStream(parent, headers); } } return(stream); }
void ChangeFileData(List <KeyValuePair <string, StringValues> > dataList) { int lineCurrent = 0, column = 0; foreach (var data in dataList) { var sCoord = data.Key.Split(','); if (!int.TryParse(sCoord[0], out lineCurrent) || !int.TryParse(sCoord[1], out column)) { continue; } while (lineCurrent >= FileData.Count()) { FileData.Add("\t\t"); } string str = FileData[lineCurrent]; List <string> elements = str.Split('\t').ToList(); StringBuilder newStr = new StringBuilder(); while (column > elements.Count() - 1) { elements.Add(""); } for (int i = 0; i < elements.Count(); i++) { if (i != 0) { newStr.Append("\t"); } newStr.Append(i != column ? elements[i] : data.Value.ToString()); } FileData[lineCurrent] = newStr.ToString(); } }
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (parent == null || headers == null) { throw new ArgumentException(); } //Check to see if we are reading a file, if it is other form data return emtpy stream if (string.IsNullOrEmpty(headers.ContentDisposition.FileName)) { return(new MemoryStream()); } var filename = Guid.NewGuid().ToString(); var blob = _blobContainer.GetBlockBlobReference(filename); blob.Properties.ContentType = headers.ContentType?.MediaType; FileData.Add(new MultipartFileData(headers, blob.Name)); return(blob.OpenWrite()); }
/// <param name="parent">The HTTP content that contains this body part.</param> /// <param name="headers">Header fields describing the body part.</param> /// <returns>The <see cref="T:System.IO.Stream"/> instance where the message body part is written.</returns> public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (parent == null) { throw new ArgumentNullException("parent"); } if (headers == null) { throw new ArgumentNullException("headers"); } MemoryStream memoryStream = new MemoryStream(); string localFileName = GetFileName(headers); if (localFileName != null) { FileData.Add(new MultipartFileData(headers, localFileName)); _UploadedStreams.Add(new KeyValuePair <HttpContentHeaders, MemoryStream>(headers, memoryStream)); } return(memoryStream); }
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (parent == null) { throw new ArgumentNullException("parent"); } if (headers == null) { throw new ArgumentNullException("headers"); } _contentCounter++; if (headers.ContentType != null && headers.ContentType.MediaType.Contains("json")) { _postProcContentMarker = _contentCounter; return(new MemoryStream()); } string localFilePath; try { var filename = GetLocalFileName(headers); localFilePath = Path.Combine(RootPath, filename); addedFiles.Add(localFilePath); } catch (Exception e) { throw new InvalidOperationException("Something went wrong when getting local file path...", e); } var fileData = new MultipartFileData(headers, localFilePath); FileData.Add(fileData); var file = new FileInfo(localFilePath); if (file.Exists) { SyncResult.UpdatedFiles.Add(localFilePath); SyncResult.Log.Add("Updated: " + localFilePath); } else { try { Directory.CreateDirectory(file.DirectoryName); SyncResult.CreatedFiles.Add(localFilePath); SyncResult.Log.Add("Created: " + localFilePath); } catch (Exception ex) { SyncResult.Errors.Add(string.Format("Error: Could not create directory {0}. Error: {1}", file.DirectoryName, ex.Message)); } } Stream fileStream; try { fileStream = File.Create(localFilePath, BufferSize, FileOptions.Asynchronous); } catch (Exception ex) { SyncResult.Errors.Add(string.Format("Error: Could not create file {0}. Error: {1}", localFilePath, ex.Message)); fileStream = new MemoryStream(); } return(fileStream); }
public override Stream GetStream(HttpContent parent, HttpContentHeaders headers) { if (string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName)) { return(new MemoryStream());//除了文件,其它的普通表单数据都使用内存流 } //假定文件流是表单的其它数据之后,只考虑一次来单个文件 FileName = GetFormValue(FileParameterName); FileMD5 = GetFormValue(FileMD5ParameterName); FileSize = long.Parse(GetFormValue(FileSizeParameterName)); var strChunks = GetFormValue(ChunksParameterName); #region 非分片上传 if (strChunks.IsNullOrWhiteSpace()) { var localFileName1 = CreateFilePath(); FileData.Add(new MultipartFileData(headers, localFileName1)); //参考顶部注释关于并发的解释 //由于是非分片,发生并发冲突是直接抛出异常阻止继续上传 if (System.IO.File.Exists(localFileName1)) { if (new FileInfo(localFileName1).Length < FileSize) { return(System.IO.File.Create(localFileName1)); } else { return(new InnerStream()); } } else { return(new FileStream(localFileName1, FileMode.CreateNew)); } } #endregion #region 分片上传 Chunks = int.Parse(strChunks); //总片数 Chunk = int.Parse(GetFormValue(ChunkParameterName)); //当前片序号 ChunkSize = long.Parse(GetFormValue(ChunkSizeParameterName)); IsChunk = true; TempDirectory = Path.Combine(RootPath, FileMD5);//分片要保存到的临时目录 if (!Directory.Exists(TempDirectory)) { Directory.CreateDirectory(TempDirectory); } //参考顶部注释关于并发的解释 var fp = Path.Combine(TempDirectory, Chunk.ToString()); FileData.Add(new MultipartFileData(headers, fp)); //参考顶部注释关于并发的解释 //由于是分片,发生并发时尽可能补救 try { if (System.IO.File.Exists(fp)) { if (new FileInfo(fp).Length < ChunkSize) { return(System.IO.File.Create(fp));//-2147024864 } else { return(new InnerStream()); } } else { return(new FileStream(fp, FileMode.CreateNew));//-2147024816 } } catch (IOException ex) { if (ex.HResult == -2147024864 || ex.HResult == -2147024816) { return(new InnerStream()); } throw; } #endregion }
public override async Task ExecutePostProcessingAsync() { await base.ExecutePostProcessingAsync(); //填充FormData属性(表单数据) if (!IsChunk) { return; } //最后几个分片可能同时上了。多个用户可能上传同一个文件,都可能造成并发冲突 //目前这种合并方式是相对好点的 string[] files = Directory.GetFiles(TempDirectory); if (Chunk != Chunks - 1 || files.Length != Chunks) { return; } var newFileName = CreateFilePath(); FileStream stream = null; try { stream = new FileStream(newFileName, FileMode.CreateNew); } catch (IOException ex) { if (ex.HResult != -2147024816) { throw; } //Logger.WarnFormat("分片上传文件时创建文件流失败:" + ex.Message); return; } using (stream) { var sortedFiles = files.OrderBy(c => int.Parse(Path.GetFileNameWithoutExtension(c))); await Task.Run(async() => { foreach (var item in sortedFiles) { #region MyRegion //此时可能另一个分片并没有读取完成 for (int i = 0; i < 10000; i++) { try { using (var fs = System.IO.File.OpenRead(item)) { fs.CopyTo(stream); } break; } catch (IOException ex) { if (ex.HResult != -2147024864) { throw; } await Task.Delay(2); } } #endregion } }); } var lastCT = FileData.First(); var heders = lastCT.Headers; base.FileData.Clear(); FileData.Add(new MultipartFileData(heders, newFileName)); Directory.Delete(TempDirectory, true); IsChunk = false; }