Example #1
0
        internal int ReadFile(Guid id, string src, string path,
                              byte[] buffer, long offset, long length, long start)
        {
            Pub(id, new FileRequest
            {
                Source = src,
                Path   = path,
                Buffer = (int)length,
                Offset = start
            });
            var           chunkRef      = BuildChunkRef(id, src, path, start);
            ReadFileChunk handle        = null;
            var           numberOfTries = 0;

            while (handle == null && (numberOfTries++) <= 50)
            {
                if (!chunks.TryGetValue(chunkRef, out handle))
                {
                    Thread.Sleep(10);
                }
            }
            var bytesRead = handle(buffer, offset, length, start);

            chunks.TryRemove(chunkRef, out handle);
            return(bytesRead);
        }
Example #2
0
        public ResponseStatus Process(object src, FileResponse msg)
        {
            var           chunkRef = BuildChunkRef(src, msg.Source, msg.Relative, msg.Offset);
            ReadFileChunk chunk    = (b, o, l, s) =>
            {
                Array.Copy(msg.Bytes, 0, b, o, Math.Min(l, msg.Length));
                return((int)msg.Length);
            };

            chunks[chunkRef] = chunk;
            return(ResponseStatus.Handled);
        }
Example #3
0
        public Task <Stream> OpenReadAsync(IUnixFileEntry file, long startPos, CancellationToken token)
        {
            var    entity = (VirtualFile)file;
            var    vfs    = Parent.Parent.Parent;
            var    folder = entity.Path.Replace(entity.Name, "");
            var    model  = vfs.GetFolder(folder, false) as VfsFolder;
            var    entry  = model[entity.Name] as IFile;
            Guid   id;
            string arg, relative;

            DetermineArgs(vfs, model, entity, out id, out arg, out relative);
            ReadFileChunk rfc = (a, b, c, d) =>
                                vfs.ReadFile(id, arg, relative, a, b, c, d);
            var str = new VirtualStream(entry, startPos, rfc);

            return(Task.FromResult <Stream>(str));
        }
Example #4
0
 public VirtualStream(IFile file, long start, ReadFileChunk chunk)
 {
     this.file  = file;
     this.start = start;
     this.chunk = chunk;
 }