public override System.Data.Common.DbConnection GetConnection(Model.ConnectionProfile profile, string username, string password)
        {
            bool isNew = false;

            if (!File.Exists(profile.Database))
            {
                SQLiteConnection.CreateFile(profile.Database);
                isNew = true;
            }
            var conn = new SQLiteConnection(String.Format("Data Source={0}", profile.Database));

            try {
                conn.Open();
            } catch (Exception ex) {
                conn.Dispose();
                conn = null;
                throw ex;
            }

            if (isNew)
            {
                CreateSchema(conn);
                conn.Close();
                return(GetConnection(profile, username, password));
            }

            return(conn);
        }
Example #2
0
        protected User connect()
        {
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
            // ReSharper disable CSharpWarnings::CS0162
            // ReSharper disable HeuristicUnreachableCode
            if (!TestProperties.RunDatabaseTests) {
                Assert.Ignore();
            }
            // ReSharper restore HeuristicUnreachableCode
            // ReSharper restore CSharpWarnings::CS0162
            // ReSharper restore ConditionIsAlwaysTrueOrFalse

            var profile = new ConnectionProfile { Server = TestProperties.Server, Database = TestProperties.Database, IntegratedSecurity = false };
            var user = new User(TestProperties.Username, TestProperties.Password, profile);
            string message;
            if (!user.Authenticate(out message)) {
                Assert.Fail("Failed to authenticate: " + message);
            }
            return user;
        }
Example #3
0
        private List<ServerViewModel> DiscoverServers(bool search)
        {
            var list = new List<ServerViewModel>();

            var profiles = Config.GetGlobal<List<ConnectionProfile>>("connection.profiles", new List<ConnectionProfile>());
            foreach (ConnectionProfile profile in profiles) {
                var existing = list.FirstOrDefault((sv) => {
                    return sv.Name.Equals(profile.Server, StringComparison.CurrentCultureIgnoreCase);
                });
                if (existing == null) {
                    list.Add(CreateServerViewModel(profile.Server));
                }
            }

            LegacySettings.TraverseSubKeys("Client", "UserProfiles", (key) => {
                ConnectionProfile profile = new ConnectionProfile();
                var server = key.GetValue("DatabaseServer") as string;

                var existing = list.FirstOrDefault((sv) => {
                    return sv.Name.Equals(server, StringComparison.CurrentCultureIgnoreCase);
                });

                if (server != null && existing == null) {
                    list.Add(CreateServerViewModel(server));
                }
            });

            if (search) {
                DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
                if (dt.Rows.Count > 0) {
                    foreach (DataRow dr in dt.Rows) {
                        var server = dr["Name"] as string;
                        var existing = list.FirstOrDefault((sv) => {
                            return sv.Name.Equals(server, StringComparison.CurrentCultureIgnoreCase);
                        });

                        if (!string.IsNullOrEmpty(server) && existing == null) {
                            list.Add(CreateServerViewModel(server));
                        }
                    }
                }
            }

            return list;
        }
Example #4
0
        private void SetupProfiles()
        {
            cmbProfile.ItemsSource = null;
            _profiles = Config.GetGlobal<List<ConnectionProfile>>("connection.profiles", new List<ConnectionProfile>());
            String lastProfile = Config.GetGlobal<string>("connection.lastprofile", null);
            if (!Config.GetGlobal<bool>("connection.skiplegacyimport", false)) {

                LegacySettings.TraverseSubKeys("Client", "UserProfiles", (key) => {
                    ConnectionProfile profile = new ConnectionProfile();
                    string name = key.Name;
                    profile.Name = key.Name.Substring(name.LastIndexOf('\\') + 1);
                    profile.Server = key.GetValue("DatabaseServer") as string;
                    profile.Database = key.GetValue("DatabaseName") as string;
                    profile.LastUser = key.GetValue("LastUser") as string;
                    profile.Timeout = key.GetValue("CommandTimeout") as Nullable<Int32>;
                    _profiles.Add(profile);
                });

                if (lastProfile == null) {
                    lastProfile = LegacySettings.GetRegSetting("Client", "UserProfiles", "LastUsedProfile", "");
                }

                // Save the new list
                Config.SetGlobal("connection.profiles", _profiles);
                // and we don'note need to do this again!
                Config.SetGlobal("connection.skiplegacyimport", true);
            }

            cmbProfile.ItemsSource = _profiles;

            if (!String.IsNullOrEmpty(lastProfile)) {
                // Look in the list for the profile with the same name.
                ConnectionProfile lastUserProfile = _profiles.Find((item) => { return item.Name.Equals(lastProfile); });
                if (lastUserProfile != null) {
                    cmbProfile.SelectedItem = lastUserProfile;
                }
            }
        }
Example #5
0
File: User.cs Project: kehh/biolink
 public User(string username, string password, ConnectionProfile profile)
 {
     this.Username = username;
     this.Password = password;
     this.ConnectionProfile = profile;
     if (profile.ConnectionType == ConnectionType.SQLServer) {
         ConnectionProvider = new SQLServerConnectionProvider();
     } else if (profile.ConnectionType == ConnectionType.Standalone) {
         ConnectionProvider = new SQLiteConnectionProvider(profile, username, password);
     }
 }
 public SQLiteConnectionProvider(Model.ConnectionProfile profile, String username, String password) : base(profile, username, password)
 {
 }
        private string BuildConnectionString(ConnectionProfile profile, String username, String password, bool oldMangleRoutine)
        {
            StringBuilder s = new StringBuilder();
            if (profile.IntegratedSecurity) {
                s.Append(String.Format("Data Source={0};Initial Catalog={1};Integrated Security=SSPI;", profile.Server, profile.Database));
            } else {
                var mangledPassword = password;
                if (oldMangleRoutine) {
                    mangledPassword = PasswordUtilities.OldManglePassword(username, password);
                } else {
                    mangledPassword = PasswordUtilities.ManglePassword(username, password);
                }

                s.Append(String.Format("Data Source={0};User Id={2};Password=\'{3}\';Initial Catalog={1};", profile.Server, profile.Database, username, mangledPassword));
            }

            return s.ToString();
        }
 public DbConnection GetConnection(ConnectionProfile profile, String username, String password)
 {
     SqlConnection conn = null;
     if (_connectionString == null) {
         _connectionString = BuildConnectionString(profile, username, password, false);
         conn = new SqlConnection(_connectionString);
         try {
             conn.Open();
         } catch (Exception) {
             _connectionString = BuildConnectionString(profile, username, password, true);
             conn = new SqlConnection(_connectionString);
             try {
                 conn.Open();
             } catch (Exception ex) {
                 _connectionString = null;
                 throw ex;
             }
         }
         return conn;
     } else {
         conn = new SqlConnection(_connectionString);
         conn.Open();
         return conn;
     }
 }
Example #9
0
 public abstract DbConnection GetConnection(ConnectionProfile profile, string username, string password);
Example #10
0
 public ConnectionProvider(ConnectionProfile profile, String username, String password)
 {
     ConnectionProfile = profile;
     Username = username;
     Password = password;
 }
Example #11
0
        private void AddNewProfile()
        {
            ConnectionProfile model = new ConnectionProfile();
            model.Name = "<New Profile>";

            var profile = new ConnectionProfileViewModel(model);
            _model.Add(profile);
            cmbProfiles.SelectedItem = profile;
            txtName.Focus();
            txtName.SelectAll();
        }