Ejemplo n.º 1
0
        public void RestoreTest00()
        {
            string filename = "C:\\temp.tmp";

            try
            {
                generateTestContext();
                RecentLearningModules.Dump(filename);

                Stream stream = null;
                stream = new FileStream(filename, FileMode.Open);
                stream.Seek(0, SeekOrigin.Begin);
                Random r = new Random();
                for (int i = 0; i < 10; i++)
                {
                    byte damage = (byte)r.Next(65, 90);
                    stream.WriteByte(damage);
                }
                stream.Close();

                RecentLearningModules.Restore(filename);
            }
            finally
            {
                try
                {
                    File.Delete(filename);
                }
                catch { }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Regenerates the recent learning modules with two unique LearningModulesIndexEntry's
        /// </summary>
        /// <returns></returns>
        /// <remarks>Documented by Dev07, 2009-03-03</remarks>
        private void generateTestContext()
        {
            RecentLearningModules.Clear();

            RecentLearningModules.Add(lm1);
            Thread.Sleep(50);
            RecentLearningModules.Add(lm2);
            Thread.Sleep(50);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the recent learning module.
        /// </summary>
        /// <param name="learningModule">The learning module.</param>
        /// <remarks>Documented by Dev03, 2009-05-11</remarks>
        public static void AddRecentLearningModule(LearningModulesIndexEntry learningModule)
        {
            RecentLearningModules.Add(learningModule);
            RecentLearningModules.Dump(Setup.RecentLearningModulesPath);

            if (RunningFromStick())
            {
                Setup.AddRecentFileToStick(learningModule);
            }
        }
Ejemplo n.º 4
0
        public void AddTest01()
        {
            generateTestContext();
            Thread.Sleep(10);
            RecentLearningModules.Add(lm1);

            // test that original recent list item was erased and replaced
            Assert.AreEqual(2, RecentLearningModules.GetRecentModules().Count);

            // test that the overwritten recent item is now the most recent
            CompareLMIndexEntry(lm1, RecentLearningModules.MostRecentLearningModule);
        }
Ejemplo n.º 5
0
        public void GetRecentModulesTest()
        {
            generateTestContext();

            List <LearningModulesIndexEntry> actual   = RecentLearningModules.GetRecentModules();
            List <LearningModulesIndexEntry> expected = new List <LearningModulesIndexEntry>();

            expected.Add(lm2);
            Thread.Sleep(10);
            expected.Add(lm1);

            CompareLMIndexEntry(expected[0], actual[0]);
            CompareLMIndexEntry(expected[1], actual[1]);
        }
Ejemplo n.º 6
0
        public void DumpRestoreTest()
        {
            try
            {
                generateTestContext();
                RecentLearningModules.Dump("C:\\temp.tmp");
                List <LearningModulesIndexEntry> expected = RecentLearningModules.GetRecentModules();

                RecentLearningModules.Restore("C:\\temp.tmp");
                List <LearningModulesIndexEntry> actual = RecentLearningModules.GetRecentModules();

                CompareLMIndexEntry(expected[0], actual[0]);
                CompareLMIndexEntry(expected[1], actual[1]);
            }
            finally
            {
                try { File.Delete("C:\\temp.tmp"); }
                catch { }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Upgrades the settings from an earlier version.
        /// </summary>
        /// <remarks>Documented by Dev05, 2007-11-14</remarks>
        public static void UpgradeFromEarlierVersion()
        {
            if (!Settings.Default.Upgraded)
            {
                try //[ML-397] ML sometimes throws an exception when trying to update old user seetings
                {
                    Settings.Default.Upgrade();
                }
                catch { }
                Settings.Default.Upgraded = true;
                Settings.Default.Save();

                //try to import recent files
                List <string> recent = GetRecentFilesFromStick();;
                if (recent.Count > 0)
                {
                    recent.Reverse();

                    recent.ForEach(delegate(String file)
                    {
                        try
                        {
                            if (!File.Exists(file))
                            {
                                return;
                            }
                        }
                        catch { return; }

                        LearningModulesIndexEntry entry = FolderIndexEntry.CreateNewOdxLearningModuleEntryStatic(file);
                        RecentLearningModules.Add(entry);
                    });

                    RecentLearningModules.Dump(RecentLearningModulesPath);
                    Settings.Default.RecentFiles = string.Empty;
                }

                Settings.Default.Save();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes the control with the specified connection (name).
        /// </summary>
        /// <param name="connectionName">Name of the connection.</param>
        /// <param name="connection">The connection.</param>
        /// <remarks>Documented by Dev05, 2009-03-03</remarks>
        public UserStruct?Initialize(ConnectionStringStruct connection, UserStruct lastUser)
        {
            ConnectionString = LearningModulesIndex.ConnectionsHandler.GetConnectionFromConnectionStringStruct(connection);
            if (ConnectionString == null)
            {
                LearningModulesIndexEntry entry = RecentLearningModules.GetRecentModules().Find(m => m.ConnectionString.ConnectionString == connection.ConnectionString);
                if (entry != null)
                {
                    ConnectionString = entry.Connection;
                }
            }

            ConnectionName = connection.Typ != DatabaseType.MsSqlCe ? (ConnectionString != null ? ConnectionString.Name : Resources.NO_CONNECTION_NAME) : Path.GetFileName(connection.ConnectionString);
            Connection     = connection;

            if (connection.Typ == DatabaseType.MsSqlCe)
            {
                comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDownList;
            }
            else
            {
                comboBoxUserSelection.DropDownStyle = ComboBoxStyle.DropDown;
            }

            #region error handling
            switch (lastUser.LastLoginError)
            {
            case LoginError.AlreadyLoggedIn:
                EmulatedTaskDialog taskDialog = new EmulatedTaskDialog();
                taskDialog.Title           = Resources.TASKDIALOG_KICK_TITLE;
                taskDialog.MainInstruction = string.Format(Resources.TASKDIALOG_KICK_MAIN, lastUser.UserName);
                taskDialog.Content         = string.Format(Resources.TASKDIALOG_KICK_CONTENT, ConnectionName);
                taskDialog.CommandButtons  = Resources.TASKDIALOG_KICK_BUTTONS;

                taskDialog.VerificationText            = string.Empty;
                taskDialog.VerificationCheckBoxChecked = false;
                taskDialog.Buttons      = TaskDialogButtons.None;
                taskDialog.MainIcon     = TaskDialogIcons.Warning;
                taskDialog.FooterIcon   = TaskDialogIcons.Warning;
                taskDialog.MainImages   = new Image[] { Resources.system_log_out, Resources.processStopBig };
                taskDialog.HoverImages  = new Image[] { Resources.system_log_out, Resources.processStopBig };
                taskDialog.CenterImages = true;
                taskDialog.BuildForm();
                DialogResult dialogResult = taskDialog.ShowDialog();

                if (dialogResult != DialogResult.Cancel && taskDialog.CommandButtonClickedIndex == 0)
                {
                    lastUser.CloseOpenSessions = true;
                    return(lastUser);
                }
                else
                {
                    AllowAutoLogin = false;
                }
                break;

            case LoginError.InvalidUsername:
                TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_USER_TITLE, Resources.TASKDIALOG_WRONG_USER_MAIN, Resources.TASKDIALOG_WRONG_USER_CONTENT,
                                      TaskDialogButtons.OK, TaskDialogIcons.Error);
                break;

            case LoginError.InvalidPassword:
                TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_PASSWORD_TITLE, Resources.TASKDIALOG_WRONG_PASSWORD_MAIN, Resources.TASKDIALOG_WRONG_PASSWORD_CONTENT,
                                      TaskDialogButtons.OK, TaskDialogIcons.Error);
                break;

            case LoginError.WrongAuthentication:
            case LoginError.ForbiddenAuthentication:
                TaskDialog.MessageBox(Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_TITLE, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_MAIN, Resources.TASKDIALOG_WRONG_AUTHENTIFICATION_CONTENT,
                                      TaskDialogButtons.OK, TaskDialogIcons.Error);
                break;

            case LoginError.NoError:
            default:
                break;
            }
            #endregion

            labelHeader.Text = string.Format(Resources.LOGIN_HEADER_TEXT, ConnectionName);

            buttonCancel.Enabled = connection.Typ != DatabaseType.MsSqlCe;

            try
            {
                SetListItems();
                UpdateSelection(false);

                #region persitancy
                Stream outputStream = null;
                try
                {
                    BinaryFormatter     binary      = new BinaryFormatter();
                    IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForAssembly();
                    outputStream   = new IsolatedStorageFileStream(Settings.Default.AuthDataFile, FileMode.Open, storageFile);
                    outputStream   = new CryptoStream(outputStream, Rijndael.Create().CreateDecryptor(Encoding.Unicode.GetBytes("mlifter"), Encoding.Unicode.GetBytes("omicron")), CryptoStreamMode.Read);
                    persitancyData = binary.Deserialize(outputStream) as Dictionary <string, SavedUserData>;
                    outputStream.Close();
                }
                catch { persitancyData = new Dictionary <string, SavedUserData>(); }
                finally
                {
                    if (outputStream != null)
                    {
                        outputStream.Close();
                    }
                }

                if (ConnectionString != null && persitancyData.ContainsKey(ConnectionString.ConnectionString))
                {
                    SavedUserData data = persitancyData[ConnectionString.ConnectionString];
                    if (data.SaveUsername)
                    {
                        checkBoxSaveUsername.Checked = true;
                        ShowOptions = true;
                        comboBoxUserSelection.Text = data.Username;
                        if (data.SavePassword)
                        {
                            checkBoxSavePassword.Checked = true;
                            textBoxPassword.Text         = data.Password;
                            textBoxPassword.Tag          = PasswordType.Hashed;
                            if (data.AutoLogin)
                            {
                                checkBoxAutoLogin.Checked = true;
                                if (AllowAutoLogin && !MLifter.BusinessLayer.User.PreventAutoLogin)
                                {
                                    Login();
                                    return(GetActualUser());
                                }
                            }
                            else
                            {
                                checkBoxAutoLogin.Checked = false;
                            }
                        }
                        else
                        {
                            checkBoxSavePassword.Checked = false;
                        }
                    }
                    else
                    {
                        checkBoxSaveUsername.Checked = false;
                        ShowOptions = false;
                    }
                }
                #endregion

                comboBoxUserSelection.Focus();

                if (lastUser.LastLoginError != LoginError.NoError)
                {
                    comboBoxUserSelection.Text = lastUser.UserName;
                    textBoxPassword.Text       = string.Empty;
                    textBoxPassword.Tag        = PasswordType.ClearText;
                }

                LoginError = lastUser.LastLoginError;
            }
            catch (ConnectionNotSetException ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return(null);
        }
Ejemplo n.º 9
0
 public void ClearTest()
 {
     generateTestContext();
     RecentLearningModules.Clear();
     Assert.AreEqual(0, RecentLearningModules.GetRecentModules().Count);
 }
Ejemplo n.º 10
0
 public void AddTest()
 {
     RecentLearningModules.Add((LearningModulesIndexEntry)null);
 }
Ejemplo n.º 11
0
 public void MostRecentLearningModuleTest()
 {
     RecentLearningModules.Add(lm1);
     CompareLMIndexEntry(lm1, RecentLearningModules.GetRecentModules()[0]);
 }