internal static bool AlreadyHasServer(string servername) { var normalized = SQLDatabaseUsageClient.NormalizeServername(servername); return(DataContext.Do(ctx => { var db = ctx.SQLDatabases.FirstOrDefault(_ => _.Servername == normalized); return db != null; })); }
internal static void FinishSession(string sessionId) { DataContext.Do(ctx => { var session = ctx.AddSQLDatabaseSessions.Find(sessionId); ctx.SQLDatabases.Add(new SQLDatabase { Servername = SQLDatabaseUsageClient.NormalizeServername(session.Servername), Password = session.Password, Username = session.Username, Version = GetVersionFromSession(session) }); ctx.SaveChanges(); }); }
internal static SqlCredentials GetCredentials(string forServer) { return(DataContext.Do(ctx => { forServer = SQLDatabaseUsageClient.NormalizeServername(forServer); var record = ctx.SQLDatabases.FirstOrDefault(_ => _.Servername == forServer); if (record == null) { throw new InvalidOperationException(string.Format("Couldn't fetch credentials for database server {0}", forServer)); } return record.Credentials; })); }