/// <summary> /// Opens an existing extension file. /// </summary> /// <remarks>Documented by Dev02, 2009-07-09</remarks> public void Open(GetLoginInformation loginDelegate) { IUser user = UserFactory.Create(loginDelegate, new ConnectionStringStruct(DatabaseType.MsSqlCe, ExtensionPath, -1), delegate { return; }, this); ConnectionStringStruct css = user.ConnectionString; css.LmId = MLifter.DAL.User.GetIdOfLearningModule(ExtensionPath, user); user.ConnectionString = css; LearningModules = user.List(); }
public LMConnectionParameter(TestContext testContext) { this.TestContext = testContext; RepositoryName = string.Empty; LearningModuleId = -1; Callback = null; ConnectionType = string.Empty; standAlone = false; Password = string.Empty; IsProtected = false; }
/// <summary> /// Initializes a new instance of the <see cref="FolderIndexEntry"/> class. /// </summary> /// <param name="path">The path.</param> /// <param name="name">The name.</param> /// <param name="parentConnection">The parent connection.</param> /// <param name="user">The user.</param> /// <param name="getLoginDelegate">The get login delegate.</param> /// <param name="dataAccessErrorDelegate">The data access error delegate.</param> /// <param name="parent">The parent.</param> /// <remarks>Documented by Dev05, 2009-03-12</remarks> private FolderIndexEntry(string path, string name, IConnectionString parentConnection, IUser user, string syncedModulesPath, GetLoginInformation getLoginDelegate, DataAccessErrorDelegate dataAccessErrorDelegate, FolderIndexEntry parent) { IsRootNode = false; Path = path; DisplayName = name; Connection = parentConnection; getLogin = getLoginDelegate; dataAccessError = dataAccessErrorDelegate; Parent = parent; SyncedModulesPath = syncedModulesPath; Login(user); }
/// <summary> /// Initializes a new instance of the <see cref="User"/> class. /// </summary> /// <param name="getLoginInformation">A delegate used to collect login information (username/password).</param> /// <param name="connectionString">A struct containing the connection info.</param> /// <param name="errorMessageDelegate">A delegate used to handle login errors.</param> /// <param name="standAlone">if set to <c>true</c> [stand alone].</param> /// <remarks>Documented by Dev03, 2008-11-25</remarks> public User(GetLoginInformation getLoginInformation, ConnectionStringStruct connectionString, DataAccessErrorDelegate errorMessageDelegate, bool standAlone) { if (getLoginInformation == null) { throw new ArgumentNullException(); } if (errorMessageDelegate == null) { throw new ArgumentNullException(); } isStandAlone = standAlone; if (standAlone) { standAloneId = Guid.NewGuid(); } connectionString.SessionId = standAlone ? standAloneId : sessionId; getLogin = getLoginInformation; ErrorMessageDelegate = errorMessageDelegate; user = new DummyUser(connectionString); switch (connectionString.Typ) { case DatabaseType.MsSqlCe: user = GetCeUser(connectionString); break; case DatabaseType.Web: user = GetWebUser(connectionString); break; case DatabaseType.Unc: user = new UncUser(new XmlUser(connectionString, errorMessageDelegate), new DbUser(new UserStruct(), Parent, connectionString, errorMessageDelegate, standAlone), connectionString); break; case DatabaseType.Xml: user = new XmlUser(connectionString, errorMessageDelegate); break; case DatabaseType.PostgreSQL: user = GetDbUser(connectionString, errorMessageDelegate, standAlone); break; default: throw new UnsupportedDatabaseTypeException(connectionString.Typ); } }
/// <summary> /// Creates the specified user depending on the settings and the user received through the login method delegate. /// </summary> /// <param name="loginMethodDelegate">The login method delegate.</param> /// <param name="connectionString">The connection string.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <param name="userContext">The context to which the user belongs (e.g. the LearnLogic).</param> /// <param name="standAlone">if set to <c>true</c> the user is stand alone (does not affect other [e.g. close session]).</param> /// <returns>A user</returns> /// <remarks>Documented by Dev05, 2008-09-10</remarks> public static IUser Create(GetLoginInformation loginMethodDelegate, ConnectionStringStruct connectionString, DataAccessErrorDelegate errorMessageDelegate, object userContext, bool standAlone) { if (currentUser.ContainsKey(userContext) && !standAlone && !(connectionString.Typ == DatabaseType.MsSqlCe && connectionString.SyncType == SyncType.HalfSynchronizedWithDbAccess)) { currentUser[userContext].Logout(); } User newUser = new User(loginMethodDelegate, connectionString, errorMessageDelegate, standAlone); if (!standAlone) { currentUser[userContext] = newUser; } return(newUser); }
/// <summary> /// Initializes a new instance of the <see cref="User"/> class. /// </summary> /// <param name="getLoginInformation">A delegate used to collect login information (username/password).</param> /// <param name="connectionString">A struct containing the connection info.</param> /// <param name="errorMessageDelegate">A delegate used to handle login errors.</param> /// <param name="standAlone">if set to <c>true</c> [stand alone].</param> /// <remarks>Documented by Dev03, 2008-11-25</remarks> public User(GetLoginInformation getLoginInformation, ConnectionStringStruct connectionString, DataAccessErrorDelegate errorMessageDelegate, bool standAlone) { if (getLoginInformation == null) throw new ArgumentNullException(); if (errorMessageDelegate == null) throw new ArgumentNullException(); isStandAlone = standAlone; if (standAlone) standAloneId = Guid.NewGuid(); connectionString.SessionId = standAlone ? standAloneId : sessionId; getLogin = getLoginInformation; ErrorMessageDelegate = errorMessageDelegate; user = new DummyUser(connectionString); switch (connectionString.Typ) { case DatabaseType.MsSqlCe: user = GetCeUser(connectionString); break; case DatabaseType.Web: user = GetWebUser(connectionString); break; case DatabaseType.Unc: user = new UncUser(new XmlUser(connectionString, errorMessageDelegate), new DbUser(new UserStruct(), Parent, connectionString, errorMessageDelegate, standAlone), connectionString); break; case DatabaseType.Xml: user = new XmlUser(connectionString, errorMessageDelegate); break; case DatabaseType.PostgreSQL: user = GetDbUser(connectionString, errorMessageDelegate, standAlone); break; default: throw new UnsupportedDatabaseTypeException(connectionString.Typ); } }
/// <summary> /// Creates the specified user depending on the settings and the user received through the login method delegate. /// </summary> /// <param name="loginMethodDelegate">The login method delegate.</param> /// <param name="connectionString">The connection string.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <param name="userContext">The context to which the user belongs (e.g. the LearnLogic).</param> /// <returns>A user</returns> /// <remarks>Documented by Dev05, 2008-09-10</remarks> public static IUser Create(GetLoginInformation loginMethodDelegate, ConnectionStringStruct connectionString, DataAccessErrorDelegate errorMessageDelegate, object userContext) { return Create(loginMethodDelegate, connectionString, errorMessageDelegate, userContext, false); }
/// <summary> /// Authenticates a user. /// </summary> /// <param name="loginCallback">The login callback.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2008-08-28</remarks> public bool Authenticate(GetLoginInformation loginCallback, ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate) { user = UserFactory.Create(loginCallback, connection, errorMessageDelegate, this); return(true); }
/// <summary> /// Creates the specified user depending on the settings and the user received through the login method delegate. /// </summary> /// <param name="loginMethodDelegate">The login method delegate.</param> /// <param name="connectionString">The connection string.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <param name="userContext">The context to which the user belongs (e.g. the LearnLogic).</param> /// <param name="standAlone">if set to <c>true</c> the user is stand alone (does not affect other [e.g. close session]).</param> /// <returns>A user</returns> /// <remarks>Documented by Dev05, 2008-09-10</remarks> public static IUser Create(GetLoginInformation loginMethodDelegate, ConnectionStringStruct connectionString, DataAccessErrorDelegate errorMessageDelegate, object userContext, bool standAlone) { if (currentUser.ContainsKey(userContext) && !standAlone && !(connectionString.Typ == DatabaseType.MsSqlCe && connectionString.SyncType == SyncType.HalfSynchronizedWithDbAccess)) currentUser[userContext].Logout(); User newUser = new User(loginMethodDelegate, connectionString, errorMessageDelegate, standAlone); if (!standAlone) currentUser[userContext] = newUser; return newUser; }
/// <summary> /// Initializes a new instance of the <see cref="LearningModulesIndex"/> class. /// </summary> /// <param name="generalPath">The general path.</param> /// <param name="userPath">The path to the user configurations.</param> /// <param name="getLoginDelegate">The get login delegate.</param> /// <param name="dataAccessErrorDelegate">The data access error delegate.</param> /// <remarks>Documented by Dev05, 2008-12-03</remarks> public LearningModulesIndex(string generalPath, string userPath, GetLoginInformation getLoginDelegate, DataAccessErrorDelegate dataAccessErrorDelegate, string syncedModulesPath) : this() { SyncedModulesPath = syncedModulesPath; getLogin = getLoginDelegate; dataAccessError = dataAccessErrorDelegate; updateTimer.Interval = 1000; updateTimer.Tick += new EventHandler(updateTimer_Tick); if (userPath != null && userPath != string.Empty) { cacheFile = System.IO.Path.Combine(userPath, Properties.Settings.Default.LMIndexCacheFilename); try { if (System.IO.File.Exists(cacheFile)) RestoreIndexCache(cacheFile); } catch (Exception e) { Trace.WriteLine("Index entry cache restore failed: " + e.ToString()); } } ConnectionsHandler = new ConnectionStringHandler(generalPath, userPath); ConnectionUsers.Clear(); foreach (IConnectionString con in ConnectionsHandler.ConnectionStrings) { ListViewGroup group = new ListViewGroup(con.Name); group.Tag = con; Groups.Add(group); } }
/// <summary> /// Sets the base user. /// </summary> /// <param name="user">The user.</param> /// <param name="getLoginDelegate">The login delegate.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <remarks>Documented by Dev05, 2008-12-12</remarks> public void SetBaseUser(IUser user, GetLoginInformation getLoginDelegate, DataAccessErrorDelegate errorMessageDelegate) { SetBaseUser(user); user.GetLoginDelegate = getLoginDelegate; user.ErrorMessageDelegate = errorMessageDelegate; }
/// <summary> /// Gets the persistent LM connection. /// </summary> /// <param name="testContext">The test context.</param> /// <param name="repositoryName">Name of the repository.</param> /// <param name="LMId">The LM id.</param> /// <param name="callback">The callback.</param> /// <returns></returns> /// <remarks>Documented by Dev10, 2008-25-09</remarks> public static IDictionary GetPersistentLMConnection(TestContext testContext, string repositoryName, int LMId, GetLoginInformation callback, bool standAlone) { return(GetPersistentLMConnection(testContext, repositoryName, LMId, callback, string.Empty, standAlone, string.Empty, false)); }
/// <summary> /// Creates the specified user depending on the settings and the user received through the login method delegate. /// </summary> /// <param name="loginMethodDelegate">The login method delegate.</param> /// <param name="connectionString">The connection string.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <param name="userContext">The context to which the user belongs (e.g. the LearnLogic).</param> /// <returns>A user</returns> /// <remarks>Documented by Dev05, 2008-09-10</remarks> public static IUser Create(GetLoginInformation loginMethodDelegate, ConnectionStringStruct connectionString, DataAccessErrorDelegate errorMessageDelegate, object userContext) { return(Create(loginMethodDelegate, connectionString, errorMessageDelegate, userContext, false)); }
/// <summary> /// Copies the contents of a learning module to another one. /// </summary> /// <param name="connectionSource">The connection source.</param> /// <param name="connectionTarget">The connection target.</param> /// <param name="getLogin">The get login delegate.</param> /// <param name="progressDelegate">The progress delegate.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <param name="user">The currently logged in user.</param> /// <param name="resetAfterCopy">if set to <c>true</c> to reset after copy.</param> /// <remarks>Documented by Dev02, 2008-09-24</remarks> /// <exception cref="DictionaryContentProtectedException"></exception> public static void CopyLearningModule(ConnectionStringStruct connectionSource, ConnectionStringStruct connectionTarget, GetLoginInformation getLogin, CopyToProgress progressDelegate, DataAccessErrorDelegate errorMessageDelegate, User user, bool resetAfterCopy) { CopyLearningModule(connectionSource, connectionTarget, getLogin, progressDelegate, errorMessageDelegate, user, resetAfterCopy, false); }
/// <summary> /// Initializes a new instance of the <see cref="LearnLogic"/> class. /// </summary> /// <remarks>Documented by Dev02, 2008-04-22</remarks> public LearnLogic(GetLoginInformation getLoginDelegate, DataAccessErrorDelegate dataAccessErrorDelegate) { GetLoginDelegate = getLoginDelegate; DataAccessErrorDelegate = dataAccessErrorDelegate; cardStack = new CardStack(this); this.LearningModuleOpened += new EventHandler(LearnLogic_LearningModuleOpened); this.user = new User(this); this.CardStack.StackChanged += new EventHandler(CardStack_StackChanged); }
/// <summary> /// Authenticates a user. /// </summary> /// <param name="loginCallback">The login callback.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2008-08-28</remarks> public bool Authenticate(GetLoginInformation loginCallback, ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate) { user = UserFactory.Create(loginCallback, connection, errorMessageDelegate, this); return true; }
/// <summary> /// Initializes a new instance of the <see cref="FolderIndexEntry"/> class. /// </summary> /// <param name="path">The path.</param> /// <param name="name">The name.</param> /// <remarks>Documented by Dev05, 2009-03-06</remarks> public FolderIndexEntry(string path, string name, IConnectionString parentConnection, IUser user, string syncedModulesPath, GetLoginInformation getLoginDelegate, DataAccessErrorDelegate dataAccessErrorDelegate) : this(path, name, parentConnection, user, syncedModulesPath, getLoginDelegate, dataAccessErrorDelegate, null) { IsRootNode = true; }
/// <summary> /// Gets the connection and returns an IDictionary (Learning Module instance) /// </summary> /// <param name="testContext">The test context.</param> /// <param name="callback">The callback.</param> /// <returns>IDictionary</returns> /// <remarks>Documented by Dev10, 2008-07-31</remarks> public static IDictionary GetLMConnection(TestContext testContext, GetLoginInformation callback) { return(GetLMConnection(testContext, callback, false)); }
/// <summary> /// Gets the persistent LM connection. /// </summary> /// <param name="testContext">The test context.</param> /// <param name="repositoryName">Name of the repository.</param> /// <param name="LMId">The LM id.</param> /// <param name="callback">The callback.</param> /// <returns></returns> /// <remarks>Documented by Dev10, 2008-25-09</remarks> public static IDictionary GetPersistentLMConnection(TestContext testContext, string repositoryName, int LMId, GetLoginInformation callback, bool standAlone) { return GetPersistentLMConnection(testContext, repositoryName, LMId, callback, string.Empty, standAlone, string.Empty, false); }
/// <summary> /// Gets the connection and returns an IDictionary (Learning Module instance) /// </summary> /// <param name="testContext">The test context.</param> /// <param name="callback">The callback.</param> /// <param name="standAlone">if set to <c>true</c> a stand alone user will be created.</param> /// <returns>IDictionary</returns> /// <remarks>Documented by Dev10, 2008-07-31</remarks> public static IDictionary GetLMConnection(TestContext testContext, GetLoginInformation callback, bool standAlone) { return(GetPersistentLMConnection(testContext, String.Empty, -1, callback, standAlone)); }
/// <summary> /// Gets the persistent LM connection. /// </summary> /// <param name="testContext">The test context.</param> /// <param name="repositoryName">Name of the repository (Hostname of the Server).</param> /// <param name="LMId">The LM id.</param> /// <param name="callback">The callback.</param> /// <param name="connectionType">Type of the connection.</param> /// <param name="standAlone">if set to <c>true</c> a stand alone user will be created.</param> /// <returns></returns> /// <remarks>Documented by Dev10, 2008-08-01</remarks> public static IDictionary GetPersistentLMConnection(TestContext testContext, string repositoryName, int LMId, GetLoginInformation callback, string connectionType, bool standAlone, string password, bool isProtected) { string connectionString = string.Empty; ConnectionStringStruct ConnectionString; string type = connectionType == "" ? (string)testContext.DataRow["Type"] : connectionType; bool IsValid = (bool)testContext.DataRow["IsValid"]; switch (type.ToLower()) { case "file": #region ODX Tests if (repositoryName == string.Empty) //Not persistent { repositoryName = MachineName; ConnectionString = new ConnectionStringStruct(DatabaseType.Xml, TestDic, false); } else //Persistent (During Unit Test) { string persistentPath; persistentPath = Path.GetTempPath() + repositoryName + Helper.OdxExtension; cleanupQueue.Enqueue(persistentPath); ConnectionString = new ConnectionStringStruct(DatabaseType.Xml, persistentPath, false); } #endregion break; case "pgsql": #region PgSQL Tests repositoryName = MachineName.ToLower(); if (testContext.DataRow["ConnectionString"] != System.DBNull.Value) { connectionString = (string)testContext.DataRow["ConnectionString"]; connectionString = connectionString.Replace("DYNAMIC", repositoryName); //Only create DataBase if it was not yet created, so only for the first time, one database for all unit tests in this run if (!DBCreated) { if (dbAccessByOtherUser) throw new Exception("DB is being accessed by other users"); else { try { DropDB(repositoryName); } catch (NpgsqlException exp) { if (exp.Code == "55006") //Pgsql error code for: Database is accessed by other users { dbAccessByOtherUser = true; throw new Exception("DB is being accessed by other users"); } } CreateDB(repositoryName, testContext, isProtected); DBCreated = true; tmpRepository = repositoryName; } } } else throw new Exception("PGSQL connection string could not be read from unit test database."); if (LMId < 0) //Persistent (During Test Run) LMId = AddNewLM(repositoryName, isProtected); ConnectionString = new ConnectionStringStruct(DatabaseType.PostgreSQL, connectionString, LMId); #endregion break; case "sqlce": #region SqlCe Tests if (repositoryName == string.Empty) //Not persistent { repositoryName = MachineName; ConnectionString = new ConnectionStringStruct(DatabaseType.MsSqlCe, TestDicSqlCE, false); } else //Persistent (During Unit Test) { string persistentPath; persistentPath = Path.GetTempPath() + repositoryName + Helper.EmbeddedDbExtension; cleanupQueue.Enqueue(persistentPath); ConnectionString = new ConnectionStringStruct(DatabaseType.MsSqlCe, persistentPath, false); } if (password != string.Empty) { ConnectionString.ProtectedLm = true; ConnectionString.Password = password; } if (LMId < 0) { string sqlCeConnString = GetFullSqlCeConnectionString(ConnectionString); using (SqlCeEngine clientEngine = new SqlCeEngine(sqlCeConnString)) { clientEngine.CreateDatabase(); clientEngine.Dispose(); } using (SqlCeConnection con = new SqlCeConnection(sqlCeConnString)) { con.Open(); SqlCeTransaction transaction = con.BeginTransaction(); string tmp = Helper.GetMsSqlCeScript(); string[] msSqlScriptArray = Helper.GetMsSqlCeScript().Split(';'); //Split the whole DB-Script into single commands (SQL-CE can not execute multiple queries) foreach (string sqlCommand in msSqlScriptArray) { if (sqlCommand.TrimStart(' ', '\r', '\n').StartsWith("--") || sqlCommand.TrimStart(' ', '\r', '\n').Length < 5) continue; using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = sqlCommand; cmd.ExecuteNonQuery(); } } int cat_id; using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT id FROM Categories WHERE global_id=@cat_id;"; cmd.Parameters.Add("@cat_id", 1); cat_id = Convert.ToInt32(cmd.ExecuteScalar()); } using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO LearningModules (guid, title, categories_id, default_settings_id, allowed_settings_id, licence_key, content_protected, cal_count) " + "VALUES (@guid, @title, @cat_id, @dset, @aset, @lk, @cp, @cals);"; cmd.Parameters.Add("@guid", new Guid().ToString()); cmd.Parameters.Add("@title", "eDB test title"); cmd.Parameters.Add("@cat_id", cat_id); cmd.Parameters.Add("@lk", "ACDED-LicenseKey-DEDAF"); cmd.Parameters.Add("@cp", password == string.Empty ? 0 : 1); cmd.Parameters.Add("@cals", 1); cmd.Parameters.Add("@dset", MsSqlCeCreateNewSettings(sqlCeConnString)); cmd.Parameters.Add("@aset", MsSqlCeCreateNewAllowedSettings(sqlCeConnString)); cmd.ExecuteNonQuery(); } using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT @@IDENTITY;"; LMId = Convert.ToInt32(cmd.ExecuteScalar()); } transaction.Commit(); } } ConnectionString.LmId = LMId; #endregion break; default: throw new Exception("TestInfrastructure Class: conditions where set which are not applicable to the current db connection infrastructure"); } IUser user; if (callback == null) user = UserFactory.Create((GetLoginInformation)GetTestUser, ConnectionString, (DataAccessErrorDelegate)delegate { return; }, standAlone); else user = UserFactory.Create(callback, ConnectionString, (DataAccessErrorDelegate)delegate { return; }, standAlone); return user.Open(); }
/// <summary> /// Gets the persistent LM connection. /// </summary> /// <param name="testContext">The test context.</param> /// <param name="repositoryName">Name of the repository (Hostname of the Server).</param> /// <param name="LMId">The LM id.</param> /// <param name="callback">The callback.</param> /// <param name="connectionType">Type of the connection.</param> /// <param name="standAlone">if set to <c>true</c> a stand alone user will be created.</param> /// <returns></returns> /// <remarks>Documented by Dev10, 2008-08-01</remarks> public static IDictionary GetPersistentLMConnection(TestContext testContext, string repositoryName, int LMId, GetLoginInformation callback, string connectionType, bool standAlone, string password, bool isProtected) { string connectionString = string.Empty; ConnectionStringStruct ConnectionString; string type = connectionType == "" ? (string)testContext.DataRow["Type"] : connectionType; bool IsValid = (bool)testContext.DataRow["IsValid"]; switch (type.ToLower()) { case "file": #region ODX Tests if (repositoryName == string.Empty) //Not persistent { repositoryName = MachineName; ConnectionString = new ConnectionStringStruct(DatabaseType.Xml, TestDic, false); } else //Persistent (During Unit Test) { string persistentPath; persistentPath = Path.GetTempPath() + repositoryName + Helper.OdxExtension; cleanupQueue.Enqueue(persistentPath); ConnectionString = new ConnectionStringStruct(DatabaseType.Xml, persistentPath, false); } #endregion break; case "pgsql": #region PgSQL Tests repositoryName = MachineName.ToLower(); if (testContext.DataRow["ConnectionString"] != System.DBNull.Value) { connectionString = (string)testContext.DataRow["ConnectionString"]; connectionString = connectionString.Replace("DYNAMIC", repositoryName); //Only create DataBase if it was not yet created, so only for the first time, one database for all unit tests in this run if (!DBCreated) { if (dbAccessByOtherUser) { throw new Exception("DB is being accessed by other users"); } else { try { DropDB(repositoryName); } catch (NpgsqlException exp) { if (exp.Code == "55006") //Pgsql error code for: Database is accessed by other users { dbAccessByOtherUser = true; throw new Exception("DB is being accessed by other users"); } } CreateDB(repositoryName, testContext, isProtected); DBCreated = true; tmpRepository = repositoryName; } } } else { throw new Exception("PGSQL connection string could not be read from unit test database."); } if (LMId < 0) //Persistent (During Test Run) { LMId = AddNewLM(repositoryName, isProtected); } ConnectionString = new ConnectionStringStruct(DatabaseType.PostgreSQL, connectionString, LMId); #endregion break; case "sqlce": #region SqlCe Tests if (repositoryName == string.Empty) //Not persistent { repositoryName = MachineName; ConnectionString = new ConnectionStringStruct(DatabaseType.MsSqlCe, TestDicSqlCE, false); } else //Persistent (During Unit Test) { string persistentPath; persistentPath = Path.GetTempPath() + repositoryName + Helper.EmbeddedDbExtension; cleanupQueue.Enqueue(persistentPath); ConnectionString = new ConnectionStringStruct(DatabaseType.MsSqlCe, persistentPath, false); } if (password != string.Empty) { ConnectionString.ProtectedLm = true; ConnectionString.Password = password; } if (LMId < 0) { string sqlCeConnString = GetFullSqlCeConnectionString(ConnectionString); using (SqlCeEngine clientEngine = new SqlCeEngine(sqlCeConnString)) { clientEngine.CreateDatabase(); clientEngine.Dispose(); } using (SqlCeConnection con = new SqlCeConnection(sqlCeConnString)) { con.Open(); SqlCeTransaction transaction = con.BeginTransaction(); string tmp = Helper.GetMsSqlCeScript(); string[] msSqlScriptArray = Helper.GetMsSqlCeScript().Split(';'); //Split the whole DB-Script into single commands (SQL-CE can not execute multiple queries) foreach (string sqlCommand in msSqlScriptArray) { if (sqlCommand.TrimStart(' ', '\r', '\n').StartsWith("--") || sqlCommand.TrimStart(' ', '\r', '\n').Length < 5) { continue; } using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = sqlCommand; cmd.ExecuteNonQuery(); } } int cat_id; using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT id FROM Categories WHERE global_id=@cat_id;"; cmd.Parameters.Add("@cat_id", 1); cat_id = Convert.ToInt32(cmd.ExecuteScalar()); } using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = "INSERT INTO LearningModules (guid, title, categories_id, default_settings_id, allowed_settings_id, licence_key, content_protected, cal_count) " + "VALUES (@guid, @title, @cat_id, @dset, @aset, @lk, @cp, @cals);"; cmd.Parameters.Add("@guid", new Guid().ToString()); cmd.Parameters.Add("@title", "eDB test title"); cmd.Parameters.Add("@cat_id", cat_id); cmd.Parameters.Add("@lk", "ACDED-LicenseKey-DEDAF"); cmd.Parameters.Add("@cp", password == string.Empty ? 0 : 1); cmd.Parameters.Add("@cals", 1); cmd.Parameters.Add("@dset", MsSqlCeCreateNewSettings(sqlCeConnString)); cmd.Parameters.Add("@aset", MsSqlCeCreateNewAllowedSettings(sqlCeConnString)); cmd.ExecuteNonQuery(); } using (SqlCeCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT @@IDENTITY;"; LMId = Convert.ToInt32(cmd.ExecuteScalar()); } transaction.Commit(); } } ConnectionString.LmId = LMId; #endregion break; default: throw new Exception("TestInfrastructure Class: conditions where set which are not applicable to the current db connection infrastructure"); } IUser user; if (callback == null) { user = UserFactory.Create((GetLoginInformation)GetTestUser, ConnectionString, (DataAccessErrorDelegate) delegate { return; }, standAlone); } else { user = UserFactory.Create(callback, ConnectionString, (DataAccessErrorDelegate) delegate { return; }, standAlone); } return(user.Open()); }
/// <summary> /// Copies the contents of a learning module to another one. /// </summary> /// <param name="connectionSource">The connection source.</param> /// <param name="connectionTarget">The connection target.</param> /// <param name="getLogin">The get login delegate.</param> /// <param name="progressDelegate">The progress delegate.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <param name="user">The currently logged in user.</param> /// <param name="resetAfterCopy">if set to <c>true</c> to reset after copy.</param> /// <remarks>Documented by Dev02, 2008-09-24</remarks> /// <exception cref="DictionaryContentProtectedException"></exception> private static void CopyLearningModule(ConnectionStringStruct connectionSource, ConnectionStringStruct connectionTarget, GetLoginInformation getLogin, CopyToProgress progressDelegate, DataAccessErrorDelegate errorMessageDelegate, User user, bool resetAfterCopy, bool ignoreProtected) { bool CurrentUserTryed; UserStruct? CurrentUser = null; try { if (user != null) { UserStruct cUser = user.BaseUser.AuthenticationStruct; cUser.CloseOpenSessions = true; cUser.UserName = cUser.UserName ?? string.Empty; cUser.AuthenticationType = cUser.AuthenticationType ?? UserAuthenticationTyp.ListAuthentication; CurrentUser = cUser; } } catch { } User userSource = new User(null); User userTarget = new User(null); try { CurrentUserTryed = false; if (connectionSource.Typ == DatabaseType.Xml) //XML needs to be in read-only mode otherwise the file would be locked connectionSource.ReadOnly = true; userSource.SetBaseUser(UserFactory.Create((GetLoginInformation)delegate(UserStruct u, ConnectionStringStruct c) { if (!CurrentUserTryed && CurrentUser.HasValue) { CurrentUserTryed = true; return CurrentUser; } return getLogin.Invoke(u, c); }, connectionSource, errorMessageDelegate, userSource, true)); if (!userSource.OpenLearningModule()) return; //don't allow import of protected LMs if (!ignoreProtected && userSource.Dictionary.DictionaryContentProtected) throw new DictionaryContentProtectedException(); CurrentUserTryed = false; userTarget.SetBaseUser(UserFactory.Create((GetLoginInformation)delegate(UserStruct u, ConnectionStringStruct c) { if (!CurrentUserTryed && CurrentUser.HasValue) { CurrentUserTryed = true; return CurrentUser; } return getLogin.Invoke(u, c); }, connectionTarget, errorMessageDelegate, userTarget, true)); if (!userTarget.OpenLearningModule()) return; userSource.Dictionary.PreloadCardCache(); //do copying userSource.Dictionary.CopyToFinished += new Dictionary.CopyToFinishedEventHandler(Dictionary_CopyToFinished); userSource.Dictionary.BeginCopyTo(userTarget.Dictionary, progressDelegate, userSource, userTarget, resetAfterCopy); } catch (Exception exp) { //clean up if (userSource != null && userSource.Dictionary != null) userSource.Dictionary.Dispose(); if (userTarget != null && userTarget.Dictionary != null) userTarget.Dictionary.Dispose(); Trace.WriteLine(exp.ToString()); throw exp; } }
/// <summary> /// Gets the connection and returns an IDictionary (Learning Module instance) /// </summary> /// <param name="testContext">The test context.</param> /// <param name="callback">The callback.</param> /// <returns>IDictionary</returns> /// <remarks>Documented by Dev10, 2008-07-31</remarks> public static IDictionary GetLMConnection(TestContext testContext, GetLoginInformation callback) { return GetLMConnection(testContext, callback, false); }
/// <summary> /// Imports the learning module. /// </summary> /// <param name="target">The target.</param> /// <param name="source">The source.</param> /// <param name="getLogin">The get login.</param> /// <param name="progressDelegate">The progress delegate.</param> /// <param name="errorMessageDelegate">The error message delegate.</param> /// <param name="user">The user.</param> /// <param name="calCount">The cal count.</param> /// <remarks>Documented by Dev05, 2009-02-12</remarks> public static void ImportLearningModule(IConnectionString target, ConnectionStringStruct source, GetLoginInformation getLogin, CopyToProgress progressDelegate, DataAccessErrorDelegate errorMessageDelegate, User user, string licenseKey, bool contentProtected, int calCount) { IDictionary dic = LearningModulesIndex.ConnectionUsers[target].List().AddNew(1, string.Empty, licenseKey, contentProtected, calCount); ConnectionStringStruct targetConnection = new ConnectionStringStruct(target.ConnectionType, dic.Connection, dic.Id); CopyLearningModule(source, targetConnection, getLogin, progressDelegate, errorMessageDelegate, user, true, contentProtected); }
/// <summary> /// Gets the connection and returns an IDictionary (Learning Module instance) /// </summary> /// <param name="testContext">The test context.</param> /// <param name="callback">The callback.</param> /// <param name="standAlone">if set to <c>true</c> a stand alone user will be created.</param> /// <returns>IDictionary</returns> /// <remarks>Documented by Dev10, 2008-07-31</remarks> public static IDictionary GetLMConnection(TestContext testContext, GetLoginInformation callback, bool standAlone) { return GetPersistentLMConnection(testContext, String.Empty, -1, callback, standAlone); }