コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public Facade()
        {
            AppSettings settings     = new AppSettings();
            string      globalConfig = Path.Combine(Application.Current.StartupUri.AbsolutePath, settings.ConfigPath);
            string      userConfig   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Properties.Settings.Default.ConfigurationFolder);

            /**** Omicron ***********************************************************************/
            LearningModules = new LearningModulesIndex(globalConfig, userConfig, GetUser, DataAccessError, String.Empty);
            List <IConnectionString> connectionStrings = LearningModulesIndex.ConnectionsHandler.ConnectionStrings.FindAll(c => c.ConnectionType == MLifter.DAL.DatabaseType.PostgreSQL);

            try
            {
                if (connectionStrings.Count > 0)
                {
                    try
                    {
                        ConnectionString = connectionStrings[0];
                        FolderIndexEntry entry = LearningModules.GetFolderOfConnection(ConnectionString);
                        CurrentUser = LearningModulesIndex.ConnectionUsers[ConnectionString];
                        if (!CurrentUser.HasPermission(CurrentUser.List(), PermissionTypes.IsAdmin))
                        {
                            throw new PermissionException();
                        }

                        SecurityFramework = MLifter.DAL.Security.SecurityFramework.GetDataAdapter(ConnectionString.ConnectionString);
                    }
                    catch (PermissionException)
                    {
                        CurrentUser.Logout();
                        MessageBox.Show(Resources.CONNECTION_ERROR_PERMISSION_TEXT, Resources.CONNECTION_ERROR_PERMISSION_CAPTION, MessageBoxButton.OK, MessageBoxImage.Warning);
                        throw;
                    }
                    catch (Exception e)
                    {
                        //MessageBox.Show(Resources.CONNECTION_ERROR_FAILURE_TEXT, Resources.CONNECTION_ERROR_FAILURE_CAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
                        TaskDialog.MessageBox(Resources.CONNECTION_ERROR_FAILURE_CAPTION, Resources.CONNECTION_ERROR_FAILURE_TEXT, string.Empty, e.ToString(), string.Empty, string.Empty, TaskDialogButtons.OK, TaskDialogIcons.Error, TaskDialogIcons.Error);
                        throw;
                    }
                }
                else
                {
                    TaskDialog.MessageBox(Resources.CONNECTION_ERROR_NO_CONNECTION_AVAILABLE_CAPTION, Resources.CONNECTION_ERROR_NO_CONNECTION_AVAILABLE_TEXT,
                                          String.Format(Resources.CONNECTION_ERROR_NO_CONNECTION_AVAILABLE_DETAILS, Settings.Default.ConfigurationFolder), TaskDialogButtons.OK, TaskDialogIcons.Error);
                    throw new Exception();
                }
            }
            catch
            {
                Environment.Exit(-1);
            }
            /**** Omicron ***********************************************************************/


            AddNewGroupCommand               = new DelegateCommand <object>(ExecuteAddNewGroupCommand, CanAddNewGroupCommand);
            RemoveGroupCommand               = new DelegateCommand <Group>(ExecuteRemoveGroupCommand, CanRemoveGroupCommand);
            AddNewUserCommand                = new DelegateCommand <object>(ExecuteAddNewUserCommand, CanAddNewUserCommand);
            RemoveUserCommand                = new DelegateCommand <UserInfo>(ExecuteRemoveUserCommand, CanRemoveUserCommand);
            ResetTypePermissionCommand       = new DelegateCommand <TypeInformation>(ExecuteResetTypePermissionCommand, CanResetTypePermissionCommand);
            ResetObjectPermissionCommand     = new DelegateCommand <ObjectInformation>(ExecuteResetObjectPermissionCommand, CanResetObjectPermissionCommand);
            RenameGroupCommand               = new DelegateCommand <Group>(ExecuteRenameGroupCommand, CanRenameGroupCommand);
            RenameUserCommand                = new DelegateCommand <UserInfo>(ExecuteRenameUserCommand, CanRenameUserCommand);
            ChangeUserPasswordCommand        = new DelegateCommand <UserInfo>(ExecuteChangeUserPasswordCommand, CanChangeUserPasswordCommand);
            ImportNewUserCommand             = new DelegateCommand <object>(ExecuteImportNewUserCommand, CanImportNewUserCommand);
            RemoveGroupFromUserCommand       = new DelegateCommand <GroupMembershipInfo>(ExecuteRemoveGroupFromUserCommand, CanRemoveGroupFromUserCommand);
            RemoveUserFromActualGroupCommand = new DelegateCommand <UserInfo>(ExecuteRemoveUserFromActualGroupCommand, CanRemoveUserFromActualGroupCommand);
            AddUserToActualGroupCommand      = new DelegateCommand <object>(ExecuteAddUserToActualGroupCommand, CanAddUserToActualGroupCommand);
        }