예제 #1
0
        private void searchGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = sender as DataGridView;

            if (dgv != null && e.ColumnIndex == 4 && e.RowIndex > -1)
            {
                DataGridViewTextBoxCell fileNameCell = dgv.Rows[e.RowIndex].Cells[1] as DataGridViewTextBoxCell;
                DataGridViewTextBoxCell macCell      = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex + 1] as DataGridViewTextBoxCell;
                DataGridViewTextBoxCell hashCell     = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex + 2] as DataGridViewTextBoxCell;
                DataGridViewTextBoxCell sizeCell     = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex + 3] as DataGridViewTextBoxCell;
                DataGridViewButtonCell  buttonCell   = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell;

                BackgroundWorker downloadRequestWorker = new BackgroundWorker();
                downloadRequestWorker.DoWork += new DoWorkEventHandler(downloadRequestWorker_DoWork);

                DownloadRequest dr = new DownloadRequest();
                dr.mac      = (String)macCell.Value;
                dr.hash     = (String)hashCell.Value;
                dr.type     = ((String)buttonCell.Value).Equals("Download") ? "direct":"bounced";
                dr.fileName = (String)fileNameCell.Value;
                dr.fileSize = (long)sizeCell.Value;

                Utils.writeLog("searchGridView_CellClick: Sending download request for file : " + dr.fileName);

                downloadRequestWorker.RunWorkerAsync(dr);

                // Switch the tab to show the new download/bounce
                MainTabControl.SelectedIndex = ((String)buttonCell.Value).Equals("Download") ? 1 : 2;
            }
        }
예제 #2
0
        private void downloadRequestWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Utils.writeLog("downloadRequestWorker_DoWork: Sending download request");

            DownloadRequest dr = e.Argument as DownloadRequest;

            RestClient  client  = new RestClient("http://" + Configuration.server);
            RestRequest request = new RestRequest("download", Method.POST);

            request.AddParameter("mac", dr.mac); //TODO: Change this
            request.AddParameter("filehash", dr.hash);
            request.AddParameter("filename", dr.fileName);
            request.AddParameter("filesize", dr.fileSize);
            request.AddParameter("type", dr.type);

            RestResponse <StatusResponse> response = (RestResponse <StatusResponse>)client.Execute <StatusResponse>(request);

            StatusResponse sr = response.Data as StatusResponse;

            if (sr != null)
            {
                Utils.writeLog("downloadRequestWorker_DoWork: Download request returned : " + sr.ToString());
                if (!sr.status.Equals("OK"))
                {
                    MessageBox.Show("Couldn't process the download request. Error: " + sr.text, "Download Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // To make the download appear in the UI faster
                    if (!pollPendingWorker.IsBusy)
                    {
                        pollPendingWorker.RunWorkerAsync();
                    }
                }
            }
            else
            {
                Utils.writeLog("downloadRequestWorker_DoWork: Download request returned null");
                MessageBox.Show("Couldn't process the download request. Error: The server failed to return a valid response",
                                "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }