public string GetResourceDownloadUrl(string apiKey, ChiliResource.ResourceType resourceType, string id, string downloadType = "original", bool async = false, int taskPriority = 0, int?pageNumber = null) { string environmnet = ApiKeyGetSettings(apiKey).environment; string requestUrl = url.Replace("main.asmx", environmnet) + $"/download.aspx?apiKey={apiKey}&resourceName={resourceType.ToString()}&id={id}&type={downloadType}&async={async.ToString().ToLower()}"; // TODO I need do something different as async will return task XML if the preview does not exist yet if (async == true) { requestUrl += $"&taskPriority={taskPriority}"; } if (pageNumber != null) { if (pageNumber < 1) { pageNumber = 1; } requestUrl += $"&pageNum={pageNumber}"; } return(requestUrl); }
public async Task <ChiliResource> ResourceItemCopy(string apiKey, ChiliResource.ResourceType resourceType, string id, string copyToPath, string newName = null) { XmlDocument xmlDocument = new XmlDocument(); if (newName == null) { ResourceItemGetDefinitionXMLResponse responseGet = await soapClient.ResourceItemGetDefinitionXMLAsync(apiKey, resourceType.ToString(), id); xmlDocument.LoadXml(responseGet.Body.ResourceItemGetDefinitionXMLResult); XmlNode xmlInfoNode = xmlDocument.SelectSingleNode("//item[@name and @id]"); if (xmlInfoNode == null) { throw new NotImplementedException("Info node is blank and you didn't do anything thing"); } else { newName = xmlInfoNode.Attributes["name"].Value; } } ResourceItemCopyResponse response = await soapClient.ResourceItemCopyAsync(apiKey, resourceType.ToString(), id, newName, copyToPath); xmlDocument.LoadXml(response.Body.ResourceItemCopyResult); //<item name="Cat.zip" id="4a769cd7-a702-496f-be20-f59c9dc4ba18" relativePath="Blank\Cat.zip.xml" documentVersion="5.4.1.1" lastAcceptedVersion="5.4.1.1"><fileInfo fileIndexed="2019-05-12T17:00:33" numPages="1" resolution="72" width="595.266" height="841.8762" fileSize="13.15 Kb"><metaData><item name="Num. Pages" value="1" /><item name="Width" value="210 mm" /><item name="Height" value="297 mm" /></metaData><boxes /></fileInfo></item> XmlNodeList nodes = xmlDocument.GetElementsByTagName("item"); if (nodes.Count > 0) { XmlNode xmlInfoNode = nodes[0]; string resourceName = xmlInfoNode.Attributes["name"].Value; string resourceID = xmlInfoNode.Attributes["id"].Value; string resourcePath = xmlInfoNode.Attributes["relativePath"].Value; ChiliResource chiliResource = new ChiliResource(resourceID, resourceName, resourceType) { pathOnServer = resourcePath, previewUrl = GetResourcePreviewUrl(apiKey, resourceType, resourceID, PreviewType.thumb) }; return(chiliResource); } return(null); }
private void GetXmlItemsInFolder(XmlNode folderNode, ref List <ChiliResource> resourceList, ChiliResource.ResourceType resourceType, int level) { foreach (XmlNode node in folderNode.ChildNodes) { if (node.Attributes["isFolder"] != null) { if (node.Attributes["isFolder"].Value == "false") { string id = node.Attributes["id"].Value; string name = node.Attributes["name"].Value; string previewUrl = url.Replace("main.asmx", "") + node.Attributes["iconURL"].Value; string path = node.Attributes["path"].Value; ChiliResource chiliResource = new ChiliResource(id, name, resourceType) { previewUrl = previewUrl, pathOnServer = path }; resourceList.Add(chiliResource); } else { GetXmlItemsInFolder(node, ref resourceList, resourceType, level + 1); } } } }
public async Task <IEnumerable <ChiliResource> > GetResourceInFolder(string apiKey, string parentFolder, ChiliResource.ResourceType resourceType = ChiliResource.ResourceType.Documents, int numLevels = 1) { List <ChiliResource> resourcesFound = new List <ChiliResource>(); ResourceGetTreeLevelResponse treeResponse = await soapClient.ResourceGetTreeLevelAsync(apiKey, resourceType.ToString(), parentFolder, numLevels); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(treeResponse.Body.ResourceGetTreeLevelResult); XmlNodeList parent = xmlDocument.GetElementsByTagName("tree"); if (parent.Count > 0 && parent[0].HasChildNodes) { GetXmlItemsInFolder(parent[0], ref resourcesFound, resourceType, 0); } return(resourcesFound); }
public string GetResourcePreviewUrl(string apiKey, ChiliResource.ResourceType resourceType, string id, PreviewType previewType) { return(GetResourceDownloadUrl(apiKey, resourceType, id, previewType.ToString())); }