コード例 #1
0
        //Button Delecte Plan Clicked
        private void DeletePlanButtonClicked(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Are you sure you want to delete this plan?", "Delete Backup Plan", MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                string       id      = ((PlanControl)sender).LabelPlanId.Text;
                DialogResult dialog2 = MessageBox.Show("Do you want to delete cloud files too?", "Delete Backup Plan", MessageBoxButtons.YesNo);
                if (dialog2 == DialogResult.Yes)
                {
                    BackupPlan backupPlan = databaseService.GetBackupPlan(Int32.Parse(id));
                    Cloud      cloud      = databaseService.GetCloud(backupPlan.cloudId);
                    if (cloud.cloudType.Equals("dropbox"))
                    {
                        new DropBoxController().DeleteFolder(cloud.token, DeleteFolderCompelte, backupPlan.name);
                    }
                    else
                    {
                        new OneDriveController().DeleteFolder(cloud.token, DeleteFolderCompelte, backupPlan.name);
                    }
                }
                Logger.Log("The plan " + ((PlanControl)sender).LabelBackupName.Text + " was deleted!");
                databaseService.DeletePlan(Int32.Parse(id));
                MainWindow.instance.LoadAllControlls();
                MessageBox.Show("Plan deleted!");
            }
        }
コード例 #2
0
ファイル: BackupScheduler.cs プロジェクト: vplauzon/cosbak
 public CollectionPlan(
     LogCollectionBackupController logController,
     ICollectionFacade collection,
     Func <IndexCollectionController> indexControllerFactory,
     BackupPlan plan)
 {
     LogController          = logController;
     Collection             = collection;
     IndexControllerFactory = indexControllerFactory;
     Plan = plan;
 }
コード例 #3
0
 public void PerformBackup(PlanControl planControl, bool isFromSchedule)
 {
     if (!MainWindow.isActiveUploadOperation)
     {
         MainWindow.isActiveUploadOperation = true;
         DisableActions();
         string             password           = new DatabaseService().GetSettings().getPassword();
         BackupPlan         backupPlan         = databaseService.GetBackupPlan(Int32.Parse(planControl.LabelPlanId.Text));
         UploadBackupAction uploadBackupAction = new UploadBackupAction(backupPlan, planControl.LabelStatus, planControl.ProgressBarArchiving, BackupCompleteEvent, password, isFromSchedule);
         uploadBackupAction.StartBackupAction();
     }
 }
コード例 #4
0
        public void LoadQueueList()
        {
            listViewPlansQueue.Items.Clear();
            List <BackupPlan> plans = databaseService.GetAllPlans();

            plans.Sort(new Comparison <BackupPlan>((x, y) => DateTime.Compare(x.nextExecution, y.nextExecution)));
            BackupPlan planToQueue = null;

            foreach (var plan in plans)
            {
                if (!plan.scheduleType.Equals("Manual"))
                {
                    if (planToQueue == null)
                    {
                        planToQueue = plan;
                    }
                    listViewPlansQueue.Items.Add(new ListViewItem(new string[]
                    {
                        plan.name,
                        plan.nextExecution.ToString()
                    }));
                }
            }

            if (planToQueue != null)
            {
                if (DateTime.Compare(planToQueue.nextExecution, DateTime.Now) < 0)
                {
                    //execute now
                    ExecuteBackup(planToQueue.id);
                }
                else
                {
                    //set timer
                    int timerTime = (int)(planToQueue.nextExecution - DateTime.Now).TotalMilliseconds;
                    if (timerTime < 0)
                    {
                        timerTime = 2000;
                    }
                    executeBackupTimer.Stop();
                    executeBackupTimer.Interval = timerTime;
                    executeBackupTimer.Tick    += (sender, e) => ExecuteBackupTimer_Tick(sender, e, planToQueue.id);
                    executeBackupTimer.Enabled  = true;
                }
            }
        }
コード例 #5
0
        public void EventRestore(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Are you sure you want to restore this backup? Your current folder will be replaced by this one.", "Restore backup", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);

            if (DialogResult.Yes == result)
            {
                if (selectedItem != null && !MainWindow.isActiveDownloadOperation)
                {
                    string     password   = new DatabaseService().GetSettings().getPassword();
                    Backup     backup     = databaseService.GetBackup((int)selectedItem.Tag);
                    BackupPlan backupPlan = databaseService.GetBackupPlan(backup.backupPlanId);
                    Cloud      cloud      = databaseService.GetCloud(backup.cloudId);
                    mainInstance.ResetDownloadAction();
                    DownloadBackupAction downloadBackupAction = new DownloadBackupAction(cloud, backup.targetPath, labelStatus, progressBar, backupPlan.path, DownloadCompleteEvent, password, true);
                    downloadBackupAction.StartDownloadBackupAction();
                }
            }
        }
コード例 #6
0
ファイル: MyUtils.cs プロジェクト: cazacmarin/eFolder
        public static DateTime GetNextExecution(BackupPlan plan)
        {
            DateTime nextUpdate = DateTime.Now;

            nextUpdate = nextUpdate.AddHours(-nextUpdate.Hour + plan.scheduleTime.Hour);
            nextUpdate = nextUpdate.AddMinutes(-nextUpdate.Minute + plan.scheduleTime.Minute);
            switch (plan.scheduleType)
            {
            case "Monthly":
                if (nextUpdate.Day == plan.scheduleDay && DateTime.Compare(DateTime.Now, nextUpdate) < 0)
                {
                    return(nextUpdate);
                }

                nextUpdate = nextUpdate.AddDays(1);
                while (nextUpdate.Day != plan.scheduleDay)
                {
                    nextUpdate = nextUpdate.AddDays(1);
                }
                return(nextUpdate);

            case "Weekly":
                int dayOfWeek = (plan.scheduleDay == 7 ? 0 : plan.scheduleDay);
                if ((int)nextUpdate.DayOfWeek == dayOfWeek && DateTime.Compare(DateTime.Now, nextUpdate) < 0)
                {
                    return(nextUpdate);
                }
                nextUpdate = nextUpdate.AddDays(1);
                while ((int)nextUpdate.DayOfWeek != dayOfWeek)
                {
                    nextUpdate = nextUpdate.AddDays(1);
                }
                return(nextUpdate);

            case "Daily":
                return(DateTime.Compare(DateTime.Now, nextUpdate) < 0 ? nextUpdate : nextUpdate.AddDays(1));
            }
            return(new DateTime(2500, 1, 1));
        }
コード例 #7
0
        // Convert collection of `FileSystemTreeView.TreeNodeTag` to `BackupPlanSourceEntry`.
        public static List <BackupPlanSourceEntry> ToBackupPlanSourceEntry(
            this Dictionary <string, FileSystemTreeNodeData> dataDict, BackupPlan plan, BackupPlanSourceEntryRepository dao)
        {
            List <BackupPlanSourceEntry> sources = new List <BackupPlanSourceEntry>(dataDict.Count);

            foreach (var entry in dataDict)
            {
                FileSystemTreeNodeData data   = entry.Value;
                BackupPlanSourceEntry  source = null;
                if (data.Id != null)
                {
                    source = dao.Get(data.Id as long?);
                }
                else
                {
                    source = new BackupPlanSourceEntry();
                }
                source.BackupPlan = plan;
                source.Type       = data.ToEntryType();
                source.Path       = data.Path;
                sources.Add(source);
            }
            return(sources);
        }
コード例 #8
0
        private static void CreateDcsInstance(DcsClient dcsClient)
        {
            List <String> azCodes = new List <string>();

            azCodes.Add("cn-north-7b");
            List <int?> backupAt = new List <int?>();

            backupAt.Add(1);
            backupAt.Add(2);
            backupAt.Add(3);
            backupAt.Add(4);
            backupAt.Add(5);
            backupAt.Add(6);
            backupAt.Add(7);
            var backupPlan = new BackupPlan()
            {
                BackupAt   = backupAt,
                BeginAt    = "16:00-17:00",
                PeriodType = "weekly"
            };
            var backupPolicy = new BackupPolicy()
            {
                BackupType           = "auto",
                PeriodicalBackupPlan = backupPlan,
                SaveDays             = 7
            };
            var createDcsInstanceRequest = new CreateDCSInstanceRequest()
            {
                Body = new CreateInstanceBody()
                {
                    Capacity             = 2,
                    Name                 = "dcs_create_instance_test",
                    Engine               = "Redis",
                    EngineVersion        = "4.0",
                    NoPasswordAccess     = true,
                    VpcId                = "5e37b3be-950a-48e1-b498-65b63d336481",
                    SubnetId             = "a4112635-3ec0-471c-95c3-5cf49b9533af",
                    SpecCode             = "redis.ha.au1.large.2",
                    AzCodes              = azCodes,
                    InstanceBackupPolicy = backupPolicy
                }
            };

            try
            {
                var response = dcsClient.CreateDCSInstance(createDcsInstanceRequest);
                Console.WriteLine(response.GetHttpBody());
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }
コード例 #9
0
 public DefaultPathScanner(BackupPlan plan, CancellationToken cancellationToken)
 {
     CancellationToken = cancellationToken;
     Plan = plan;
 }
コード例 #10
0
        public IEnumerable <BackupPlan> Read()
        {
            List <BackupPlan> plans = new List <BackupPlan>();

            configurationProvider.ReadConfigurationStreams(reader =>
            {
                var yamlStream = new YamlStream();
                try
                {
                    yamlStream.Load(reader);

                    if (yamlStream.Documents[0].RootNode is YamlSequenceNode root)
                    {
                        foreach (var planEntry in root.Children.OfType <YamlMappingNode>())
                        {
                            List <BackupStep> steps = new List <BackupStep>();
                            var planType            = (GetChildNode(planEntry.Children, "on") as YamlScalarNode)?.Value ?? BackupPlan.OnSelectionRunType;
                            var plan = new BackupPlan(planType)
                            {
                                Steps = steps
                            };

                            foreach (var planProperty in planEntry.Children)
                            {
                                if (planProperty.Key is YamlScalarNode scalarKey &&
                                    planProperty.Value is YamlScalarNode scalarValue)
                                {
                                    if (scalarKey.Value == "on")
                                    {
                                        continue;
                                    }
                                    if (scalarKey.Value == "plan")
                                    {
                                        plan.Name = scalarValue.Value;
                                    }
                                    else
                                    {
                                        if (scalarKey.Value != null)
                                        {
                                            plan[scalarKey.Value] = (planProperty.Value as YamlScalarNode)?.Value;
                                        }
                                    }
                                }
                            }

                            if (GetChildNode(planEntry.Children, "steps") is YamlSequenceNode stepsEntries)
                            {
                                foreach (var stepEntry in stepsEntries.Children.OfType <YamlMappingNode>())
                                {
                                    if (stepEntry.Children.Any())
                                    {
                                        var firstYamlChild = stepEntry.Children.First();
                                        var stepType       = (firstYamlChild.Key as YamlScalarNode)?.Value;

                                        if (stepType != null)
                                        {
                                            var step = new BackupStep(stepType);

                                            bool firstProperty = true;
                                            foreach (var stepProperty in stepEntry.Children)
                                            {
                                                if (stepProperty.Key is YamlScalarNode scalarKey &&
                                                    stepProperty.Value is YamlScalarNode scalarValue)
                                                {
                                                    if (firstProperty)
                                                    {
                                                        step.DefaultProperty = scalarValue?.Value;
                                                    }
                                                    else
                                                    {
                                                        if (scalarKey.Value != null)
                                                        {
                                                            step[scalarKey.Value] = scalarValue?.Value;
                                                        }
                                                    }
                                                    firstProperty = false;
                                                }
                                            }

                                            steps.Add(step);
                                        }
                                        else
                                        {
                                            steps.Add(new InvalidBackupStep("Step has no type."));
                                        }
                                    }
                                }
                            }

                            plans.Add(plan);
                        }
                    }
                }
                catch (Exception ex) when(ex is SyntaxErrorException || ex is SemanticErrorException)
                {
                    throw new InvalidOperationException("Faulty backup plan configuration.", ex);
                }
            });

            return(plans);
        }
コード例 #11
0
 public ExecutableBackupPlan(BackupPlan backupPlan, IPlanExecution execution, IPlanExecutionEvents events)
 {
     BackupPlan = backupPlan;
     Execution  = execution;
     Events     = events;
 }