本文整理汇总了C#中FileAccess.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# FileAccess.HasFlag方法的具体用法?C# FileAccess.HasFlag怎么用?C# FileAccess.HasFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileAccess
的用法示例。
在下文中一共展示了FileAccess.HasFlag方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSupportedTypes
/// <summary>
/// Gets the set of Types this binder supports based on the specified <see cref="FileAccess"/>.
/// From the base stream, this binder will handle conversions to the other types.
/// </summary>
public static IEnumerable<Type> GetSupportedTypes(FileAccess access)
{
IEnumerable<Type> supportedTypes = Enumerable.Empty<Type>();
if (access.HasFlag(FileAccess.Read))
{
supportedTypes = supportedTypes.Union(ReadAccessTypes);
}
if (access.HasFlag(FileAccess.Write))
{
supportedTypes = supportedTypes.Union(WriteAccessTypes);
}
return supportedTypes.Distinct();
}
示例2: NetworkStream
public NetworkStream(Socket socket, FileAccess access)
{
_socket = socket.ThrowIfNull("socket");
if (_socket.ProtocolType != ProtocolType.Tcp)
{
throw new ArgumentException("socket protocol type must be tcp.");
}
if (!_socket.Connected)
{
throw new IOException("socket is not connected");
}
_readable = access.HasFlag(FileAccess.Read);
_writeable = access.HasFlag(FileAccess.Write);
}
示例3: FileDbContext
public FileDbContext(FileAccess access, string connectionString = "ACTSfilesConnection")
{
var fileDbConnectionString = ConfigurationManager.ConnectionStrings[connectionString].ConnectionString;
var fileDbPath = Path.Combine((string)AppDomain.CurrentDomain.GetData("DataDirectory"), fileDbConnectionString);
Files = new FileDB(fileDbPath, access);
if (access.HasFlag(FileAccess.Write))
lock (_lockObj)
_writeCounter++;
}
示例4: SftpContextStream
internal SftpContextStream(SftpSession session, string path, FileMode mode, FileAccess access,
SftpFileAttributes attributes)
{
Flags flags = Flags.None;
switch (access)
{
case FileAccess.Read:
flags = Flags.Read;
break;
case FileAccess.Write:
flags = Flags.Write;
break;
case FileAccess.ReadWrite:
flags = Flags.Read | Flags.Write;
break;
}
switch (mode)
{
case FileMode.Append:
flags |= Flags.Append;
break;
case FileMode.Create:
if (attributes == null)
{
flags |= Flags.CreateNew;
}
else
{
flags |= Flags.Truncate;
}
break;
case FileMode.CreateNew:
flags |= Flags.CreateNew;
break;
case FileMode.Open:
break;
case FileMode.OpenOrCreate:
flags |= Flags.CreateNewOrOpen;
break;
case FileMode.Truncate:
flags |= Flags.Truncate;
break;
}
_session = session;
_handle = _session.RequestOpen(path, flags);
_attributes = attributes ?? _session.RequestFStat(_handle);
if (access.HasFlag(FileAccess.Write))
{
_writeBuffer = new byte[WRITE_BUFFER_SIZE];
_writeMode = true;
}
_position = mode != FileMode.Append ? 0 : _attributes.Size;
}
示例5: GetAccessControlRules
private IEnumerable<FileSystemAccessRule> GetAccessControlRules(FileAccess access, string username)
{
if ((int)access == 0)
{
// If no flags are set just return
return new FileSystemAccessRule[0];
}
FileSystemAccessRule accessRule;
const InheritanceFlags inheritanceFlags = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
List<FileSystemAccessRule> rules = new List<FileSystemAccessRule>();
if (access.HasFlag(FileAccess.Read))
{
accessRule = new FileSystemAccessRule(username, FileSystemRights.ReadAndExecute, inheritanceFlags, PropagationFlags.None, AccessControlType.Allow);
rules.Add(accessRule);
}
if (access.HasFlag(FileAccess.Write))
{
accessRule = new FileSystemAccessRule(username, FileSystemRights.Write, inheritanceFlags, PropagationFlags.None, AccessControlType.Allow);
rules.Add(accessRule);
accessRule = new FileSystemAccessRule(username, FileSystemRights.Delete, inheritanceFlags, PropagationFlags.None, AccessControlType.Allow);
rules.Add(accessRule);
}
return rules;
}
示例6: Open
public unsafe void Open(FileAccess desiredAccess)
{
string fileName = String.Format(@"\\.\{0}", mFileName);
mDiskHandle = CreateFile(fileName,
desiredAccess,
FileShare.ReadWrite, // drives must be opened with read and write share access
0,
FileMode.Open,
FileAttributes.Normal,
IntPtr.Zero);
if (mDiskHandle.IsInvalid)
throw new Win32Exception(Marshal.GetLastWin32Error());
if (desiredAccess.HasFlag(FileAccess.Write))
{
// Unmount & lock the drive
uint pByteReturned = 0;
bool ret = DeviceIoControl(mDiskHandle, FSCTL_DISMOUNT_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, out pByteReturned, IntPtr.Zero);
if (!ret)
throw new Win32Exception(Marshal.GetLastWin32Error());
ret = DeviceIoControl(mDiskHandle, FSCTL_LOCK_VOLUME, IntPtr.Zero, 0, IntPtr.Zero, 0, out pByteReturned, IntPtr.Zero);
if (!ret)
throw new Win32Exception(Marshal.GetLastWin32Error());
}
InStream = new FileStream(mDiskHandle, desiredAccess);
{
binaryReader = new BinaryReader(InStream);
{
bootSector = Utils.ByteToType<FATBS>(binaryReader);
//TODO: Check jmpSector for valid FAT
ulong rootDirSectors = (ulong)((bootSector.root_entry_count * 32) + (bootSector.bytes_per_sector - 1)) / bootSector.bytes_per_sector;
if (rootDirSectors == 0)
type = Type.FAT32;
if (type == Type.FAT32)
fat32ExtBS = Utils.ByteToType<FAT32ExtBS>(binaryReader);
else
fat16ExtBS = Utils.ByteToType<FAT16ExtBS>(binaryReader);
uint tableSize = 0;
if (bootSector.table_size_16 != 0)
tableSize = bootSector.table_size_16;
else
tableSize = fat32ExtBS.table_size_32;
ulong firstDataSector = (ulong)(bootSector.reserved_sector_count + (bootSector.table_count * tableSize) + rootDirSectors);
uint totalSectors;
if (bootSector.total_sectors_16 != 0)
totalSectors = bootSector.total_sectors_16;
else
totalSectors = bootSector.total_sectors_32;
ulong dataSectors = (ulong)totalSectors - (bootSector.reserved_sector_count + (bootSector.table_count * tableSize) + rootDirSectors);
ulong totalClusters = (ulong)(dataSectors / bootSector.sectors_per_cluster);
if (totalClusters < 4085)
type = Type.FAT12;
else if (totalClusters < 65525)
type = Type.FAT16;
else
type = Type.FAT32;
if (type == Type.FAT12)
throw new NotSupportedException("FAT12 is not supported");
logger.Log("Detected new partition: {0}", new object[] { type });
if (type == Type.FAT16)
fatImplementation = new FAT16(mFileName, bootSector, fat16ExtBS, binaryReader, InStream, logger);
else
fatImplementation = new FAT32(mFileName, bootSector, fat32ExtBS, binaryReader, InStream, logger);
fatImplementation.rootDirSectors = rootDirSectors;
fatImplementation.tableSize = tableSize;
fatImplementation.totalClusters = totalClusters;
fatImplementation.totalSectors = totalSectors;
fatImplementation.dataSectors = dataSectors;
fatImplementation.firstDataSector = firstDataSector;
fatImplementation.mbrOffsetInByte = 0;
logger.Log("Table size: {0}", new object[] { tableSize });
logger.Log("Clusters: {0}", new object[] { totalClusters });
logger.Log("Sectors: {0}", new object[] { totalSectors });
logger.Log("");
logger.Log("Reading FAT...");
fatImplementation.ReadRootDirectory();
logger.Log("Reading done.");
}
}
//.........这里部分代码省略.........
示例7: OpenStream
public override Stream OpenStream(FileAccess access)
{
return new FileStream(_file, access.HasFlag(FileAccess.Read) ? FileMode.Open : FileMode.Create, access, FileShare.None);
}
示例8: CreateFile
public int CreateFile(String filename, FileAccess access, FileShare share,
FileMode mode, FileOptions options, DokanFileInfo info)
{
Logging.Write("CreateFile (" + filename + ")");
if(mode.HasFlag(FileMode.Open)) { Logging.Write("\tFileMode.Open true"); }
if(mode.HasFlag(FileMode.OpenOrCreate)) { Logging.Write("\tFileMode.OpenOrCreate true"); }
if(access.HasFlag(FileAccess.Read)) { Logging.Write("\tFileAccess.Read true"); }
if(access.HasFlag(FileAccess.ReadWrite)) { Logging.Write("\tFileAccess.ReadWrite true"); }
int nodeid = SoundCloudFS.FileTree.Node.FindNode(filename);
if(nodeid < 0)
{
string pfilename = SoundCloudFS.FileTree.Node.ParseNodeName(filename);
int ttnid = SoundCloudFS.FileTree.Node.FindNode(pfilename);
if(ttnid < 0)
{
// This node just straight up not found
return -DokanNet.ERROR_FILE_NOT_FOUND;
}
else
{
return 0;
}
}
else
{
return 0;
}
/*
string path = GetPath(filename);
info.Context = count_++;
if (File.Exists(path))
{
return 0;
}
else if(Directory.Exists(path))
{
info.IsDirectory = true;
return 0;
}
else
{
return -DokanNet.ERROR_FILE_NOT_FOUND;
}*/
}