Exemple #1
0
        public void Init(string tempPath, string testname, QTIVersion version)
        {
            var engine = new RazorLightEngineBuilder()
                         //.UseProject(new EmbeddedRazorProject(typeof(QtiPackageCreator)))
                         .UseEmbeddedResourcesProject(typeof(QtiPackageCreator))
                         .UseMemoryCachingProvider()
                         .Build();

            _choiceInterationCreator     = new ChoiceInteractionCreator(version, engine);
            _textEntryInteractionCreator = new TextEntryInteractionCreator(version, engine);
            _testCreator     = new TestCreator(version, engine);
            _manifestCreator = new ManifestCreator(version, engine);
            _testname        = testname;
            var dir = new DirectoryInfo(tempPath);

            if (!dir.Exists)
            {
                dir.Create();
            }
            var packagePath = Path.Combine(tempPath, Path.GetRandomFileName());
            var itemPath    = Path.Combine(packagePath, "items");
            var baseDir     = new DirectoryInfo(packagePath);
            var itemDir     = new DirectoryInfo(itemPath);

            if (!baseDir.Exists)
            {
                baseDir.Create();
            }
            if (!itemDir.Exists)
            {
                itemDir.Create();
            }
        }
        /// <summary>
        /// Gets the or create item.
        /// </summary>
        /// <param name="iCreateItem">The i create item.</param>
        /// <param name="itemCreated">if set to <c>true</c> [item created].</param>
        /// <returns></returns>
        /// <remarks>
        /// This is an updated version which has the complex dependencies removed
        /// So that it can be unit tested
        /// This method can/should be used directly, but for backwards compatability we still have the
        /// overloads which call this
        /// </remarks>
        public static ID GetOrCreateItem(ICreateItem iCreateItem, out bool itemCreated)
        {
            // Initialize itemCreated to be false.
            itemCreated = false;
            if (iCreateItem == null)
            {
                return((ID)null);
            }

            // call the algorithm to see if the child already exists
            ID itemId = iCreateItem.GetChild();

            // if we didn't find the item,
            // call the algorithm to create it
            if (itemId == (ID)null || ID.IsNullOrEmpty(itemId))
            {
                itemId      = iCreateItem.CreateChild();
                itemCreated = true;
            }
            return(itemId);
        }
        /// <summary>
        /// Gets the or create item.
        /// </summary>
        /// <param name="iCreateItem">The i create item.</param>
        /// <param name="itemCreated">if set to <c>true</c> [item created].</param>
        /// <returns></returns>
        /// <remarks>
        /// This is an updated version which has the complex dependencies removed
        /// So that it can be unit tested
        /// This method can/should be used directly, but for backwards compatability we still have the 
        /// overloads which call this
        /// </remarks>
        public static ID GetOrCreateItem(ICreateItem iCreateItem, out bool itemCreated)
        {
            // Initialize itemCreated to be false.
            itemCreated = false;
            if (iCreateItem == null) return (ID)null;

            // call the algorithm to see if the child already exists
            ID itemId = iCreateItem.GetChild();

            // if we didn't find the item,
            // call the algorithm to create it
            if (itemId == (ID)null || ID.IsNullOrEmpty(itemId))
            {
                itemId = iCreateItem.CreateChild();
                itemCreated = true;
            }
            return itemId;
        }