Ejemplo n.º 1
0
        public static bool CheckPgDumpVersion(PgDumpBuilder builder)
        {
            var    option      = (typeof(Settings).GetField($"{builder.PgDumpName}Args").GetValue(null) as Arg).Original;
            var    connVersion = builder.Connection.ServerVersion.Split(".").First();
            string fullDumpVersion;
            string dumpVersion;

            try
            {
                fullDumpVersion = builder.GetDumpVersion();
                dumpVersion     = fullDumpVersion.Split(".").First();
            }
            catch (Exception e)
            {
                PgDumpError(connVersion, e, option);
                return(false);
            }

            if (!string.Equals(connVersion, dumpVersion))
            {
                builder.SetPgDumpName(string.Format(Value.PgDumpFallback, connVersion));
                try
                {
                    fullDumpVersion = builder.GetDumpVersion();
                    dumpVersion     = fullDumpVersion.Split(".").First();
                }
                catch (Exception e)
                {
                    PgDumpError(connVersion, e, option);
                    return(false);
                }

                var value = typeof(Settings).GetProperty(builder.PgDumpName).GetValue(Value);
                if (!string.Equals(connVersion, dumpVersion))
                {
                    PgDumpMistmatch(builder.Connection, connVersion, fullDumpVersion, dumpVersion, value, option);
                    return(false);
                }
                Program.WriteLine(ConsoleColor.Yellow, "",
                                  $"WARNING: Using fall-back path for pg_dump: {value}. To remove this warning set the {option} setting to point to this path.");
            }
            return(true);
        }