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)), })); } }
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); }
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); }
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; }
public Stream GetDocumentStream(BoxEntry document) { long size; return(GetDocumentStream(document, out size)); }
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; }
public Stream GetDocumentStream(BoxEntry document) { long size; return GetDocumentStream(document, out size); }
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)), })); } }