Esempio n. 1
0
        public void PatchVerticals(EdxCourse course, IEnumerable <Vertical[]> verticals, bool replaceExisting = true)
        {
            var newVerticals = new List <Vertical>();

            foreach (var subverticals in verticals)
            {
                var existsMap = subverticals.ToDictionary(sv => sv, sv => File.Exists($"{OlxPath}/vertical/{sv.UrlName}.xml"));
                if (subverticals.Any(x => existsMap[x]))
                {
                    if (replaceExisting)
                    {
                        foreach (var subvertical in subverticals)
                        {
                            subvertical.Save(OlxPath);
                        }

                        if (subverticals.Length > 1)
                        {
                            SaveSequentialContainingSubverticals(
                                course,
                                subverticals.Where(x => !existsMap[x]).ToArray(),
                                subverticals.First(x => existsMap[x])
                                );
                        }
                    }
                }
                else
                {
                    newVerticals.AddRange(subverticals);
                }
            }

            Add(course, newVerticals.ToArray());
        }
Esempio n. 2
0
 public void Add(EdxCourse course, Vertical[] verticals)
 {
     if (verticals.Length != 0)
     {
         course.CreateUnsortedChapter(OlxPath, verticals);
     }
 }
Esempio n. 3
0
        public void PatchComponents(EdxCourse course, IEnumerable <Component> components, bool replaceExisting = true)
        {
            var newVerticals = new List <Vertical>();

            foreach (var component in components)
            {
                var filename = string.Format("{0}/{1}/{2}.xml", OlxPath, component.SubfolderName, component.UrlName);
                if (File.Exists(filename))
                {
                    if (replaceExisting)
                    {
                        string displayName;
                        try
                        {
                            var xml = new XmlDocument();
                            xml.Load(filename);
                            displayName = xml.DocumentElement.Attributes["display_name"].InnerText;
                        }
                        catch (Exception)
                        {
                            displayName = component.DisplayName;
                        }

                        component.DisplayName = displayName;
                        component.Save(OlxPath);
                    }
                }
                else
                {
                    newVerticals.Add(new Vertical(Utils.NewNormalizedGuid(), component.DisplayName, new[] { component }));
                }
            }

            Add(course, newVerticals.ToArray());
        }
Esempio n. 4
0
        private void SaveSequentialContainingSubverticals(EdxCourse course, IEnumerable <Vertical> verticalsToAdd, Vertical afterThisVertical)
        {
            var sequential    = course.GetSequentialContainingVertical(afterThisVertical.UrlName);
            var filename      = string.Format("{0}/sequential/{1}.xml", OlxPath, sequential.UrlName);
            var sequentialXml = XDocument.Load(filename).Root ?? new XElement("sequential");
            var refs          = sequentialXml.Elements("vertical").ToList();
            var insertIndex   = refs
                                .Select((v, i) => new { urlName = v.Attribute("url_name").Value, i })
                                .First(v => v.urlName == afterThisVertical.UrlName).i + 1;

            refs.InsertRange(insertIndex, verticalsToAdd.Select(v => new XElement("vertical", new XAttribute("url_name", v.UrlName))));
            sequentialXml.ReplaceNodes(refs);
            sequentialXml.Save(filename);
            new FileInfo(filename).RemoveXmlDeclaration();
        }