Exemple #1
0
        private static async Task <List <string> > GetFileList(string folder)
        {
            using (var client = new HttpClientWithAuth())
            {
                var urlWithQueryString = $"{_fileApiUrl}/List?directory={folder}";

                var response = await client.GetAsync(urlWithQueryString);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    return(JsonConvert.DeserializeObject <List <string> >(await response.Content.ReadAsStringAsync()));
                }

                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    return(null);
                }

                throw new Exception($"Failed to get list of files in {folder}.");
            }
        }
Exemple #2
0
        private static async Task <string> GetFileContent(string pathToFile)
        {
            var fileName = Path.GetFileName(pathToFile);
            var folder   = GetPathWithoutFileName(pathToFile);

            using (var client = new HttpClientWithAuth())
            {
                var urlWithQueryString = $"{_fileApiUrl}?fileName={pathToFile}";

                var response = await client.GetAsync(urlWithQueryString);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(await response.Content.ReadAsStringAsync());
                }

                if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(null);
                }

                throw new Exception($"Failed to download {fileName}.");
            }
        }