예제 #1
0
 private static void RetrieveTree(BoxEntry boxEntry, XElement folderElement)
 {
     //select folders
     if (folderElement.Element("folders") != null)
     {
         var subFolders = folderElement.Element("folders").Elements("folder");
         foreach (var subFolder in subFolders)
         {
             var entry = new BoxEntry
             {
                 IsFolder = true,
                 Title    = subFolder.Attribute("name").Value,
                 Id       = subFolder.Attribute("id").Value
             };
             boxEntry.Childs.Add(entry);
             RetrieveTree(entry, subFolder);
         }
     }
     if (folderElement.Element("files") != null)
     {
         var files = folderElement.Element("files").Elements("file");
         boxEntry.Childs.AddRange(files.Select(file => new BoxEntry
         {
             IsFolder  = false,
             Title     = file.Attribute("file_name").Value,
             Id        = file.Attribute("id").Value,
             Size      = int.Parse(file.Attribute("size").Value),
             Published = FromUnixDate(long.Parse(file.Attribute("created").Value)),
             Updated   = FromUnixDate(long.Parse(file.Attribute("updated").Value)),
         }));
     }
 }
예제 #2
0
        public Stream GetDocumentStream(BoxEntry document, out long size)
        {
            if (document.IsFolder)
            {
                throw new ArgumentException("entry must be a file not folder!");
            }

            var url      = string.Format(DownloadUrl, AuthKey, document.Id);
            var request  = WebRequest.Create(url);
            var responce = request.GetResponse();

            size = responce.ContentLength;
            return(responce != null?responce.GetResponseStream() : null);
        }
예제 #3
0
        public BoxEntry GetDocuments()
        {
            if (_rootEntry == null)
            {
                //Download xml
                var treeResponce = GetClient().DownloadData(string.Format(TreeUrl, ApiKey, AuthKey));
                var response     = DocumentLoader.GetDoc(treeResponce).Element("response");
                //Check status
                if (response.Element("status").Value != "listing_ok")
                {
                    throw new InvalidOperationException("bad listing status " +
                                                        response.Element("status").Value);
                }
                var rootFolders = response.Element("tree").Elements("folder");

                //create root entry
                _rootEntry = new BoxEntry();
                foreach (var rootFolder in rootFolders)
                {
                    RetrieveTree(_rootEntry, rootFolder);
                }
            }
            return(_rootEntry);
        }
예제 #4
0
        public BoxEntry GetDocuments()
        {
            if (_rootEntry == null)
            {
                //Download xml
                var treeResponce = GetClient().DownloadData(string.Format(TreeUrl, ApiKey, AuthKey));
                var response = DocumentLoader.GetDoc(treeResponce).Element("response");
                //Check status
                if (response.Element("status").Value != "listing_ok")
                {
                    throw new InvalidOperationException("bad listing status " +
                                                        response.Element("status").Value);
                }
                var rootFolders = response.Element("tree").Elements("folder");

                //create root entry
                _rootEntry = new BoxEntry();
                foreach (var rootFolder in rootFolders)
                {
                    RetrieveTree(_rootEntry, rootFolder);
                }
            }
            return _rootEntry;
        }
예제 #5
0
        public Stream GetDocumentStream(BoxEntry document)
        {
            long size;

            return(GetDocumentStream(document, out size));
        }
예제 #6
0
        public Stream GetDocumentStream(BoxEntry document, out long size)
        {
            if (document.IsFolder)
                throw new ArgumentException("entry must be a file not folder!");

            var url = string.Format(DownloadUrl, AuthKey, document.Id);
            var request = WebRequest.Create(url);
            var responce = request.GetResponse();
            size = responce.ContentLength;
            return responce != null ? responce.GetResponseStream() : null;
        }
예제 #7
0
 public Stream GetDocumentStream(BoxEntry document)
 {
     long size;
     return GetDocumentStream(document, out size);
 }
예제 #8
0
 private static void RetrieveTree(BoxEntry boxEntry, XElement folderElement)
 {
     //select folders
     if (folderElement.Element("folders") != null)
     {
         var subFolders = folderElement.Element("folders").Elements("folder");
         foreach (var subFolder in subFolders)
         {
             var entry = new BoxEntry
                             {
                                 IsFolder = true,
                                 Title = subFolder.Attribute("name").Value,
                                 Id = subFolder.Attribute("id").Value
                             };
             boxEntry.Childs.Add(entry);
             RetrieveTree(entry, subFolder);
         }
     }
     if (folderElement.Element("files") != null)
     {
         var files = folderElement.Element("files").Elements("file");
         boxEntry.Childs.AddRange(files.Select(file => new BoxEntry
                                                    {
                                                        IsFolder = false,
                                                        Title = file.Attribute("file_name").Value,
                                                        Id = file.Attribute("id").Value,
                                                        Size = int.Parse(file.Attribute("size").Value),
                                                        Published = FromUnixDate(long.Parse(file.Attribute("created").Value)),
                                                        Updated = FromUnixDate(long.Parse(file.Attribute("updated").Value)),
                                                    }));
     }
 }