Example #1
0
        public override DirectorySecurity GetAccessControl(string path)
        {
            VirtualFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");
            path = EnsurePathEndsWithDirectorySeparator(path);

            if (!VirtualFileDataAccessor.Directory.Exists(path))
            {
                throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("COULD_NOT_FIND_PART_OF_PATH_EXCEPTION"), path));
            }

            var directoryData = (VirtualDirectoryData)VirtualFileDataAccessor.GetFile(path);

            return(directoryData.AccessControl);
        }
Example #2
0
        public VirtualFileStream(IVirtualFileDataAccessor VirtualFileDataAccessor, string path, StreamType streamType)
        {
            if (VirtualFileDataAccessor == null)
            {
                throw new ArgumentNullException("VirtualFileDataAccessor");
            }

            this.VirtualFileDataAccessor = VirtualFileDataAccessor;
            this.path = path;

            if (VirtualFileDataAccessor.FileExists(path))
            {
                /* only way to make an expandable MemoryStream that starts with a particular content */
                var data = VirtualFileDataAccessor.GetFile(path).Contents;
                if (data != null && data.Length > 0)
                {
                    Write(data, 0, data.Length);
                    Seek(0, StreamType.APPEND.Equals(streamType)
                        ? SeekOrigin.End
                        : SeekOrigin.Begin);
                }
            }
            else
            {
                if (StreamType.READ.Equals(streamType))
                {
                    throw new FileNotFoundException("File not found.", path);
                }
                VirtualFileDataAccessor.AddFile(path, new VirtualFileData(new byte[] { }));
            }
        }
Example #3
0
 private void InternalFlush()
 {
     if (VirtualFileDataAccessor.FileExists(path))
     {
         var VirtualFileData = VirtualFileDataAccessor.GetFile(path);
         /* reset back to the beginning .. */
         Seek(0, SeekOrigin.Begin);
         /* .. read everything out */
         var data = new byte[Length];
         Read(data, 0, (int)Length);
         /* .. put it in the Virtual system */
         VirtualFileData.Contents = data;
     }
 }
Example #4
0
        public override void AppendAllText(string path, string contents, Encoding encoding)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException("encoding");
            }

            VirtualFileDataAccessor.PathVerifier.IsLegalAbsoluteOrRelative(path, "path");

            if (!VirtualFileDataAccessor.FileExists(path))
            {
                var dir = VirtualFileDataAccessor.Path.GetDirectoryName(path);
                if (!VirtualFileDataAccessor.Directory.Exists(dir))
                {
                    throw new DirectoryNotFoundException(string.Format(CultureInfo.InvariantCulture, StringResources.Manager.GetString("COULD_NOT_FIND_PART_OF_PATH_EXCEPTION"), path));
                }

                VirtualFileDataAccessor.AddFile(path, new VirtualFileData(contents, encoding));
            }
            else
            {
                var file          = VirtualFileDataAccessor.GetFile(path);
                var bytesToAppend = encoding.GetBytes(contents);
                file.Contents = file.Contents.Concat(bytesToAppend).ToArray();
            }
        }