本文整理汇总了C#中FileAccess类的典型用法代码示例。如果您正苦于以下问题:C# FileAccess类的具体用法?C# FileAccess怎么用?C# FileAccess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileAccess类属于命名空间,在下文中一共展示了FileAccess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FileStream
internal FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isConsoleWrapper)
{
if (handle == MonoIO.InvalidHandle)
throw new ArgumentException ("handle", Locale.GetText ("Invalid."));
Init (new SafeFileHandle (handle, false), access, ownsHandle, bufferSize, isAsync, isConsoleWrapper);
}
示例2: Open
/**
* open file.
* @param void.
* @return void.
*/
public bool Open(string strFileName, FileMode eMode, FileAccess eAccess)
{
if (string.IsNullOrEmpty(strFileName))
{
return false;
}
if ((FileMode.Open == eMode) && !File.Exists(strFileName))
{
return false;
}
try
{
m_cStream = new FileStream(strFileName, eMode, eAccess);
}
catch (Exception cEx)
{
Console.Write(cEx.Message);
}
if (null == m_cStream)
{
return false;
}
m_bOpen = true;
return true;
}
示例3: ClusterStream
internal ClusterStream(FatFileSystem fileSystem, FileAccess access, uint firstCluster, uint length)
{
_access = access;
_reader = fileSystem.ClusterReader;
_fat = fileSystem.Fat;
_length = length;
_knownClusters = new List<uint>();
if (firstCluster != 0)
{
_knownClusters.Add(firstCluster);
}
else
{
_knownClusters.Add(FatBuffer.EndOfChain);
}
if (_length == uint.MaxValue)
{
_length = DetectLength();
}
_currentCluster = uint.MaxValue;
_clusterBuffer = new byte[_reader.ClusterSize];
}
示例4: TransactionFileStream
public TransactionFileStream(string path, FileAccess fileAccess)
{
PATH = path;
BACKED_UP_PATH = Path.Combine(new string[] { path + ORIGIN_CONSTANT });
LOG_PATH = Path.Combine(new string[] { path + FILE_FLAG_CONSTANT });
switch (fileAccess)
{
case FileAccess.Read:
{
fileStream = new FileStream(PATH, FileMode.OpenOrCreate, fileAccess);
break;
}
case FileAccess.Write:
{
if (!File.Exists(path))
{
File.Create(path);
}
if (!File.Exists(path) && File.Exists(BACKED_UP_PATH))
{
recoverBackup();
}
else
{
fileStream = new FileStream(LOG_PATH, FileMode.OpenOrCreate, fileAccess);
}
break;
}
default:{
throw new Exception();
}
}
}
示例5: CreateFile
public static Stream CreateFile(
string fileName, FileAccess fileAccess, FileShare fileShare, FileMode fileMode, FileAttributes flags)
{
// TODO: This is not quite right, but it's close.
//
var nativeAccess = fileAccess;
if ((nativeAccess & FileAccess.Read) != 0)
{
nativeAccess &= ~FileAccess.Read;
nativeAccess |= (FileAccess)GENERIC_READ;
}
if ((nativeAccess & FileAccess.Write) != 0)
{
nativeAccess &= ~FileAccess.Write;
nativeAccess |= (FileAccess)GENERIC_WRITE;
}
var handle = _CreateFile(fileName, nativeAccess, fileShare, IntPtr.Zero, fileMode, flags, IntPtr.Zero);
if (handle.IsInvalid)
{
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
}
return new SimpleFileStream(handle);
}
示例6: TableBinding
public TableBinding(ScriptHostConfiguration config, TableBindingMetadata metadata, FileAccess access)
: base(config, metadata, access)
{
if (string.IsNullOrEmpty(metadata.TableName))
{
throw new ArgumentException("The table name cannot be null or empty.");
}
TableName = metadata.TableName;
PartitionKey = metadata.PartitionKey;
if (!string.IsNullOrEmpty(PartitionKey))
{
_partitionKeyBindingTemplate = BindingTemplate.FromString(PartitionKey);
}
RowKey = metadata.RowKey;
if (!string.IsNullOrEmpty(RowKey))
{
_rowKeyBindingTemplate = BindingTemplate.FromString(RowKey);
}
_tableQuery = new TableQuery
{
TakeCount = metadata.Take ?? 50,
FilterString = metadata.Filter
};
}
示例7: FileStream
/// <summary>
/// Initialize a filestream from and input and/or output stream.
/// </summary>
private FileStream(RandomAccessFile file, FileAccess access)
{
if (file == null)
throw new ArgumentNullException("file");
this.file = file;
this.access = access;
}
示例8: CreateFile
public int CreateFile(String filename, FileAccess access, FileShare share,
FileMode mode, FileOptions options, DokanFileInfo info)
{
string path = GetPath(filename);
try
{
if (Directory.Exists(path))
{
info.IsDirectory = true;
}
else
{
FileStream fs = new FileStream(path, mode, access, share, 8, options);
fs.Close();
}
//Console.WriteLine("Create file: {0}\t access: {1}", filename, access);
return DokanNet.DOKAN_SUCCESS;
}
catch (Exception e)
{
return -DokanNet.DOKAN_ERROR;
}
}
示例9: OpenFileEventArgs
public OpenFileEventArgs(VirtualRawPath virtualRawPath, IntPtr handle,
FileAccess fileAccess)
: base(virtualRawPath)
{
_handle = handle;
_fileAccess = fileAccess;
}
示例10: OpenFileStream
/// <summary>
/// File might be locked when attempting to open it. This will attempt to open the file the number of times specified by <paramref name="retry"/>
/// </summary>
/// <param name="fileInfo">The file to attempt to get a file stream for</param>
/// <param name="retry">The number of times a file open should be attempted</param>
/// <param name="fileMode">The file mode to use</param>
/// <param name="fileAccess">The file access to use</param>
/// <param name="fileShare">The file sharing to use</param>
/// <returns>A file stream of the file</returns>
/// <remarks>
/// It attempt to open the file in increasingly longer periods and throw an exception if it cannot open it within the
/// specified number of retries.
/// </remarks>
public FileStream OpenFileStream(FileInfo fileInfo, int retry, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
{
var delay = 0;
for (var i = 0; i < retry; i++)
{
try
{
var stream = new FileStream(fileInfo.FullName, fileMode, fileAccess, fileShare);
return stream;
}
catch(FileNotFoundException)
{
throw;
}
catch (IOException)
{
delay += 100;
if (i == retry) throw;
}
Thread.Sleep(delay);
}
//We will never get here
throw new IOException("Unable to open file - " + fileInfo.FullName);
}
示例11: ToString
static internal string ToString(string path, FileMode mode, FileAccess access, FileShare share)
{
// http://ee.php.net/fopen
//'r' Open for reading only; place the file pointer at the beginning of the file.
//'r+' Open for reading and writing; place the file pointer at the beginning of the file.
//'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
//'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
//'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
//'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
//'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
//'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.
if (mode == FileMode.OpenOrCreate)
{
if (access == FileAccess.Write)
{
if (File.Exists(path))
return "r+b";
else
return "x+b";
}
if (access == FileAccess.Read)
{
if (File.Exists(path))
return "rb";
else
return "xb";
}
}
var e = new { mode, access, share };
throw new NotImplementedException(e.ToString());
}
示例12: DiskImageFile
/// <summary>
/// Represents a single EWF file.
/// </summary>
/// <param name="path">Path to the ewf file.</param>
/// <param name="access">Desired access.</param>
public DiskImageFile(string path, FileAccess access)
{
if (_content == null)
{
_content = new EWFStream(path);
}
}
示例13: FileAccess
internal static void FileAccess(FileMode fileMode, FileAccess fileAccess)
{
// exception if:
// !write && append
// !write && create
// !write && createNew
// !write && truncate
var noWrite = (fileAccess & System.IO.FileAccess.Write) == 0;
if (noWrite && fileMode == FileMode.CreateNew)
throw new ArgumentException(string.Format(
"Can only open files in {0} mode when requesting FileAccess.Write access.", fileMode));
if (noWrite && fileMode == FileMode.Truncate)
throw new IOException("Cannot truncate a file if file mode doesn't include WRITE.");
// or if:
// readwrite && append
// read && append
if (fileAccess == System.IO.FileAccess.Read && fileMode == FileMode.Append)
throw new ArgumentException("Cannot open file in read-mode when having FileMode.Append");
//if (
// ((fileMode == FileMode.Append) && fileAccess != FileAccess.Write) ||
// ((fileMode == FileMode.CreateNew || fileMode == FileMode.Create || fileMode == FileMode.Truncate)
// && (fileAccess != FileAccess.Write && fileAccess != FileAccess.ReadWrite)) ||
// false //((Exists && fileMode == FileMode.OpenOrCreate && fileAccess == FileAccess.Write))
// )
}
示例14: OpenFile
public Stream OpenFile(FileSystemPath path, FileAccess access)
{
var fs = GetFirst(path);
if (fs == null)
throw new FileNotFoundException();
return fs.OpenFile(path, access);
}
示例15: Binding
public Binding(string name, string type, FileAccess fileAccess, bool isTrigger)
{
Name = name;
Type = type;
FileAccess = fileAccess;
IsTrigger = isTrigger;
}