Exemplo n.º 1
0
        public async Task <ZamzarResult> QueryAsync(int jobId)
        {
            string url = endpoint + "/v1/jobs/" + jobId.ToString();

            using (HttpClientHandler handler = new HttpClientHandler {
                Credentials = new NetworkCredential(key, "")
            })
                using (HttpClient client = new HttpClient(handler))
                    using (HttpResponseMessage response = await client.GetAsync(url))
                        using (HttpContent content = response.Content)
                        {
                            string data = await content.ReadAsStringAsync();

                            ZamzarResult zResult = JsonSerializer.Deserialize <ZamzarResult>(data);
                            return(zResult);
                        }
        }
Exemplo n.º 2
0
        private async Task <string> DownloadFromConverter(ExcelConverter converter, ZamzarResult result, string company)
        {
            if (result.target_files.Length == 0)
            {
                throw new ApplicationException($"Unable to find a file for result: {result}");
            }

            string filename = Path.Combine(company, result.target_files[0].name);
            int    fileId   = result.target_files[0].id;

            if (await converter.DownloadAsync(fileId, filename))
            {
                System.Console.WriteLine($"Downloaded: {filename}");
                return(filename);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        private async Task ProcessResultAsync(ZamzarResult result, SettlementHistory settlement)
        {
            string filename = result.target_files[0].name;

            if (!File.Exists(filename))
            {
                filename = await DownloadFromConverter(converter, result,
                                                       settlement.CompanyId.ToString());

                settlement.ConvertedTimestamp = DateTime.Now;
            }

            if (filename != null)
            {
                if (SaveFileToDatabase(filename, settlement))
                {
                    await converter.DeleteAsync(result.target_files[0].id);
                }
            }
        }
Exemplo n.º 4
0
        public async Task <ZamzarResult> UploadAsync(string sourceFile)
        {
            const string url = endpoint + "/v1/jobs";

            using (HttpClientHandler handler = new HttpClientHandler {
                Credentials = new NetworkCredential(key, "")
            })
                using (HttpClient client = new HttpClient(handler))
                {
                    var request = new MultipartFormDataContent();
                    request.Add(new StringContent(targetFormat), "target_format");
                    request.Add(new StreamContent(File.OpenRead(sourceFile)), "source_file", new FileInfo(sourceFile).Name);
                    using (HttpResponseMessage response = await client.PostAsync(url, request).ConfigureAwait(false))
                        using (HttpContent content = response.Content)
                        {
                            string data = await content.ReadAsStringAsync();

                            ZamzarResult zResult = JsonSerializer.Deserialize <ZamzarResult>(data);
                            return(zResult);
                        }
                }
        }
Exemplo n.º 5
0
 private string GetSettlementId(ZamzarResult result)
 {
     return(SettlementHistoryParser.GetSettlementIdFromFile(
                result.target_files[0].name));
 }