//sitemap kurzu s lokalizaci. Pro headerOnly => pouze jeden root node (pro pouziti v seznau produktu v q:\LMCom\rew\Web4\Schools\EACourses\courses.json ) public static root courseSitemapWithLoc(ProductsDefine.productDescrLow prod, bool headerOnly) { ProductsDefine.courseDescr cfg = null; Func<ProductsDefine.courseDescr, ProductsDefine.courseDescr> fake = c => { cfg = c; return c; }; // ROOT node var res = new root() { courseId = prod.courseId, line = CommonLib.CourseIdToLineId(prod.course), title = prod.title, fileName = prod.productId(), }; if (prod.hasPretest()) res.pretestCrsId = prod.course; //Add course tree and grammar (including localization) to sitemap if (!headerOnly) { res.courses = createCourses(prod).ToArray(); //sitemap tree //grammar s lokalizaci schools.grammarNode gram; var trados = Grammar.getGrammar(prod, out gram); //Pouziti grammar v course sitemap res.grammar = gram; trados.Add(Langs.no, JsonConvert.SerializeObject(res, Newtonsoft.Json.Formatting.Indented, EADeployLib.jsonSet)); //write EADeployLib.writeFiles(Machines.basicPath + @"rew\Web4\Schools\EACourses\", res.fileName + ".json", trados, true); //vypis zdroje i JSON prekladu XmlUtils.ObjectToFile(Machines.basicPath + @"rew\Web4\Schools\EACourses\" + res.fileName + ".xml", res); //pro info jeste do XML } return res; }
static IEnumerable<course> createCourses(ProductsDefine.productDescrLow prod, List<string> modules = null, List<string> lessons = null) { var cnt = 0; foreach (var pd in prod.productParts()) { yield return new course() { lessons = createLessons(pd.getLessons()), jsonId = (cnt++).ToString(), title = pd.title, level = pd.partLevelName(), testFileName = pd.testFileName(), //LMLevel = pd.partIdx / 2, }; } }
//Sitemap gramatiky s lokalizaci //Pouzito v Products.export (= generace sitemap pro kurz) public static Dictionary<Langs, string> getGrammar(ProductsDefine.productDescrLow prod, out schools.grammarNode gramm) { int[] gramLevs = prod.grammarLevels().ToArray(); gramm = null; if (gramLevs.Length == 0) return prod.locs().ToDictionary(l => l, l => "{}"); CourseIds crsId = prod.course; XElement root = XElement.Load(Machines.lmcomData + @"Statistic_Grammar.xml"); var crsNode = root.Elements("folder").FirstOrDefault(nd => LowUtils.EnumParse<CourseIds>(nd.AttributeValue("id")) == crsId); if (crsNode == null) return prod.locs().ToDictionary(l => l, l => "{}"); //******************* grammar sitemap for crsId a lmLevels int gramLev = -1; gramm = new schools.grammarNode() { title = crsNode.AttributeValue("title"), courseId = crsId, items = crsNode.Elements("folder"). Where((e, idx) => gramLevs.Contains(gramLev = getGramLev(crsId, idx))). Select(e => new schools.grammarNode() { title = e.AttributeValue("title"), jsonId = fileName(crsId, gramLev), //napr. english_0 LMLevel = gramLev, items = grItems(e.Elements("folder")).ToArray() }).ToArray() }; if (gramm != null && gramm.items.Length == 1) { gramm = (schools.grammarNode)gramm.items[0]; gramm.courseId = crsId; } //******************* sitemap localization for crsId a lmLevels var rootToLoc = new XElement("folder", new XAttribute("title", crsNode.AttributeValue("title")), crsNode.Elements().Where(el => el.Name.LocalName != "folder")); var s1 = new XElement[] { crsNode }; var s2 = crsNode.Elements("folder").Where((e, idx) => gramLevs.Contains(getGramLev(crsId, idx))); var s3 = s2.SelectMany(n => n.Descendants("folder")); var siteLocs = prod.locs(). Select(l => new { lang = l, locs = JsonConvert.SerializeObject( s1.Concat(s2).Concat(s3). Select(n => n.Elements(l.ToString()).SingleOrDefault()). Where(n => n != null). Select(n => new { id = n.Parent.AttributeValue("title"), title = n.Value }). Where(it => it.id.StartsWith("{{")). ToArray(). ToDictionary(it => it.id.Substring(2, it.id.Length - 4), it => it.title), Newtonsoft.Json.Formatting.Indented, EADeployLib.jsonSet ) }). ToDictionary(l => l.lang, l => l.locs); return siteLocs; }