예제 #1
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();
            }
        }
예제 #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[] { }));
            }
        }
예제 #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;
     }
 }