예제 #1
0
        /// <summary>
        /// Gets data from the publish link (attaches a bearer token in case it's private) and
        /// converts the resulting CSV into a data table. If no parameters are included,
        /// </summary>
        /// <param name="PublishLink">The publish link from which we will get the data</param>
        /// <param name="ApiParameters">Changes the behavior of the Api calls</param>
        /// <returns>A data table representing the data from the publish link</returns>
        public async Task <DataTable> GetAquaCsvData(string PublishLink, ApiParametersContainer ApiParameters = null)
        {
            LoggingFunction?.Invoke($"Fetching CSV data from {PublishLink}");

            // publish links should never be cached responses unless specified
            var publishLinkResponse = await this.GetAsync(PublishLink, (ApiParameters ?? new ApiParametersContainer()
            {
                UseCaching = false
            }));

            if (!publishLinkResponse.IsSuccessful)
            {
                throw new Exception("Retrieval of data from publish link was unsuccessful: " + PublishLink);
            }

            // convert to CSV
            var jobName = ApiParameters?.JobName == null ? "" : $"{ApiParameters?.JobName}: ";

            LoggingFunction?.Invoke($"{jobName}Converting CSV data to DataTable");
            var tableFromCsv = DataTableUtility.ParseFromCsv(publishLinkResponse.Content);

            LoggingFunction?.Invoke($"{jobName}Successfully converted CSV data to DataTable");
            return(tableFromCsv);
        }