public static Stream Create(string path) { if (_provider == null) { return(File.Create(path)); } return(_provider.Create(path)); }
//ToDo: primary key constraint or identity column feature! //ToDo: add parent navigation properties to appropriate file public void Add <TItem>(TItem item) { var itemType = typeof(TItem); var path = GetFilePath(itemType); if (_fileProvider.Exists(path)) { _fileProvider.GetFile(path).AppendLine(GetCsvLine(item)); } else { var file = _fileProvider.Create(path); file.AppendLine(GetHeader(itemType)); file.AppendLine(GetCsvLine(item)); } }
private void SetupMockFile(string path, string[] lines) { var file = _mockFileProvider.Create(path); foreach (var line in lines) { file.AppendLine(line); } }
public async Task <string> CreateFileAsync(long uploadLength, string metadata, CancellationToken cancellationToken) { var fileId = new InternalFileId(); _fileProvider.Create(_fileRepFactory.Data(fileId).Path).Dispose(); if (uploadLength != -1) { await SetUploadLengthAsync(fileId.FileId, uploadLength, cancellationToken); } _fileRepFactory.Metadata(fileId).Write(metadata); return(fileId.FileId); }
public async Task <IHttpActionResult> PostFile(string fileName, string folder = "Uploaded") { using (var inStream = await Request.Content.ReadAsStreamAsync()) { var outStream = _fileProvider.Create($"{(folder == "Published" ? _fileProvider.PublishedFilesDirectory : _fileProvider.UploadedFilesDirectory)}/{fileName}"); try { await inStream.CopyToAsync(outStream, StreamExtensions.BufferSize); } catch { } finally { outStream.Close(); } } return(Ok()); }
public bool Create(string filename, string path = null, string content = null) { if (string.IsNullOrWhiteSpace(path)) { path = UserDirectory.Get(); } bool isNull = string.IsNullOrEmpty(filename); if (!isNull) { bool IsTxt = FileProvider.CheckFileExtension(filename); if (IsTxt) { var exist = IsExist(filename, path); if (!exist) { if (string.IsNullOrWhiteSpace(content)) { return(FileProvider.Create(filename, path, content)); } else { return(FileProvider.AppendAllText(filename, path, content)); } } else { return(FileProvider.WriteAllText(filename, path, content)); } } else { throw new FileExtensionException($"The file \"{filename}\" is not a text file"); } } else { throw new NoFileNameException("CREATE: FileName is missing"); } }