Exemple #1
0
        private async Task <string> _ValidateRunAsync(int i)
        {
            var file = this.Files.ElementAtOrDefault(i);

            // Write Log
            string t = FormatCli.H2($"Task: { (i + 1).ToString() }");

            t += FormatCli.KeyValue("File", file.File);
            t += FormatCli.KeyValue("Checksum", file.Checksum);

            //Checks
            var path = DirFile.Combine(this.AppSettings.Path.Export, file.File);

            if (!System.IO.File.Exists(path))
            {
                t += Environment.NewLine;
                t += $"Error: Could not find file {path}";
                return(t);
            }

            var checksum = await Task.Run(() => FilesModel.Hash(path));

            if (checksum != file.Checksum)
            {
                t += Environment.NewLine;
                t += $"Error: Checksum is not identical, backup maybe corrupted!";
                return(t);
            }

            t += FormatCli.KeyValue("Status", "Valid!");

            return(t);
        }
Exemple #2
0
        private async Task <string> _ImportRunTaskAsync(int i)
        {
            var file = this.Files.ElementAtOrDefault(i);

            // Write Log
            string t = FormatCli.H2($"Task: { (i + 1).ToString() }");

            t += FormatCli.KeyValue("File", file.File);
            t += FormatCli.KeyValue("Checksum", file.Checksum);

            //Checks
            var path = DirFile.Combine(this.AppSettings.Path.Export, file.File);

            if (!System.IO.File.Exists(path))
            {
                t += Environment.NewLine;
                t += $"Error: Could not find file {path}";
                return(t);
            }
            this.Import.File = path;

            // Validate
            if (this.Import.SkipValidation)
            {
                t += FormatCli.KeyValue("Status", "Skipped!");
            }
            else
            {
                var checksum = await Task.Run(() => FilesModel.Hash(path));

                if (checksum != file.Checksum)
                {
                    t += Environment.NewLine;
                    t += $"Error: Checksum is not identical, backup maybe corrupted!";
                    return(t);
                }

                t += FormatCli.KeyValue("Status", "Valid!");
            }

            // Decompress
            var decompress = await this.Import.DecompressAsync();

            // Import
            var task = await this.Import.RunAsync(this.Connect, this.Output);

            task.Duartion.Add(decompress.Duartion);

            t += FormatCli.KeyValue("Duration", task.Duartion.TotalMinutes + " min");
            if (this.Import.Config.Verbose)
            {
                t += FormatCli.H3("Parameter");
                var connector = this.Import.Config.Format == "p" ? new Connectors.Psql(AppSettings).BinName : this.Import.BinName;
                t += $"{ connector } { this.Import.GetPatameters(this.Connect) }" + Environment.NewLine;
            }

            if (!string.IsNullOrEmpty(task.Ouput))
            {
                t += FormatCli.H3("Output:");
                t += task.Ouput;
            }

            if (!string.IsNullOrEmpty(task.Error))
            {
                t += FormatCli.H3("Error:");
                t += task.Error;
            }

            return(t);
        }