本文整理汇总了C#中IFileSystem.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.OpenFile方法的具体用法?C# IFileSystem.OpenFile怎么用?C# IFileSystem.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileSystem
的用法示例。
在下文中一共展示了IFileSystem.OpenFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: UploadPartialFile
// Upload partial file
private IEnumerable<FilesStatus> UploadPartialFile(string fileName, HttpContext context, IFileSystem fs, SelectionUtility selection)
{
if (context.Request.Files.Count != 1) throw new HttpRequestValidationException("Attempt to upload chunked file containing more than one fragment per request");
var fileUpload = context.Request.Files[0];
var inputStream = fileUpload.InputStream;
var virtualPath = Url.Combine(selection.SelectedItem.Url, fileName);
if (!IsFilenameTrusted(fileName))
{
yield return new FilesStatus(virtualPath, 0) { error = "Unsafe filename" };
}
else
{
using (var s = fs.OpenFile(virtualPath))
{
var buffer = new byte[1024];
var l = inputStream.Read(buffer, 0, 1024);
while (l > 0)
{
s.Write(buffer, 0, l);
l = inputStream.Read(buffer, 0, 1024);
}
s.Flush();
s.Close();
}
yield return new FilesStatus(virtualPath, fileUpload.ContentLength);
}
}
示例3: GetDocument
private static XDocument GetDocument(IFileSystem fileSystem, string path)
{
using (Stream configStream = fileSystem.OpenFile(path))
{
return XDocument.Load(configStream);
}
}
示例4: GetDocument
private static XDocument GetDocument(IFileSystem fileSystem, string path)
{
using (Stream configStream = fileSystem.OpenFile(path))
{
return XDocument.Load(configStream, LoadOptions.PreserveWhitespace);
}
}
示例5: GetDocument
internal static XDocument GetDocument(IFileSystem fileSystem, string path)
{
using (Stream configStream = fileSystem.OpenFile(path))
{
return XmlUtility.LoadSafe(configStream, LoadOptions.PreserveWhitespace);
}
}
示例6: 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;
}
示例7: ReadDocument
private static string ReadDocument(IFileSystem fileSystem, string path)
{
string document;
using (Stream stream = fileSystem.OpenFile(path))
using (StreamReader sr = new StreamReader(stream))
{
document = sr.ReadToEnd();
}
return document;
}
示例8: GetInputStream
private Stream GetInputStream(IFileSystem fs, string url)
{
byte[] image;
using (var s = fs.OpenFile(url))
{
image = new byte[s.Length];
s.Read(image, 0, image.Length);
}
return new MemoryStream(image);
}
示例9: GetOrCreateDocument
internal static XDocument GetOrCreateDocument(XName rootName, IFileSystem fileSystem, string path)
{
if (fileSystem.FileExists(path)) {
try {
using (Stream configSream = fileSystem.OpenFile(path)) {
return XDocument.Load(configSream);
}
}
catch (FileNotFoundException) {
return CreateDocument(rootName, fileSystem, path);
}
}
return CreateDocument(rootName, fileSystem, path);
}
示例10: SafeResolveRefreshPath
private static string SafeResolveRefreshPath(IFileSystem fileSystem, string file)
{
string relativePath;
try
{
using (var stream = fileSystem.OpenFile(file))
{
relativePath = stream.ReadToEnd();
}
return fileSystem.GetFullPath(relativePath);
}
catch
{
// Ignore the .refresh file if it cannot be read.
}
return null;
}
示例11: Intro
public override void Intro( params object [] args )
{
variableTable = new VariableTable ();
fileSystem = FileSystemManager.GetFileSystem ( "LocalFileSystem" );
if ( fileSystem.IsFileExist ( "vartab.dat" ) )
variableTable.Load ( fileSystem.OpenFile ( "vartab.dat" ) );
else
{
variableTable.AddPackageVariableTable ( myGuid, 3 );
variableTable.SetVariable ( myGuid, 0, 0 );
variableTable.SetVariable ( myGuid, 1, 0.0 );
variableTable.SetVariable ( myGuid, 2, false );
}
base.Intro ( args );
}
示例12: Solution
public Solution(IFileSystem fileSystem, string solutionFileName)
{
var solutionParser = _solutionParserType.GetConstructor(
BindingFlags.Instance | BindingFlags.NonPublic,
binder: null, types: Type.EmptyTypes, modifiers: null).Invoke(null);
using (var streamReader = new StreamReader(fileSystem.OpenFile(solutionFileName)))
{
_solutionReaderProperty.SetValue(solutionParser, streamReader, index: null);
_parseSolutionMethod.Invoke(solutionParser, parameters: null);
}
var projects = new List<ProjectInSolution>();
foreach (var proj in (object[])_projectsProperty.GetValue(solutionParser, index: null))
{
projects.Add(new ProjectInSolution(proj));
}
this.Projects = projects;
}
示例13: 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);
}
示例14: Write
public void Write(IFileSystem fs, ContentItem item, XmlTextWriter writer)
{
string url = item[Name] as string;
if(!string.IsNullOrEmpty(url))
{
string path = url;
if(fs.FileExists(path))
{
using(ElementWriter ew = new ElementWriter("file", writer))
{
ew.WriteAttribute("url", url);
byte[] fileContents = ReadFully(fs.OpenFile(path));
string base64representation = Convert.ToBase64String(fileContents);
ew.Write(base64representation);
}
}
}
}
示例15: EnsureFileExists
private static void EnsureFileExists(IFileSystem fileSystem, string configFilePath)
{
using (fileSystem.OpenFile(configFilePath))
{
// Do nothing
}
}