Ejemplo n.º 1
0
        public void CopyFile(string fromVirtualPath, string destinationVirtualPath)
        {
            var source = Path.File(fromVirtualPath);
            var target = Path.File(destinationVirtualPath);

            using (var trx = _sessionProvider.OpenSession.Session.BeginTransaction())
            {
                AssertParentExists(target);

                var file = GetSpecificItem(source);

                var copy = new FileSystemItem
                {
                    Path = target,
                    Data = file.Data,
                    Length = file.Length,
                    Created = DateTime.Now
                };

                _sessionProvider.OpenSession.Session.Save(copy);
                trx.Commit();
            }

            if (FileCopied != null)
            {
                FileCopied.Invoke(this, new FileEventArgs(destinationVirtualPath, fromVirtualPath));
            }
        }
Ejemplo n.º 2
0
        public DatabaseFileSystemStream(FileSystemItem file, DatabaseFileSystem fileSys, ISession session, int chunkSize)
        {
            if (file == null) throw new Exception("attachedTo must not be null");
            if (fileSys == null) throw new Exception("fileSys most not be null");

            this.file = file;
            this.fs = fileSys;
            this.session = session;
            this.chunkSize = chunkSize;

            Position = 0;
        }
Ejemplo n.º 3
0
        public void CopyFile(string fromVirtualPath, string destinationVirtualPath)
        {
            var source = FileSystemPath.File(fromVirtualPath);
            var target = FileSystemPath.File(destinationVirtualPath);

            var s = Session;
            using (var trx = s.BeginTransaction())
            {
                AssertParentExists(target);

                var file = GetSpecificItem(source);

                var copy = new FileSystemItem
                {
                    Path = target,
                    Length = file.Length,
                    Created = Utility.CurrentTime(),
                    Updated = Utility.CurrentTime()
                };

                s.Save(copy);

                foreach (var sourceChunk in GetChunks(file))
                {
                    var chunkCopy = CreateChunk(copy, sourceChunk.Offset, sourceChunk.Data);
                    s.Save(chunkCopy);

                    s.Flush();
                    s.Evict(sourceChunk);
                    s.Evict(chunkCopy);
                }

                trx.Commit();
            }

            if (FileCopied != null)
            {
                FileCopied.Invoke(this, new FileEventArgs(destinationVirtualPath, fromVirtualPath));
            }
        }
Ejemplo n.º 4
0
 private IEnumerable<FileSystemChunk> GetChunks(FileSystemItem file)
 {
     return Session.CreateQuery("from FileSystemChunk fsc where fsc.BelongsTo = :belongsTo order by fsc.Offset")
         .SetParameter("belongsTo", file)
         .Enumerable<FileSystemChunk>();
 }
Ejemplo n.º 5
0
        private void CreateFile(FileSystemPath virtualPath, Stream inputStream)
        {
            EnsureParentExists(virtualPath);

            CheckStreamSize(inputStream, virtualPath);
            long fileSize = inputStream.CanSeek ? inputStream.Length : 0;

            using (var trx = Session.BeginTransaction())
            {
                var item = new FileSystemItem
                {
                    Path = virtualPath,
                    Created = Utility.CurrentTime(),
                    Updated = Utility.CurrentTime(),
                    Length = fileSize
                };
                Session.Save(item);

                var temp = new byte[chunkSize];
                int offset = 0;
                int size = 0;
                while(true)
                {
                    size = inputStream.Read(temp, 0, temp.Length);
                    if (size <= 0)
                        break;

                    var buffer = Copy(temp, size);

                    var chunk = CreateChunk(item, offset, buffer);
                    Session.Save(chunk);

                    if (size < temp.Length)
                        break;

                    offset += size;
                }

                if (fileSize == 0)
                {
                    item.Length = offset + size;
                    Session.Update(item);
                }

                trx.Commit();
            }
            //using (var buffer = (inputStream.CanSeek && (inputStream.Length <= int.MaxValue) ? new MemoryStream((int)inputStream.Length) : new MemoryStream()))
            //{
            //    AssertParentExists(virtualPath);

            //    inputStream.Position = 0;
            //    CopyStream(inputStream, buffer);
            //    inputStream.Position = 0;

            //    var item = new FileSystemItem
            //                   {
            //                       Path = virtualPath,
            //                       Data = (inputStream.CanSeek && inputStream.Length == buffer.GetBuffer().Length ) ? buffer.GetBuffer() : buffer.ToArray(),
            //                       Created = Utility.CurrentTime(),
            //                       Updated = Utility.CurrentTime(),
            //                       Length = buffer.Length
            //                   };

            //    Session.Save(item);
            //    trx.Commit();
            //}
        }
Ejemplo n.º 6
0
        private void CreateDirectoryInternal(string virtualPath)
        {
            var path = FileSystemPath.Directory(virtualPath);

            if (virtualPath != "/")
            {
                EnsureParentExists(path);
            }

            var item = new FileSystemItem
                           {
                               Path = path,
                               Created = Utility.CurrentTime(),
                               Updated = Utility.CurrentTime()
                           };

            Session.Save(item);
        }
Ejemplo n.º 7
0
 private static FileSystemChunk CreateChunk(FileSystemItem item, int offset, byte[] buffer)
 {
     var chunk = new FileSystemChunk
     {
         BelongsTo = item,
         Data = buffer,
         Offset = offset
     };
     return chunk;
 }
Ejemplo n.º 8
0
            public DatabaseFileSystemStream(FileSystemItem attachedTo, DatabaseFileSystem fileSys, byte [] data)
            {
                if(attachedTo==null) throw new Exception("attachedTo must not be null");
                if(fileSys == null) throw new Exception("fileSys most not be null");

                this.attachedTo = attachedTo;
                this.fileSys = fileSys;

                base.Write(data, 0, data.Length);
                Position = 0;
            }
Ejemplo n.º 9
0
        private void _CreateDirectory(string virtualPath)
        {
            var path = Path.Directory(virtualPath);

            if (virtualPath != "/")
            {
                EnsureParentExists(path);
            }

            var item = new FileSystemItem
                           {
                               Path = path,
                               Created = DateTime.Now
                           };

            _sessionProvider.OpenSession.Session.Save(item);
        }
Ejemplo n.º 10
0
        private void CreateFile(Path virtualPath, Stream inputStream)
        {
            CheckStreamSize(inputStream,virtualPath);

            using (var trx = _sessionProvider.OpenSession.Session.BeginTransaction())
            using (var buffer = (inputStream.CanSeek && (inputStream.Length <= int.MaxValue) ? new MemoryStream((int)inputStream.Length) : new MemoryStream()))
            {
                AssertParentExists(virtualPath);

                inputStream.Position = 0;
                CopyStream(inputStream, buffer);
                inputStream.Position = 0;

                var item = new FileSystemItem
                               {
                                   Path = virtualPath,
                                   Data = (inputStream.CanSeek && inputStream.Length == buffer.GetBuffer().Length ) ? buffer.GetBuffer() : buffer.ToArray(),
                                   Created = DateTime.Now,
                                   Length = buffer.Length
                               };

                _sessionProvider.OpenSession.Session.Save(item);
                trx.Commit();
            }
        }
Ejemplo n.º 11
0
 private IEnumerable <FileSystemChunk> GetChunks(FileSystemItem file)
 {
     return(Session.CreateQuery("from FileSystemChunk fsc where fsc.BelongsTo = :belongsTo order by fsc.Offset")
            .SetParameter("belongsTo", file)
            .Enumerable <FileSystemChunk>());
 }
Ejemplo n.º 12
0
        private void CreateFile(FileSystemPath virtualPath, Stream inputStream)
        {
            EnsureParentExists(virtualPath);

            CheckStreamSize(inputStream, virtualPath);
            long fileSize = inputStream.CanSeek ? inputStream.Length : 0;

            using (var trx = Session.BeginTransaction())
            {
                var item = new FileSystemItem
                {
                    Path    = virtualPath,
                    Created = Utility.CurrentTime(),
                    Updated = Utility.CurrentTime(),
                    Length  = fileSize
                };
                Session.Save(item);

                var temp   = new byte[chunkSize];
                int offset = 0;
                int size   = 0;
                while (true)
                {
                    size = inputStream.Read(temp, 0, temp.Length);
                    if (size <= 0)
                    {
                        break;
                    }

                    var buffer = Copy(temp, size);

                    var chunk = CreateChunk(item, offset, buffer);
                    Session.Save(chunk);

                    if (size < temp.Length)
                    {
                        break;
                    }

                    offset += size;
                }

                if (fileSize == 0)
                {
                    item.Length = offset + size;
                    Session.Update(item);
                }

                trx.Commit();
            }
            //using (var buffer = (inputStream.CanSeek && (inputStream.Length <= int.MaxValue) ? new MemoryStream((int)inputStream.Length) : new MemoryStream()))
            //{
            //  AssertParentExists(virtualPath);

            //  inputStream.Position = 0;
            //  CopyStream(inputStream, buffer);
            //  inputStream.Position = 0;

            //  var item = new FileSystemItem
            //                 {
            //                     Path = virtualPath,
            //                     Data = (inputStream.CanSeek && inputStream.Length == buffer.GetBuffer().Length ) ? buffer.GetBuffer() : buffer.ToArray(),
            //                     Created = Utility.CurrentTime(),
            //                     Updated = Utility.CurrentTime(),
            //                     Length = buffer.Length
            //                 };

            //  Session.Save(item);
            //  trx.Commit();
            //}
        }