internal DbUser(UserStruct? user, ParentClass parent, ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate, bool standAlone) { this.parent = parent; connectionString = connection; ErrorMessageDelegate = errorMessageDelegate; cache = new Cache(true); if (!user.HasValue) throw new NoValidUserException(); this.authenticationStruct = user.Value; this.username = user.Value.UserName; this.hashedPassword = user.Value.Password; this.standAlone = standAlone; this.user = user; securityFramework = MLifter.DAL.Security.SecurityFramework.GetDataAdapter(this); if (username != null && securityFramework != null) { try { securityToken = securityFramework.CreateSecurityToken(this.username); securityToken.IsCaching = cachePermissions; } catch (Exception ex) { Debug.WriteLine("Failed to create security token! (" + ex.Message + ")"); } } Login(); }
/// <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> /// Gets the db user. /// </summary> /// <param name="connection">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> /// <returns>A DB user which implements IUser</returns> /// <remarks>Documented by Dev03, 2008-11-25</remarks> private IUser GetDbUser(ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate, bool standAlone) { CheckConnection(connection); UserAuthenticationTyp authTyp = connector.GetAllowedAuthenticationModes().Value; bool ldUserChecked = false; IUser dbUser = null; UserStruct?userStruct = null; while (dbUser == null) { if (!IsWebService && !ldUserChecked && (authTyp & UserAuthenticationTyp.LocalDirectoryAuthentication) == UserAuthenticationTyp.LocalDirectoryAuthentication) { ldUserChecked = true; try { userStruct = GetLocalDirectoryUser(); } catch (NoValidUserException) { userStruct = null; } } else { userStruct = getLogin.Invoke(userStruct.HasValue ? userStruct.Value : new UserStruct(string.Empty, authTyp), ConnectionString); } if (userStruct.HasValue) { UserStruct lastUser = userStruct.Value; try { dbUser = new DbUser(userStruct, Parent, connection, errorMessageDelegate, standAlone); lastUser.LastLoginError = LoginError.NoError; } catch (InvalidUsernameException) { lastUser.LastLoginError = LoginError.InvalidUsername; } catch (InvalidPasswordException) { lastUser.LastLoginError = LoginError.InvalidPassword; } catch (WrongAuthenticationException) { lastUser.LastLoginError = LoginError.WrongAuthentication; } catch (ForbiddenAuthenticationException) { lastUser.LastLoginError = LoginError.ForbiddenAuthentication; } catch (UserSessionCreationException) { lastUser.LastLoginError = LoginError.AlreadyLoggedIn; } userStruct = lastUser; } else { throw new NoValidUserException(); } } return(dbUser); }
internal DbUser(UserStruct?user, ParentClass parent, ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate, bool standAlone) { this.parent = parent; connectionString = connection; ErrorMessageDelegate = errorMessageDelegate; cache = new Cache(true); if (!user.HasValue) { throw new NoValidUserException(); } this.authenticationStruct = user.Value; this.username = user.Value.UserName; this.hashedPassword = user.Value.Password; this.standAlone = standAlone; this.user = user; securityFramework = MLifter.DAL.Security.SecurityFramework.GetDataAdapter(this); if (username != null && securityFramework != null) { try { securityToken = securityFramework.CreateSecurityToken(this.username); securityToken.IsCaching = cachePermissions; } catch (Exception ex) { Debug.WriteLine("Failed to create security token! (" + ex.Message + ")"); } } Login(); }
/// <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> /// 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)); }
internal XmlUser(ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate) { connectionString = connection; ErrorMessageDelegate = errorMessageDelegate; }
/// <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> /// 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> /// 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> /// 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="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> /// 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> /// 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> /// 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> /// 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> /// 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 db user. /// </summary> /// <param name="connection">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> /// <returns>A DB user which implements IUser</returns> /// <remarks>Documented by Dev03, 2008-11-25</remarks> private IUser GetDbUser(ConnectionStringStruct connection, DataAccessErrorDelegate errorMessageDelegate, bool standAlone) { CheckConnection(connection); UserAuthenticationTyp authTyp = connector.GetAllowedAuthenticationModes().Value; bool ldUserChecked = false; IUser dbUser = null; UserStruct? userStruct = null; while (dbUser == null) { if (!IsWebService && !ldUserChecked && (authTyp & UserAuthenticationTyp.LocalDirectoryAuthentication) == UserAuthenticationTyp.LocalDirectoryAuthentication) { ldUserChecked = true; try { userStruct = GetLocalDirectoryUser(); } catch (NoValidUserException) { userStruct = null; } } else userStruct = getLogin.Invoke(userStruct.HasValue ? userStruct.Value : new UserStruct(string.Empty, authTyp), ConnectionString); if (userStruct.HasValue) { UserStruct lastUser = userStruct.Value; try { dbUser = new DbUser(userStruct, Parent, connection, errorMessageDelegate, standAlone); lastUser.LastLoginError = LoginError.NoError; } catch (InvalidUsernameException) { lastUser.LastLoginError = LoginError.InvalidUsername; } catch (InvalidPasswordException) { lastUser.LastLoginError = LoginError.InvalidPassword; } catch (WrongAuthenticationException) { lastUser.LastLoginError = LoginError.WrongAuthentication; } catch (ForbiddenAuthenticationException) { lastUser.LastLoginError = LoginError.ForbiddenAuthentication; } catch (UserSessionCreationException) { lastUser.LastLoginError = LoginError.AlreadyLoggedIn; } userStruct = lastUser; } else throw new NoValidUserException(); } return dbUser; }