예제 #1
0
        void RequestFileManifest()
        {
            if (!backup.IsConnected)
            {
                MessageBox.Show(this, "Not connected to remote, cannot request file manifest",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            BGWorkForm worker = new BGWorkForm("Manifest", "Requesting file manifest", (args, report, cancel, workName) =>
            {
                backup.RequestFileManifest();
                Invoke((MethodInvoker)delegate { UpdateList(); });
            }, null, false, false);

            worker.ShowDialog(this);
        }
예제 #2
0
        private void btnBackupNow_Click(object sender, EventArgs e)
        {
            if (!backup.IsConnected)
            {
                Connect();
                return;
            }

            BGWorkForm worker = new BGWorkForm("Backing up", ".", (args, report, cancel, workName) =>
            {
                backup.DoBackups(s => workName(s), p => report((int)p));
            }, null, true, false);

            worker.ShowDialog(this);
        }
예제 #3
0
        void Connect()
        {
            if (string.IsNullOrWhiteSpace(backup.Remote))
            {
                MessageBox.Show(this, "No remote set",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int status = 0; // TODO: ugly
            BGWorkForm worker = new BGWorkForm("Connect", $"Attempting connection to {backup.Remote}", (args, report, cancel, workName) =>
            {
                DiscoverResult discoverResult = backup.DiscoverRemote();
                if (discoverResult == DiscoverResult.NotFound)
                {
                    args.Result = Tuple.Create(ConnectResult.RemoteNotDiscovered, "");
                    return;
                }
                else if (discoverResult == DiscoverResult.Canceled)
                {
                    args.Cancel = true;
                    return;
                }

                status = 1;

                workName($"Connecting to {backup.Remote}");

                string keyHash = "";

                KeyForm keyForm = new KeyForm();
                keyForm.Text = $"Key for {backup.Remote}";

                if (keyForm.ShowDialog() == DialogResult.OK)
                    keyHash = keyForm.GetKeyHash();
                else
                {
                    args.Cancel = true;
                    return;
                }

                string error = "";
                ConnectResult res = backup.Connect(keyHash, out error);
                args.Result = Tuple.Create(res, error);

            }, () =>
            {
                if (status == 0)
                    backup.CancelDiscover();
                else
                    backup.CancelConnect();
            }, false);

            DialogResult result = worker.ShowDialog(this);

            switch (result)
            {
                case DialogResult.OK:
                    Tuple<ConnectResult, string> res = (Tuple<ConnectResult, string>)worker.WorkResult;
                    switch (res.Item1)
                    {
                        case ConnectResult.Approved:
                            RequestFileManifest();
                            break;

                        case ConnectResult.Error:
                            MessageBox.Show(worker, !string.IsNullOrWhiteSpace(res.Item2) ? res.Item2 : "Unspecified error",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;

                        case ConnectResult.NoRemote:
                            MessageBox.Show(worker, "No remote set",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;

                        case ConnectResult.RemoteNotDiscovered:
                            MessageBox.Show(worker, $"Couldn't find remote at {backup.Remote}",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;

                        case ConnectResult.Canceled:
                            break;
                    }
                    break;
            }
        }