Пример #1
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);
            }
        }
Пример #2
0
        private void registerWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            StatusResponse sr = (StatusResponse)e.Result;

            // Happens in both cases - if disconnected, will attempt to reconnect.
            if (sr == null || sr.status == null)
            {
                Utils.writeLog("registerWorker_RunWorkerCompleted: Error in registering");
                statusPictureBox.Image = Resources.connection_working;
                mainToolTip.SetToolTip(statusPictureBox, "Trying to connect..");
                actionButton.Enabled   = true;
                reconnectTimer.Enabled = true;
                return;
            }

            if (sr.status.Equals("OK"))
            {
                statusPictureBox.Image = Resources.connection_done;
                mainToolTip.SetToolTip(statusPictureBox, "Connected");
                statusLabel.Text = "Connected";
                Utils.writeLog("registerWorker_RunWorkerCompleted: Registered successfully");
                pollPendingTimer.Enabled = true;
                reconnectTimer.Enabled   = false;

                // If we had a failed sync, and are now connected
                if (syncPending && !syncWorker.IsBusy)
                {
                    syncWorker.RunWorkerAsync();
                }
            }
            else
            {
                statusPictureBox.Image = Resources.connection_working;
                mainToolTip.SetToolTip(statusPictureBox, "Trying to connect..");
                statusLabel.Text = sr.text;
                Utils.writeLog("registerWorker_RunWorkerCompleted: Could not register..");
                actionButton.Enabled   = true;
                reconnectTimer.Enabled = true;
            }
        }