//zpracovani captured stranek (instrukce, stranky gramatiky a kurzu) //singlePage: pro instrukce, pouze jedna stranka, neni potreba tabulka dle stranek public static Dictionary<Langs, string> pageGroupEnd(NewEATradosCtx ctx, bool singlePage = false) { //vysledky lokalizace na konci zpracovani skupiny stranek if (singlePage && ctx.pages.Count != 1) throw new Exception(); //pages muze byt predvyplnen z jineho zdroje nez odpovidajici .RESX soubor foreach (var pg in ctx.pages) pg.loc = loadAllResx(pg); //pro kazdy jazyk stringy k lokalizaci Dictionary<string, Dictionary<string, string>> groupLoc = new Dictionary<string, Dictionary<string, string>>(); Dictionary<Langs, string> res = new Dictionary<Langs, string>(); foreach (Langs lng in AllLocs) { if (singlePage) res[lng] = JsonConvert.SerializeObject(ctx.pages[0].loc[lng], Newtonsoft.Json.Formatting.Indented); else { groupLoc.Clear(); foreach (var pg in ctx.pages) groupLoc.Add(pg.id, pg.loc[lng]); res[lng] = JsonConvert.SerializeObject(groupLoc, Newtonsoft.Json.Formatting.Indented); } } ctx.pages.Clear(); //actPage = null; return res; }
public static void run() { var ctx = new NewEATradosCtx(); MemoryStream str = new MemoryStream(); NewEATradosLib.pageGroupStart(ctx); NewEATradosLib.pageStart(ctx, CourseIds.no, "instructions", "framework/instructions/instructions.lmdata"); NewEATradosLib.doHack = () => true; NewEATradosLib.doHackEx = () => new ConfigNewEA() { courseId = CourseIds.English }; TradosLib.LocalizeXmlLow(@"q:\LMNet2\WebApps\EduAuthorNew\framework\instructions\Instructions.lmdata", Langs.en_gb, str, true); string instr = Encoding.UTF8.GetString(str.ToArray()); var body = XElement.Parse(instr); foreach (var nd in body.DescendantNodes().Where(n => n.NodeType == XmlNodeType.Comment).ToArray()) nd.Remove(); var instrs = JsonConvert.SerializeObject( body. Descendants(lm + "page_instruction"). Select(el => new { type = el.AttributeValue("type"), value = LowUtils.InnerXml(el).Replace(" xmlns=\"htmlPassivePage\"", null) }). ToDictionary(i => i.type.ToLowerInvariant(), i => i.value), Newtonsoft.Json.Formatting.Indented, EADeployLib.jsonSet); NewEATradosLib.doHack = null; var tradosRes = NewEATradosLib.pageGroupEnd(ctx, true); //JSON prelozenych retezcu tradosRes.Add(Langs.no, instrs); EADeployLib.writeFiles(Machines.basicPath + @"rew\Web4\Schools\EAData\", "instructions.json", tradosRes); //vypis zdroje i JSON prekladu }
//Lokalizovane stranky gramatiky, seskupene dle CourseId a LMLevel (= napr. 0,1,2,3,4 pro English) public static string run() { XElement root = XElement.Load(Machines.lmcomData + @"Statistic_Grammar.xml"); StringBuilder sb = new StringBuilder(); var ctx = new NewEATradosCtx(); var logFn = @"q:\temp\EANewDeployGrammar.log"; //******************* stranky gramatiky dle Course a druhe urovne grammar Sitemap (levels-grammar, levels-ku&b) using (var wr = new StreamWriter(logFn)) foreach (var crsRoot in root.Elements("folder")) { var crsId = LowUtils.EnumParse<CourseIds>(crsRoot.AttributeValue("id")); if (!ProductsDefine.Lib.allCourses.Contains(crsId)) continue; //if (crsId != CourseIds.EnglishE) continue; foreach (var lvRoots in crsRoot.Elements("folder").Select((el, idx) => new { el, idx }).GroupBy(ei => getGramLev(crsId, ei.idx))) { var levRoots = lvRoots.Select(i => i.el); //muze byt vice uzlu, napr. gramtika a Kub sb.Length = 0; //***************** Grammar pages generation //vsechny stranky var leafs = levRoots. //listy tree Descendants("folder"). Where(e => !e.Elements("folder").Any()). //podminka - pouze leafs Select(e => new { title = e.AttributeValue("title"), id = e.AttributeValue("spaceId") + "/" + e.AttributeValue("globalId"), node = e }). ToArray(); NewEATradosLib.pageGroupStart(ctx); //capture stranky s gramatikou foreach (var pg in leafs) { var pgInfo = NewEATradosLib.pageStart(ctx, crsId, pg.id, pg.id); //predvypln pgInfo o lokalizaci titulku var title = pg.node.AttributeValue("title"); if (title.StartsWith("{{")) pgInfo.loc = NewEATradosLib.AllLocs.ToDictionary( l => l, l => new Dictionary<string, string> { { title.Substring(2, title.Length - 4), pg.node.Element(l.ToString()).Value } } ); //capture stranky var cfg = new LMComLib.ConfigNewEA() { isGrammar = true, ExerciseUrl = pg.id.Replace(".htm", null), CourseLang = CommonLib.CourseIdToLang(crsId), Lang = crsId == CourseIds.EnglishE ? "en-gb" : "en-gb", courseId = crsId }; try { var page = LowUtils.DownloadStr(string.Format("http://www.langmaster.com/comcz/framework/deployment/EANew-DeployGenerator.aspx?NewEACfg={0}", HttpUtility.UrlEncode(LowUtils.JSONEncode(cfg)))); page = brNormalize.Replace(scriptOut.Replace(page, ""), "<br/>"); schools.exStatic meta = new exStatic() { title = pg.title, url = pg.id }; sb.Append(JsonConvert.SerializeObject(meta)); sb.Append("$$$"); sb.Append(page); sb.Append("$$$"); //sb.Append(pg.id); sb.Append("$$$"); sb.Append(pg.title); sb.Append("$$$"); sb.Append(page); sb.Append("$$$"); } catch (Exception exp) { wr.WriteLine(pg.id + ": " + exp.Message); } //break; } // **************** Output all //pro vsechny stranky (vlozene pomoci NewEATradosLib.pageStart) najdi vsechny jazykove .RESX a zjisti z nich lokalizaci. var tradosRes = NewEATradosLib.pageGroupEnd(ctx); //JSON prelozenych retezcu tradosRes[Langs.no] = sb.ToString(); //pridej source EADeployLib.writeFiles(Machines.basicPath + @"rew\Web4\Schools\EAGrammar\", fileName(crsId, lvRoots.Key) + ".json", tradosRes); //vypis zdroje i JSON prekladu } //break; } return File.ReadAllText(logFn); }
public static string run(IEnumerable<ProductsDefine.modInfo> mods, bool newFormatOnly = false) { //var logFn = @"q:\temp\EANewDeploy.log"; using (var wr = new StringWriter()) { Parallel.ForEach(mods, new ParallelOptions() { MaxDegreeOfParallelism = 6 }, mod => { StringBuilder sb = new StringBuilder(); //using (StringWriter wr = new StringWriter(err)) { var ctx = new NewEATradosCtx(); string lastExId = null; try { sb.Length = 0; NewEATradosLib.pageGroupStart(ctx); foreach (var ex in mod.exs) { lastExId = ex.Id; StringBuilder err = new StringBuilder(); schools.exStatic meta = new exStatic() { title = ex.Title }; try { string res; if (ex.NewDataFormat) { meta.url = ex.Id; meta.format = ExFormat.rew; res = CourseModel.Lib.Json(err, Machines.basicPath + @"rew\Web4\RwCourses\" + meta.url.Replace('/', '\\') + ".xml"); } else if (!newFormatOnly) { meta.url = ex.Id.Split('/').Last(); meta.format = ExFormat.ea; NewEATradosLib.pageStart(ctx, mod.crsId, meta.url, ex.Id + ".htm"); var cfg = new LMComLib.ConfigNewEA() { ExerciseUrl = ex.Id, CourseLang = urlToSrcLang(ex.Id), Lang = mod.crsId == CourseIds.EnglishE ? "en-gb" : "en-gb", courseId = mod.crsId }; res = LowUtils.DownloadStr(string.Format("http://www.langmaster.com/comcz/framework/deployment/EANew-DeployGenerator.aspx?NewEACfg={0}", HttpUtility.UrlEncode(LowUtils.JSONEncode(cfg)))); } else continue; sb.Append(JsonConvert.SerializeObject(meta)); sb.Append("$$$"); sb.Append(res); sb.Append("$$$"); } finally { if (err.Length > 0) lock (typeof(Exercise)) { wr.WriteLine(">>>> " + ex.Id); wr.WriteLine(err.ToString()); } } } if (!newFormatOnly || sb.Length > 0) { var tradosRes = NewEATradosLib.pageGroupEnd(ctx); //JSON prelozenych retezcu tradosRes[Langs.no] = sb.ToString(); //fake - pridej zdroj EADeployLib.writeFiles(Machines.basicPath + @"rew\Web4\Schools\EAData\", mod.jsonId + ".json", tradosRes); //vypis zdroje i JSON prekladu } } catch (Exception exp) { lock (typeof(Exercise)) { wr.WriteLine("******* ERROR: " + mod.path + "/" + lastExId + ": " + exp.Message); } } }); return wr.ToString(); } }
public static pageInfo pageStart(NewEATradosCtx ctx, CourseIds crsId, string pageId, string eaPath) { //notifikace o zacatku zpracovani pageId-stranky (obsazen v fileName) // english1/grammar/sec01/G01.htm => q:\LMNet2\WebApps\EduAuthorNew\english1\grammar\sec01\App_LocalResources\g01.htm var res = new pageInfo() { id = pageId, EAPath = eaPath, courseId = crsId }; ctx.pages.Add(res);//, fileName = @"q:\LMNet2\WebApps\EduAuthorNew\" + pageId }); return res; }
//**************** Volano v q:\LMNet2\WebApps\EduAuthorNew\framework\deployment\EANew-Deploy.aspx public static void pageGroupStart(NewEATradosCtx ctx) { //notifikace o zacatku zpracovani skupiny stranek ctx.pages.Clear(); //actPage = null; }