当前位置: 首页>>代码示例>>C#>>正文


C# FileOptions.HasFlag方法代码示例

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


在下文中一共展示了FileOptions.HasFlag方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LogFSActionInit

        DokanError IDokanOperations.CreateFile(string fileName, FileAccess access, FileShare share,
            FileMode mode, FileOptions options,
            FileAttributes attributes, DokanFileInfo info)
        {
            if (fileName.EndsWith("desktop.ini", StringComparison.OrdinalIgnoreCase) ||
                fileName.EndsWith("autorun.inf", StringComparison.OrdinalIgnoreCase)) //....
            {
                return DokanError.ErrorFileNotFound;
            }

            LogFSActionInit("OpenFile", fileName, (SftpContext)info.Context, "Mode:{0} Options:{1}", mode,options);

            string path = GetUnixPath(fileName);
            //  var  sftpFileAttributes = GetAttributes(path);
            //var sftpFileAttributes = _cache.Get(path) as SftpFileAttributes;
            var sftpFileAttributes = this.CacheGetAttr(path);

            if (sftpFileAttributes == null)
            {
                //Log("cache miss");

                sftpFileAttributes = GetAttributes(path);
                if (sftpFileAttributes != null)
                    //_cache.Add(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout));
                    CacheAddAttr(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout));
                else
                {
                    LogFSActionOther("OpenFile", fileName, (SftpContext)info.Context, "get attributes failed");
                }
            }
            /*Log("Open| Name:{0},\n Mode:{1},\n Share{2},\n Disp:{3},\n Flags{4},\n Attr:{5},\nPagingIO:{6} NoCache:{7} SynIO:{8}\n", fileName, access,
                share, mode, options, attributes, info.PagingIo, info.NoCache, info.SynchronousIo);*/

            switch (mode)
            {
                case FileMode.Open:
                    if (sftpFileAttributes != null)
                    {
                        if (((uint)access & 0xe0000027) == 0 || sftpFileAttributes.IsDirectory)
                        //check if only wants to read attributes,security info or open directory
                        {
                            //Log("JustInfo:{0},{1}", fileName, sftpFileAttributes.IsDirectory);
                            info.IsDirectory = sftpFileAttributes.IsDirectory;

                            if (options.HasFlag(FileOptions.DeleteOnClose))
                            {
                                return DokanError.ErrorError;//this will result in calling DeleteFile in Windows Explorer
                            }
                            info.Context = new SftpContext(sftpFileAttributes, false);

                            LogFSActionOther("OpenFile", fileName, (SftpContext)info.Context, "Dir open or get attrs");
                            return DokanError.ErrorSuccess;
                        }
                    }
                    else
                    {
                        LogFSActionError("OpenFile", fileName, (SftpContext)info.Context, "File not found");
                        return DokanError.ErrorFileNotFound;
                    }
                    break;
                case FileMode.CreateNew:
                    if (sftpFileAttributes != null)
                        return DokanError.ErrorAlreadyExists;

                    CacheResetParent(path);
                    break;
                case FileMode.Truncate:
                    if (sftpFileAttributes == null)
                        return DokanError.ErrorFileNotFound;
                    CacheResetParent(path);
                    //_cache.Remove(path);
                    this.CacheReset(path);
                    break;
                default:

                    CacheResetParent(path);
                    break;
            }
            //Log("NotJustInfo:{0}-{1}", info.Context, mode);
            try
            {
                info.Context = new SftpContext(_sftpSession, path, mode,
                                               ((ulong) access & 0x40010006) == 0
                                                   ? System.IO.FileAccess.Read
                                                   : System.IO.FileAccess.ReadWrite, sftpFileAttributes);
            }
            catch (SshException ex) // Don't have access rights or try to read broken symlink
            {
                var ownerpath = path.Substring(0, path.LastIndexOf('/'));
                //var sftpPathAttributes = _cache.Get(ownerpath) as SftpFileAttributes;
                var sftpPathAttributes = CacheGetAttr(ownerpath);

                if (sftpPathAttributes == null)
                {
                    //Log("cache miss");

                    sftpPathAttributes = GetAttributes(ownerpath);
                    if (sftpPathAttributes != null)
                        //_cache.Add(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout));
                        CacheAddAttr(path, sftpFileAttributes, DateTimeOffset.UtcNow.AddSeconds(_attributeCacheTimeout));
//.........这里部分代码省略.........
开发者ID:cpascal,项目名称:win-sshfs,代码行数:101,代码来源:SftpFilesystem.cs

示例2: Open

        /// <summary>
        /// Opens a <see cref="Open(string,System.IO.FileMode,System.IO.FileAccess)"/> on the specified path, having the specified mode with read, write, or read/write access and the specified sharing option.
        /// </summary>
        /// <param name="path">The file to open.</param>
        /// <param name="mode">A <see cref="FileMode"/> value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.</param>
        /// <param name="access">A <see cref="FileAccess"/> value that specifies the operations that can be performed on the file.</param>
        /// <param name="share">A <see cref="FileShare"/> value specifying the type of access other threads have to the file.</param>
        /// <param name="bufferSize">The number of bytes buffered for reads and writes to the file.</param>
        /// <param name="options">One of the <see cref="FileOptions"/> values that describes how to create or overwrite the file.</param>
        /// <returns>A <see cref="FileStream"/> on the specified path, having the specified mode with read, write, or read/write access and the specified sharing option.</returns>
        /// <exception cref="UnauthorizedAccessException">
        /// The caller does not have the required permission.
        ///     <para>-or-</para>
        /// <paramref name="path"/> specified a file that is read-only.
        ///     <para>-or-</para>
        /// <see cref="FileOptions.Encrypted"/> is specified for options and file encryption is not supported on the current platform.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="path"/> is a zero-length string, contains only white space, or contains one or more invalid characters as defined by <see cref="Path.GetInvalidPathChars"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
        /// <exception cref="PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.</exception>
        /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive.</exception>
        /// <exception cref="IOException">An I/O error occurred while creating the file.</exception>
        /// <exception cref="NotSupportedException"><paramref name="path"/> is in an invalid format.</exception>
        private static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (bufferSize <= 0)
            {
                bufferSize = LongPathFile.DefaultBufferSize;
            }

            string normalizedPath = LongPathCommon.NormalizePath(path);

            SafeFileHandle handle = LongPathFile.GetFileHandle(normalizedPath, mode, access, share, options);
            return new FileStream(handle, access, bufferSize, options.HasFlag(FileOptions.Asynchronous));
        }
开发者ID:aleksk,项目名称:LongPath,代码行数:40,代码来源:LongPathFile.cs


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