public void DeleteAllStatisticsTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); try { learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") { return; } else { throw; } } learnLogic.OnLearningModuleOptionsChanged(); learnLogic.ResetLearningProgress(); LearnStats learnStats = learnLogic.Dictionary.Statistics.GetCurrentStats(); Assert.AreEqual <int>(0, learnStats.NumberOfRights, "DeleteAllStatistics() did not delete all Stats!"); Assert.AreEqual <int>(0, learnStats.NumberOfWrongs, "DeleteAllStatistics() did not delete all Stats!"); Assert.IsTrue(learnLogic.Dictionary.Statistics.GetNewestStatistic().StartTimestamp == learnLogic.Dictionary.Statistics.GetOldestStatistic().StartTimestamp, "GetNewestStatistic() and GetOldestStatistic seems to be not equal. There should be only ONE stat in the restarted LM"); } }
public void DoubleLoginTest() { if (TestInfrastructure.IsActive(TestContext)) { switch (TestInfrastructure.ConnectionType(TestContext)) { case "File": case "sqlce": throw new DoubleLoginException(); default: break; } ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionString(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); learnLogic.User.Authenticate((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser, connectionString, (DataAccessErrorDelegate) delegate { return; }); //Doesn't throw the Exception because the UserFactory logs out the previous user LearnLogic lLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); lLogic.User.Authenticate((GetLoginInformation)GetLoginErrorMethod, connectionString, (DataAccessErrorDelegate) delegate { return; }); //Check instead if old user is logged out properly if (!learnLogic.UserSessionAlive) { throw new DoubleLoginException(); } } else { throw new DoubleLoginException(); } }
/// <summary> /// Gets the admin user. /// </summary> /// <param name="userStr">The user struct.</param> /// <param name="con">The connectionStringStruct.</param> /// <returns>The user struct.</returns> /// <remarks>Documented by Dev08</remarks> public static UserStruct?GetAdminUser(UserStruct userStr, ConnectionStringStruct con) { UserStruct userStruct = new UserStruct("admin", "admin", UserAuthenticationTyp.FormsAuthentication, false); userStruct.CloseOpenSessions = true; return(userStruct); }
/// <summary> /// Gets the testuser. /// </summary> /// <param name="userStr">The user struct.</param> /// <param name="con">The connectionStringStruct.</param> /// <returns></returns> /// <remarks>Documented by Dev08</remarks> public static UserStruct?GetTestUser(UserStruct userStr, ConnectionStringStruct con) { UserStruct userStruct = new UserStruct("testuser", UserAuthenticationTyp.ListAuthentication); userStruct.CloseOpenSessions = true; return(userStruct); }
private void LearnLogic_CopyToFinished(object sender, EventArgs e) { LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished); HideStatusMessage(); if (cleanUpOdx) { ConnectionStringStruct css = new ConnectionStringStruct(DatabaseType.Xml, Path.GetDirectoryName(odxFile), odxFile, true); IUser xmlUser = UserFactory.Create((GetLoginInformation) delegate(UserStruct u, ConnectionStringStruct c) { return(u); }, css, DataAccessError, null); xmlUser.List().Delete(css); } else { FileInfo fi = new FileInfo(odxFile); if (File.Exists(odxFile + ".bak")) { try { File.Delete(odxFile + ".bak"); } catch { } } try { fi.MoveTo(odxFile + ".bak"); } catch { } } OnConvertedFinish(new ConvertingEventArgs(edbFile)); }
/// <summary> /// Serializes the index cache. /// </summary> /// <param name="stream">The stream.</param> /// <remarks>Documented by Dev02, 2008-12-04</remarks> private void SerializeIndexCache(Stream stream) { //cache for passwords - they must not be saved in the disk cache Dictionary <string, string> passwords = new Dictionary <string, string>(); foreach (KeyValuePair <string, LearningModulesIndexEntry> pair in indexCache) { if (pair.Value.ConnectionString.Password != string.Empty) { passwords.Add(pair.Key, pair.Value.ConnectionString.Password); ConnectionStringStruct css = pair.Value.ConnectionString; css.Password = string.Empty; pair.Value.ConnectionString = css; } } IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, indexCacheTimestamps); formatter.Serialize(stream, indexCache); foreach (KeyValuePair <string, string> pair in passwords) { LearningModulesIndexEntry entry = indexCache[pair.Key]; ConnectionStringStruct css = entry.ConnectionString; css.Password = pair.Value; entry.ConnectionString = css; } }
/// <summary> /// Connects to the LM database. /// </summary> /// <returns>True if success</returns> /// <remarks>Documented by Dev03, 2008-11-18</remarks> private bool Connect() { if (connected) { return(true); } try { if (m_learnLogic != null) { m_learnLogic.CloseLearningModule(); } ConnectionStringStruct connectionTarget = new ConnectionStringStruct(DatabaseType.PostgreSQL, textBoxConnectionString.Text, -1); m_learnLogic.User.Authenticate(GetUser, connectionTarget, DataAccessError); dictionaries = m_learnLogic.User.GetLearningModuleList(); File.WriteAllText(connectionstringfile, textBoxConnectionString.Text); textBoxCurrentUser.Text = m_learnLogic.User.ToString(); connected = true; } catch (Exception exp) { System.Diagnostics.Trace.Write(exp.ToString()); return(false); } return(true); }
/// <summary> /// Copies a XML Learning Module to the database. /// </summary> /// <returns></returns> /// <remarks>Documented by Dev03, 2008-11-18</remarks> private void CopyLM() { if (!File.Exists(textBoxSource.Text)) { return; } ConnectionStringStruct connectionTarget; ConnectionStringStruct connectionSource = new ConnectionStringStruct(DatabaseType.Xml, textBoxSource.Text, false); int newLmId = dictionaries.AddNew(MLifter.DAL.Category.DefaultCategory, string.Empty).Id; connectionTarget = dictionaries.Parent.CurrentUser.ConnectionString; connectionTarget.LmId = importedId = newLmId; ShowStatusMessage(true); LearnLogic.CopyToFinished += new EventHandler(LearnLogic_CopyToFinished); try { LearnLogic.CopyLearningModule(connectionSource, connectionTarget, (GetLoginInformation)LoginForm.OpenLoginForm, (CopyToProgress)UpdateStatusMessage, (DataAccessErrorDelegate) delegate(object o, Exception ex) { return; }, m_learnLogic.User); } catch { HideStatusMessage(); //delete partially created dictionary dictionaries.Delete(connectionTarget); MessageBox.Show(Properties.Resources.DIC_ERROR_LOADING_TEXT, Properties.Resources.DIC_ERROR_LOADING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Generates the test data. /// </summary> /// <remarks>Documented by Dev03, 2008-11-18</remarks> private void GenerateTestData() { if (CheckedLearningModules.Count < 1) { MessageBox.Show(Properties.Resources.ERROR_NO_LM_SELECTED_TEXT, Properties.Resources.ERROR_NO_LM_SELECTED_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } ShowStatusMessage(false); try { ConnectionStringStruct connectionTarget = new ConnectionStringStruct(DatabaseType.PostgreSQL, textBoxConnectionString.Text, -1); m_learnLogic.CurrentLearningModule = new LearningModulesIndexEntry(connectionTarget); TestDataGenerator gen = new TestDataGenerator(m_learnLogic); gen.TestStatusProgressChanged += new TestStatusEventHandler(gen_TestStatusProgressChanged); gen.Generate(CheckedLearningModules, ParseSessionNum(), ParseCardNum()); } catch (Exception e) { MessageBox.Show(String.Format(Properties.Resources.ERROR_GENERATE_TEXT, e.Message), Properties.Resources.ERROR_GENERATE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { HideStatusMessage(); } connected = false; }
/// <summary> /// Deletes the specified id. /// </summary> /// <param name="css">The connection string struct</param> /// <remarks>Documented by Dev02, 2008-07-28</remarks> /// <remarks>Documented by Dev03, 2008-12-02</remarks> /// <remarks>Documented by Dev08, 2008-12-09</remarks> public void Delete(ConnectionStringStruct css) { foreach (IDictionary lmDelete in Dictionaries) { if (lmDelete.Connection != css.ConnectionString) { continue; } //Delete the LM if (File.Exists(lmDelete.Connection)) { try { Directory.Delete(Path.Combine(Path.GetDirectoryName(lmDelete.Connection), lmDelete.MediaDirectory), true); } catch (Exception ex) { Trace.WriteLine("Can't delete LM media folder - " + lmDelete.MediaDirectory + "! " + ex.Message); } string filename = lmDelete.Connection; try { File.Delete(filename); } catch (Exception ex) { Trace.WriteLine("Can't delete LM - " + filename + "! " + ex.Message); } } break; } }
/// <summary> /// Serializes to the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <remarks>Documented by Dev02, 2008-12-04</remarks> private static void Serialize(Stream stream) { //cache for passwords - they must not be saved on disk Dictionary <DateTime, string> passwords = new Dictionary <DateTime, string>(); foreach (KeyValuePair <DateTime, LearningModulesIndexEntry> pair in recentModules) { if (pair.Value.ConnectionString.Password != string.Empty) { passwords.Add(pair.Key, pair.Value.ConnectionString.Password); ConnectionStringStruct css = pair.Value.ConnectionString; css.Password = string.Empty; pair.Value.ConnectionString = css; } } IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, recentModules); foreach (KeyValuePair <DateTime, string> pair in passwords) { LearningModulesIndexEntry entry = recentModules[pair.Key]; ConnectionStringStruct css = entry.ConnectionString; css.Password = pair.Value; entry.ConnectionString = css; } }
private LearningModulesIndexEntry CreateNewOdxLearningModuleEntry(string path) { ConnectionStringStruct css = new ConnectionStringStruct(DatabaseType.Xml, path, true); IUser user = UserFactory.Create(getLogin, css, dataAccessError, path); IDictionary dic = DAL.User.GetPreviewDictionary(path, user, false); return(CreateLerningModuleEntry(dic, user)); }
/// <summary> /// Initializes a new instance of the <see cref="WebUser"/> class. /// </summary> /// <param name="userId">The user id.</param> /// <param name="authenticationStruct">The authentication struct.</param> /// <param name="connection">The connection.</param> /// <param name="service">The service.</param> /// <param name="parent">The parent.</param> /// <remarks>Documented by Dev05, 2009-03-06</remarks> internal WebUser(int userId, UserStruct authenticationStruct, ConnectionStringStruct connection, MLifterLearningModulesService service, ParentClass parent) { id = userId; authStruct = authenticationStruct; ConnectionString = connection; WebService = service; this.parent = parent; }
internal void GenerateNewSession() { sessionId = Guid.NewGuid(); ConnectionStringStruct css = user.ConnectionString; css.SessionId = sessionId; user.ConnectionString = css; }
/// <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(); }
/// <summary> /// Gets the security data adapter. /// </summary> /// <param name="connectionString">The connection string struct.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2009-01-14</remarks> internal static Framework GetDataAdapter(ConnectionStringStruct connectionString) { XmlSecurityDataAdapter adapter; //TODO implement data adapter code here //adapter = new DbSecurityDataAdapter(); //test code using XmlSecurityDataAdapter adapter = new XmlSecurityDataAdapter("Resources\\XmlSecurityFramework.xml"); return(new SecurityFramework(adapter)); }
public static PgSqlDictionariesConnector GetInstance(ParentClass parentClass) { ConnectionStringStruct connection = parentClass.CurrentUser.ConnectionString; if (!instances.ContainsKey(connection)) { instances.Add(connection, new PgSqlDictionariesConnector(parentClass)); } return(instances[connection]); }
private static string GetFullSqlCeConnectionString(ConnectionStringStruct connectionString) { string output = GetFullSqlCeConnectionString(connectionString.ConnectionString); if (connectionString.Password != string.Empty) { output += "Encrypt Database=True;Password="******";"; } return(output); }
public static MsSqlCeChapterConnector GetInstance(ParentClass parentClass) { ConnectionStringStruct connection = parentClass.CurrentUser.ConnectionString; if (!instances.ContainsKey(connection)) { instances.Add(connection, new MsSqlCeChapterConnector(parentClass)); } return(instances[connection]); }
/// <summary> /// Gets a static instance of this class. /// </summary> /// <value>The instance.</value> /// <remarks>Documented by Dev03, 2008-09-10</remarks> public static DbDatabase GetInstance(ParentClass parentClass) { ConnectionStringStruct connection = parentClass.CurrentUser.ConnectionString; if (!instances.ContainsKey(connection)) { instances.Add(connection, new DbDatabase(parentClass)); } return(instances[connection]); }
/// <summary> /// Upgrades the database to the current version. /// </summary> /// <param name="currentVersion">The current version of the database.</param> /// <returns>[true] if success.</returns> /// <remarks>Documented by Dev03, 2009-04-30</remarks> public bool UpgradeDatabase(Version currentVersion) { ConnectionStringStruct css = Parent.CurrentUser.ConnectionString; if (css.Typ != DatabaseType.MsSqlCe) { return(false); } return(MsSqlCe.MSSQLCEConn.UpgradeDatabase(Parent.CurrentUser, currentVersion)); }
/// <summary> /// Checks if the given database can be opened. /// </summary> /// <param name="connectionString">The connection string.</param> /// <returns>LearningModuleIOStatus</returns> /// <remarks>Documented by Dev08, 2009-04-29</remarks> public static LearningModuleIOStatus CanOpenLearningModule(ConnectionStringStruct connectionString) { //1. Check if there is already a open connection on this file bool learningModuleWasAlreadyConnected = false; lock (connections) { if (connections.ContainsKey(connectionString.ConnectionString) && connections[connectionString.ConnectionString].State == ConnectionState.Open) { learningModuleWasAlreadyConnected = true; connections[connectionString.ConnectionString].Close(); } } //2. Create a new connection and check, if it can be opened... SqlCeConnection myConnection = new SqlCeConnection(GetFullConnectionString(connectionString.ConnectionString, connectionString.Password)); try { myConnection.Open(); } catch (SqlCeException exp) { switch (exp.NativeError) { case 25079: case 25028: return(LearningModuleIOStatus.Protected); case 25035: return(LearningModuleIOStatus.FileUsedByAnotherProcess); } } finally { myConnection.Close(); //3. If necessary, open the last connection. if (learningModuleWasAlreadyConnected) { lock (connections) { try { connections[connectionString.ConnectionString].Open(); } catch { } } } } return(LearningModuleIOStatus.NotProtected); }
/// <summary> /// Sets the connection string. /// </summary> /// <param name="css">The CSS.</param> /// <remarks>Documented by Dev05, 2010-02-03</remarks> public void SetConnectionString(ConnectionStringStruct css) { con = css; if (con.Typ == DatabaseType.MsSqlCe) { dbUser.SetConnectionString(con); } else { xmlUser.SetConnectionString(con); } }
/// <summary> /// Opens the learning module (or schedules it for opening). /// </summary> /// <param name="configFilePath">The config file path.</param> /// <param name="LmId">The lm id.</param> /// <param name="LmName">Name of the lm.</param> /// <param name="UserId">The user id.</param> /// <param name="UserName">Name of the user.</param> /// <param name="UserPassword">The user password (needed for FormsAuthentication, else empty).</param> /// <remarks>Documented by Dev02, 2009-06-26</remarks> /// <exception cref="MLHasOpenFormsException">Occurs when settings or the learning module could not be changed because MemoryLifter has other forms/windows open.</exception> /// <exception cref="ConfigFileParseException">Occurs when the supplied config file could not be parsed properly or does not contain a valid connection.</exception> /// <exception cref="MLCouldNotBeStartedException">Occurs when MemoryLifter did not start or did not react to connection attempts.</exception> public void OpenLearningModule(string configFilePath, int LmId, string LmName, int UserId, string UserName, string UserPassword) { ConnectionStringHandler csHandler = new ConnectionStringHandler(configFilePath); if (csHandler.ConnectionStrings.Count < 1) { throw new ConfigFileParseException(); } Debug.WriteLine(string.Format("Config file parsed ({0}), building connection...", configFilePath)); IConnectionString connectionString = csHandler.ConnectionStrings[0]; ConnectionStringStruct css = new ConnectionStringStruct(); css.LmId = LmId; css.Typ = connectionString.ConnectionType; css.ConnectionString = connectionString.ConnectionString; if (connectionString is UncConnectionStringBuilder) { css.ConnectionString = Path.Combine(css.ConnectionString, LmName + Helper.EmbeddedDbExtension); css.Typ = DatabaseType.MsSqlCe; } if (connectionString is ISyncableConnectionString) { ISyncableConnectionString syncConnectionString = (ISyncableConnectionString)connectionString; css.LearningModuleFolder = syncConnectionString.MediaURI; css.ExtensionURI = syncConnectionString.ExtensionURI; css.SyncType = syncConnectionString.SyncType; } LearningModulesIndexEntry entry = new LearningModulesIndexEntry(css); entry.User = new DummyUser(UserId, UserName); ((DummyUser)entry.User).Password = UserPassword; entry.UserName = UserName; entry.UserId = UserId; entry.Connection = connectionString; entry.DisplayName = LmName; entry.SyncedPath = LmName + Helper.SyncedEmbeddedDbExtension; Debug.WriteLine("Opening learning module..."); try { loader.LoadDictionary(entry); } catch (MLifter.Classes.FormsOpenException) { throw new MLHasOpenFormsException(); } }
public static MsSqlCeStatisticConnector GetInstance(ParentClass parent) { lock (instance) { ConnectionStringStruct connection = parent.CurrentUser.ConnectionString; if (!instance.ContainsKey(connection)) { instance.Add(connection, new MsSqlCeStatisticConnector(parent)); } return(instance[connection]); } }
/// <summary> /// Gets the instance. /// </summary> /// <param name="ParentClass">The parent class.</param> /// <returns></returns> /// <remarks>Documented by Dev05, 2009-01-16</remarks> public static MsSqlCeQueryDirectionsConnector GetInstance(ParentClass ParentClass) { lock (instances) { ConnectionStringStruct connection = ParentClass.CurrentUser.ConnectionString; if (!instances.ContainsKey(connection)) { instances.Add(connection, new MsSqlCeQueryDirectionsConnector(ParentClass)); } return(instances[connection]); } }
private static IDbUserConnector GetConnector(ConnectionStringStruct connection) { switch (connection.Typ) { case DatabaseType.PostgreSQL: return(PgSqlUserConnector.GetInstance(new ParentClass(new DummyUser(connection), null))); case DatabaseType.MsSqlCe: return(MsSqlCeUserConnector.GetInstance(new ParentClass(new DummyUser(connection), null))); default: throw new UnsupportedDatabaseTypeException(connection.Typ); } }
public void LearnLogicLearnModeTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); //learnLogic.User.Authenticate(OpenUserProfileTests.GetUserAdmin, connectionString, (DataAccessErrorDelegate)delegate { return; }); try { learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") //success { return; } else { throw; } } learnLogic.User.Dictionary.Settings.QueryTypes.ImageRecognition = true; learnLogic.User.Dictionary.Settings.QueryTypes.ListeningComprehension = true; learnLogic.User.Dictionary.Settings.QueryTypes.Sentence = true; for (int i = 0; i < TestInfrastructure.LoopCount; i++) { learnLogic.OnLearningModuleOptionsChanged(); Card card = learnLogic.User.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID); switch (learnLogic.User.Dictionary.LearnMode) { case LearnModes.ImageRecognition: Assert.IsTrue(card.ContainsImage(Side.Question.ToString()), "Card must contain image for ImageRecognition mode."); break; case LearnModes.ListeningComprehension: Assert.IsTrue(card.ContainsAudio(Side.Question.ToString()), "Card must contain audio for ListeningComprehension mode."); break; case LearnModes.Sentence: Assert.IsTrue(card.CurrentQuestionExample.Words.Count > 0, "Card must contain example for Sentence mode."); break; default: continue; } } } }
public static PgSqlQueryMultipleChoiceOptionsConnector GetInstance(ParentClass parentClass) { lock (instances) { ConnectionStringStruct connection = parentClass.CurrentUser.ConnectionString; if (!instances.ContainsKey(connection)) { instances.Add(connection, new PgSqlQueryMultipleChoiceOptionsConnector(parentClass)); } return(instances[connection]); } }
public void GetBoxContentTest() { if (TestInfrastructure.IsActive(TestContext)) { ConnectionStringStruct connectionString = TestInfrastructure.GetConnectionStringWithDummyData(TestContext); LearnLogic learnLogic = new LearnLogic(OpenUserProfileTests.GetUserAdmin, (DataAccessErrorDelegate) delegate { return; }); //learnLogic.User.Authenticate((GetLoginInformation)MLifterTest.DAL.TestInfrastructure.GetTestUser, // connectionString, (DataAccessErrorDelegate)delegate { return; }); try { learnLogic.OpenLearningModule(new LearningModulesIndexEntry(connectionString)); } catch (IsOdxFormatException) { if (TestInfrastructure.ConnectionType(TestContext) == "File") { return; } else { throw; } } learnLogic.OnLearningModuleOptionsChanged(); learnLogic.ResetLearningProgress(); Card currentCard = learnLogic.Dictionary.Cards.GetCardByID(learnLogic.CurrentCardID); //Answer Card correct UserInputSubmitEventArgs e = new UserInputSubmitTextEventArgs(0, currentCard.CurrentAnswer.Words.Count, currentCard.CurrentAnswer.Words.Count, true, currentCard.CurrentAnswer.Words.ToString()); learnLogic.OnUserInputSubmit(this, e); learnLogic.OnUserInputSubmit(this, new UserInputSubmitEventArgs()); Assert.AreEqual <int>(1, learnLogic.Dictionary.Statistics.GetBoxContent(2, DateTime.Now.AddDays(1)), "GetBoxContent() did not return the correct number of cards"); for (int i = 1; i < 10; i++) { if (i == 2) { continue; } else { Assert.AreEqual <int>(0, learnLogic.Dictionary.Statistics.GetBoxContent(i, DateTime.Now.AddDays(1)), "GetBoxContent() says the Box " + i + " is NOT 0 (although it should)"); } } } }