Exemple #1
0
        public void Export(List <Control> controls)
        {
            Directory.CreateDirectory(Parameter.RepoConfig);
            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }
            var flow = new ConfigurationFlow {
                Name     = "setup.conf",
                Path     = FilePath,
                Controls = controls
            };

            if (!File.Exists(FilePath))
            {
                File.WriteAllText(FilePath, JsonConvert.SerializeObject(flow, Formatting.Indented));
            }
        }
Exemple #2
0
        public void Set()
        {
            Directory.CreateDirectory(Parameter.RepoConfig);
            if (!File.Exists(FilePath))
            {
                var backupConfigFile = $"{Parameter.RepoConfig}/network/000network.cfg";
                if (File.Exists(backupConfigFile))
                {
                    var lines          = File.ReadAllLines(backupConfigFile).ToArray();
                    var importControls = new List <Control>();
                    for (var i = 0; i < lines.Length; i++)
                    {
                        Bash.Execute(lines[i], false);
                        importControls.Add(new Control {
                            Index          = i,
                            FirstCommand   = lines[i],
                            ControlCommand = "",
                            Check          = ""
                        });
                    }
                    ConsoleLogger.Log("setup configuration file does not exist");
                    var importFlow = new ConfigurationFlow {
                        Name     = "setup.conf",
                        Path     = $"{Parameter.RepoConfig}/setup.conf",
                        Controls = importControls
                    };
                    if (File.Exists(importFlow.Path))
                    {
                        return;
                    }
                    File.WriteAllText(importFlow.Path, JsonConvert.SerializeObject(importFlow, Formatting.Indented));
                    ConsoleLogger.Log("a setup configuration file template has been created");
                    return;
                }
                ConsoleLogger.Log("setup configuration file does not exist");
                var tempFlow = new ConfigurationFlow {
                    Name     = ".setup.conf",
                    Path     = $"{Parameter.RepoConfig}/.setup.conf",
                    Controls = new List <Control> {
                        new Control {
                            Index          = 0,
                            FirstCommand   = "command that applies a configuration",
                            ControlCommand = "command that checks if the correct configuration has been applied",
                            Check          = "this value must be found in the ControlCommand result, leave blank if not needed"
                        },
                        new Control {
                            Index          = 1,
                            FirstCommand   = "command that applies a configuration",
                            ControlCommand = "command that checks if the correct configuration has been applied",
                            Check          = "this value must be found in the ControlCommand result, leave blank if not needed"
                        }
                    }
                };
                if (!File.Exists(tempFlow.Path))
                {
                    File.WriteAllText(tempFlow.Path, JsonConvert.SerializeObject(tempFlow, Formatting.Indented));
                    ConsoleLogger.Log("a setup configuration file template has been created");
                }
                return;
            }
            var text     = File.ReadAllText(FilePath);
            var flow     = JsonConvert.DeserializeObject <ConfigurationFlow>(text);
            var controls = flow?.Controls?.OrderBy(_ => _.Index);

            if (controls == null)
            {
                return;
            }
            foreach (var control in controls)
            {
                Launch(control);
            }
        }