Exemplo n.º 1
0
        /// <summary>
        /// Create connection string
        /// </summary>
        /// <param name="connection">Connection Model</param>
        /// <returns></returns>
        public string ConnectionString(Connection.IBaseModel connection)
        {
            if (connection == null)
            {
                return(string.Empty);
            }

            var con = string.Format(
                "--host {0} --port {2} --username \"{1}\"",
                connection.Server,
                connection.User,
                connection.Port);

            if (!string.IsNullOrEmpty(connection.Database) && !string.IsNullOrWhiteSpace(connection.Database))
            {
                con += " --dbname \"" + connection.Database + "\"";
            }

            if (string.IsNullOrEmpty(connection.Password) && string.IsNullOrWhiteSpace(connection.Password))
            {
                con += " --no-password";
            }

            return(con);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Run application with given parameters
        /// </summary>
        /// <param name="connection">Connection Model</param>
        /// <param name="output">display output</param>
        /// <returns></returns>
        public ProcessResultModel Run(Connection.IBaseModel connection, bool output = false)
        {
            if (connection == null)
            {
                return(null);
            }

            try
            {
                using (Process p = this.CreateProcess(output))
                {
                    var timer = new Stopwatch();

                    // Encoding
                    System.Environment.SetEnvironmentVariable("PGCLIENTENCODING", connection.Encoding);
                    ////p.StartInfo.EnvironmentVariables.Add("PGCLIENTENCODING", connection.Encoding);

                    // Password
                    if (!StringExtensions.IsEmpty(connection.Password))
                    {
                        // Set password as env var
                        System.Environment.SetEnvironmentVariable("PGPASSWORD", connection.Password);
                        ////p.StartInfo.EnvironmentVariables.Add("PGPASSWORD", connection.Password);
                    }

                    p.StartInfo.Arguments = this.GetPatameters(connection);

                    timer.Start();
                    p.Start();

                    string res   = string.Empty;
                    string error = string.Empty;
                    if (output)
                    {
                        res   = p.StandardOutput.ReadToEnd();
                        error = p.StandardError.ReadToEnd();
                    }
                    else
                    {
                        error = p.StandardError.ReadToEnd();
                    }

                    p.WaitForExit();
                    timer.Stop();

                    return(new ProcessResultModel()
                    {
                        Duartion = timer.Elapsed,
                        Error = error,
                        Ouput = res,
                    });
                }
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Create parameters
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        public string GetPatameters(Connection.IBaseModel connection, bool table)
        {
            if (connection == null)
            {
                return(string.Empty);
            }

            // Prepare stuff
            this.Clean();

            var param = string.Format(
                " --format {0} --jobs {1}",
                this.Config.Format,
                this.Config.Worker);

            if (this.Config.Verbose)
            {
                param += " --verbose";
            }

            if (this.Config.DataOnly)
            {
                param += " --data-only";
            }
            else
            {
                if (this.Config.SchemaOnly)
                {
                    param += " --schema-only";
                }
            }

            if (this.Tables != null && this.Tables.Any() && table)
            {
                foreach (var item in this.Tables)
                {
                    if (!string.IsNullOrEmpty(item) && !string.IsNullOrWhiteSpace(item))
                    {
                        param += " --table " + Pgsql.Common.EscapeName(item);
                    }
                }
            }

            if (this.Config.CleanDb)
            {
                param += " --clean";
            }

            if (this.Config.Create)
            {
                param += " --create";
            }

            return(base.GetPatameters(connection) + param);
        }
 /// <summary>
 /// Create parameters
 /// </summary>
 /// <param name="connection"></param>
 /// <returns></returns>
 public override string GetPatameters(Connection.IBaseModel connection)
 {
     return(this.GetPatameters(connection, true));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Run application with given parameters
 /// </summary>
 /// <param name="connection">Connection Model</param>
 /// <param name="output">display output</param>
 /// <returns></returns>
 public virtual async Task <ProcessResultModel> RunAsync(Connection.IBaseModel connection, bool output = false)
 {
     return(await Task.Run(() => this.Run(connection, output)));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Create parameters
 /// </summary>
 /// <param name="connection">Connection Model</param>
 /// <returns></returns>
 public virtual string GetPatameters(Connection.IBaseModel connection)
 {
     return(this.ConnectionString(connection));
 }