Esempio n. 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public AfcRestDemoForm()
        {
            // Initialize controls
            InitializeComponent();
            maxTimeComboBox.Text    = "10";
            maxThreadsComboBox.Text = "5";
            usernameTextBox.Text    = ConfigurationManager.AppSettings["DefaultUsername"];
            passwordTextBox.Text    = ConfigurationManager.AppSettings["DefaultPassword"];
            clientIDTextBox.Text    = ConfigurationManager.AppSettings["DefaultClientID"];
            profileIDTextBox.Text   = ConfigurationManager.AppSettings["DefaultProfileID"];
            urlStatusLabel.Text     = $"URL: {ConfigurationManager.AppSettings["AfcRestApiUrl"]}";
            versionStatusLabel.Text = string.Empty;

            // Initialize line series for chart
            lineSeries             = new Telerik.WinControls.UI.LineSeries();
            chart.ShowLegend       = false;
            lineSeries.BorderColor = Color.Orange;
            chart.Series.Add(lineSeries);
            chart.Area.Axes[0].Title = "Time Elapsed (minutes)";
            chart.Area.Axes[1].Title = "Requests Per Minute";

            // Set default sample request
            CalcTaxesRequest request     = CreateDefaultRequest();
            string           requestBody = Newtonsoft.Json.JsonConvert.SerializeObject(request, Newtonsoft.Json.Formatting.Indented);

            requestTextBox.Text = requestBody;
        }
Esempio n. 2
0
        /// <summary>
        /// Invokes the Avalara for Communications REST API to process the sample request.
        /// </summary>
        private async Task ProcessSampleRequest()
        {
            // Get client for invoking Avalara for Communications REST API
            AfcRestClient client = await GetAfcRestClient();

            if (client == null)
            {
                return;
            }

            // Get request from input
            CalcTaxesRequest request = GetSampleRequest();

            if (request == null)
            {
                return;
            }

            try
            {
                CalcTaxesResponse response = await client.CalcTaxes(request);

                responseTextBox.Text = Newtonsoft.Json.JsonConvert.SerializeObject(response, Newtonsoft.Json.Formatting.Indented);
            }
            catch (AggregateException ex)
            {
                MessageBox.Show(this, ex.InnerException?.Message ?? ex.Message, "Error Processing Sample Request",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error Processing Sample Request", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                client.Dispose();
            }
        }
        /// <summary>
        /// Performs tax calculations on all invoices and line items within the request body.
        /// </summary>
        /// <exception cref="avalara.comms.rest.v2.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="calcTaxesRequest">CalcTaxesRequest object containing invoices to process and data required               for performing tax calculations. (optional)</param>
        /// <returns>Task of ApiResponse (CalcTaxesResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <CalcTaxesResponse> > ApiV2AfcCalcTaxesPostAsyncWithHttpInfo(CalcTaxesRequest calcTaxesRequest = default(CalcTaxesRequest))
        {
            var    localVarPath         = "/api/v2/afc/CalcTaxes";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "text/plain",
                "application/json",
                "text/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (calcTaxesRequest != null && calcTaxesRequest.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(calcTaxesRequest); // http body (model) parameter
            }
            else
            {
                localVarPostBody = calcTaxesRequest; // byte array
            }

            // authentication (Basic) required
            // http basic authentication required
            if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password))
            {
                localVarHeaderParams["Authorization"] = "Basic " + ApiClient.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password);
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("ApiV2AfcCalcTaxesPost", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <CalcTaxesResponse>(localVarStatusCode,
                                                       localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
                                                       (CalcTaxesResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(CalcTaxesResponse))));
        }
        /// <summary>
        /// Performs tax calculations on all invoices and line items within the request body.
        /// </summary>
        /// <exception cref="avalara.comms.rest.v2.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="calcTaxesRequest">CalcTaxesRequest object containing invoices to process and data required               for performing tax calculations. (optional)</param>
        /// <returns>Task of CalcTaxesResponse</returns>
        public async System.Threading.Tasks.Task <CalcTaxesResponse> ApiV2AfcCalcTaxesPostAsync(CalcTaxesRequest calcTaxesRequest = default(CalcTaxesRequest))
        {
            ApiResponse <CalcTaxesResponse> localVarResponse = await ApiV2AfcCalcTaxesPostAsyncWithHttpInfo(calcTaxesRequest);

            return(localVarResponse.Data);
        }
        /// <summary>
        /// Performs tax calculations on all invoices and line items within the request body.
        /// </summary>
        /// <exception cref="avalara.comms.rest.v2.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="calcTaxesRequest">CalcTaxesRequest object containing invoices to process and data required               for performing tax calculations. (optional)</param>
        /// <returns>CalcTaxesResponse</returns>
        public CalcTaxesResponse ApiV2AfcCalcTaxesPost(CalcTaxesRequest calcTaxesRequest = default(CalcTaxesRequest))
        {
            ApiResponse <CalcTaxesResponse> localVarResponse = ApiV2AfcCalcTaxesPostWithHttpInfo(calcTaxesRequest);

            return(localVarResponse.Data);
        }
Esempio n. 6
0
        /// <summary>
        /// Begins running the performance test for the Avalara for Communications REST service.
        /// </summary>
        private async Task StartPerformanceTest()
        {
            ClearPerformanceStats();

            // Get client for invoking Avalara for Communications REST API
            AfcRestClient afcClient = await GetAfcRestClient();

            if (afcClient == null)
            {
                EndPerformanceTest(false);
                return;
            }

            // Get request from input
            performanceTestRequest = GetSampleRequest();

            if (performanceTestRequest == null)
            {
                EndPerformanceTest(false);
                return;
            }

            try
            {
                // Process request once to validate request body
                await afcClient.CalcTaxes(performanceTestRequest);

                maxThreads = int.Parse(maxThreadsComboBox.Text);
                maxMinutes = int.Parse(maxTimeComboBox.Text);

                // Create tasks for the specified number of threads
                var tasks = new List <Task>();

                for (int threadCount = 0; threadCount < maxThreads; threadCount++)
                {
                    tasks.Add(new Task(async() =>
                    {
                        AfcRestClient client = afcClient;
                        Stopwatch stopwatch  = new Stopwatch();

                        try
                        {
                            while (!cancellationToken.IsCancellationRequested)
                            {
                                stopwatch.Restart();
                                var response = await client.CalcTaxes(performanceTestRequest);
                                stopwatch.Stop();
                                responseStats.Enqueue((int)stopwatch.ElapsedMilliseconds);
                                int taxCount = response.InvoiceResults?.Sum(inv => inv.ItemResults?.Sum(item => item.Taxes?.Count() ?? 0) ?? 0) ?? 0;
                                Interlocked.Increment(ref requestCount);
                                Interlocked.Add(ref taxesReturned, taxCount);
                            }
                        }
                        catch
                        {
                            Interlocked.Increment(ref failedRequests);
                        }
                    }));
                }

                // Begin making calls to Avalara for Communications REST API
                startTime = DateTime.UtcNow;
                tasks.ForEach(t => t.Start());
            }
            catch
            {
                afcClient.Dispose();
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Performs tax calculations on one or multiple invoices and returns the taxes generated.
 /// </summary>
 /// <param name="calcTaxesRequest">Object containing invoice data to be processed for tax calculations.</param>
 /// <returns>Object containing tax calculation results.</returns>
 public async Task <CalcTaxesResponse> CalcTaxes(CalcTaxesRequest calcTaxesRequest)
 {
     return(await PostAsJsonAsync <CalcTaxesResponse>("api/v2/afc/CalcTaxes", calcTaxesRequest));
 }
        /// <summary>
        /// Performs tax calculations on all invoices and line items within the request body.
        /// </summary>
        /// <exception cref="avalara.comms.rest.v2.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="calcTaxesRequest">CalcTaxesRequest object containing invoices to process and data required               for performing tax calculations. (optional)</param>
        /// <returns>Task of ApiResponse (CalcTaxesResponse)</returns>
        public async System.Threading.Tasks.Task <avalara.comms.rest.v2.Client.ApiResponse <CalcTaxesResponse> > ApiV2AfcCalcTaxesPostAsyncWithHttpInfo(CalcTaxesRequest calcTaxesRequest = default(CalcTaxesRequest))
        {
            avalara.comms.rest.v2.Client.RequestOptions localVarRequestOptions = new avalara.comms.rest.v2.Client.RequestOptions();

            String[] _contentTypes = new String[] {
                "application/json-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };

            // to determine the Accept header
            String[] _accepts = new String[] {
                "text/plain",
                "application/json",
                "text/json"
            };

            foreach (var _contentType in _contentTypes)
            {
                localVarRequestOptions.HeaderParameters.Add("Content-Type", _contentType);
            }

            foreach (var _accept in _accepts)
            {
                localVarRequestOptions.HeaderParameters.Add("Accept", _accept);
            }

            localVarRequestOptions.Data = calcTaxesRequest;

            // authentication (Basic) required
            // http basic authentication required
            if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password))
            {
                localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + avalara.comms.rest.v2.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
            }

            // make the HTTP request

            var localVarResponse = await this.AsynchronousClient.PostAsync <CalcTaxesResponse>("/api/v2/afc/CalcTaxes", localVarRequestOptions, this.Configuration);

            if (this.ExceptionFactory != null)
            {
                Exception _exception = this.ExceptionFactory("ApiV2AfcCalcTaxesPost", localVarResponse);
                if (_exception != null)
                {
                    throw _exception;
                }
            }

            return(localVarResponse);
        }
 /// <summary>
 /// Performs tax calculations on all invoices and line items within the request body.
 /// </summary>
 /// <exception cref="avalara.comms.rest.v2.Client.ApiException">Thrown when fails to make API call</exception>
 /// <param name="calcTaxesRequest">CalcTaxesRequest object containing invoices to process and data required               for performing tax calculations. (optional)</param>
 /// <returns>CalcTaxesResponse</returns>
 public CalcTaxesResponse ApiV2AfcCalcTaxesPost(CalcTaxesRequest calcTaxesRequest = default(CalcTaxesRequest))
 {
     avalara.comms.rest.v2.Client.ApiResponse <CalcTaxesResponse> localVarResponse = ApiV2AfcCalcTaxesPostWithHttpInfo(calcTaxesRequest);
     return(localVarResponse.Data);
 }