Exemplo n.º 1
0
        private void DownloadFile(string controller, string action, List <ServerRequestParameter> list)
        {
            byte[] res;

            try
            {
                Client      client = new Client();
                RequestBody rb     = RequestBody.Create(controller, action);
                foreach (var parameter in list)
                {
                    rb.AddParameter(parameter.Key, parameter.Value);
                }

                client.SendRequest(rb);
                res            = client.GetResultFile();
                ServerResponse = client.Response;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.ShowDialog();

            if (string.IsNullOrEmpty(dialog.FileName))
            {
                return;
            }


            File.WriteAllBytes(dialog.FileName, res);
        }
Exemplo n.º 2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button1.Text    = "Sending request...";

            var    list       = ((IEnumerable)dataGrid.DataSource).Cast <ServerRequestParameter>().ToList();
            string controller = txController.Text;
            string action     = txAction.Text;

            if (ckFileResult.Checked)
            {
                DownloadFile(controller, action, list);
                Result = new OperationResult()
                {
                    Status  = 600,
                    Entity  = "",
                    Message = "File saved"
                };
                Close();
                return;
            }

            SaveCache();

            OperationResult res = await Task.Run(() =>
            {
                try
                {
                    Client client  = new Client();
                    RequestBody rb = RequestBody.Create(controller, action);
                    foreach (var parameter in list)
                    {
                        rb.AddParameter(parameter.Key, parameter.Value);
                    }

                    client.SendRequest(rb);

                    var result     = client.GetResult();
                    ServerResponse = client.Response;
                    return(result);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
            });

            Result = res;
            Close();
        }
Exemplo n.º 3
0
        private async void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button1.Text    = "Sending request...";

            var list = ((IEnumerable)dataGrid.DataSource)
                       .Cast <ServerRequestParameter>()
                       .Where(p => !string.IsNullOrEmpty(p.Key))
                       .ToList();
            string controller = txController.Text;
            string action     = txAction.Text;

            if (ckFileResult.Checked)
            {
                DownloadFile(controller, action, list);
                Result = new OperationResult()
                {
                    Status  = 600,
                    Entity  = "",
                    Message = "File saved"
                };
                Close();
                return;
            }

            SaveCache();
            int             chunkSize         = (int)txChunkResponseSize.Value;
            string          responseStorageId = txMemoryStorageId.Text;
            OperationResult res = await Task.Run(() =>
            {
                try
                {
                    Client client  = new Client();
                    RequestBody rb = RequestBody.Create(controller, action);
                    if (!string.IsNullOrEmpty(responseStorageId) &&
                        chunkSize > 0)
                    {
                        rb.SaveOnMemoryStorage(txMemoryStorageId.Text);
                    }
                    foreach (var parameter in list)
                    {
                        rb.AddParameter(parameter.Key, parameter.Value);
                    }
                    rb.AddParameter("authorization", Auth.Token ?? "");

                    client.SendRequest(rb);

                    OperationResult result = (chunkSize == 0
                        ? client.GetResult()
                        : client.GetChunkedResult(chunkSize));
                    ServerResponse = client.Response;
                    return(result);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }
            });

            Result = res;
            Close();
        }