• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# FileOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中FileOptions的典型用法代码示例。如果您正苦于以下问题:C# FileOptions类的具体用法?C# FileOptions怎么用?C# FileOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileOptions类属于命名空间,在下文中一共展示了FileOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
 }
开发者ID:LaurentLeeJS,项目名称:Laurent.Lee.Framework,代码行数:12,代码来源:TmphFileBlockStream.cs


示例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;
            }
        }
开发者ID:richorama,项目名称:AzureFileDrive,代码行数:26,代码来源:AzureOperations.cs


示例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);
        }
开发者ID:AtsushiKan,项目名称:coreclr,代码行数:26,代码来源:FileStream.Unix.cs


示例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);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:SqlFileStream.cs


示例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;
        }
开发者ID:WishSummer,项目名称:FS,代码行数:59,代码来源:FSDrive.cs


示例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);
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:59,代码来源:FileStream.cs


示例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() );
 }
开发者ID:dbremner,项目名称:TransactionalFileManager,代码行数:8,代码来源:CreateFileOperation.cs


示例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));
 }
开发者ID:chcosta,项目名称:corefx,代码行数:10,代码来源:ctor_str_fm_fa_fs_buffer_fo.cs


示例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);
 }
开发者ID:akrisiun,项目名称:dotnet-cli,代码行数:10,代码来源:FileWrapper.cs


示例10: CreateFile

 public virtual int CreateFile(string filename, 
     FileAccess access, 
     FileShare share, 
     FileMode mode, 
     FileOptions options, 
     DokanFileInfo info)
 {
     try { return -1; }
     catch { return -1; }
 }
开发者ID:meowthsli,项目名称:tagfs,代码行数:10,代码来源:TaggedFileSystem.cs


示例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;
 }
开发者ID:daveroberts,项目名称:FUSEManager,代码行数:10,代码来源:LoggingFS.cs


示例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;
        }
开发者ID:JangWonWoong,项目名称:dokan-dotnet,代码行数:11,代码来源:Mirror.cs


示例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"]);
        }
开发者ID:martindevans,项目名称:dokan-gae-client,代码行数:11,代码来源:GaeFs.cs


示例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;
        }
开发者ID:Zapados,项目名称:SyncTrayzor,代码行数:11,代码来源:AtomicFileStream.cs


示例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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:12,代码来源:WinRTFileStream.cs


示例16: Trace

        private NtStatus Trace(string method, string fileName, DokanFileInfo info,
            FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes,
            NtStatus result)
        {
#if TRACE
            logger.Debug(
                DokanFormat(
                    $"{method}('{fileName}', {info}, [{access}], [{share}], [{mode}], [{options}], [{attributes}]) -> {result}"));
#endif

            return result;
        }
开发者ID:viciousviper,项目名称:dokan-dotnet,代码行数:12,代码来源:Mirror.cs


示例17: OpenHandle

        private FileStreamCompletionSource _currentOverlappedOwner; // async op currently using the preallocated overlapped

        private SafeFileHandle OpenHandle(FileMode mode, FileShare share, FileOptions options)
        {
            Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = GetSecAttrs(share);

            int fAccess =
                ((_access & FileAccess.Read) == FileAccess.Read ? GENERIC_READ : 0) |
                ((_access & FileAccess.Write) == FileAccess.Write ? GENERIC_WRITE : 0);

            // Our Inheritable bit was stolen from Windows, but should be set in
            // the security attributes class.  Don't leave this bit set.
            share &= ~FileShare.Inheritable;

            // Must use a valid Win32 constant here...
            if (mode == FileMode.Append)
                mode = FileMode.OpenOrCreate;

            int flagsAndAttributes = (int)options;

            // For mitigating local elevation of privilege attack through named pipes
            // make sure we always call CreateFile with SECURITY_ANONYMOUS so that the
            // named pipe server can't impersonate a high privileged client security context
            flagsAndAttributes |= (Interop.Kernel32.SecurityOptions.SECURITY_SQOS_PRESENT | Interop.Kernel32.SecurityOptions.SECURITY_ANONYMOUS);

            // Don't pop up a dialog for reading from an empty floppy drive
            uint oldMode = Interop.Kernel32.SetErrorMode(Interop.Kernel32.SEM_FAILCRITICALERRORS);
            try
            {
                SafeFileHandle fileHandle = Interop.Kernel32.SafeCreateFile(_path, fAccess, share, ref secAttrs, mode, flagsAndAttributes, IntPtr.Zero);
                fileHandle.IsAsync = _useAsyncIO;

                if (fileHandle.IsInvalid)
                {
                    // Return a meaningful exception with the full path.

                    // NT5 oddity - when trying to open "C:\" as a Win32FileStream,
                    // we usually get ERROR_PATH_NOT_FOUND from the OS.  We should
                    // probably be consistent w/ every other directory.
                    int errorCode = Marshal.GetLastWin32Error();

                    if (errorCode == Interop.Errors.ERROR_PATH_NOT_FOUND && _path.Equals(Directory.InternalGetDirectoryRoot(_path)))
                        errorCode = Interop.Errors.ERROR_ACCESS_DENIED;

                    throw Win32Marshal.GetExceptionForWin32Error(errorCode, _path);
                }

                return fileHandle;
            }
            finally
            {
                Interop.Kernel32.SetErrorMode(oldMode);
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:54,代码来源:FileStream.Win32.cs


示例18: Open

        public static AtomicFileStream Open(string path, string tempPath, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
        {
            if (access == FileAccess.Read)
                throw new ArgumentException("If you're just opening the file for reading, AtomicFileStream won't help you at all");

            if (File.Exists(tempPath))
                File.Delete(tempPath);

            if (File.Exists(path) && (mode == FileMode.Append || mode == FileMode.Open || mode == FileMode.OpenOrCreate))
                File.Copy(path, tempPath);

            return new AtomicFileStream(path, tempPath, mode, access, share, bufferSize, options);
        }
开发者ID:RipleyBooya,项目名称:SyncTrayzor,代码行数:13,代码来源:AtomicFileStream.cs


示例19: CreateFile

 public NtStatus CreateFile(
     string filename,
     FileAccess access,
     FileShare share,
     FileMode mode,
     FileOptions options,
     FileAttributes attributes,
     DokanFileInfo info)
 {
     if (info.IsDirectory && mode == FileMode.CreateNew)
         return DokanResult.AccessDenied;
     return DokanResult.Success;
 }
开发者ID:viciousviper,项目名称:dokan-dotnet,代码行数:13,代码来源:Program.cs


示例20: FromFile

 public static FileMap FromFile(string path, FileMapProtect prot, int offset, int length, FileOptions options)
 {
     FileStream stream;
     FileMap map;
     try { stream = new FileStream(path, FileMode.Open, (prot == FileMapProtect.ReadWrite) ? FileAccess.ReadWrite : FileAccess.Read, FileShare.Read, 8, options); }
     catch //File is currently in use, but we can copy it to a temp location and read that
     {
         string tempPath = Path.GetTempFileName();
         File.Copy(path, tempPath, true);
         stream = new FileStream(tempPath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, 8, options | FileOptions.DeleteOnClose);
     }
     try { map = FromStreamInternal(stream, prot, offset, length); }
     catch (Exception x) { stream.Dispose(); throw x; }
     map._path = path; //In case we're using a temp file
     return map;
 }
开发者ID:soneek,项目名称:Sm4sh-Tools,代码行数:16,代码来源:FileMap.cs



注:本文中的FileOptions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# FilePath类代码示例发布时间:2022-05-24
下一篇:
C# FileOffset类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap