public FileValueBinder(ParameterInfo parameter, FileAttribute attribute, FileInfo fileInfo)
     : base(parameter)
 {
     _parameter = parameter;
     _attribute = attribute;
     _fileInfo = fileInfo;
 }
 public FileBinding(FilesConfiguration config, ParameterInfo parameter, BindingTemplate bindingTemplate)
 {
     _config = config;
     _parameter = parameter;
     _bindingTemplate = bindingTemplate;
     _attribute = _parameter.GetCustomAttribute<FileAttribute>(inherit: false);
 }
        public void File_DefaultError_ReturnsDefaultErrorMessage()
        {
            var name = "File";

            var sut = new FileAttribute(new[] { FileType.Doc });

            var errorMessage = sut.FormatErrorMessage(name);

            Assert.AreEqual(string.Format(DataAnnotationsResources.FileAttribute_Invalid, name), errorMessage);
        }
        public void File_ErrorResource_ReturnsErrorResource()
        {
            var name = "File";
            var sut  = new FileAttribute(new[] { FileType.Doc })
            {
                ErrorMessageResourceName = "FileAttribute_InvalidFileModels", ErrorMessageResourceType = typeof(DataAnnotationsResources)
            };

            var errorMessage = sut.FormatErrorMessage(name);

            Assert.AreEqual(string.Format(DataAnnotationsResources.FileAttribute_InvalidFileModels, name), errorMessage);
        }
        public void File_ErrorMessage_ReturnsErrorMessage()
        {
            var errorMessageFormat = "My error";
            var sut = new FileAttribute(new[] { FileType.Doc })
            {
                ErrorMessage = errorMessageFormat
            };

            var errorMessage = sut.FormatErrorMessage(string.Empty);

            Assert.AreEqual(errorMessageFormat, errorMessage);
        }
        public void File_Rtf_Validates()
        {
            var validationContext = new ValidationContext(this, null, null);

            validationContext.DisplayName = "File";

            mockFile.Setup(m => m.FileName).Returns("file.rtf");
            mockFile.Setup(m => m.ContentLength).Returns(FileResources.RTF.Length);
            mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(new UTF8Encoding().GetBytes(FileResources.RTF)));

            var sut = new FileAttribute(new[] { FileType.Rtf });

            var valid = sut.GetValidationResult(mockFile.Object, validationContext);

            Assert.AreEqual(ValidationResult.Success, valid);
        }
        /// <summary>
        /// Provide a text field that operates like a button which opens a file dialogue
        /// A help box is shown when the resulting string is invalid
        /// </summary>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            FileAttribute dA = (FileAttribute)attribute;
            Rect          r  = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

            EditorGUI.PropertyField(r, property, GUIContent.none);
            r.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

            if (string.IsNullOrEmpty(property.stringValue) || !File.Exists(property.stringValue))
            {
                string path = dA.FileIsLocalToProject ? "Assets" : Application.dataPath;

                property.stringValue = FileButton(r, property, dA, path);
                r.y      += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                r.height *= 2;
                EditorGUI.HelpBox(r, "File is invalid or has not been not set", MessageType.Error);
                property.stringValue = FileButton(default, property, dA, property.stringValue, true);
        public void File_RtfWithDrawing_Fails()
        {
            var validationContext = new ValidationContext(this, null, null);

            validationContext.DisplayName = "File";

            mockFile.Setup(m => m.FileName).Returns("file.rtf");
            mockFile.Setup(m => m.ContentLength).Returns(FileResources.RTF_Drawing.Length);
            mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(new UTF8Encoding().GetBytes(FileResources.RTF_Drawing)));

            var sut = new FileAttribute(new[] { FileType.Rtf });

            var valid = sut.GetValidationResult(mockFile.Object, validationContext);

            Assert.IsNotNull(valid);
            Assert.AreEqual(string.Format(DataAnnotationsResources.FileAttribute_InvalidRtfImage, validationContext.DisplayName), valid.ErrorMessage);
        }
        public static int GetAttributeId(SQLiteConnection db, string name)
        {
            if (_fileAttributes == null) {
                _fileAttributes = new List<FileAttribute>();
                _fileAttributes.AddRange(db.Table<FileAttribute>());
            }

            var fi = _fileAttributes.FirstOrDefault(item => item.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
            if (fi == null) {
                fi = new FileAttribute() {
                    Name = name
                };
                db.Insert(fi);
                _fileAttributes.Add(fi);
            }
            return fi.AttributeId;
        }
        public void File_Png_Validates()
        {
            var validationContext = new ValidationContext(this, null, null);

            validationContext.DisplayName = "File";

            var data = (byte[])new ImageConverter().ConvertTo(FileResources.PNG, typeof(byte[]));

            mockFile.Setup(m => m.FileName).Returns("file.png");
            mockFile.Setup(m => m.ContentLength).Returns(data.Length);
            mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(data));

            var sut = new FileAttribute(new[] { FileType.Png });

            var valid = sut.GetValidationResult(mockFile.Object, validationContext);

            Assert.AreEqual(ValidationResult.Success, valid);
        }
        public void File_ExpectingRtfButGetGif_Fails()
        {
            var validationContext = new ValidationContext(this, null, null);

            validationContext.DisplayName = "File";

            var data = (byte[])new ImageConverter().ConvertTo(FileResources.GIF, typeof(byte[]));

            mockFile.Setup(m => m.FileName).Returns("file.gif");
            mockFile.Setup(m => m.ContentLength).Returns(data.Length);
            mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(data));

            var sut = new FileAttribute(new[] { FileType.Rtf });

            var valid = sut.GetValidationResult(mockFile.Object, validationContext);

            Assert.AreNotEqual(ValidationResult.Success, valid);
            Assert.IsNotNull(valid);
            Assert.IsTrue(!string.IsNullOrEmpty(valid.ErrorMessage));
        }
        public string GetAttribute(FileAttribute a, string format)
        {
            string result = string.Empty;

            PropertyInfo pi = null;

            try
            {
                pi = fi.GetType().GetProperty(a.Name) as PropertyInfo;
            }
            catch
            {
            }

            if (pi == null)
            {
                return(string.Empty);
            }

            var name = pi.GetValue(fi, null).ToString();

            Regex rx = new Regex(@"WP_(\d{8})_.*\.mp4");

            var match = rx.Match(name);

            if (!match.Success)
            {
                return(result);
            }

            var matchValue = match.Groups[1].Value;

            DateTime tempOut = DateTime.MinValue;

            if (!DateTime.TryParseExact(matchValue, "yyyyMMdd", new CultureInfo("en-US"), DateTimeStyles.None, out tempOut))
            {
                return(result);
            }

            return(tempOut.ToString(format));
        }
 internal static MessageStatus WorkaroundCreateFile(FileNameStatus fileNameStatus, CreateOptions createOption, FileAccess desiredAccess, FileType openFileType, FileAttribute desiredFileAttribute, MessageStatus returnedStatus, ITestSite site)
 {
     if (openFileType == FileType.DirectoryFile && desiredFileAttribute == FileAttribute.TEMPORARY)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(507, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT
        && desiredAccess == FileAccess.FILE_READ_DATA)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(369, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT
        && desiredAccess == FileAccess.FILE_READ_DATA)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(2373, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.DELETE_ON_CLOSE &&
         (desiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY))
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(371, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT))
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(373, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER))
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(507, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING &&
         (desiredAccess == FileAccess.FILE_APPEND_DATA || desiredAccess == FileAccess.FILE_ADD_SUBDIRECTORY))
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(376, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     return returnedStatus;
 }
        public void File_RtfBlueword_Fails()
        {
            mockAdwService.Setup(m => m.GetRelatedCodes("OFTW", "UNA")).Returns(new List <RelatedCodeModel> {
                new RelatedCodeModel {
                    Dominant = true, DominantCode = "DominantCode", SubordinateDescription = "foo", RelatedCode = "OFTW", SubordinateCode = "UNA"
                }
            });

            var validationContext = new ValidationContext(this, null, null);

            validationContext.DisplayName = "File";

            mockFile.Setup(m => m.FileName).Returns("file.rtf");
            mockFile.Setup(m => m.ContentLength).Returns(FileResources.RTF.Length);
            mockFile.Setup(m => m.InputStream).Returns(new MemoryStream(new UTF8Encoding().GetBytes(FileResources.RTF)));

            var sut = new FileAttribute(new[] { FileType.Rtf });

            var valid = sut.GetValidationResult(mockFile.Object, validationContext);

            Assert.AreEqual(string.Format(DataAnnotationsResources.BlueWordAttribute_InvalidWithBlueWords, validationContext.DisplayName, "foo"), valid.ErrorMessage);
        }
Beispiel #15
0
 /// <summary>
 /// 文件包初始化--每次文件传输最大按200字节计算
 /// </summary>
 /// <param name="attribute">文件属性</param>
 /// <param name="fileData">文件数据</param>
 public FilePacketManager(FileAttribute attribute, byte[] fileData)
     : this(attribute)
 {
     try
     {
         if (fileData.Length == 0)
         {
             throw new ArgumentException("打包数据长度不能为0");
         }
         int max    = 200;
         int count  = fileData.Length / max;
         int remain = fileData.Length % max;
         for (int i = 0; i < count; i++)
         {
             UInt32 frage  = (UInt32)(i * max);
             var    packet = new FileDataThransmitPacket(OperatSign.WriteFileThransmit, mAttribute.ID,
                                                         frage, FllowingFlag.Exist, fileData, (int)frage, max);
             listPacket.Add(packet);
             addCount = (UInt32)(addCount + max);
         }
         if (remain != 0)
         {
             UInt32 frage  = (UInt32)(count * max);
             var    packet = new FileDataThransmitPacket(OperatSign.WriteFileThransmit, mAttribute.ID,
                                                         frage, FllowingFlag.Nothing, fileData, (int)frage, remain);
             addCount = (UInt32)(addCount + remain);
         }
         else
         {
             CurrentPacket.Fllow = FllowingFlag.Nothing;
         }
         fullFlag = true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #16
0
        /// <summary>
        ///     Reads a file from the <paramref name="reader"/>.
        /// </summary>
        /// <param name="reader">The reader from which to read the file.</param>
        /// <returns>The file.</returns>
        internal static File ReadFile(this MessageReader <MessageCode.Peer> reader)
        {
            var code      = reader.ReadByte();
            var filename  = reader.ReadString();
            var size      = reader.ReadLong();
            var extension = reader.ReadString();

            // check for an overflow, most likely sent from Soulseek NS due to a file size
            // exceeding 2gb.
            if (size < 0)
            {
                var sizeBytes = BitConverter.GetBytes(size);

                if (sizeBytes.Skip(4).All(b => b == 0xFF))
                {
                    size = BitConverter.ToUInt32(sizeBytes.Take(4).ToArray(), 0);
                }
            }

            var attributeCount = reader.ReadInteger();
            var attributeList  = new List <FileAttribute>();

            for (int i = 0; i < attributeCount; i++)
            {
                var attribute = new FileAttribute(
                    type: (FileAttributeType)reader.ReadInteger(),
                    value: reader.ReadInteger());

                attributeList.Add(attribute);
            }

            return(new File(
                       code,
                       filename,
                       size,
                       extension,
                       attributeList));
        }
 public static extern IntPtr CreateFile(string fileName,
   AccessMode desiredAccess, ShareMode shareMode, IntPtr securityAttributes,
   CreationMode creationDisposition, FileAttribute flagsAndAttributes,
   IntPtr templateFilehandle);
        public static MessageStatus CreateFile(
            FileAttribute desiredFileAttribute,
            CreateOptions createOption,
            StreamTypeNameToOPen streamTypeNameToOPen,
            FileAccess desiredAccess,
            ShareAccess shareAccess,
            CreateDisposition createDisposition,
            StreamFoundType streamFoundType,
            SymbolicLinkType symbolicLinkType,
            FileType openFileType,
            FileNameStatus fileNameStatus
            )
        {
            MessageStatus status = OpenFileinitial(
            desiredAccess,
            shareAccess,
            createOption,
            createDisposition,
            desiredFileAttribute,
            streamFoundType,
            symbolicLinkType,
            streamTypeNameToOPen,
            openFileType,
            fileNameStatus);

            if (status != MessageStatus.SUCCESS)
            {
                return status;
            }

            #region Pseudocode for the operation

            //If FileTypeToOpen is DirectoryFile and DesiredFileAttributes.FILE_ATTRIBUTE_TEMPORARY is set
            if (gfileTypeToOpen == FileType.DirectoryFile &&
                desiredFileAttribute == FileAttribute.TEMPORARY)
            {
                Helper.CaptureRequirement(418, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If FileTypeToOpen is DirectoryFile and DesiredFileAttributes.FILE_ATTRIBUTE_TEMPORARY is set, the operation MUST be failed with STATUS_INVALID_PARAMETER.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If DesiredFileAttributes.FILE_ATTRIBUTE_READONLY and CreateOptions.FILE_DELETE_ON_CLOSE
            //are both set
            if (desiredFileAttribute == FileAttribute.READONLY &&
                createOption == CreateOptions.DELETE_ON_CLOSE)
            {
                Helper.CaptureRequirement(419, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If DesiredFileAttributes.FILE_ATTRIBUTE_READONLY and CreateOptions.FILE_DELETE_ON_CLOSE are both set, the operation MUST be failed with STATUS_CANNOT_DELETE.");
                return MessageStatus.CANNOT_DELETE;
            }

            //If StreamTypeNameToOpen is non-empty and has a value other than "$DATA" or
            //"$INDEX_ALLOCATION", the operation MUST be failed with STATUS_ACCESS_DENIED.
            if (streamTypeNameToOPen == StreamTypeNameToOPen.Other)
            {
                Helper.CaptureRequirement(420, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If StreamTypeNameToOpen is non-empty and has a value other than \""$DATA"",the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.OBJECT_NAME_INVALID;
            }

            //If Open.RemainingDesiredAccess.ACCESS_SYSTEM_SECURITY is set and
            //Open.GrantedAccess.ACCESS_SYSTEM_SECURITY is not set and
            //SecurityContext.PrivilegeSet does not contain "SeSecurityPrivilege"
            //3 indicate SeBackupPrivilege and SeRestorePrivilege
            if (gOpenRemainingDesiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY &&
                gOpenGrantedAccess == FileAccess.FILE_APPEND_DATA &&
                gSecurityContext.privilegeSet == (PrivilegeSet.SeBackupPrivilege | PrivilegeSet.SeRestorePrivilege))
            {
                Helper.CaptureRequirement(422, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If Open.RemainingDesiredAccess.ACCESS_SYSTEM_SECURITY is set and Open.GrantedAccess.ACCESS_SYSTEM_SECURITY is not set and SecurityContext.PrivilegeSet does not contain \""SeSecurityPrivilege"", the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            //If FileTypeToOpen is DataFile and Open.GrantedAccess.FILE_ADD_FILE is not set
            //and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor,
            //FILE_ADD_FILE ) returns FALSE and Open.HasRestoreAccess is FALSE

            if (gfileTypeToOpen == FileType.DataFile &&
                gOpenGrantedAccess == FileAccess.FILE_ADD_SUBDIRECTORY &&
                !isOpenHasRestoreAccess)
            {
                Helper.CaptureRequirement(423, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                    If FileTypeToOpen is DataFile and Open.GrantedAccess.FILE_ADD_FILE is not set and
                    AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_ADD_FILE )
                    returns FALSE and Open.HasRestoreAccess is FALSE, the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            //If FileTypeToOpen is DirectoryFile and Open.GrantedAccess.FILE_ADD_SUBDIRECTORY
            //is not set and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor,
            //FILE_ADD_SUBDIRECTORY ) returns FALSE and Open.HasRestoreAccess is FALSE

            if (gfileTypeToOpen == FileType.DirectoryFile &&
                gOpenGrantedAccess == FileAccess.FILE_ADD_FILE &&
                !isOpenHasRestoreAccess)
            {
                Helper.CaptureRequirement(424, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                   If FileTypeToOpen is DirectoryFile and Open.GrantedAccess.FILE_ADD_SUBDIRECTORY is not set and
                   AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_ADD_SUBDIRECTORY )
                   returns FALSE and Open.HasRestoreAccess is FALSE, the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            if (streamTypeNameToOPen == StreamTypeNameToOPen.DATA ||
                streamTypeNameToOPen == StreamTypeNameToOPen.NULL)
            {
                gStreamType = StreamType.DataStream;
            }
            else
            {
                gStreamType = StreamType.DirectoryStream;
            }

            gFileAttribute = desiredFileAttribute;
            Helper.CaptureRequirement(475, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                The object store MUST return:CreateAction set to FILE_CREATED.");
            gCreateAction = CreateAction.CREATED;

            #endregion

            Helper.CaptureRequirement(474, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                The object store MUST return :Status set to STATUS_SUCCESS.");
            return MessageStatus.SUCCESS;
        }
Beispiel #19
0
 public static extern UInt32 SetAttribute(IntPtr inDirItemRef, FileAttribute inFileAttribute);
Beispiel #20
0
 public static extern UInt32 GetAttribute(IntPtr inDirItemRef, out FileAttribute outFileAttribute);
Beispiel #21
0
 private static extern IntPtr SHGetFileInfo(string pszPath, FileAttribute dwFileAttributes, ref SHFileInfo sfi, uint cbFileInfo, SHFileInfoFlags uFlags);
Beispiel #22
0
 /// <summary>         
 /// 获取文件类型         
 /// </summary>         
 /// <param name="path">文件名</param>         
 /// <param name="dwAttr">文件信息</param>         
 /// <param name="dwFlag">信息控制字</param>        
 /// <returns></returns>         
 private static string GetTypeName(string path, FileAttribute dwAttr, SHFileInfoFlags dwFlag)
 {
     try
     {
         SHFileInfo fi = new SHFileInfo();
         int iTotal = (int)SHGetFileInfo(path, dwAttr, ref fi, 0, dwFlag);
         if (iTotal > 0)
         {
             return fi.szTypeName;
         }
         else
         {
             return "";
         }
     }
     catch
     {
         return "";
     }
 }
 public static extern IntPtr SHGetFileInfo(string pszPath, FileAttribute dwFileAttributes, ref ShFileInfo sfi, int cbFileInfo, SHGFI uFlags);
	public static void SetAttr(string PathName, FileAttribute Attributes) {}
	public static string Dir(string PathName, FileAttribute Attributes) {}
 internal static MessageStatus WorkaroundOpenExistingFile(ShareAccess shareAccess, FileAccess desiredAccess,
     bool streamFound, bool isSymbolicLink, FileType openFileType, FileNameStatus fileNameStatus,
     CreateOptions existingOpenModeCreateOption, ShareAccess existOpenShareModeShareAccess,
     FileAccess existOpenDesiredAccess, CreateOptions createOption, CreateDisposition createDisposition,
     StreamTypeNameToOPen streamTypeNameToOPen, FileAttribute fileAttribute,
     FileAttribute desiredFileAttribute, MessageStatus returnedStatus, ITestSite site)
 {
     if (shareAccess == ShareAccess.FILE_SHARE_READ && desiredAccess == FileAccess.FILE_ADD_SUBDIRECTORY
         && !streamFound && !isSymbolicLink && openFileType == FileType.DataFile && fileNameStatus == FileNameStatus.Normal
         && existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && existOpenShareModeShareAccess == ShareAccess.FILE_SHARE_READ
         && existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING
         && createDisposition == CreateDisposition.OPEN_IF && streamTypeNameToOPen == StreamTypeNameToOPen.NULL
         && fileAttribute == FileAttribute.NORMAL && desiredFileAttribute == FileAttribute.NORMAL)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(376, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT))
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(373, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT
        && desiredAccess == FileAccess.FILE_READ_DATA)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(369, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT
         && desiredAccess == FileAccess.FILE_READ_DATA)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(2373, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.DELETE_ON_CLOSE &&
         (desiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY))
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(371, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER))
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (streamFound && !isSymbolicLink && openFileType == FileType.DataFile &&
         existingOpenModeCreateOption == CreateOptions.DIRECTORY_FILE &&
         existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY &&
         createOption == CreateOptions.DIRECTORY_FILE)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.ACCESS_VIOLATION, returnedStatus, site);
     }
     else if (!streamFound && !isSymbolicLink && openFileType == FileType.DataFile &&
         existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE &&
         existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY &&
         createOption == CreateOptions.NON_DIRECTORY_FILE &&
         fileAttribute == FileAttribute.READONLY)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(375, MessageStatus.ACCESS_DENIED, returnedStatus, site);
     }
     return returnedStatus;
 }
 public static void SetAttr(string PathName, FileAttribute Attributes)
 {
     if ((PathName == null) || (PathName.Length == 0))
     {
         throw ExceptionUtils.VbMakeException(new ArgumentException(Utils.GetResourceString("Argument_PathNullOrEmpty")), 0x34);
     }
     Assembly callingAssembly = Assembly.GetCallingAssembly();
     VB6CheckPathname(ProjectData.GetProjectData().GetAssemblyData(callingAssembly), PathName, OpenMode.Input);
     if ((Attributes | (FileAttribute.Archive | FileAttribute.System | FileAttribute.Hidden | FileAttribute.ReadOnly)) != (FileAttribute.Archive | FileAttribute.System | FileAttribute.Hidden | FileAttribute.ReadOnly))
     {
         throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Attributes" }));
     }
     FileAttributes fileAttributes = (FileAttributes) Attributes;
     File.SetAttributes(PathName, fileAttributes);
 }
        public static MessageStatus OpenFileinitial(
            FileAccess desiredAccess,
            ShareAccess shareAccess,
            CreateOptions createOption,
            CreateDisposition createDisposition,
            FileAttribute fileAttribute,
            StreamFoundType streamFoundType,
            SymbolicLinkType symbolicLinkType,
            StreamTypeNameToOPen streamTypeNameToOPen,
            FileType openFileType,
            FileNameStatus fileNameStatus)
        {
            #region phase 1  Parameter Validation

            //If DesiredAccess is not a valid value as specified in MS-SMB2 section 2.2.13.1
            if (desiredAccess == FileAccess.None)
            {
                Helper.CaptureRequirement(366, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]If any of the bits in the mask 0x0CE0FE00 are set,
                    the operation MUST be failed with STATUS_ACCESS_DENIED.");
                //If DesiredAccess is zero
                Helper.CaptureRequirement(377, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]If DesiredAccess is zero, the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            //If ShareAccess is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (shareAccess == ShareAccess.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(2370, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If ShareAccess are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (createOption == CreateOptions.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(2371, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateDisposition is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (createDisposition == CreateDisposition.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(2372, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateDisposition are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If FileAttributes is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (fileAttribute == FileAttribute.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(404, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If FileAttributes are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE.
            //65 indicates CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE
            if (createOption == (CreateOptions.DIRECTORY_FILE | CreateOptions.NON_DIRECTORY_FILE))
            {
                Helper.CaptureRequirement(368, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && !DesiredAccess.SYNCHRONIZE.
            //updated by meying:desiredAccess == FileAccess.FILE_READ_DATA
            if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT
               && desiredAccess == FileAccess.FILE_READ_DATA)
            {
                Helper.CaptureRequirement(369, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && !DesiredAccess.SYNCHRONIZE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If Create.FILE_SYNCHRONOUS_IO_NONALERT && !DesiredAccess.SYNCHRONIZE.
            //updated by meying:desiredAccess == FileAccess.FILE_READ_DATA
            if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT
               && desiredAccess == FileAccess.FILE_READ_DATA)
            {
                Helper.CaptureRequirement(2373, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If Create.FILE_SYNCHRONOUS_IO_NONALERT&& !DesiredAccess.SYNCHRONIZE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DELETE_ON_CLOSE && !DesiredAccess.DELETE.
            if (createOption == CreateOptions.DELETE_ON_CLOSE &&
                (desiredAccess == FileAccess.FILE_READ_DATA))
            {
                Helper.CaptureRequirement(371, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DELETE_ON_CLOSE && !DesiredAccess.DELETE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT
            //48 indicates CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT
            if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT))
            {
                Helper.CaptureRequirement(373, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE.
            if (createOption == CreateOptions.DIRECTORY_FILE &&
                createDisposition == CreateDisposition.OVERWRITE)
            {
                Helper.CaptureRequirement(2375, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == NONE .
            if (createOption == CreateOptions.DIRECTORY_FILE &&
                createDisposition == CreateDisposition.SUPERSEDE)
            {
                Helper.CaptureRequirement(2374, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == SUPERSEDE .");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE_IF.
            if (createOption == CreateOptions.DIRECTORY_FILE &&
                createDisposition == CreateDisposition.OVERWRITE_IF)
            {
                Helper.CaptureRequirement(2376, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE_IF).");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER
            //if ((createOption & (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) != 0)
            //1048832 indicates CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER
            if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER))
            {
                Helper.CaptureRequirement(375, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING && DesiredAccess.FILE_APPEND_DATA.
            if (createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING &&
                desiredAccess == FileAccess.FILE_APPEND_DATA)
            {
                Helper.CaptureRequirement(376, @"[In Application Requests an Open of a File ,Phase 1 - Parameter Validation:]
                    The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING && DesiredAccess.FILE_APPEND_DATA.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If PathName is not valid as specified in [MS-FSCC] section 2.1.5.
            if (fileNameStatus == FileNameStatus.NotPathNameValid)
            {
                Helper.CaptureRequirement(379, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under any of the following conditions:
                    If PathName is not valid as specified in [MS-FSCC] section 2.1.5.");
                return MessageStatus.OBJECT_NAME_INVALID;
            }

            //If PathName contains a trailing backslash and CreateOptions.FILE_NON_DIRECTORY_FILE is true
            if (fileNameStatus == FileNameStatus.BlacklashName &&
                createOption == CreateOptions.NON_DIRECTORY_FILE &&
                desiredAccess == FileAccess.FILE_READ_DATA)
            {
                Helper.CaptureRequirement(380, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under any of the following conditions:
                    If PathName contains a trailing backslash and CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE.");
                return MessageStatus.OBJECT_NAME_INVALID;
            }

            #endregion

            #region phase 2  Volume State

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == FILE_CREATE)
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.CREATE))
            {
                Helper.CaptureRequirement(2377, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly && CreateDisposition == FILE_CREATE,then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == FILE_SUPERSEDE)
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.SUPERSEDE))
            {
                Helper.CaptureRequirement(2378, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly &&CreateDisposition == FILE_SUPERSEDE, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == OVERWRITE)
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.OVERWRITE))
            {
                Helper.CaptureRequirement(2379, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly &&CreateDisposition == OVERWRITE, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == OVERWRITE_IF)
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.OVERWRITE_IF))
            {
                Helper.CaptureRequirement(2380, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly &&CreateDisposition == OVERWRITE_IF, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            #endregion

            #region Phase 3  Initialization of Open Object

            gOpenRemainingDesiredAccess = desiredAccess;
            gOpenSharingMode = shareAccess;
            //4158 indicates (createOption & (CreateOptions.WRITE_THROUGH |
            //CreateOptions.SEQUENTIAL_ONLY | CreateOptions.NO_INTERMEDIATE_BUFFERING |
            //CreateOptions.SYNCHRONOUS_IO_ALERT | CreateOptions.SYNCHRONOUS_IO_NONALERT |
            //CreateOptions.DELETE_ON_CLOSE));

            gOpenMode = (CreateOptions.WRITE_THROUGH |
            CreateOptions.SEQUENTIAL_ONLY | CreateOptions.NO_INTERMEDIATE_BUFFERING |
            CreateOptions.SYNCHRONOUS_IO_ALERT | CreateOptions.SYNCHRONOUS_IO_NONALERT |
            CreateOptions.DELETE_ON_CLOSE);
            if (gSecurityContext.privilegeSet == PrivilegeSet.SeBackupPrivilege)
            {
                isOpenHasBackupAccess = true;
            }

            if (gSecurityContext.privilegeSet == PrivilegeSet.SeRestorePrivilege)
            {
                isOpenHasRestoreAccess = true;
            }

            if (gSecurityContext.privilegeSet == PrivilegeSet.SeCreateSymbolicLinkPrivilege)
            {
                isOpenHasCreateSymbolicLinkAccess = true;
            }

            if (gSecurityContext.privilegeSet == PrivilegeSet.SeManageVolumePrivilege)
            {
                isOpenHasManageVolumeAccess = true;
            }

            if (gSecurityContext.isSecurityContextSIDsContainWellKnown)
            {
                isOpenIsAdministrator = true;
            }

            #endregion

            #region phase 4  Check for backup/restore intent

            //If CreateOptions.FILE_OPEN_FOR_BACKUP_INTENT is set and (CreateDisposition ==
            //FILE_OPEN || CreateDisposition == FILE_OPEN_IF || CreateDisposition ==
            //FILE_OVERWRITE_IF) and Open.HasBackupAccess is true, then the object store
            //SHOULD grant backup access as shown in the following pseudocode:
            if (createOption == CreateOptions.OPEN_FOR_BACKUP_INTENT &&
                (createDisposition == CreateDisposition.OPEN ||
                createDisposition == CreateDisposition.OPEN_IF ||
                createDisposition == CreateDisposition.OVERWRITE_IF) && isOpenHasBackupAccess)
            {
                //2164391968 indicates FileAccess.READ_CONTROL |
                //FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_READ |
                //FileAccess.FILE_TRAVERSE;
                FileAccess BackupAccess = FileAccess.READ_CONTROL |
                FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_READ |
                FileAccess.FILE_TRAVERSE;

                if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED)
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | BackupAccess;
                }
                else
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | (gOpenRemainingDesiredAccess & BackupAccess);
                }

                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess);
            }

            //If CreateOptions.FILE_OPEN_FOR_BACKUP_INTENT is set and Open.HasRestoreAccess is true,
            //then the object store SHOULD grant restore access as shown in the following pseudocode:
            if (createOption == CreateOptions.OPEN_FOR_BACKUP_INTENT && isHasRestoreAccess)
            {
                //1091309574 indicates FileAccess.WRITE_DAC | FileAccess.WRITE_OWNER |
                //FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_WRITE |
                //FileAccess.FILE_ADD_FILE | FileAccess.FILE_ADD_SUBDIRECTORY |
                //FileAccess.DELETE
                FileAccess RestoreAccess = FileAccess.WRITE_DAC | FileAccess.WRITE_OWNER |
                FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_WRITE |
                FileAccess.FILE_ADD_FILE | FileAccess.FILE_ADD_SUBDIRECTORY |
                FileAccess.DELETE;

                if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED)
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | RestoreAccess;
                }
                else
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | (gOpenRemainingDesiredAccess & RestoreAccess);
                }

                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess);
            }

            #endregion

            #region phase 5  Parse path name

            //If any StreamTypeNamei is "$INDEX_ALLOCATION" and the corresponding
            //StreamNamei has a value other than an empty string or "$I30"
            if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION)
            {
                if (sutPlatForm != PlatformType.NoneWindows)
                {
                    Helper.CaptureRequirement(507, @"[In Application Requests an Open of a File ,Phase 5 -- Parse path name:]
                        If any StreamTypeNamei is \""$INDEX_ALLOCATION"" and the corresponding StreamNamei has a value other than an empty string
                        or \""$I30"", the operation is failed with STATUS_INVALID_PARAMETER in Windows.");
                    return MessageStatus.INVALID_PARAMETER;
                }
                else if (isR507Implemented)
                {
                    Helper.CaptureRequirement(392, @"[In Application Requests an Open of a File ,Phase 5 -- Parse path name:]
                        If any StreamTypeNamei is \""$INDEX_ALLOCATION"" and the corresponding StreamNamei has a value other than an empty string
                        or \""$I30\"", the operation SHOULD be failed with STATUS_INVALID_PARAMETER.");
                    return MessageStatus.INVALID_PARAMETER;
                }
            }

            #endregion

            #region phase 6  Location of file

            if (streamFoundType == StreamFoundType.StreamIsNotFound)
            {
                //If (CreateDisposition == FILE_OPEN )
                if (createDisposition == CreateDisposition.OPEN)
                {
                    Helper.CaptureRequirement(513, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Else:[If such a link is not found:]
                        If CreateDisposition == FILE_OPEN, the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND.");
                    return MessageStatus.OBJECT_NAME_NOT_FOUND;
                }

                //If (CreateDisposition == FILE_OVERWRITE)
                if (createDisposition == CreateDisposition.OVERWRITE)
                {
                    Helper.CaptureRequirement(2395, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Else:[If such a link is not found:]If CreateDisposition == FILE_OVERWRITE),
                        the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND.");
                    return MessageStatus.OBJECT_NAME_NOT_FOUND;
                }

                //If RootOpen.Volume.IsReadOnly
                if (isFileVolumeReadOnly)
                {
                    Helper.CaptureRequirement(514, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Else:[If such a link is not found:]If RootOpen.Volume.IsReadOnly
                        then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                    return MessageStatus.MEDIA_WRITE_PROTECTED;
                }

                //Helper.CaptureRequirement(547, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:Phase 6 -- Location of file:] for this search is as follows:For i = 1 to n-1:Search ParentFile.DirectoryList for a Link where Link.Name or Link.ShortName matches FileNamei,If no such link is found, the operation MUST be failed with STATUS_OBJECT_PATH_NOT_FOUND.");
                //return MessageStatus.OBJECT_PATH_NOT_FOUND;
            }

            //If Open.GrantedAccess.FILE_TRAVERSE is not set and
            //AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE )
            //returns FALSE,
            if ((gOpenGrantedAccess & FileAccess.FILE_TRAVERSE) == 0)
            {
                if (sutPlatForm != PlatformType.NoneWindows)
                {
                    Helper.CaptureRequirement(405, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Pseudocode for this search:For i = 1 to n-1:
                        If Open.GrantedAccess.FILE_TRAVERSE is not set and AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE )
                        returns FALSE, the operation is not  failed with STATUS_ACCESS_DENIED in Windows.");
                }
                if (isR405Implemented)
                {
                    Helper.CaptureRequirement(397, @"[In Application Requests an Open of a File ,
                        Pseudocode for the operation is as follows:Phase 6 -- Location of file:]
                        Pseudocode for this search:For i = 1 to n-1:If Open.GrantedAccess.FILE_TRAVERSE is not set
                        and AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE ) returns FALSE, the operation MAY be failed with STATUS_ACCESS_DENIED.");
                    return MessageStatus.ACCESS_DENIED;
                }
            }
            //If Link.File.IsSymbolicLink is true
            if (symbolicLinkType == SymbolicLinkType.IsSymbolicLink)
            {
                Helper.CaptureRequirement(399, @"[In Application Requests an Open of a File ,
                     Pseudocode for the operation is as follows:Phase 6 - Location of file:]
                     Pseudocode for this search:For i = 1 to n-1:If Link.File.IsSymbolicLink is TRUE,
                     the operation MUST be failed with Status set to STATUS_STOPPED_ON_SYMLINK .");
                return MessageStatus.STOPPED_ON_SYMLINK;
            }

            #endregion

            #region phase 7  Type of file to open

            //If CreateOptions.FILE_DIRECTORY_FILE is true
            if (createOption == CreateOptions.DIRECTORY_FILE)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //Else if CreateOptions.FILE_NON_DIRECTORY_FILE is true
            else if (createOption == CreateOptions.NON_DIRECTORY_FILE)
            {
                gfileTypeToOpen = FileType.DataFile;
            }
            //Else if StreamTypeNameToOpen is "$INDEX_ALLOCATION"
            else if (streamTypeNameToOPen == StreamTypeNameToOPen.INDEX_ALLOCATION)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //Else if StreamTypeNameToOpen is "$DATA"
            else if (streamTypeNameToOPen == StreamTypeNameToOPen.DATA)
            {
                gfileTypeToOpen = FileType.DataFile;
            }
            //Else if Open.File is not NULL and Open.File.FileType is DirectoryFile
            else if (fileNameStatus == FileNameStatus.OpenFileNotNull &&
                openFileType == FileType.DirectoryFile)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //Else if PathName contains a trailing backslash
            else if (fileNameStatus == FileNameStatus.PathNameTraiblack)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //else
            else
            {
                gfileTypeToOpen = FileType.DataFile;
            }

            //If FileTypeToOpen is DirectoryFile and Open.File is not NULL and
            //Open.File.FileType is not DirectoryFile:
            if (gfileTypeToOpen == FileType.DirectoryFile &&
                fileNameStatus == FileNameStatus.OpenFileNotNull &&
                openFileType == FileType.DataFile)
            {
                //If CreateDisposition == FILE_CREATE
                if (createDisposition == CreateDisposition.CREATE)
                {
                    Helper.CaptureRequirement(414, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 7 -- Type of file to open:]If FileTypeToOpen is DirectoryFile and Open.File is not NULL
                        and Open.File.FileType is not DirectoryFile:If CreateDisposition == FILE_CREATE then the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION.");
                    return MessageStatus.OBJECT_NAME_COLLISION;
                }
                //else
                else
                {
                    Helper.CaptureRequirement(2396, @"[In Application Requests an Open of a File , Phase 7 -- Type of file to open:]
                        If FileTypeToOpen is DirectoryFile and Open.File is not NULL and Open.File.FileType is not DirectoryFile:
                        else[If CreateDisposition != FILE_CREATE] the operation MUST be failed with STATUS_NOT_A_DIRECTORY.");
                    return MessageStatus.NOT_A_DIRECTORY;
                }
            }

            //If FileTypeToOpen is DataFile and StreamNameToOpen is empty and Open.File
            //is not NULL and Open.File.FileType is DirectoryFile
            if (gfileTypeToOpen == FileType.DataFile &&
                streamTypeNameToOPen == StreamTypeNameToOPen.NULL &&
                fileNameStatus == FileNameStatus.OpenFileNotNull &&
                openFileType == FileType.DirectoryFile)
            {
                Helper.CaptureRequirement(415, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                    Phase 7 -- Type of file to open:]If FileTypeToOpen is DataFile and StreamNameToOpen is empty and Open.File is not NULL
                    and Open.File.FileType is DirectoryFile, the operation MUST be failed with STATUS_FILE_IS_A_DIRECTORY.");
                return MessageStatus.FILE_IS_A_DIRECTORY;
            }

            #endregion

            return MessageStatus.SUCCESS;
        }
        public static MessageStatus CheckExistingFileAccess(
            FileType openFileType,
            FileAttribute fileAttribute,
            FileAccess desiredAccess,
            CreateOptions createOption,
            CreateOptions existingOpenModeCreateOption,
            StreamTypeNameToOPen streamTypeNameToOPen,
            ShareAccess shareAccess,
            ShareAccess existOpenShareModeShareAccess)
        {
            //If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY &&
            //(DesiredAccess.FILE_WRITE_DATA))
            if (openFileType == FileType.DataFile &&
                existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE &&
                (fileAttribute == FileAttribute.READONLY &&
                desiredAccess == FileAccess.FILE_WRITE_DATA))
            {
                Helper.CaptureRequirement(2422, @"[In Algorithm to Check Access to an Existing File]Pseudocode for these checks is as follows:
                    If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY && (DesiredAccess.FILE_APPEND_DATA)),
                    then return STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            //If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY &&
            //(DesiredAccess.FILE_APPEND_DATA))
            if (openFileType == FileType.DataFile &&
                existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE &&
                (fileAttribute == FileAttribute.READONLY &&
                desiredAccess == FileAccess.FILE_APPEND_DATA))
            {
                Helper.CaptureRequirement(53, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:]
                    If Open.File.FileType is DataFile and (File.FileAttributes.FILE_ATTRIBUTE_READONLY && (DesiredAccess.FILE_WRITE_DATA )), then return STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            //If ((File.FileAttributes.FILE_ATTRIBUTE_READONLY ) &&
            //CreateOptions.FILE_DELETE_ON_CLOSE)
            if (fileAttribute == FileAttribute.READONLY &&
                (createOption == CreateOptions.DELETE_ON_CLOSE))
            {
                Helper.CaptureRequirement(54, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:]
                    If ((File.FileAttributes.FILE_ATTRIBUTE_READONLY) && CreateOptions.FILE_DELETE_ON_CLOSE), then return STATUS_CANNOT_DELETE.");
                return MessageStatus.CANNOT_DELETE;
            }

            //If ((File.Volume.IsReadOnly) &&
            //CreateOptions.FILE_DELETE_ON_CLOSE)
            if (isFileVolumeReadOnly &&
                (createOption == CreateOptions.DELETE_ON_CLOSE))
            {
                Helper.CaptureRequirement(2423, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:]
                    If (( File.Volume.IsReadOnly) && CreateOptions.FILE_DELETE_ON_CLOSE), then return STATUS_CANNOT_DELETE.");

                return MessageStatus.CANNOT_DELETE;
            }

            //If Open.RemainingDesiredAccess is nonzero
            if (gOpenRemainingDesiredAccess != FileAccess.None)
            {
                //If Open.RemainingDesiredAccess.MAXIMUM_ALLOWED
                if ((gOpenRemainingDesiredAccess & FileAccess.MAXIMUM_ALLOWED) != 0)
                {
                    //For each Access Flag in FILE_ALL_ACCESS, the object store MUST set Open.GrantedAccess.
                    //Access if SecurityContext has Access based on File.SecurityDescriptor
                    //gOpenGrantedAccess = FileAccess.FILE_ALL_ACCESS;
                    //If File.FileAttributes.FILE_ATTRIBUTE_READONLY or File.Volume.IsReadOnly
                    if ((fileAttribute == FileAttribute.READONLY) || isFileVolumeReadOnly)
                    {
                        //then the object store MUST clear (FILE_WRITE_DATA | FILE_APPEND_DATA |
                        //FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD) from Open.GrantedAccess.
                        gOpenGrantedAccess = gOpenGrantedAccess & (~(FileAccess.FILE_WRITE_DATA |
                            FileAccess.FILE_APPEND_DATA | FileAccess.FILE_ADD_SUBDIRECTORY |
                            FileAccess.FILE_DELETE_CHILD));
                    }
                }
                else
                {
                    //For each Access Flag in Open.RemainingDesired.Access, the object store MUST set
                    //Open.GrantedAccess.Access if SecurityContext has Access based on File.SecurityDescriptor
                    gOpenGrantedAccess = gOpenRemainingDesiredAccess;
                }

                //If (Open.RemainingDesiredAccess.MAXIMUM_ALLOWED || Open.RemainingDesiredAccess.DELETE),
                //the object store MUST set Open.GrantedAccess.DELETE if AccessCheck( SecurityContext,
                //Open.Link.ParentFile.SecurityDescriptor, FILE_DELETE_CHILD ) returns true

                if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED ||
                    gOpenRemainingDesiredAccess == FileAccess.DELETE)
                {
                    //the object store MUST set Open.GrantedAccess.FILE_READ_ATTRIBUTES
                    gOpenGrantedAccess = FileAccess.DELETE;
                }
                //If (Open.RemainingDesiredAccess.MAXIMUM_ALLOWED || Open.RemainingDesiredAccess.
                //FILE_READ_ATTRIBUTES), the object store MUST set Open.GrantedAccess.FILE_READ_ATTRIBUTES
                //if AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_LIST_DIRECTORY )
                //returns true

                if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED ||
                    gOpenRemainingDesiredAccess == FileAccess.FILE_READ_ATTRIBUTES)
                {
                    //the object store MUST set Open.GrantedAccess.FILE_READ_ATTRIBUTES
                    gOpenGrantedAccess = FileAccess.FILE_READ_ATTRIBUTES;
                }
                //Open.RemainingDesiredAccess &= ~(Open.GrantedAccess | MAXIMUM_ALLOWED)
                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess &
                    (~(gOpenGrantedAccess | FileAccess.MAXIMUM_ALLOWED));
                //If Open.RemainingDesiredAccess is nonzero, then return STATUS_ACCESS_DENIED.
                if (gOpenRemainingDesiredAccess != FileAccess.None)
                {
                    Helper.CaptureRequirement(61, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:,
                        If Open.RemainingDesiredAccess is nonzero:]If Open.RemainingDesiredAccess is nonzero, then return STATUS_ACCESS_DENIED.");
                    return MessageStatus.ACCESS_DENIED;
                }
            }
            //If Open.SharingMode.FILE_SHARE_DELETE is FALSE and Open.GrantedAccess contains any
            //one or more of (FILE_EXECUTE | FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA):
            if ((gOpenSharingMode & ShareAccess.FILE_SHARE_DELETE) != 0 &&
                (gOpenGrantedAccess & (FileAccess.FILE_EXECUTE |
                FileAccess.FILE_READ_DATA | FileAccess.FILE_WRITE_DATA |
                FileAccess.FILE_APPEND_DATA)) != 0)
            {
                //For each ExistingOpen is Open.File.OpenList:
                //If ExistingOpen.Mode.FILE_DELETE_ON_CLOSE is true and ExistingOpen.Stream.StreamType is
                //DirectoryStream
                if ((existingOpenModeCreateOption & CreateOptions.DELETE_ON_CLOSE) != 0 &&
                    openFileType == FileType.DirectoryFile)
                {
                    Helper.CaptureRequirement(68, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:]
                        Pseudocode for these checks is as follows:If Open.SharingMode.FILE_SHARE_DELETE is FALSE and Open.
                        GrantedAccess contains any one or more of (FILE_EXECUTE | FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA):
                        For each ExistingOpen is Open.File.OpenList:
                        If ExistingOpen.Mode.FILE_DELETE_ON_CLOSE is TRUE and ExistingOpen.Stream.StreamType is DirectoryStream, then return STATUS_SHARING_VIOLATION.");
                    return MessageStatus.SHARING_VIOLATION;
                }
            }

            //If Open.GrantedAccess.DELETE is true and Open.Stream.StreamType is DirectoryStream
            if ((gOpenGrantedAccess & FileAccess.DELETE) != 0 &&
                (streamTypeNameToOPen == StreamTypeNameToOPen.INDEX_ALLOCATION))
            {
                //For each ExistingOpen in Open.File.OpenList:
                //If ExistingOpen.SharingMode.FILE_SHARE_DELETE is FALSE
                if (existOpenShareModeShareAccess != ShareAccess.FILE_SHARE_DELETE)
                {
                    Helper.CaptureRequirement(66, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:]
                        If Open.GrantedAccess.DELETE is TRUE and Open.Stream.StreamType is DirectoryStream:For each ExistingOpen in Open.File.OpenList:
                        If ExistingOpen.SharingMode.FILE_SHARE_DELETE is FALSE, then return STATUS_SHARING_VIOLATION.");
                    return MessageStatus.SHARING_VIOLATION;
                }
            }

            Helper.CaptureRequirement(65, @"[In Algorithm to Check Access to an Existing File,Pseudocode for these checks is as follows:,
                if the sharing conflicts check has no violation]Return STATUS_SUCCESS.");
            return MessageStatus.SUCCESS;
        }
	// Set the attributes on a file.
	public static void SetAttr(String PathName, FileAttribute Attributes)
			{
				System.IO.File.SetAttributes
					(PathName, (FileAttributes)Attributes);
			}
Beispiel #31
0
 /// <summary>         
 /// 获取系统图标,不要试图释放由该方法返回的图标对象,因为它指向一个公共句柄         
 /// </summary>         
 /// <param name="path">文件名或路径名</param>         
 /// <param name="dwAttr">文件信息</param>         
 /// <param name="dwFlag">信息控制字</param>         
 /// <param name="imageIndex">输出与返回图标对应的系统图标索引号</param>         
 /// <returns>获取到的Icon对象</returns>         
 private static Icon GetIcon(string path, FileAttribute dwAttr, SHFileInfoFlags dwFlag, out long imageIndex)
 {
     if (dwAttr == FileAttribute.Directory)
     {
         imageIndex = ErrorFolderIndex;
     }
     else
     {
         imageIndex = ErrorFileIndex;
     }
     SHFileInfo shfi = new SHFileInfo();
     int iTotal = (int)SHGetFileInfo(path, dwAttr, ref shfi, (uint)Marshal.SizeOf(shfi), dwFlag);
     //int iTotal = (int)SHGetFileInfo(path, 0, ref shfi, (uint)Marshal.SizeOf(shfi), dwFlag);
     Icon icon = null;
     if (iTotal > 0)
     {
         icon = Icon.FromHandle(shfi.hIcon).Clone() as Icon;
         imageIndex = shfi.iIcon.ToInt64();
     }
     DestroyIcon(shfi.hIcon); //释放资源
     return icon;
 }
Beispiel #32
0
 public static extern IntPtr CreateFile(
     String fileName,
     FileAccess desiredAccess,
     FileShareModes shareMode,
     IntPtr securityAttributes,
     FileCreationDisposition creationDisposition,
     FileAttribute flagsAndAttributes,
     IntPtr templateFile);
 public static string Dir(string PathName, FileAttribute Attributes = 0)
 {
     if (Attributes == FileAttribute.Volume)
     {
         IntPtr ptr;
         StringBuilder lpVolumeNameBuffer = new StringBuilder(0x100);
         string lpRootPathName = null;
         if (PathName.Length > 0)
         {
             lpRootPathName = Path.GetPathRoot(PathName);
             if (lpRootPathName[lpRootPathName.Length - 1] != Path.DirectorySeparatorChar)
             {
                 lpRootPathName = lpRootPathName + Conversions.ToString(Path.DirectorySeparatorChar);
             }
         }
         int lpVolumeSerialNumber = 0;
         int lpMaximumComponentLength = 0;
         int lpFileSystemFlags = 0;
         if (Microsoft.VisualBasic.CompilerServices.NativeMethods.GetVolumeInformation(lpRootPathName, lpVolumeNameBuffer, 0x100, ref lpVolumeSerialNumber, ref lpMaximumComponentLength, ref lpFileSystemFlags, ptr, 0) != 0)
         {
             return lpVolumeNameBuffer.ToString();
         }
         return "";
     }
     FileAttributes attributes = ((FileAttributes) Attributes) | FileAttributes.Normal;
     return IOUtils.FindFirstFile(Assembly.GetCallingAssembly(), PathName, attributes);
 }
 public static extern IntPtr SHGetFileInfo(IntPtr ppidl, FileAttribute dwFileAttributes, ref ShFileInfo sfi, int cbFileInfo, SHGFI uFlags);
        public static MessageStatus OpenExistingFile(
            ShareAccess shareAccess,
            FileAccess desiredAccess,
            StreamFoundType streamFoundType,
            SymbolicLinkType symbolicLinkType,
            FileType openFileType,
            FileNameStatus fileNameStatus,
            CreateOptions existingOpenModeCreateOption,
            ShareAccess existOpenShareModeShareAccess,
            FileAccess existOpenDesiredAccess,
            CreateOptions createOption,
            CreateDisposition createDisposition,
            StreamTypeNameToOPen streamTypeNameToOPen,
            FileAttribute fileAttribute,
            FileAttribute desiredFileAttribute
            )
        {
            MessageStatus statusShareAccess = MessageStatus.SUCCESS;
            MessageStatus statusExistAccess = MessageStatus.SUCCESS;

            //call 3.1.5.1 openInitial
            MessageStatus statusInitial = OpenFileinitial(
            desiredAccess,
            shareAccess,
            createOption,
            createDisposition,
            desiredFileAttribute,
            streamFoundType,
            symbolicLinkType,
            streamTypeNameToOPen,
            openFileType,
            fileNameStatus);

            if (statusInitial != MessageStatus.SUCCESS)
            {
                return statusInitial;
            }

            #region FileTypeToOpen

            //If FileTypeToOpen is DirectoryFile
            if (gfileTypeToOpen == FileType.DirectoryFile)
            {
                //If CreateDisposition is FILE_OPEN
                if (createDisposition == CreateDisposition.OPEN)
                {
                    //call 3.1.5.1.2.1
                    statusExistAccess = CheckExistingFileAccess(
                    openFileType,
                    fileAttribute,
                    desiredAccess,
                    createOption,
                    existingOpenModeCreateOption,
                    streamTypeNameToOPen,
                    shareAccess,
                    existOpenShareModeShareAccess);

                    if (statusExistAccess != MessageStatus.SUCCESS)
                    {
                        Helper.CaptureRequirement(635, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                            If FileTypeToOpen is DirectoryFile:If CreateDisposition is FILE_OPEN then:]
                            If this[Perform access checks as described in section 3.1.5.1.2.1.] fails, the request MUST be failed with the same status.");
                        return statusExistAccess;
                    }

                    //call 3.1.5.1.2.2
                    statusShareAccess = CheckShareAccess(
                    streamFoundType,
                    existOpenShareModeShareAccess,
                    desiredAccess,
                    existOpenDesiredAccess,
                    shareAccess);

                    if (statusShareAccess != MessageStatus.SUCCESS)
                    {
                        Helper.CaptureRequirement(636, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                            If OpenFileType is DirectoryFile:If CreateDisposition is FILE_OPEN_IF then:]
                            If this[Perform access checks as described in section 3.1.5.1.2.1.] fails, the request MUST be failed with the same status.");
                        return statusShareAccess;
                    }

                    gCreateAction = CreateAction.OPENED;
                }
                //If CreateDisposition is FILE_OPEN_IF then
                else if (createDisposition == CreateDisposition.OPEN_IF)
                {
                    //call 3.1.5.1.2.1
                    statusExistAccess = CheckExistingFileAccess(
                    openFileType,
                    fileAttribute,
                    desiredAccess,
                    createOption,
                    existingOpenModeCreateOption,
                    streamTypeNameToOPen,
                    shareAccess,
                    existOpenShareModeShareAccess);

                    if (statusExistAccess != MessageStatus.SUCCESS)
                    {
                        Helper.CaptureRequirement(640, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                            If FileTypeToOpen is DirectoryFile:If CreateDisposition is FILE_OPEN_IF then:]
                            If this[Perform sharing access checks as described in section 3.1.5.1.2.2.] fails, the request MUST be failed with the same status.");
                        return statusExistAccess;
                    }

                    //call 3.1.5.1.2.2
                    statusShareAccess = CheckShareAccess(
                    streamFoundType,
                    existOpenShareModeShareAccess,
                    desiredAccess,
                    existOpenDesiredAccess,
                    shareAccess);

                    if (statusShareAccess != MessageStatus.SUCCESS)
                    {
                        Helper.CaptureRequirement(639, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                            If FileTypeToOpen is DirectoryFile:If CreateDisposition is FILE_OPEN then:]
                            If this [Perform sharing access checks as described in section 3.1.5.1.2.2.]fails, the request MUST be failed with the same status.");
                        return statusShareAccess;
                    }

                    gCreateAction = CreateAction.OPENED;
                }
                else
                {
                    //Existing directories cannot be overwritten/superseded
                    //If File == File.Volume.RootDirectory
                    if (isFileEqualRootDirectory)
                    {
                        Helper.CaptureRequirement(578, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                            If FileTypeToOpen is DirectoryFile:]
                            Else If File == File.Volume.RootDirectory then the operation MUST be failed with STATUS_ACCESS_DENIED.");
                        return MessageStatus.ACCESS_DENIED;
                    }
                    else
                    {
                        Helper.CaptureRequirement(579, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                            If FileTypeToOpen is DirectoryFile:]
                            else[If File != File.Volume.RootDirectory ] the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION.");
                        return MessageStatus.OBJECT_NAME_COLLISION;
                    }
                }
            }
            //Else if FileTypeToOpen is DataFile
            else if (gfileTypeToOpen == FileType.DataFile)
            {
                #region If Stream was found

                if (streamFoundType == StreamFoundType.StreamIsFound)
                {
                    //If CreateDisposition is FILE_CREATE
                    if (createDisposition == CreateDisposition.CREATE)
                    {
                        Helper.CaptureRequirement(584, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                            Else if FileTypeToOpen is DataFile,If Stream was found,]If CreateDisposition is FILE_CREATE,
                            then the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION.");
                        return MessageStatus.OBJECT_NAME_COLLISION;
                    }

                    //If CreateDisposition is FILE_OPEN_IF
                    if (createDisposition == CreateDisposition.OPEN_IF)
                    {
                        //call 3.1.5.1.2.1
                        statusExistAccess = CheckExistingFileAccess(
                        openFileType,
                        fileAttribute,
                        desiredAccess,
                        createOption,
                        existingOpenModeCreateOption,
                        streamTypeNameToOPen,
                        shareAccess,
                        existOpenShareModeShareAccess);

                        if (statusExistAccess != MessageStatus.SUCCESS)
                        {
                            return statusExistAccess;
                        }

                        //call 3.1.5.1.2.2
                        statusShareAccess = CheckShareAccess(
                        streamFoundType,
                        existOpenShareModeShareAccess,
                        desiredAccess,
                        existOpenDesiredAccess,
                        shareAccess);

                        if (statusShareAccess != MessageStatus.SUCCESS)
                        {
                            return statusShareAccess;
                        }

                        gCreateAction = CreateAction.OPENED;
                    }
                    //If CreateDisposition is FILE_OPEN
                    else if (createDisposition == CreateDisposition.OPEN)
                    {

                        //call 3.1.5.1.2.1
                        statusExistAccess = CheckExistingFileAccess(
                        openFileType,
                        fileAttribute,
                        desiredAccess,
                        createOption,
                        existingOpenModeCreateOption,
                        streamTypeNameToOPen,
                        shareAccess,
                        existOpenShareModeShareAccess);

                        if (statusExistAccess != MessageStatus.SUCCESS)
                        {
                            return statusExistAccess;
                        }

                        //call 3.1.5.1.2.2
                        statusShareAccess = CheckShareAccess(
                        streamFoundType,
                        existOpenShareModeShareAccess,
                        desiredAccess,
                        existOpenDesiredAccess,
                        shareAccess);

                        if (statusShareAccess != MessageStatus.SUCCESS)
                        {
                            return statusShareAccess;
                        }
                        gCreateAction = CreateAction.OPENED;
                    }
                    else
                    {
                        //If File.Volume.IsReadOnly is true
                        if (isFileVolumeReadOnly)
                        {
                            Helper.CaptureRequirement(596, @"[In Open of an Existing File,Pseudocode for the operation is as follows:
                                Else if FileTypeToOpen is DataFile:If Stream was found]Else (CreateDisposition is not FILE_OPEN and is not FILE_OPEN_IF)
                                If File.Volume.IsReadOnly is true, the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                            return MessageStatus.MEDIA_WRITE_PROTECTED;
                        }

                        //If Stream.Name is empty
                        if (fileNameStatus == FileNameStatus.StreamNameNull)
                        {
                            //If File.FileAttributes.FILE_ATTRIBUTE_HIDDEN is true and
                            //DesiredFileAttributes.FILE_ATTRIBUTE_HIDDEN is FALSE
                            if (fileAttribute == FileAttribute.HIDDEN &&
                                desiredFileAttribute != FileAttribute.HIDDEN)
                            {
                                Helper.CaptureRequirement(487, @"[In Open of an Existing File,Pseudocode for these checks is as follows:
                                    Else if FileTypeToOpen is DataFile,If Stream was found,Else (CreateDisposition is not FILE_OPEN and is not FILE_OPEN_IF),
                                    If Stream.Name is empty:]If File.FileAttributes.FILE_ATTRIBUTE_HIDDEN is TRUE
                                    and DesiredFileAttributes.FILE_ATTRIBUTE_HIDDEN is FALSE, then the operation MUST be failed with STATUS_ACCESS_DENIED.");
                                return MessageStatus.ACCESS_DENIED;
                            }
                            //If File.FileAttributes.FILE_ATTRIBUTE_SYSTEM is true and
                            //DesiredFileAttributes.FILE_ATTRIBUTE_SYSTEM is FALSE
                            if (fileAttribute == FileAttribute.SYSTEM &&
                                desiredFileAttribute != FileAttribute.SYSTEM)
                            {
                                Helper.CaptureRequirement(488, @"[In Open of an Existing File,Pseudocode for these checks is as follows:
                                    Else if FileTypeToOpen is DataFile,If Stream was found,Else (CreateDisposition is not FILE_OPEN and is not FILE_OPEN_IF),
                                    If Stream.Name is empty:]If File.FileAttributes.FILE_ATTRIBUTE_SYSTEM is TRUE
                                    and DesiredFileAttributes.FILE_ATTRIBUTE_SYSTEM is FALSE, then the operation MUST be failed with STATUS_ACCESS_DENIED.");
                                return MessageStatus.ACCESS_DENIED;
                            }

                            //Set DesiredFileAttributes.FILE_ATTRIBUTE_ARCHIVE to true.
                            desiredFileAttribute = desiredFileAttribute | FileAttribute.ARCHIVE;

                            //Set DesiredFileAttributes.FILE_ATTRIBUTE_NORMAL to FALSE.
                            desiredFileAttribute = desiredFileAttribute & (~FileAttribute.NORMAL);

                            //Set DesiredFileAttributes.FILE_ATTRIBUTE_NOT_CONTENT_INDEXED to FALSE
                            desiredFileAttribute = desiredFileAttribute &
                                (~FileAttribute.NOT_CONTENT_INDEXED);

                            //If File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is true, then
                            //set DesiredFileAttributes.FILE_ATTRIBUTE_ENCRYPTED to true.
                            if ((fileAttribute & FileAttribute.ENCRYPTED) != 0)
                            {
                                desiredFileAttribute = desiredFileAttribute | FileAttribute.ENCRYPTED;
                            }

                            //If Open.HasRestoreAccess is true
                            if (isOpenHasRestoreAccess)
                            {
                                //set Open.GrantedAccess.FILE_WRITE_EA to true
                                gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_EA;

                                //set Open.GrantedAccess.FILE_WRITE_ATTRIBUTES to true
                                gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_ATTRIBUTES;
                            }
                            else
                            {
                                //set Open.RemainingDesiredAccess
                                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess |
                                    FileAccess.FILE_WRITE_EA;

                                //store must set Open.RemainingDesiredAccess.FILE_WRITE_ATTRIBUTES to
                                //true
                                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess |
                                    FileAccess.FILE_WRITE_ATTRIBUTES;
                            }
                        }

                        //If CreateDisposition is FILE_SUPERSEDE
                        if (createDisposition == CreateDisposition.SUPERSEDE)
                        {
                            //If Open.HasRestoreAccess is true
                            if (isOpenHasRestoreAccess)
                            {
                                //set Open.GrantedAccess.DELETE to true
                                gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.DELETE;
                            }
                            else
                            {
                                //Otherwise, the object store must set Open.RemainingDesiredAccess.
                                //FILE_WRITE_DATA to true
                                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess | FileAccess.DELETE;
                            }
                        }
                        else
                        {
                            //If Open.HasRestoreAccess is true
                            if (isOpenHasRestoreAccess)
                            {
                                //set Open.GrantedAccess.DELETE to true
                                gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_DATA;
                            }
                            else
                            {
                                //Otherwise, the object store must set Open.RemainingDesiredAccess.
                                //FILE_WRITE_DATA to true
                                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess |
                                    FileAccess.FILE_WRITE_DATA;
                            }
                        }

                        gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess);

                        if (createDisposition == CreateDisposition.SUPERSEDE)
                        {
                            gCreateAction = CreateAction.SUPERSEDED;
                        }
                        else
                        {
                            gCreateAction = CreateAction.OVERWRITTEN;
                        }
                    }
                }

                #endregion

                #region Stream not found

                else
                {
                    //If CreateDisposition is FILE_OPEN or FILE_OVERWRITE
                    if (createDisposition == CreateDisposition.OPEN)
                    {
                        Helper.CaptureRequirement(610, @"[In Open of an Existing File,Pseudocode for these checks is as follows:
                            Else if FileTypeToOpen is DataFile,Else (Steam not found)]If CreateDisposition is FILE_OPEN ,
                            the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND.");
                        return MessageStatus.OBJECT_NAME_NOT_FOUND;
                    }

                    //If CreateDisposition is FILE_OPEN or FILE_OVERWRITE
                    if (createDisposition == CreateDisposition.OVERWRITE)
                    {
                        Helper.CaptureRequirement(2416, @"[In Open of an Existing File,Pseudocode for these checks is as follows:
                            Else if FileTypeToOpen is DataFile,Else (Steam not found)]If CreateDisposition is FILE_OVERWRITE, the operation
                            MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND.");
                        return MessageStatus.OBJECT_NAME_NOT_FOUND;
                    }

                    //If Open.GrantedAccess.FILE_WRITE_DATA is not set and Open.RemainingDesiredAccess.
                    //FILE_WRITE_DATA is not set:
                    if ((gOpenGrantedAccess & FileAccess.FILE_WRITE_DATA) == 0 &&
                        (gOpenRemainingDesiredAccess & FileAccess.FILE_WRITE_DATA) == 0)
                    {
                        //If Open.HasRestoreAccess is true
                        if (isOpenHasRestoreAccess)
                        {
                            //then the object store MUST set Open.GrantedAccess.FILE_WRITE_DATA to true.
                            gOpenGrantedAccess = gOpenGrantedAccess | FileAccess.FILE_WRITE_DATA;
                        }
                        else
                        {
                            //Otherwise, the object store MUST set Open.RemainingDesiredAccess.
                            //FILE_WRITE_DATA to true.
                            gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess | FileAccess.FILE_WRITE_DATA;
                        }
                    }

                    //call 3.1.5.1.2.1
                    statusExistAccess = CheckExistingFileAccess(
                    openFileType,
                    fileAttribute,
                    desiredAccess,
                    createOption,
                    existingOpenModeCreateOption,
                    streamTypeNameToOPen,
                    shareAccess,
                    existOpenShareModeShareAccess);

                    if (statusExistAccess != MessageStatus.SUCCESS)
                    {
                        Helper.CaptureRequirement(9840, @"[In Open of an Existing File,Pseudocode for these checks is as follows:
                            Else if FileTypeToOpen is DataFile,Else (Steam not found)] If this[Perform access checks as described in section 3.1.5.1.2.1] fails,
                            the request MUST be failed with the same status.");

                        return statusExistAccess;
                    }

                    //If File.Volume.IsReadOnly is true
                    if (isFileVolumeReadOnly)
                    {
                        Helper.CaptureRequirement(614, @"[In Open of an Existing File,Pseudocode for these checks is as follows:
                            Else if FileTypeToOpen is DataFile,Else (Steam not found)]If File.Volume.IsReadOnly is TRUE,
                            the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                        return MessageStatus.MEDIA_WRITE_PROTECTED;
                    }

                    //Set CreateAction to FILE_CREATED.
                    gCreateAction = CreateAction.CREATED;
                }

                #endregion

            }

            #endregion

            // If the object store implements encryption:
            if (gSecurityContext.isImplementsEncryption)
            {
                //If (CreateAction is FILE_OVERWRITTEN) and
                //(Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is true)
                //and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE) then:
                if ((gCreateAction == CreateAction.OVERWRITTEN)
                    && (fileNameStatus == FileNameStatus.StreamNameNull) &&
                    ((desiredFileAttribute & FileAttribute.ENCRYPTED) != 0)
                    && ((fileAttribute & FileAttribute.ENCRYPTED) == 0))
                {
                    //If File.OpenList is non-empty
                    //the openList must not empty
                    Helper.CaptureRequirement(623, @"[In Open of an Existing File,Pseudocode for these checks is as follows:]
                        If the object store implements encryption:If (CreateAction is FILE_OVERWRITTEN) and (Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is TRUE) and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE), then:If File.OpenList is non-empty, then the operation MUST be failed with STATUS_SHARING_VIOLATION.");
                    return MessageStatus.SHARING_VIOLATION;
                }

                //If (CreateAction is FILE_SUPERSEDED) and
                //(Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is true)
                //and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE) then:
                if ((gCreateAction == CreateAction.SUPERSEDED)
                    && (fileNameStatus == FileNameStatus.FileNameNull) &&
                    ((desiredFileAttribute & FileAttribute.ENCRYPTED) != 0)
                    && ((fileAttribute & FileAttribute.ENCRYPTED) == 0))
                {
                    //If File.OpenList is non-empty
                    //the openList must not empty
                    Helper.CaptureRequirement(2417, @"[In Open of an Existing File,Pseudocode for these checks is as follows:]
                        If the object store implements encryption:If (CreateAction is FILE_SUPERSEDED) and (Stream.Name is empty) and (DesiredAttributes.FILE_ATTRIBUTE_ENCRYPTED is TRUE) and (File.FileAttributes.FILE_ATTRIBUTE_ENCRYPTED is FALSE), then:If File.OpenList is non-empty, then the operation MUST be failed with STATUS_SHARING_VIOLATION.");
                    return MessageStatus.SHARING_VIOLATION;
                }
            }

            // If CreateAction is FILE_OVERWRITTEN
            if (gCreateAction == CreateAction.OVERWRITTEN)
            {
                if (fileNameStatus == FileNameStatus.FileNameNull)
                {
                    //Set File.FileAttributes to DesiredFileAttributes
                    fileAttribute = desiredFileAttribute;
                }
            }

            // If CreateAction is FILE_SUPERSEDED
            if (gCreateAction == CreateAction.SUPERSEDED)
            {
                if (fileNameStatus == FileNameStatus.FileNameNull)
                {
                    //Set File.FileAttributes to DesiredFileAttributes
                    fileAttribute = desiredFileAttribute;
                }
            }

            Helper.CaptureRequirement(631, @"[In Open of an Existing File,Pseudocode for these checks is as follows:]
                The object store MUST return :CreateAction set to FILE_OPENED.");
            gCreateAction = CreateAction.OPENED;

            Helper.CaptureRequirement(630, @"[In Open of an Existing File,Pseudocode for these checks is as follows:]
                The object store MUST return:Status set to STATUS_SUCCESS.");
            return MessageStatus.SUCCESS;
        }