Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether the report export is created.
        /// </summary>
        /// <param name="exportfileid">The export file ID.</param>
        /// <returns>
        ///   <c>true</c> if the report export is created; otherwise, <c>false</c>.
        /// </returns>
        public bool IsReportExportCreated(string exportfileid)
        {
            try
            {
                var           request  = new RestRequest($"api/files/{exportfileid}/index", Method.GET);
                IRestResponse response = _client.Execute(request);
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpResponseException(new HttpResponseMessage(response.StatusCode)
                    {
                        Content = new StringContent(response.Content)
                    });
                }

                try
                {
                    NcoaResponse file = JsonConvert.DeserializeObject <NcoaResponse>(response.Content);
                    return(file.Status == "Exported" || file.Status == "Processed");
                }
                catch
                {
                    throw new Exception($"Failed to deserialize NCOA response: {response.Content}");
                }
            }
            catch (Exception ex)
            {
                throw new AggregateException("Communication with NCOA server failed: Could not check if the export is created. Possible cause is the NCOA API server is down.", ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the NCOA file on the NCOA server.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="companyName">Name of the company.</param>
        /// <param name="id">The identifier.</param>
        public void CreateFile(string fileName, string companyName, out string id)
        {
            id = null;
            try
            {
                // submit for exporting
                var request = new RestRequest($"api/files/{fileName}/index", Method.POST);
                request.AddParameter("application/x-www-form-urlencoded", $"caption={Uri.EscapeDataString(companyName)}", ParameterType.RequestBody);
                IRestResponse response = _client.Execute(request);
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpResponseException(new HttpResponseMessage(response.StatusCode)
                    {
                        Content = new StringContent(response.Content)
                    });
                }

                try
                {
                    NcoaResponse file = JsonConvert.DeserializeObject <NcoaResponse>(response.Content);
                    id = file.Id;
                }
                catch
                {
                    throw new Exception($"Failed to deserialize NCOA response: {response.Content}");
                }
            }
            catch (Exception ex)
            {
                throw new AggregateException("Communication with NCOA server failed: Could not create address file on the NCOA server that is required to begin processing. Possible cause is the NCOA API server is down.", ex);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the report export.
        /// </summary>
        /// <param name="id">Name of the file.</param>
        /// <param name="exportfileid">The export file ID.</param>
        public void CreateReportExport(string id, out string exportfileid)
        {
            exportfileid = null;
            try
            {
                // submit for exporting
                var request = new RestRequest($"api/files/{id}/index", Method.PATCH);
                request.AddParameter("application/x-www-form-urlencoded", "status=export", ParameterType.RequestBody);
                IRestResponse response = _client.Execute(request);
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpResponseException(new HttpResponseMessage(response.StatusCode)
                    {
                        Content = new StringContent(response.Content)
                    });
                }

                try
                {
                    NcoaResponse file = JsonConvert.DeserializeObject <NcoaResponse>(response.Content);
                    exportfileid = file.Id;
                }
                catch
                {
                    throw new Exception($"Failed to deserialize NCOA response: {response.Content}");
                }
            }
            catch (Exception ex)
            {
                throw new AggregateException("Communication with NCOA server failed: Could not create export. Possible cause is the NCOA API server is down.", ex);
            }
        }