public byte[] GetLearningModuleIndexEntry(int learningModuleId, string clientId) { try { if ((int)Session["uid"] < 0) throw new NoValidUserException(); string key = string.Format("user-{0}", (int)Session["uid"]); string lmKey = string.Format("lm-{0}", learningModuleId); IUser user = null; lock (formatter) { try { user = HttpContext.Current.Cache[key] as IUser; } catch { } if (user == null) { user = UserFactory.Create((GetLoginInformation)delegate(UserStruct u, ConnectionStringStruct c) { if (u.LastLoginError != LoginError.NoError) throw new InvalidCredentialsException("Some of the submited credentials are wrong!"); string username = Session["username"].ToString(); string password = Session["password"].ToString(); UserAuthenticationTyp authType = password == string.Empty ? UserAuthenticationTyp.ListAuthentication : UserAuthenticationTyp.FormsAuthentication; return new UserStruct(username, password, authType, true, true); }, new ConnectionStringStruct(DatabaseType.PostgreSQL, ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, -1), (DataAccessErrorDelegate)delegate { return; }, ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, true); HttpContext.Current.Cache[key] = user; } } IDictionary dic = new MLifter.DAL.DB.DbDictionary(learningModuleId, user); LearningModulesIndexEntry entry = new LearningModulesIndexEntry(); entry.User = user; entry.Dictionary = dic; entry.DisplayName = dic.Title; entry.Type = LearningModuleType.Remote; entry.Type = LearningModuleType.Remote; entry.ConnectionString = new ConnectionStringStruct(DatabaseType.PostgreSQL, dic.Connection, dic.Id, user.ConnectionString.SessionId); LearningModulesIndex.LoadEntry(entry); if (entry.Dictionary.ContentProtected) { // MemoryLifter > 2.3 does not support DRM protected content entry.IsAccessible = false; entry.NotAccessibleReason = LearningModuleNotAccessibleReason.Protected; } ConnectionStringStruct conString = entry.ConnectionString; conString.ConnectionString = string.Empty; entry.ConnectionString = conString; MemoryStream stream = new MemoryStream(); formatter.Serialize(stream, entry); return stream.ToArray(); } catch (Exception exp) { try { WriteLogEntry(exp.ToString()); } catch { throw exp; } return null; } }
public byte[] GetLearningModuleIndexEntry(int learningModuleId, string clientId) { try { if ((int)Session["uid"] < 0) { throw new NoValidUserException(); } string key = string.Format("user-{0}", (int)Session["uid"]); string lmKey = string.Format("lm-{0}", learningModuleId); IUser user = null; lock (formatter) { try { user = HttpContext.Current.Cache[key] as IUser; } catch { } if (user == null) { user = UserFactory.Create((GetLoginInformation) delegate(UserStruct u, ConnectionStringStruct c) { if (u.LastLoginError != LoginError.NoError) { throw new InvalidCredentialsException("Some of the submited credentials are wrong!"); } string username = Session["username"].ToString(); string password = Session["password"].ToString(); UserAuthenticationTyp authType = password == string.Empty ? UserAuthenticationTyp.ListAuthentication : UserAuthenticationTyp.FormsAuthentication; return(new UserStruct(username, password, authType, true, true)); }, new ConnectionStringStruct(DatabaseType.PostgreSQL, ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, -1), (DataAccessErrorDelegate) delegate { return; }, ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, true); HttpContext.Current.Cache[key] = user; } } IDictionary dic = new MLifter.DAL.DB.DbDictionary(learningModuleId, user); LearningModulesIndexEntry entry = new LearningModulesIndexEntry(); entry.User = user; entry.Dictionary = dic; entry.DisplayName = dic.Title; entry.Type = LearningModuleType.Remote; entry.Type = LearningModuleType.Remote; entry.ConnectionString = new ConnectionStringStruct(DatabaseType.PostgreSQL, dic.Connection, dic.Id, user.ConnectionString.SessionId); LearningModulesIndex.LoadEntry(entry); if (entry.Dictionary.ContentProtected) { // MemoryLifter > 2.3 does not support DRM protected content entry.IsAccessible = false; entry.NotAccessibleReason = LearningModuleNotAccessibleReason.Protected; } ConnectionStringStruct conString = entry.ConnectionString; conString.ConnectionString = string.Empty; entry.ConnectionString = conString; MemoryStream stream = new MemoryStream(); formatter.Serialize(stream, entry); return(stream.ToArray()); } catch (Exception exp) { try { WriteLogEntry(exp.ToString()); } catch { throw exp; } return(null); } }