Example #1
0
        public void Backup(string groupName)
        {
            const string robocopy = "robocopy";

            if (!ProcUtil.Exists(robocopy))
            {
                Console.Error.WriteLine($"Cannot find {robocopy}, program terminated");
                return;
            }

            var config = JsonConfigOperator <RobocopyConfig> .LoadCreate(RobocopyConfigParameters.fullConfigFilePath);

            foreach (var group in config.BackupGroups)
            {
                if (group.GroupName == groupName)
                {
                    string flags = $"/MT:16 /R:1 /W:3 /MIR /FFT /NP /LOG+:recover_{groupName}-{new Random().Next(0, 99999)}.log";

                    bool firstItem = true;
                    foreach (var backup in group.BackupItems)
                    {
                        if (!firstItem)
                        {
                            Console.WriteLine("-----------------------------------------------");
                        }
                        string arguments = $"\"{backup.Source}\" \"{backup.Target}\" {flags}";
                        Console.WriteLine($"Executing: {robocopy} {arguments}");
                        ProcUtil.Run(robocopy, arguments);
                        firstItem = false;
                    }
                }
            }
        }
Example #2
0
        public void Spawn(int ms)
        {
            try
            {
                const string logPrefix = "Test :>";
                Console.WriteLine($"{logPrefix} Start {Process.GetCurrentProcess().Id}");

                var info = ProcUtil.GetDotnetExeFullPath(); // or just use "dotnet" directly

                // start self
                // ==========
                var proc = Process.Start(info, $@"{ProcUtil.GetDllFullPath(this.GetType())} proc work {ms}");
                //var proc = Process.Start(info,$@"{procUtil.GetDllFullPath()} proc dll")

                // start a different dll
                // =====================
                //var proc = Process.Start(info, $@"I:\rp\git\CoreCmd\DependentConsoleApp\bin\Debug\netcoreapp3.1\DependentConsoleApp.dll demo progress-bar");

                /** NOTE
                 * If not call WaitForExit(), when the program will:
                 * - execute asynchronously
                 * - wait for console input to quit when the spawned process finishes ---> don't know why
                 */
                proc.WaitForExit();
                Console.WriteLine($"{logPrefix} Finish");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #3
0
 public void Exist(string command)
 {
     if (ProcUtil.Exists(command))
     {
         Console.WriteLine($"{command} exists");
     }
     else
     {
         Console.WriteLine($"{command} does not exists");
     }
 }
Example #4
0
    static HashSet <string> MatchGitFiles(Regex regex, int groupIndex)
    {
        var res = new HashSet <string>();

        foreach (var line in ProcUtil.OutputAsLines("git", "status --porcelain"))
        {
            var path = regex.Match(line).Groups[groupIndex].ToString();
            if (!String.IsNullOrEmpty(path))
            {
                res.Add(path);
            }
        }
        return(res);
    }
Example #5
0
 public void Dll()
 {
     Console.WriteLine(ProcUtil.GetDllDir());
     Console.WriteLine(ProcUtil.GetDllFullPath(this.GetType()));
     Console.WriteLine(ProcUtil.GetDotnetExeFullPath());
 }