Пример #1
0
 public Importer(Manifest manifest, Course course, ICourseStorage courseStorage)
 {
     _Manifest = manifest;
     _Course = course;
     _CourseStorage = courseStorage;
     _CoursePath = _CourseStorage.GetCoursePath(_Course.Id);
     _CourseTempPath = _CourseStorage.GetCourseTempPath(_Course.Id);
 }
Пример #2
0
 public Importer(Manifest manifest, Course course, ICourseStorage courseStorage)
 {
     this.manifest = manifest;
     this.course = course;
     this.courseStorage = courseStorage;
     this.coursePath = this.courseStorage.GetCoursePath(this.course.Id);
     this.courseTempPath = this.courseStorage.GetCourseTempPath(this.course.Id);
 }
Пример #3
0
        public static void Serialize(Manifest manifest, StreamWriter writer)
        {
            var xs = new XmlSerializer(typeof(Manifest));

            var xsn = new XmlSerializerNamespaces();
            xsn.Add(SCORM.Adlcp, SCORM.AdlcpNamespaceV1P3);
            xsn.Add(SCORM.Imsss, SCORM.ImsssNamespace);
            xsn.Add(SCORM.Adlseq, SCORM.AdlseqNamespace);
            xsn.Add(SCORM.Adlnav, SCORM.AdlnavNamespace);
            xsn.Add(SCORM.Imsss, SCORM.ImsssNamespace);

            xs.Serialize(writer, manifest, xsn);
        }
Пример #4
0
        public void MetadataTest()
        {
            var manifest = new Manifest();

            manifest.Metadata = new ManifestMetadata
                {
                   Metadata = new Metadata(), Schema = "schema", SchemaVersion = "v1.0" 
                };
            manifest.Base = "base";
            manifest.Organizations.AddOrganization(new Organization());
            manifest.Organizations.Default = "1";
            manifest.Resources.ResourcesList.Add(new Resource());
            manifest.Version = "1.0";

            var path = Path.Combine(this.root, "manifest.xml");
            manifest.Serialize(new StreamWriter(path));
            Assert.IsTrue(File.Exists(path));
        }
Пример #5
0
        public void Organizationtest()
        {
            var organization = new Organization();

            var completionThreshhold = new CompletionThreshold
                {
                   CompletedByMeasure = true, MinProgressMeasure = 0, ProgressWeight = 1 
                };
            organization.CompletionThreshold = completionThreshhold;
            organization.Identifier = "id";
            organization.Items.Add(
                new Item("res id")
                    {
                        CompletionThreshold = completionThreshhold, 
                        Data =
                            new List<Map>(
                            new[] { new Map { ReadSharedData = false, TargetID = "target id", WriteSharedData = false } })
                    });
            organization.Items = new List<Item>();
            organization.Items.Add(new Item("123"));
            organization.Items.Add(new Item());
            organization.Metadata = new Metadata();
            organization.ObjectivesGlobalToSystem = organization.Items[1].IsParent;
            organization.Sequencing = new Sequencing();
            organization.SharedDataGlobalToSystem = true;
            organization.Structure = "structure";
            organization.Title = "title";

            var manifest = new Manifest();
            manifest.Organizations.AddOrganization(organization);
            manifest.Organizations.Default = "def";

            var path = Path.Combine(this.root, "organization.xml");
            manifest.Serialize(new StreamWriter(path));
            Assert.IsTrue(File.Exists(path));
        }
Пример #6
0
        private Item AddSubItems(Item parentItem, Node parentNode, int courseId, ManifestManager helper, ref Manifest manifest)
        {
            var nodes = parentNode == null ? GetNodes(courseId) : GetNodes(courseId, parentNode.Id);
            
            foreach (var node in nodes)
            {
                if (node.IsFolder)
                {
                    var item = helper.CreateItem();
                    item.Title = node.Name;

                    if (node.Sequencing != null)
                    {
                        var xml = new XmlSerializer(typeof (Sequencing));
                        item.Sequencing = (Sequencing) xml.DeserializeXElement(node.Sequencing);
                    }

                    item = AddSubItems(item, node, courseId, helper, ref manifest);

                    parentItem = ManifestManager.AddItem(parentItem, item);
                }
                else
                {
                    var files = new List<ManifestModels.ResourceModels.File>();
                    files.Add(new ManifestModels.ResourceModels.File(node.Id + ".html"));

                    var resource = helper.CreateResource(ScormType.SCO, files, new[] { _ResourceIdForTemplateFiles });
                    resource.Href = node.Id + ".html";

                    manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource);
                 
                    var item = helper.CreateItem(resource.Identifier);
                    item.Title = node.Name;

                    if (node.Sequencing != null)
                    {
                        var xml = new XmlSerializer(typeof(Sequencing));
                        item.Sequencing = (Sequencing)xml.DeserializeXElement(node.Sequencing);
                    }

                    parentItem = ManifestManager.AddItem(parentItem, item);
                }
            }
            return parentItem;
        }
Пример #7
0
        public string Export(int id)
        {
            var course = GetCourse(id);

            var path = GetCoursePath(id);

            if (course.Locked != null && course.Locked.Value)
            {
                return path + ".zip";
            }

            path = Path.Combine(path, Guid.NewGuid().ToString());
            path = Path.Combine(path, course.Name);

            Directory.CreateDirectory(path);


            var nodes = GetNodes(id).ToList();

            for (var i = 0; i < nodes.Count; i++)
            {
                if (nodes[i].IsFolder == false)
                {
                    File.Copy(GetNodePath(nodes[i].Id) + ".html", Path.Combine(path, nodes[i].Id + ".html"));
                }
                else
                {
                    var subNodes = GetNodes(id, nodes[i].Id);
                    nodes.AddRange(subNodes);
                }
            }

            var coursePath = GetCoursePath(id);

            FileHelper.DirectoryCopy(Path.Combine(coursePath, "Node"), Path.Combine(path, "Node"));

            foreach (var file in _TemplateFiles)
            {
                File.Copy(Path.Combine(coursePath, file), Path.Combine(path, file));
            }

            var helper = new ManifestManager();

            var manifest = new Manifest();
            var sw = new StreamWriter(Path.Combine(path, SCORM.ImsManifset));
            var parentItem = new Item();

            parentItem = AddSubItems(parentItem, null, id, helper, ref manifest);
            manifest.Organizations = ManifestManager.AddOrganization(manifest.Organizations, helper.CreateOrganization());
            manifest.Organizations.Default = manifest.Organizations[0].Identifier;
            manifest.Organizations[0].Items = parentItem.Items;
            manifest.Organizations[0].Title = course.Name;

            if (course.Sequencing != null)
            {
                var xml = new XmlSerializer(typeof(Sequencing));
                manifest.Organizations[0].Sequencing = (Sequencing)xml.DeserializeXElement(course.Sequencing);
            }
            var resource = new Resource
                               {
                                   Identifier = _ResourceIdForTemplateFiles,
                                   Files = _TemplateFiles.Select(file => new ManifestModels.ResourceModels.File(file)).ToList(),
                                   ScormType = ScormType.Asset
                               };

            manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource);

            ManifestManager.Serialize(manifest, sw);
            sw.Close();

            Zipper.CreateZip(path + ".zip", path);

            return path + ".zip";
        }
Пример #8
0
        public virtual string Export(int id, bool exportForPlayCourse = false)
        {

            var course = this.GetCourse(id);

            var path = this.GetCoursePath(id);

            if (course.Locked != null && course.Locked.Value)
            {
                return path + ".zip";
            }

            path = Path.Combine(path, Guid.NewGuid().ToString());
            path = Path.Combine(path, course.Name);

            Directory.CreateDirectory(path);

            var nodes = this.GetNodes(id).ToList();

            for (var i = 0; i < nodes.Count; i++)
            {
                if (nodes[i].IsFolder == false)
                {
                    File.Copy(this.GetNodePath(nodes[i].Id) + ".html", Path.Combine(path, nodes[i].Id + ".html"));
                }
                else
                {
                    var subNodes = GetNodes(id, nodes[i].Id);
                    nodes.AddRange(subNodes);
                }
            }

            var coursePath = this.GetCoursePath(id);

            FileHelper.DirectoryCopy(Path.Combine(coursePath, "Node"), Path.Combine(path, "Node"));

            foreach (var file in this.templateFiles)
            {
               try
               {
                  File.Copy(Path.Combine(coursePath, file), Path.Combine(path, file), true);
               }
               catch (FileNotFoundException)
               {
                  continue;
               }
               
            }

            var helper = new ManifestManager();

            var manifest = new Manifest();
            var sw = new StreamWriter(Path.Combine(path, SCORM.ImsManifset));
            var parentItem = new Item();

            parentItem = this.AddSubItems(parentItem, null, id, helper, ref manifest);
            manifest.Organizations = ManifestManager.AddOrganization(manifest.Organizations, helper.CreateOrganization());
            manifest.Organizations.Default = manifest.Organizations[0].Identifier;
            manifest.Organizations[0].Items = parentItem.Items;
            manifest.Organizations[0].Title = course.Name;

            if (course.Sequencing != null)
            {
                var xml = new XmlSerializer(typeof(Sequencing));
                manifest.Organizations[0].Sequencing = (Sequencing)xml.DeserializeXElement(course.Sequencing);
            }
            var resource = new Resource
            {
                Identifier = ResourceIdForTemplateFiles,
                Files = this.templateFiles.Select(file => new ManifestModels.ResourceModels.File(file)).ToList(),
                ScormType = ScormType.Asset
            };

            manifest.Resources = ManifestManager.AddResource(manifest.Resources, resource);

            ManifestManager.Serialize(manifest, sw);
            sw.Close();

            Zipper.CreateZip(path + ".zip", path);

            if (exportForPlayCourse)
            {
                try
                {
                    IudicoCourseInfo ci = CourseParser.Parse(course, this);
                    this.AddCourseInfo(ci);
                }
                catch (Exception ex)
                {
                    log.Error(string.Format("Exception message: {0}\nData: {1}\nHelp Link: {2}\nInner exception: {3}\nSource: {4}\nStack trace: {5}\nTarget site: {6}", ex.Message, ex.Data, ex.HelpLink, ex.InnerException, ex.Source, ex.StackTrace, ex.TargetSite));
                }
            }

            return path + ".zip";
        }
Пример #9
0
 public Item AddSubItemsTest(Item parentItem, Node parentNode, int courseId, ManifestManager helper, ref Manifest manifest)
 {
     return AddSubItems(parentItem,parentNode,courseId, helper, ref manifest);
 }
Пример #10
0
        public void ResourceTest()
        {
            var resource = new Resource();
            resource.Base = "base";
            resource.Dependencies.Add(new Dependency("ref"));
            resource.Files.Add(
                new IUDICO.CourseManagement.Models.ManifestModels.ResourceModels.File("href")
                    {
                       Metadata = new Metadata() 
                    });
            resource.Href = "href";
            resource.Metadata = new Metadata();
            resource.ScormType = ScormType.SCO;
            resource.Type = "web";

            var manifest = new Manifest();
            manifest.Resources.ResourcesList.Add(resource);

            var path = Path.Combine(this.root, "resource.xml");
            manifest.Serialize(new StreamWriter(path));
            Assert.IsTrue(File.Exists(path));
        }
Пример #11
0
        public void SequencingTest()
        {
            var sequencing = new Sequencing();
            sequencing.AdlObjectives = new AdlObjectives();
            sequencing.AdlObjectives.Objectives = new List<AdlObjective>();
            sequencing.AuxiliaryResources = "res";
            sequencing.ConstrainedChoiceConsiderations = new ConstrainedChoiceConsiderations
                {
                   ConstrainChoice = true, CourseId = 1, NodeId = 2, PreventActivation = false, Type = "type" 
                };
            sequencing.ControlMode = new ControlMode
                {
                    Choice = true, 
                    ChoiceExit = false, 
                    CourseId = 1, 
                    Flow = false, 
                    ForwardOnly = false, 
                    NodeId = 2, 
                    Type = "type", 
                    UseCurrentAttemptObjectiveInfo = false, 
                    UseCurrentAttemptProgressInfo = true
                };
            sequencing.DeliveryControls = new DeliveryControls
                {
                    CompletionSetByContent = true, 
                    CourseId = 1, 
                    NodeId = 2, 
                    ObjectiveSetByContent = false, 
                    Tracked = false, 
                    Type = "type"
                };
            sequencing.Id = "id";
            sequencing.IdRef = "ref";
            sequencing.LimitConditions = new LimitConditions
                {
                   AttemptAbsoluteDurationLimit = "1", AttemptLimit = 0, CourseId = 1, NodeId = 2, Type = "type" 
                };

            sequencing.Objectives = new Objectives();
            sequencing.RandomizationControls = new RandomizationControls
                {
                    CourseId = 1, 
                    NodeId = 2, 
                    RandomizationTiming = Timing.Once, 
                    ReorderChildren = true, 
                    SelectCount = 1, 
                    SelectionTiming = Timing.Never
                };
            sequencing.RollupConsiderations = new RollupConsiderations
                {
                    CourseId = 1, 
                    NodeId = 2, 
                    MeasureSatisfactionIfActive = false, 
                    RequiredForCompleted = Required.IfNotSkipped, 
                    RequiredForIncomplete = Required.IfNotSuspended, 
                    RequiredForNotSatisfied = Required.Always, 
                    RequiredForSatisfied = Required.IfAttempted, 
                    Type = "type", 
                };
            sequencing.RollupRules = new RollupRules
                {
                    CourseId = 1, 
                    NodeId = 2, 
                    ObjectiveMeasureWeight = 1, 
                    RollupObjectiveSatisfied = false, 
                    RollupProgressCompletion = true, 
                    RollupRulesList = new List<RollupRule>()
                };
            sequencing.SequencingRules = new SequencingRules
                {
                    ExitConditionRule =
                        new Rule
                            {
                                RuleAction = new RuleAction { Action = Action.Previous }, 
                                RuleConditions =
                                    new RuleConditions
                                        {
                                            ConditionCombination = ConditionCombination.All, 
                                            RuleConditionsList = new List<RuleCondition>()
                                        }
                            }
                };
            var rule = new RollupRule
                {
                    ChildActivitySet = ChildActivitySet.All, 
                    CourseId = 1, 
                    NodeId = 2, 
                    Type = "type", 
                    MinimumCount = 1, 
                    MinimumPercent = 1, 
                    RollupAction = new RollupAction { Action = RollupActions.Completed }
                };
            var con = new RollupConsiderations
                {
                    CourseId = 1, 
                    NodeId = 2, 
                    MeasureSatisfactionIfActive = false, 
                    RequiredForCompleted = Required.Always, 
                    RequiredForIncomplete = Required.IfNotSkipped, 
                    RequiredForNotSatisfied = Required.IfNotSkipped, 
                    RequiredForSatisfied = Required.IfAttempted, 
                    Type = "type"
                };
            sequencing.RollupConsiderations = con;
            sequencing.RollupRules = new RollupRules
                {
                    CourseId = 1, 
                    NodeId = 2, 
                    ObjectiveMeasureWeight = 1, 
                    RollupObjectiveSatisfied = false, 
                    RollupProgressCompletion = true, 
                    RollupRulesList = new List<RollupRule>()
                };

            sequencing.RollupRules.RollupRulesList.Add(rule);

            var manifest = new Manifest();
            manifest.SequencingCollection = new SequencingCollection();
            manifest.SequencingCollection.Sequencings = new List<Sequencing>();
            manifest.SequencingCollection.Sequencings.Add(sequencing);

            var path = Path.Combine(this.root, "sequencing.xml");
            manifest.Serialize(new StreamWriter(path));
            Assert.IsTrue(File.Exists(path));
        }