Beispiel #1
0
        private async void logGetButton_Click(object sender, EventArgs e)
        {
            AfcRestClient client = await GetAfcRestClient();

            if (client == null)
            {
                return;
            }
            try
            {
                if (processIdTextBox.Text != null)
                {
                    var response = await client.GetGeoBatchLog(processIdTextBox.Text);

                    geoBatchResponseTextBox.Text = Newtonsoft.Json.JsonConvert.SerializeObject(response, Newtonsoft.Json.Formatting.Indented);
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error Processing Sample Request", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                client.Dispose();
            }
        }
Beispiel #2
0
        private async void uploadButton_ClickAsync(object sender, EventArgs e)
        {
            // Get client for invoking Avalara for Communications REST API
            AfcRestClient client = await GetAfcRestClient();

            if (client == null)
            {
                return;
            }

            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                fileUploadLabel.Text = "File Uploaded:" + dialog.SafeFileName;
                byte[] buffer = File.ReadAllBytes(dialog.FileName);
                try
                {
                    var response = await client.GeoBatchUpload(buffer, dialog.SafeFileName);

                    geoBatchResponseTextBox.Text = Newtonsoft.Json.JsonConvert.SerializeObject(response, Newtonsoft.Json.Formatting.Indented);
                    processIdTextBox.Text        = response.ProcessId.ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error Processing Sample Request", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    client.Dispose();
                }
            }
        }
Beispiel #3
0
        private async void statusGetButton_Click(object sender, EventArgs e)
        {
            AfcRestClient client = await GetAfcRestClient();

            if (client == null)
            {
                return;
            }
            try
            {
                if (processIdTextBox.Text != null)
                {
                    var response = await client.GetGeoBatchStatus(processIdTextBox.Text);

                    geoBatchResponseTextBox.Text = Newtonsoft.Json.JsonConvert.SerializeObject(response, Newtonsoft.Json.Formatting.Indented);
                    geoBatchInputFileLink        = response.Downloads.InputFileDownload;
                    geoBatchOutputFileLink       = response.Downloads.OutputFileDownload;
                    if (!string.IsNullOrEmpty(geoBatchInputFileLink))
                    {
                        geoBatchInputDownloadButton.Visible = true;
                        geoBatchFileNotReadyLabel.Visible   = true;
                    }
                    if (!string.IsNullOrEmpty(geoBatchOutputFileLink))
                    {
                        geoBatchOutputDownloadButton.Visible = true;
                        geoBatchFileNotReadyLabel.Visible    = true;
                    }
                }
                else
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error Processing Sample Request", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                client.Dispose();
            }
        }
Beispiel #4
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();
            }
        }
Beispiel #5
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();
            }
        }