本文整理汇总了C#中IFileSystem.CreateFile方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.CreateFile方法的具体用法?C# IFileSystem.CreateFile怎么用?C# IFileSystem.CreateFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.CreateFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Move
public void Move(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath)
{
bool isFile;
if ((isFile = sourcePath.IsFile) != destinationPath.IsFile)
throw new ArgumentException("The specified destination-path is of a different type than the source-path.");
if (isFile)
{
using (var sourceStream = source.OpenFile(sourcePath, FileAccess.Read))
{
using (var destinationStream = destination.CreateFile(destinationPath))
{
byte[] buffer = new byte[BufferSize];
int readBytes;
while ((readBytes = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
destinationStream.Write(buffer, 0, readBytes);
}
}
source.Delete(sourcePath);
}
else
{
destination.CreateDirectory(destinationPath);
foreach (var ep in source.GetEntities(sourcePath).ToArray())
{
var destinationEntityPath = ep.IsFile
? destinationPath.AppendFile(ep.EntityName)
: destinationPath.AppendDirectory(ep.EntityName);
Move(source, ep, destination, destinationEntityPath);
}
if (!sourcePath.IsRoot)
source.Delete(sourcePath);
}
}
示例2: StreamFile
public StreamFile(IFileSystem fileSystem, string path, bool readOnly)
{
file = fileSystem.FileExists(path) ? fileSystem.OpenFile(path, readOnly) : fileSystem.CreateFile(path);
endPointer = file.Length;
fileStream = new StreamFileStream(this);
ownsFile = true;
}
示例3: ArgParser
public ArgParser(string[] args, IFileSystem FileSystem)
{
if (FileSystem == null) { throw new ArgumentNullException("FileSystem can not be null"); };
string configFileContents = FileSystem.ReadFile("default.json");
if(String.IsNullOrEmpty(configFileContents)) {
FileSystem.CreateFile("default.json",_defaultConfig);
configFileContents = _defaultConfig;
}
ProjectConfig = Config.LoadConfig(configFileContents);
if(args != null && !String.IsNullOrEmpty(args[0])) {
Command = new NewProject(FileSystem) { Config=ProjectConfig, Name=args[0] };
}
}
示例4: Logger
public Logger(IFileSystem fileSystem)
{
//Create the StreamWriter which the logger will use for outputting to file
_fileSystem = fileSystem;
if (!fileSystem.FileExists(_LOG_FILE_PATH))
{
_logFileStream = fileSystem.CreateFile(_LOG_FILE_PATH);
}
else
{
_logFileStream = fileSystem.OpenFile(_LOG_FILE_PATH, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
}
_logFileStreamWriter = new StreamWriter(_logFileStream);
//Since we are logging, set autoflush to true for immediate writes
_logFileStreamWriter.AutoFlush = true;
_logFileStreamWriter.WriteLine("------------ New Buttercup Session (" + DateTime.Now + ") ------------" + Environment.NewLine);
}
示例5: Copy
public static async Task<bool> Copy (this IFile src, IFileSystem destFileSystem, string destPath)
{
#if PORTABLE
return false;
#else
IFile dest = null;
var r = false;
LocalFileAccess srcLocal = null;
LocalFileAccess destLocal = null;
try {
dest = await destFileSystem.CreateFile (destPath, "");
srcLocal = await src.BeginLocalAccess ();
destLocal = await dest.BeginLocalAccess ();
var srcLocalPath = srcLocal.LocalPath;
var destLocalPath = destLocal.LocalPath;
System.IO.File.Copy (srcLocalPath, destLocalPath, overwrite: true);
r = true;
} catch (Exception ex) {
Debug.WriteLine (ex);
r = false;
}
if (srcLocal != null) await srcLocal.End ();
if (destLocal != null) await destLocal.End ();
return r;
// await Task.Factory.StartNew (() => {
//
// var fc = new NSFileCoordinator (filePresenterOrNil: null);
// NSError coordErr;
//
// fc.CoordinateReadWrite (
// srcPath, NSFileCoordinatorReadingOptions.WithoutChanges,
// destPath, NSFileCoordinatorWritingOptions.ForReplacing,
// out coordErr, (readUrl, writeUrl) => {
//
// var r = false;
// try {
// File.Copy (readUrl.Path, writeUrl.Path, overwrite: true);
// r = true;
// } catch (Exception) {
// r = false;
// }
// tcs.SetResult (r);
// });
// });
#endif
}
示例6: CopyFileAsync
static async Task<IFile> CopyFileAsync (this IFileSystem src, IFile file, IFileSystem dest, string destDir)
{
var contents = await file.ReadAllBytesAsync ();
var newPath = await dest.GetAvailableNameAsync (Path.Combine (destDir, Path.GetFileName (file.Path)));
return await dest.CreateFile (newPath, contents);
}
示例7: New
public static async Task<DocumentReference> New (string directory, string baseName, string ext, IFileSystem fs, DocumentConstructor dctor, string contents = null)
{
if (ext [0] != '.') {
ext = '.' + ext;
}
//
// Get a name
//
var n = baseName + ext;
var i = 1;
var p = Path.Combine (directory, n);
var files = await fs.ListFiles (directory);
while (files.Exists (x => x.Path == p)) {
i++;
n = baseName + " " + i + ext;
p = Path.Combine (directory, n);
}
return new DocumentReference (await fs.CreateFile (p, contents), dctor, isNew: true);
}