Esempio n. 1
0
        private void btnBackupSelected_Click(object sender, EventArgs e)
        {
            if (listTargets.SelectedItems.Count == 0)
                return;

            var target = Backup.GetTarget(listTargets.SelectedItems[0].Text);
            using (var worker = new BGWorkForm<bool>("Backing up...", "",
                helper =>
                {
                    target.Backup(helper.WorkName, helper.Progress);
                }, null, true, false))
            {
                var result = worker.ShowDialog(this);
                switch (result)
                {
                    case DialogResult.OK:
                        MessageBox.Show($"Succesfully backed up \"{target.What}\"");
                        break;

                    case DialogResult.No:
                        throw worker.WorkException;
                }
            }
        }
Esempio n. 2
0
        private void btnShouldCompress_Click(object sender, EventArgs e)
        {
            using (var worker = new BGWorkForm<Tuple<bool, long, long>>("Testing compression...", $"Testing {CompressionLevel.ToString()} {CompressionAlgo.ToString()}",
                helper =>
                {
                    using (var fileStream = File.Open(What, FileMode.Open, FileAccess.ReadWrite))
                    {
                        var length = fileStream.Length;
                        var result = length;
                        helper.SetResult(Tuple.Create(
                            CompressionUtil.TestCompression(fileStream, CompressionAlgo, CompressionLevel,
                            helper.Progress, out result),
                            length, result));
                    }
            }, null, true, false))
            {
                var result = worker.ShowDialog(this);
                switch (result)
                {
                    case DialogResult.OK:
                        checkCompressed.Checked = worker.WorkResult.Item1;
                        MessageBox.Show($"{worker.WorkTime.ToString(@"mm\:ss\:fff")}{Environment.NewLine}" +
                            $"{worker.WorkResult.Item2:n0} => {worker.WorkResult.Item3:n0}" +
                            $" ({Math.Round(100d - ((double)worker.WorkResult.Item3 / worker.WorkResult.Item2) * 100d, 3)}%, {worker.WorkResult.Item3 - worker.WorkResult.Item2:n0})");
                        break;

                    case DialogResult.No:
                        MessageBox.Show(this, $"Compression failed: {worker.WorkException.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                }
            }
        }
Esempio n. 3
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            if (Backup.TargetCount() > 0)
            {
                UpdateList();

                var missed = Backup.MissedTargetCount();
                if (missed > 0)
                {
                    var backupPolicy = (MissedBackupPolicy)Settings.Default.MissedBackup;
                    if (((backupPolicy == MissedBackupPolicy.Ask && MessageBox.Show(this,

                        $"{missed} file backup{(missed == 1 ? " has" : "s have")} been missed. Would you like to back {(missed == 1 ? "it" : "them")} up now?" +
                        Environment.NewLine + Environment.NewLine +
                        string.Join(Environment.NewLine, Backup.MissedTargetWhats.Take(3)) +
                        $"{(Backup.MissedTargetCount() > 3 ? $"{Environment.NewLine}... and {Backup.MissedTargetCount() - 3} more" : "")}",

                        "Missed backups", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) ||
                        backupPolicy == MissedBackupPolicy.Never))
                    {
                        Backup.SkipTargetsToNextBackups();
                        return;
                    }

                    using (var worker = new BGWorkForm<bool>($"Backing up missed file{(missed > 1 ? "s" : "")}...", "",
                    helper =>
                    {
                        Backup.EnsureBackups(helper.WorkName, helper.Progress);
                    }, null, true, false))
                    {
                        var result = worker.ShowDialog(this);
                        switch (result)
                        {
                            case DialogResult.OK:
                                MessageBox.Show(this, $"Succesfully backed up missed file{(missed > 1 ? "s" : "")}",
                                    "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                break;
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 void DoBackups()
 {
     using (var worker = new BGWorkForm<bool>("Doing backups...", "",
         helper =>
         {
             Backup.DoBackups(helper.WorkName, helper.Progress);
         }, null, true, false))
     {
         var result = worker.ShowDialog(this);
         switch (result)
         {
             case DialogResult.OK:
                 MessageBox.Show("Succesfully backed up your shit");
                 break;
         }
     }
 }