Пример #1
0
        /// <summary>
        /// get list of directories
        /// </summary>
        /// <param name="path">virtual path</param>
        /// <returns>list of directories</returns>
        public IEnumerable<UplDirectory> GetDirectories(string path)
        {
            path = string.Concat(Root, "/", path);
            path = MapPath(path);

            var list = new List<UplDirectory>();
            var dirs = Directory.GetDirectories(path);

            foreach (var dir in dirs)
            {
                var finfo = new FileInfo(dir);

                var item = new UplDirectory
                {
                    DirectoryName = finfo.Name,
                    Modified = finfo.LastWriteTime
                };

                list.Add(item);
            }

            return list;
        }
Пример #2
0
        /// <summary>
        /// get directories in path
        /// </summary>
        /// <param name="path">root path</param>
        /// <returns>list of directories</returns>
        public IEnumerable<UplDirectory> GetDirectories(string path)
        {
            var list = new List<UplDirectory>();

            if (path == "/") path = "";

            path = path.TrimStart('/');

            var request = new ListObjectsRequest
            {
                BucketName = _bucket
            };

            var response = _client.ListObjects(request);

            var objects = from x in response.S3Objects
                          where (x.Key).StartsWith(path)
                          select x;

            foreach (var obj in objects)
            {
                // do some crazy stuff to prevent like-named folders from doing strange things
                var t1 = obj.Key;
                var t2 = (path + "/").TrimStart('/');

                if (!t1.StartsWith(t2)) continue;

                var pathLength = path.Length;
                var directoryName = obj.Key.Substring(pathLength).TrimStart('/');
                if (!FolderIsInRoot(directoryName)) continue;
                if (directoryName == "") continue;

                var item = new UplDirectory
                {
                    DirectoryName = directoryName.TrimEnd('/'),
                    Modified = Convert.ToDateTime(obj.LastModified)
                };

                if (item.DirectoryName != "")
                    list.Add(item);
            }

            return list;
        }