Пример #1
0
        void UpdateUIForStep(BackupStep step)
        {
            CurrentStep = step;
            switch (step)
            {
            case BackupStep.BACKUP_SETTING:
                backupSettingsUserControl.Show();
                backupProcessingUserControl.Hide();
                backupCompleteUserControl.Hide();
                btn_Backup.Show();
                btn_Cancel.Show();
                btn_Complete.Hide();
                break;

            case BackupStep.BACKUP_PROCESSING:
                backupSettingsUserControl.Hide();
                backupProcessingUserControl.Show();
                backupCompleteUserControl.Hide();
                btn_Backup.Hide();
                btn_Cancel.Hide();
                btn_Complete.Hide();
                break;

            case BackupStep.BACKUP_COMPLETE:
                backupSettingsUserControl.Hide();
                backupProcessingUserControl.Hide();
                backupCompleteUserControl.Show();
                btn_Backup.Hide();
                btn_Cancel.Hide();
                btn_Complete.Show();
                break;
            }
        }
Пример #2
0
        public IEnumerable <BackupPlan> Read()
        {
            List <BackupPlan> plans = new List <BackupPlan>();

            configurationProvider.ReadConfigurationStreams(reader =>
            {
                List <BackupStep> steps = new();
                BackupPlan backupPlan   = new(BackupPlan.OnSelectionRunType)
                {
                    Steps = steps
                };

                bool beginOfFile       = true;
                bool isFirstCollection = true;
                BackupStep?lastStep    = null;
                foreach ((var key, var value, var newCollection) in ParseStream(reader))
                {
                    if (beginOfFile && !newCollection)
                    {
                        throw new InvalidOperationException("Faulty backup plan configuration.");
                    }

                    if (!beginOfFile && newCollection)
                    {
                        isFirstCollection = false;
                    }

                    if (isFirstCollection)
                    {
                        if (newCollection)
                        {
                            if (key == "plan")
                            {
                                backupPlan.Name = value;
                            }
                            else
                            {
                                throw new InvalidOperationException("Faulty backup plan configuration.");
                            }
                        }
                        else
                        {
                            if (key == "on")
                            {
                                backupPlan.RunType = value;
                            }
                            else
                            {
                                backupPlan[key] = value;
                            }
                        }
                    }
                    else
                    {
                        if (newCollection)
                        {
                            lastStep = new BackupStep(key)
                            {
                                DefaultProperty = value
                            };
                            steps.Add(lastStep);
                        }
                        else if (lastStep != null)
                        {
                            lastStep[key] = value;
                        }
                    }

                    beginOfFile = false;
                }

                plans.Add(backupPlan);
            });

            return(plans);
        }
Пример #3
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);
        }