Exemplo n.º 1
0
        DokanError IDokanOperations.ReadFile(string fileName, byte[] buffer, out int bytesRead, long offset,
                                             DokanFileInfo info)
        {
            Log("ReadFile:{0}:{1}|lenght:[{2}]|offset:[{3}]", fileName,
                info.Context, buffer.Length, offset);

            if (info.Context == null)
            {
                //called when file is read as memory memory mapeded file usualy notepad and stuff
                var handle = _sftpSession.RequestOpen(GetUnixPath(fileName), Flags.Read);
                var data   = _sftpSession.RequestRead(handle, (ulong)offset, (uint)buffer.Length);
                _sftpSession.RequestClose(handle);
                Buffer.BlockCopy(data, 0, buffer, 0, data.Length);
                bytesRead = data.Length;
            }
            else
            {
                // var watch = Stopwatch.StartNew();
                var stream = (info.Context as SftpContext).Stream;
                lock (stream)
                {
                    stream.Position = offset;
                    bytesRead       = stream.Read(buffer, 0, buffer.Length);
                }
                //  watch.Stop();
                // Log("{0}",watch.ElapsedMilliseconds);
            }
            Log("END READ:{0},{1}", offset, info.Context);
            return(DokanError.ErrorSuccess);
        }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);


            if (_handle != null)
            {
                if (_writeMode)
                {
                    FlushWriteBuffer();
                }

                _session.RequestClose(_handle);

                _handle = null;
            }
        }