本文整理汇总了C#中FileAccess类的典型用法代码示例。如果您正苦于以下问题:C# FileAccess类的具体用法?C# FileAccess怎么用?C# FileAccess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileAccess类属于命名空间,在下文中一共展示了FileAccess类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:FileStream.cs
示例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;
}
开发者ID:602147629,项目名称:2DPlatformer-SLua,代码行数:34,代码来源:YwArchiveBinFile.cs
示例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];
}
开发者ID:AnotherAltr,项目名称:Rc.Core,代码行数:25,代码来源:ClusterStream.cs
示例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();
}
}
}
开发者ID:cpm2710,项目名称:cellbank,代码行数:34,代码来源:TransactionStream.cs
示例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);
}
开发者ID:DeCarabas,项目名称:sudo,代码行数:25,代码来源:NativeMethods.cs
示例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
};
}
开发者ID:isaacabraham,项目名称:azure-webjobs-sdk-script,代码行数:28,代码来源:TableBinding.cs
示例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;
}
开发者ID:nguyenkien,项目名称:api,代码行数:10,代码来源:FileStream.cs
示例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;
}
}
开发者ID:Legend1991,项目名称:SecureBox_WPF,代码行数:25,代码来源:CryptoMirror.cs
示例9: OpenFileEventArgs
public OpenFileEventArgs(VirtualRawPath virtualRawPath, IntPtr handle,
FileAccess fileAccess)
: base(virtualRawPath)
{
_handle = handle;
_fileAccess = fileAccess;
}
开发者ID:xujyan,项目名称:hurricane,代码行数:7,代码来源:FilesysEventArgs.cs
示例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);
}
开发者ID:atifaziz,项目名称:talifun-web,代码行数:40,代码来源:RetryableFileOpener.cs
示例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());
}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:35,代码来源:FileStream.cs
示例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);
}
}
开发者ID:easymetadata,项目名称:discutils_Ewf-POC,代码行数:12,代码来源:DiskImageFile.cs
示例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))
// )
}
开发者ID:bittercoder,项目名称:Windsor,代码行数:31,代码来源:Validate.cs
示例14: OpenFile
public Stream OpenFile(FileSystemPath path, FileAccess access)
{
var fs = GetFirst(path);
if (fs == null)
throw new FileNotFoundException();
return fs.OpenFile(path, access);
}
开发者ID:Maxwolf,项目名称:FakeFilesystem,代码行数:7,代码来源:MergedFileSystem.cs
示例15: Binding
public Binding(string name, string type, FileAccess fileAccess, bool isTrigger)
{
Name = name;
Type = type;
FileAccess = fileAccess;
IsTrigger = isTrigger;
}
开发者ID:wondenge,项目名称:azure-webjobs-sdk-script,代码行数:7,代码来源:Binding.cs
示例16: Visio2003Adapter
/// <summary>
/// Instantiates a non-strict Visio 2003 DatadiagramML (VDX file) adapter for reading from an URI.
/// It is possible to load only a selection of pages from the Visio file.
/// </summary>
/// <remarks>
/// Only READ mode is supported!
/// </remarks>
/// <param name="uriVDX">The URI to read from.</param>
/// <param name="mode">The FileAccess mode.</param>
/// <param name="pageNames">An optional list of page names.</param>
public Visio2003Adapter(string uriVDX, FileAccess mode, params string[] pageNames)
{
// manually open the file so that we can specify share permissions (thanks Eric Lyons!)
using(Stream streamVDX = new FileStream(uriVDX, FileMode.Open, mode, FileShare.ReadWrite)) {
Init(new XPathDocument(streamVDX), mode, false, pageNames);
}
}
开发者ID:plamikcho,项目名称:xbrlpoc,代码行数:17,代码来源:Visio2003Adapter.cs
示例17: FileOpen
public Stream FileOpen(string filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
{
#if WINDOWS_STORE_APP
var folder = ApplicationData.Current.LocalFolder;
if (fileMode == FileMode.Create || fileMode == FileMode.CreateNew)
{
return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult();
}
else if (fileMode == FileMode.OpenOrCreate)
{
if (fileAccess == FileAccess.Read)
return folder.OpenStreamForReadAsync(filePath).GetAwaiter().GetResult();
else
{
// Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning
var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult();
return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
}
}
else if (fileMode == FileMode.Truncate)
{
return folder.OpenStreamForWriteAsync(filePath, CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult();
}
else
{
//if (fileMode == FileMode.Append)
// Not using OpenStreamForReadAsync because the stream position is placed at the end of the file, instead of the beginning
folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult().OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
var f = folder.CreateFileAsync(filePath, CreationCollisionOption.OpenIfExists).AsTask().GetAwaiter().GetResult();
return f.OpenAsync(FileAccessMode.ReadWrite).AsTask().GetAwaiter().GetResult().AsStream();
}
#else
return File.Open(filePath, fileMode, fileAccess, fileShare);
#endif
}
开发者ID:jandujar,项目名称:AdrotatorV2,代码行数:35,代码来源:FileHelpers.cs
示例18: UpdateModeFlagFromFileAccess
/// <summary>
/// Utility function to update a grfMode value based on FileAccess.
/// 6/12/2002: Fixes bug #4938, 4960, 5096, 4858
/// </summary>
/// <param name="access">FileAccess we're translating</param>
/// <param name="grfMode">Mode flag parameter to modify</param>
// <SecurityNote>
// SecurityTreatAsSafe: Makes NO call to security suppressed unmanaged code
// </SecurityNote>
internal static void UpdateModeFlagFromFileAccess( FileAccess access, ref int grfMode )
{
// Supporting write-only scenarios container-wide gets tricky and it
// is rarely used. Don't support it for now because of poor
// cost/benefit ratio.
if( FileAccess.Write == access )
throw new NotSupportedException(
SR.Get(SRID.WriteOnlyUnsupported));
// Generate STGM from FileAccess
// STGM_READ is 0x00, so it's "by default"
if( ( FileAccess.ReadWrite == (access & FileAccess.ReadWrite) ) ||
( (FileAccess.Read | FileAccess.Write) == (access & (FileAccess.Read | FileAccess.Write))) )
{
grfMode |= SafeNativeCompoundFileConstants.STGM_READWRITE;
}
else if( FileAccess.Write == (access & FileAccess.Write) )
{
grfMode |= SafeNativeCompoundFileConstants.STGM_WRITE;
}
else if( FileAccess.Read != (access & FileAccess.Read))
{
throw new ArgumentException(
SR.Get(SRID.FileAccessInvalid));
}
}
开发者ID:JianwenSun,项目名称:cc,代码行数:35,代码来源:NativeCompoundFileAPIs.cs
示例19: 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="filePath">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 Stream OpenFileStream(string filePath, int retry, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
{
var delay = 0;
for(var i = 0; i < retry; i++)
{
try
{
var stream = new FileStream(filePath, fileMode, fileAccess, fileShare);
return stream;
}
catch(DirectoryNotFoundException)
{
CreateDirectoryStructure(filePath);
}
catch(FileNotFoundException)
{
throw;
}
catch(IOException)
{
delay += 100;
if(i == retry) throw;
}
Thread.Sleep(delay);
}
//We will never get here
throw new IOException(string.Format("Unable to open file '{0}'", filePath));
}
开发者ID:Worthaboutapig,项目名称:SquishIt,代码行数:43,代码来源:RetryableFileOpener.cs
示例20: 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;
}
}
开发者ID:richorama,项目名称:AzureFileDrive,代码行数:26,代码来源:AzureOperations.cs
注:本文中的FileAccess类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论