本文整理汇总了C#中FileOptions类的典型用法代码示例。如果您正苦于以下问题:C# FileOptions类的具体用法?C# FileOptions怎么用?C# FileOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileOptions类属于命名空间,在下文中一共展示了FileOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TmphFileBlockStream
/// <summary>
/// 文件分块写入流
/// </summary>
/// <param name="fileName">文件全名</param>
/// <param name="fileOption">附加选项</param>
public TmphFileBlockStream(string fileName, FileOptions fileOption = FileOptions.None)
: base(fileName, File.Exists(fileName) ? FileMode.Open : FileMode.CreateNew, FileShare.Read, fileOption)
{
fileReader = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read, bufferLength,
fileOption);
waitHandle = wait;
}
示例2: CreateFile
public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
{
Trace.WriteLine(string.Format("CreateFile FILENAME({0}) ACCESS({1}) SHARE({2}) MODE({3})", filename, access, share, mode));
if (mode == FileMode.Create || mode == FileMode.OpenOrCreate || mode == FileMode.CreateNew)
{
// we want to write a file
var fileRef = Extensions.GetFileReference(root, filename.ToFileString());
fileRef.Create(0);
return 0;
}
if (share == FileShare.Delete)
{
return DeleteFile(filename, info);
}
if (GetFileInformation(filename, new FileInformation(), new DokanFileInfo(0)) == 0)
{
return 0;
}
else
{
return -DokanNet.ERROR_FILE_NOT_FOUND;
}
}
示例3: OpenHandle
private SafeFileHandle OpenHandle(FileMode mode, FileShare share, FileOptions options)
{
// FileStream performs most of the general argument validation. We can assume here that the arguments
// are all checked and consistent (e.g. non-null-or-empty path; valid enums in mode, access, share, and options; etc.)
// Store the arguments
_mode = mode;
_options = options;
if (_useAsyncIO)
_asyncState = new AsyncState();
// Translate the arguments into arguments for an open call.
Interop.Sys.OpenFlags openFlags = PreOpenConfigurationFromOptions(mode, _access, options); // FileShare currently ignored
// If the file gets created a new, we'll select the permissions for it. Most Unix utilities by default use 666 (read and
// write for all), so we do the same (even though this doesn't match Windows, where by default it's possible to write out
// a file and then execute it). No matter what we choose, it'll be subject to the umask applied by the system, such that the
// actual permissions will typically be less than what we select here.
const Interop.Sys.Permissions OpenPermissions =
Interop.Sys.Permissions.S_IRUSR | Interop.Sys.Permissions.S_IWUSR |
Interop.Sys.Permissions.S_IRGRP | Interop.Sys.Permissions.S_IWGRP |
Interop.Sys.Permissions.S_IROTH | Interop.Sys.Permissions.S_IWOTH;
// Open the file and store the safe handle.
return SafeFileHandle.Open(_path, openFlags, (int)OpenPermissions);
}
示例4: SqlFileStream
public SqlFileStream(string path, byte[] transactionContext, FileAccess access, FileOptions options, long allocationSize)
{
IntPtr ptr;
this.ObjectID = Interlocked.Increment(ref _objectTypeCount);
Bid.ScopeEnter(out ptr, "<sc.SqlFileStream.ctor|API> %d# access=%d options=%d path='%ls' ", this.ObjectID, (int) access, (int) options, path);
try
{
if (transactionContext == null)
{
throw ADP.ArgumentNull("transactionContext");
}
if (path == null)
{
throw ADP.ArgumentNull("path");
}
this.m_disposed = false;
this.m_fs = null;
this.OpenSqlFileStream(path, transactionContext, access, options, allocationSize);
this.Name = path;
this.TransactionContext = transactionContext;
}
finally
{
Bid.ScopeLeave(ref ptr);
}
}
示例5: CreateFile
public DokanError CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
{
info.DeleteOnClose = (options & FileOptions.DeleteOnClose) != 0;
//Console.WriteLine("CreateFile: {0}, mode = {1}", fileName, mode);
if (fileName == "\\")
{
return DokanError.ErrorSuccess;
}
Directory dir = new Directory(Util.GetPathDirectory(fileName));
if (!dir.Exists())
{
return DokanError.ErrorPathNotFound;
}
String name = Util.GetPathFileName(fileName);
if (name.Length == 0)
{
return DokanError.ErrorInvalidName;
}
if (name.IndexOfAny(Path.GetInvalidFileNameChars()) > -1)
{
return DokanError.ErrorInvalidName;
}
// dokan API 要求在目标文件是目录时候,设置 info.IsDirectory = true
if (dir.Contains(name) && (dir.GetItemInfo(name).attribute & FileAttributes.Directory) != 0)
{
info.IsDirectory = true;
return DokanError.ErrorSuccess;
}
try
{
File f = new File(fileName, mode);
f.flagDeleteOnClose = info.DeleteOnClose;
info.Context = f;
}
catch (FileNotFoundException)
{
return DokanError.ErrorFileNotFound;
}
catch (IOException)
{
return DokanError.ErrorAlreadyExists;
}
catch (NotImplementedException)
{
return DokanError.ErrorAccessDenied;
}
catch (Exception)
{
return DokanError.ErrorError;
}
return DokanError.ErrorSuccess;
}
示例6: Init
private void Init(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
{
if (path == null)
throw new ArgumentNullException("path", SR.ArgumentNull_Path);
if (path.Length == 0)
throw new ArgumentException(SR.Argument_EmptyPath, "path");
// don't include inheritable in our bounds check for share
FileShare tempshare = share & ~FileShare.Inheritable;
String badArg = null;
if (mode < FileMode.CreateNew || mode > FileMode.Append)
badArg = "mode";
else if (access < FileAccess.Read || access > FileAccess.ReadWrite)
badArg = "access";
else if (tempshare < FileShare.None || tempshare > (FileShare.ReadWrite | FileShare.Delete))
badArg = "share";
if (badArg != null)
throw new ArgumentOutOfRangeException(badArg, SR.ArgumentOutOfRange_Enum);
// NOTE: any change to FileOptions enum needs to be matched here in the error validation
if (options != FileOptions.None && (options & ~(FileOptions.WriteThrough | FileOptions.Asynchronous | FileOptions.RandomAccess | FileOptions.DeleteOnClose | FileOptions.SequentialScan | FileOptions.Encrypted | (FileOptions)0x20000000 /* NoBuffering */)) != 0)
throw new ArgumentOutOfRangeException("options", SR.ArgumentOutOfRange_Enum);
if (bufferSize <= 0)
throw new ArgumentOutOfRangeException("bufferSize", SR.ArgumentOutOfRange_NeedPosNum);
// Write access validation
if ((access & FileAccess.Write) == 0)
{
if (mode == FileMode.Truncate || mode == FileMode.CreateNew || mode == FileMode.Create || mode == FileMode.Append)
{
// No write access
throw new ArgumentException(SR.Format(SR.Argument_InvalidFileModeAndAccessCombo, mode, access));
}
}
string fullPath = PathHelpers.GetFullPathInternal(path);
// Prevent access to your disk drives as raw block devices.
if (fullPath.StartsWith("\\\\.\\", StringComparison.Ordinal))
throw new ArgumentException(SR.Arg_DevicesNotSupported);
#if !PLATFORM_UNIX
// Check for additional invalid characters. Most invalid characters were checked above
// in our call to Path.GetFullPath(path);
if (HasAdditionalInvalidCharacters(fullPath))
throw new ArgumentException(SR.Argument_InvalidPathChars);
if (fullPath.IndexOf(':', 2) != -1)
throw new NotSupportedException(SR.Argument_PathFormatNotSupported);
#endif
if ((access & FileAccess.Read) != 0 && mode == FileMode.Append)
throw new ArgumentException(SR.Argument_InvalidAppendMode);
this._innerStream = FileSystem.Current.Open(fullPath, mode, access, share, bufferSize, options, this);
}
示例7: CreateFileOperation
public CreateFileOperation( string path, int bufferSize, FileOptions options, FileSecurity fileSecurity )
{
this.path = path;
this.bufferSize = bufferSize;
this.options = options;
this.fileSecurity = fileSecurity;
tempFilePath = Path.Combine( Path.GetTempPath(), Path.GetRandomFileName() );
}
示例8: DeleteOnClose_FileDeletedAfterClose
public void DeleteOnClose_FileDeletedAfterClose(FileOptions options)
{
string path = GetTestFilePath();
Assert.False(File.Exists(path));
using (CreateFileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 0x1000, options))
{
Assert.True(File.Exists(path));
}
Assert.False(File.Exists(path));
}
示例9: OpenFile
public Stream OpenFile(
string path,
FileMode fileMode,
FileAccess fileAccess,
FileShare fileShare,
int bufferSize,
FileOptions fileOptions)
{
return new FileStream(path, fileMode, fileAccess, fileShare, bufferSize, fileOptions);
}
示例10: CreateFile
public virtual int CreateFile(string filename,
FileAccess access,
FileShare share,
FileMode mode,
FileOptions options,
DokanFileInfo info)
{
try { return -1; }
catch { return -1; }
}
示例11: CreateFile
public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
{
int result = _fileSystem.CreateFile(filename, access, share, mode, options, info);
if (this._logging)
{
Console.WriteLine("CreateFile: " + filename);
Console.WriteLine("Result: " + result);
}
return result;
}
示例12: Trace
private NtStatus Trace(string method, string fileName, DokanFileInfo info,
FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes,
NtStatus result)
{
#if TRACE
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}('{1}', {2}, [{3}], [{4}], [{5}], [{6}], [{7}]) -> {8}",
method, fileName, ToTrace(info), access, share, mode, options, attributes, result));
#endif
return result;
}
示例13: CreateFile
public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
{
Console.WriteLine("Create File : " + filename);
var response = MakeComplexRequest(Path + CREATE_FILE_REQUEST_STRING, SecurityElement.Escape(filename), (int)access, (int)share, (int)mode, (int)options, info.ProcessId);
if (response.ContainsKey("message"))
Console.WriteLine("Create File Message : " + response["message"]);
return int.Parse(response["response_code"]);
}
示例14: AtomicFileStream
private AtomicFileStream(string path, string tempPath, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
: base(tempPath, mode, access, share, bufferSize, options)
{
if (path == null)
throw new ArgumentNullException("path");
if (tempPath == null)
throw new ArgumentNullException("tempPath");
this.path = path;
this.tempPath = tempPath;
}
示例15: WinRTFileStream
internal WinRTFileStream(Stream innerStream, StorageFile file, FileAccess access, FileOptions options, FileStream parent)
: base(parent)
{
Debug.Assert(innerStream != null);
Debug.Assert(file != null);
this._access = access;
this._disposed = false;
this._file = file;
this._innerStream = innerStream;
this._options = options;
}