public object Get()
        {
            Fields fields;
            FileId parentId;
            string nameFilter, physicalPath;

            PreGet(out parentId, out nameFilter, out physicalPath, out fields);

            if (physicalPath != null)
            {
                return(GetByPhysicalPath(physicalPath, fields));
            }

            if (parentId != null && !_provider.DirectoryExists(parentId.PhysicalPath))
            {
                return(NotFound());
            }

            var models = new List <object>();
            IEnumerable <IFileInfo> children = parentId != null?GetChildren(parentId.PhysicalPath, nameFilter) : GetFromLocations(nameFilter);

            foreach (IFileInfo child in children)
            {
                models.Add(_helper.ToJsonModelRef(child, fields));
            }

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(models.Count);
            this.Context.Response.Headers[HeaderNames.AcceptRanges] = _units;

            return(new
            {
                files = models
            });
        }
Beispiel #2
0
        public object Head()
        {
            Fields fields;
            FileId parentId;
            string nameFilter, physicalPath;

            PreGet(out parentId, out nameFilter, out physicalPath, out fields);

            if (physicalPath != null)
            {
                return(GetByPhysicalPath(physicalPath, fields));
            }

            if (parentId != null && !_provider.GetDirectory(parentId.PhysicalPath).Exists)
            {
                return(NotFound());
            }

            IEnumerable <object> children = null;

            if (parentId == null)
            {
                var list = new List <object>();
                children = list;

                foreach (IFileInfo child in GetFromLocations(nameFilter))
                {
                    list.Add(_helper.ToJsonModelRef(child, fields));
                }
            }
            else
            {
                IFileInfo parent = _provider.GetDirectory(parentId.PhysicalPath);
                children = _helper.DirectoryContentToJsonModel(parent, GetChildren(parent, nameFilter), fields);
            }

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(children.Count());
            this.Context.Response.Headers[HeaderNames.AcceptRanges] = _units;

            return(Ok());
        }
        public object ToJsonModel(MoveOperation move)
        {
            dynamic obj = new ExpandoObject();

            obj.id           = move.Id;
            obj.status       = "running";
            obj.created      = move.Created;
            obj.current_size = move.CurrentSize;
            obj.total_size   = move.TotalSize;
            obj.file         = _filesHelper.ToJsonModelRef(move.Destination);

            return(Core.Environment.Hal.Apply(Defines.CopyResource.Guid, obj));
        }