예제 #1
0
        /// <summary>
        /// GetMySqlServer
        /// If windows based automatiallky generates login info
        /// Linux assumes local account.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="databaseName"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static BasicDBServer GetMySqlServer(string server, string databaseName, string user = "")
        {
            Logger.WriteLine("Linux=" + LinuxUtility.IsLinux());

            if (LinuxUtility.IsLinux())
            {//Linux login is from config file.  Assuming localhost access
                if (user == "")
                {
                    user = WindowsUtility.GetShortUserName();
                }

                var cs = "server=" + server + ";uid="
                         + user + ";"
                         + "database=" + databaseName + ";";
                Logger.WriteLine(cs);
                return(new MySqlServer(cs));
            }
            else
            { // use windows login for username
                var cs = "server=" + server + ";uid="
                         + GetWindowsUserName() + ";"
                         + "pwd=" + GeneratePassword() + ";database=" + databaseName + ";";
                string msg = cs;
                msg = msg.Replace("pwd=" + GeneratePassword(), "pwd=" + "xxxxx");
                Logger.WriteLine(msg);

                return(new MySqlServer(cs));
            }
        }
예제 #2
0
        /// <summary>
        /// GetMySqlServer
        /// If windows based automatiallky generates login info
        /// Linux assumes local account.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="databaseName"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static BasicDBServer GetMySqlServer(string server, string databaseName, string user = "", string password = "")
        {
            Logger.WriteLine("Linux=" + LinuxUtility.IsLinux());

            if (LinuxUtility.IsLinux() || server == "localhost")
            {//Linux login is from config file.  Assuming localhost access
                if (user == "")
                {
                    user = WindowsUtility.GetShortUserName();
                }

                var cs = "server=" + server + ";uid="
                         + user + ";"
                         + "database=" + databaseName + ";";
                Logger.WriteLine(cs);

                if (password != "")
                {
                    cs += "pwd=" + password + ";";
                }
                var msg = cs;
                msg = msg.Replace("pwd=" + password, "pwd=" + "xxxxx");
                Logger.WriteLine(msg);
                return(new MySqlServer(cs));
            }
            else
            {
                if (password == "")
                {
                    var fn = "mysql_key.txt";
                    if (File.Exists(fn) && File.ReadAllLines(fn).Length > 0)
                    {
                        password = user + File.ReadAllLines(@"mysql_key.txt", Encoding.UTF8)[0];
                    }
                }
                var cs = "server=" + server + ";uid=" + GetWindowsUserName() + ";" + "pwd=" + password +
                         ";database=" + databaseName + ";";
                string msg = cs;
                msg = msg.Replace("pwd=" + password, "pwd=" + "xxxxx");
                Logger.WriteLine(msg);

                return(new MySqlServer(cs));
            }
        }