/// <summary>
        /// Initializes a new instance of the <see cref="RecentLearningModulesTest"/> class.
        /// </summary>
        /// <remarks>Documented by Dev07, 2009-03-03</remarks>
        public OfflineModulesTest()
        {
            tempFolder = Path.Combine(Path.GetTempPath(), "ML_Temp");
            Directory.CreateDirectory(tempFolder);

            File.Create(Path.Combine(tempFolder, "lm1.mlm"));
            File.Create(Path.Combine(tempFolder, "lm2.mlm"));

            lm1 = new LearningModulesIndexEntry();
            lm2 = new LearningModulesIndexEntry();
            ConnectionStringStruct css1 = new ConnectionStringStruct();
            css1.ConnectionString = Path.Combine(tempFolder, "lm1.mlm");
            css1.Typ = MLifter.DAL.DatabaseType.MsSqlCe;
            css1.LmId = 1;

            ConnectionStringStruct css2 = new ConnectionStringStruct();
            css2.ConnectionString = Path.Combine(tempFolder, "lm2.mlm");
            css2.Typ = MLifter.DAL.DatabaseType.MsSqlCe;
            css2.LmId = 2;

            IConnectionString con = new UncConnectionStringBuilder(tempFolder);

            lm1.DisplayName = "learnmodule1";
            lm1.ConnectionName = "connectionname1";
            lm1.Connection = con;
            lm1.ConnectionString = css1;
            lm1.SyncedPath = css1.ConnectionString;

            lm2.DisplayName = "learnmodule2";
            lm2.ConnectionName = "connectionname2";
            lm2.Connection = con;
            lm2.ConnectionString = css2;
            lm2.SyncedPath = css2.ConnectionString;
        }
Exemple #2
0
        /// <summary>
        /// Creates the default config.
        /// </summary>
        /// <param name="defaultLerningModulesPath">The default lerning modules path.</param>
        /// <remarks>Documented by Dev03, 2009-05-07</remarks>
        public static void CreateDefaultConfig(string defaultLerningModulesPath)
        {
            if (Directory.Exists(defaultLerningModulesPath))
            {
                Settings.Default.DicDir = defaultLerningModulesPath;
                Settings.Default.Save();

                string configPath = Setup.UserConfigPath;

                //Get the only connection from
                IConnectionString defaultConnection = ConnectionStringHandler.GetDefaultConnectionString(configPath);
                if (defaultConnection as UncConnectionStringBuilder == null)
                    ConnectionStringHandler.CreateUncConnection(Resources.DEFAULT_CONNECTION_NAME, defaultLerningModulesPath, configPath, Resources.DEFAULT_CONNECTION_FILE, true, Setup.IsPathOnStick(defaultLerningModulesPath));
                else
                {
                    UncConnectionStringBuilder builder = new UncConnectionStringBuilder(defaultLerningModulesPath, true, Setup.IsPathOnStick(defaultLerningModulesPath));
                    builder.Name = defaultConnection.Name;

                    ConnectionStringHandler.CreateUncConnection(builder, Path.GetDirectoryName(defaultConnection.ConfigFileName), Path.GetFileName(defaultConnection.ConfigFileName));
                }
            }
        }
        private UncConnectionStringBuilder PrepareUncConnectionStringBuilder(out Dictionary<string, string> referenceValues)
        {
            referenceValues = new Dictionary<string, string>();
            referenceValues.Add("ConnectionString", @"c:\lms");
            referenceValues.Add("Name", "Test ConnectionString");

            UncConnectionStringBuilder csb = new UncConnectionStringBuilder(referenceValues["ConnectionString"]);
            csb.Name = referenceValues["Name"];
            return csb;
        }
        public void UncStickCSBReadWriteTest()
        {
            List<DriveInfo> drives = Methods.GetMLifterSticks();
            if (drives.Count < 1)
                Assert.Inconclusive("No Stick plugged in! To test the stick functionality please plug in a stick!");

            string LMPath = Path.Combine(drives[0].RootDirectory.ToString(), "LearningModules");
            UncConnectionStringBuilder stick = new UncConnectionStringBuilder(Path.Combine(drives[0].RootDirectory.ToString(), "LearningModules"), false, true);
            ConnectionStringHandler.CreateUncConnection("StickTest", LMPath, drives[0].RootDirectory.ToString(), "defaultConnection.mlcfg", false, true);

            // test that the file was generated with the proper placeholder
            StreamReader sreader = new StreamReader(drives[0].RootDirectory.ToString() + "defaultConnection.mlcfg");
            Assert.AreNotEqual(-1, sreader.ReadToEnd().IndexOf("MEMSTICK:\\"), "MEMSTICK identifier not found");
            sreader.Close();

            // test that reading the file translates to the proper drive letter
            ConnectionStringHandler handler = new ConnectionStringHandler(drives[0].RootDirectory.ToString(), string.Empty);
            IConnectionString connection = handler.ConnectionStrings.Find(c => c.Name == "StickTest");
            Assert.IsNotNull(connection, "MEMSTICK config file not generated");
            Assert.AreEqual<string>(drives[0].RootDirectory.ToString() + "defaultConnection.mlcfg", connection.ConfigFileName);

            File.Delete(Path.Combine(drives[0].RootDirectory.ToString(), "defaultConnection.mlcfg"));
        }
Exemple #5
0
        /// <summary>
        /// Creates the new odx learning module entry.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev02, 2009-06-15</remarks>
        public static LearningModulesIndexEntry CreateNewOdxLearningModuleEntryStatic(string path)
        {
            ConnectionStringStruct css = new ConnectionStringStruct(DatabaseType.Xml, path, true);
            IUser user = UserFactory.Create((GetLoginInformation)delegate(UserStruct u, ConnectionStringStruct c) { return u; }, css, (DataAccessErrorDelegate)delegate(object sender, Exception e) { }, path);
            IDictionary dic = DAL.User.GetPreviewDictionary(path, user, false);

            string directory = new FileInfo(path).DirectoryName;
            UncConnectionStringBuilder connection = new UncConnectionStringBuilder(directory);
            connection.Name = directory;

            LearningModulesIndexEntry entry = new LearningModulesIndexEntry();
            entry.Connection = connection;
            entry.User = user;
            entry.Dictionary = dic;
            entry.DisplayName = dic.Title;
            entry.Type = LearningModuleType.Local;
            css.ProtectedLm = false;
            entry.ConnectionString = css;

            return entry;
        }
        /// <summary>
        /// Adds the usb drive connection.
        /// </summary>
        /// <param name="drive">The drive.</param>
        /// <remarks>Documented by Dev05, 2009-04-01</remarks>
        public IConnectionString AddUsbDrive(DriveInfo drive)
        {
            //TODO this needs to be fixed
            UncConnectionStringBuilder uncCon = new UncConnectionStringBuilder(Path.Combine(drive.RootDirectory.FullName, Properties.Settings.Default.StickLMFolder), false, true);
            uncCon.Name = String.Format(Resources.CSH_CONNECTION_NAME, drive.RootDirectory.FullName);
            uncCon.ConfigFileName = string.Empty;
            if (!connectionStrings.Contains(uncCon as IConnectionString))
                connectionStrings.Add(uncCon as IConnectionString);

            return uncCon;
        }
        /// <summary>
        /// Creates a new UNC connection.
        /// </summary>
        /// <param name="connection">The UNC connection.</param>
        /// <param name="configPath">The config path.</param>
        /// <param name="configFile">The config file.</param>
        /// <remarks>Documented by Dev03, 2008-12-19</remarks>
        public static void CreateUncConnection(UncConnectionStringBuilder connection, string configPath, string configFile)
        {
            if (connection == null)
                throw new ArgumentNullException("connection can't be null");
            if (configPath == null)
                throw new ArgumentNullException("configPath can't be null");
            if (configFile == null)
                throw new ArgumentNullException("configFile can't be null");
            if (configPath.Trim().Length == 0)
                throw new ArgumentException("configPath can't be null");
            if (configFile.Trim().Length == 0)
                throw new ArgumentException("configFile can't be null");

            XmlSerializer uncSerializer = new XmlSerializer(typeof(UncConnectionStringBuilder));
            Directory.CreateDirectory(configPath);
            using (Stream uncStream = File.Create(Path.Combine(configPath, configFile)))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                XmlWriter writer = XmlTextWriter.Create(uncStream, settings);
                writer.WriteStartElement("Configuration");
                writer.WriteStartElement("Connections");
                uncSerializer.Serialize(writer, connection);
                writer.WriteEndElement();
                writer.WriteEndElement();

                writer.Close();
                uncStream.Close();
            }
        }
        /// <summary>
        /// Creates the unc connection.
        /// </summary>
        /// <param name="connectionName">Name of the connection.</param>
        /// <param name="connectionPath">The connection path.</param>
        /// <param name="configPath">The config path.</param>
        /// <param name="configFile">The config file.</param>
        /// <param name="isDefault">if set to <c>true</c> [is default].</param>
        /// <remarks>Documented by Dev08, 2009-03-02</remarks>
        public static void CreateUncConnection(string connectionName, string learningModulesPath, string configPath, string configFile, bool isDefault, bool isOnStick)
        {
            if (connectionName == null)
                throw new ArgumentNullException("connectionName can't be null");
            if (learningModulesPath == null)
                throw new ArgumentNullException("connectionPath can't be null. Connection Name: " + connectionName);
            if (connectionName.Trim().Length == 0)
                throw new ArgumentException("connectionName can't be null");
            if (learningModulesPath.Trim().Length == 0)
                throw new ArgumentException("connectionPath can't be null");

            UncConnectionStringBuilder uncConnection = new UncConnectionStringBuilder(learningModulesPath, isDefault, isOnStick);
            uncConnection.Name = connectionName;
            CreateUncConnection(uncConnection, configPath, configFile);
        }
        public void TestOfflineStorage()
        {
            string storageFile = Path.Combine(tempFolder, "storage.dat");
            IConnectionString con = new UncConnectionStringBuilder(tempFolder);
            SyncedModulesIndex.Clear();

            SyncedModulesIndex.Add(lm1.Connection, lm1);
            SyncedModulesIndex.Add(lm2.Connection, lm2);
            SyncedModulesIndex.Dump(storageFile);
            Assert.AreEqual<int>(2, SyncedModulesIndex.Get(con).Count);

            SyncedModulesIndex.Clear();
            Assert.AreEqual<int>(0, SyncedModulesIndex.Get(con).Count);

            SyncedModulesIndex.Restore(storageFile);
            Assert.AreEqual<int>(2, SyncedModulesIndex.Get(con).Count);
            Assert.AreEqual<string>(lm1.ConnectionString.ConnectionString, SyncedModulesIndex.Get(con)[0].ConnectionString.ConnectionString);
            Assert.AreEqual<string>(lm2.ConnectionString.ConnectionString, SyncedModulesIndex.Get(con)[1].ConnectionString.ConnectionString);
        }