Exemplo n.º 1
0
        protected internal override void DoDeleteItem(FileSystemSessionItem item)
        {
            var s3session = (S3V4FileSystemSession)item.Session;
            var handle    = (S3V4FSH)item.Handle;

            FileSystemFile file = item as FileSystemFile;

            if (file != null)
            {
                S3V4.RemoveItem(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs);
                return;
            }

            FileSystemDirectory dir = item as FileSystemDirectory;

            if (dir != null)
            {
                // reverse order to get children prior to parents
                foreach (S3V4ListBucketItem subItem in getSubitemNames(dir, true).Reverse())
                {
                    string subItemPath = CombinePaths(handle.Path, subItem.Key);
                    S3V4.RemoveItem(subItemPath, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs);
                }

                S3V4.RemoveFolder(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs);
                return;
            }
        }
Exemplo n.º 2
0
        protected internal override ulong DoGetItemSize(FileSystemSessionItem item)
        {
            var s3session = (S3V4FileSystemSession)item.Session;
            var handle    = item.Handle as S3V4FSH;

            FileSystemFile file = item as FileSystemFile;

            if (file != null)
            {
                IDictionary <string, string> metaHeaders = S3V4.GetItemMetadata(handle.Path,
                                                                                s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs);
                return((ulong)metaHeaders["Content-Length"].AsLong());
            }

            FileSystemDirectory dir = item as FileSystemDirectory;

            if (dir != null)
            {
                ulong size = 0;
                foreach (S3V4ListBucketItem subItem in getSubitemNames(dir, true).Where(si => !si.IsFolder))
                {
                    size += subItem.Size;
                }
                return(size);
            }

            throw new NFXException(NFX.Web.StringConsts.ARGUMENT_ERROR + this.GetType().Name + ".DoGetItemSize(item is FileSystemFile or FileSystemDirectory)");
        }
Exemplo n.º 3
0
        private IEnumerable <S3V4ListBucketItem> getSubitemNames(FileSystemDirectory directory, bool recursive, int maxKeys = 1000)
        {
            var    s3session = (S3V4FileSystemSession)directory.Session;
            var    handle    = directory.Handle as S3V4FSH;
            string prefix    = handle.Path.ToDirectoryPath().TrimStart(PATH_SEPARATOR);

            string xml = S3V4.ListBucket(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs,
                                         prefix, maxKeys: maxKeys);
            S3V4ListBucketResult list = S3V4ListBucketResult.FromXML(xml);

            while (list.IsTruncated)
            {
                xml = S3V4.ListBucket(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs,
                                      prefix, marker: list.Items.Last().Key, maxKeys: maxKeys);
                list.AddXML(xml);
            }

            IEnumerable <S3V4ListBucketItem> q = list.Items;

            if (!recursive)
            {
                q = q.Where(i => !i.IsNested);
            }

            return(q.ToList());
        }
Exemplo n.º 4
0
 protected override void DoFlush()
 {
     if (m_IsChanged)
     {
         //S3V4.PutFile(m_Uri, m_Session.AccessKey, m_Session.SecretKey, BufferStream);
         S3V4.PutFile(m_Handle.Path, m_Session.AccessKey, m_Session.SecretKey, m_Session.Bucket, m_Session.Region, BufferStream, m_timeoutMs);
         m_IsChanged = false;
     }
 }
Exemplo n.º 5
0
        protected internal override DateTime?DoGetModificationTimestamp(FileSystemSessionItem item)
        {
            var s3session = (S3V4FileSystemSession)item.Session;
            var handle    = item.Handle as S3V4FSH;

            var metaHeaders = S3V4.GetItemMetadata(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region,
                                                   s3session.TimeoutMs);

            return(metaHeaders["Last-Modified"].AsDateTime());
        }
Exemplo n.º 6
0
        protected internal override FileSystemDirectory DoCreateDirectory(FileSystemDirectory dir, string name)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;
            var dirPath   = this.CombinePaths(dir.Path, name);
            var handle    = new S3V4FSH(dirPath);

            S3V4.PutFolder(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs);

            return(new FileSystemDirectory(s3session, handle.Parent, handle.Name, handle));
        }
Exemplo n.º 7
0
        public S3V4FileSystemStream(FileSystemFile file, Action <FileSystemStream> disposeAction, int timeoutMs) : base(file, disposeAction)
        {
            m_Handle = (S3V4FileSystem.S3V4FSH)file.Handle;

            m_timeoutMs = timeoutMs;

            m_Session = file.Session as S3V4FileSystemSession;

            m_IsNewFile = !S3V4.FileExists(m_Handle.Path, m_Session.AccessKey, m_Session.SecretKey, m_Session.Bucket, m_Session.Region,
                                           timeoutMs);
        }
Exemplo n.º 8
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, string localFile, bool readOnly)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;
            var filePath  = this.CombinePaths(dir.Path, name);
            var handle    = new S3V4FSH(filePath);

            using (System.IO.FileStream r = new System.IO.FileStream(localFile, System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                S3V4.PutFile(filePath, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, r, s3session.TimeoutMs);
                return(new FileSystemFile(dir.Session, handle.Parent, handle.Name, handle));
            }
        }
Exemplo n.º 9
0
        protected internal override FileSystemFile DoCreateFile(FileSystemDirectory dir, string name, int size)
        {
            var s3session = (S3V4FileSystemSession)dir.Session;

            var filePath = this.CombinePaths(dir.Path, name);
            var handle   = new S3V4FSH(filePath);

            byte[]       bytes         = new byte[size];
            MemoryStream contentStream = new MemoryStream(bytes);

            S3V4.PutFile(handle.Path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, contentStream, s3session.TimeoutMs);

            return(new FileSystemFile(s3session, handle.Parent, handle.Name, handle));
        }
Exemplo n.º 10
0
        protected internal override FileSystemSessionItem DoNavigate(FileSystemSession session, string path)
        {
            var s3session = (S3V4FileSystemSession)session;

            S3V4FSH handle = new S3V4FSH(path);

            if (path != "" && S3V4.FileExists(path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs))
            {
                return(new FileSystemFile(s3session, handle.Parent, handle.Name, handle));
            }

            if (S3V4.FolderExists(path, s3session.AccessKey, s3session.SecretKey, s3session.Bucket, s3session.Region, s3session.TimeoutMs))
            {
                return(new FileSystemDirectory(s3session, handle.Parent, handle.Name, handle));
            }

            return(null);
        }