public static void writeFile(string dir, string fn, Langs Key, string Value, bool incRJson = false) { string destFn = dir + (Key == Langs.no ? null : Key.ToString().Replace('_', '-') + "\\") + fn; LowUtils.AdjustFileDir(destFn); File.WriteAllText(destFn, Value); string value = Value; if (incRJson) { destFn = destFn.Replace(".json", ".rjson"); value = Noesis.Lib.JSON2RJSON(Value); File.WriteAllText(destFn, value); } using (Stream msOut = File.OpenWrite(destFn + ".gzip")) { using (GZipStream gzip = new GZipStream(msOut, CompressionMode.Compress)) using (StreamWriter wrg = new StreamWriter(gzip)) wrg.Write(value); } }
static void Main(string[] args) { Random rand = new Random(); int[,,] numTimesRun = new int[3, 2, 3]; System.Console.WriteLine("algo\tprog\tlang\tresult"); while (!Finished(numTimesRun, numIterations)) { int algoNum; int progNum; int langNum; // Generate values randomly, ignoring them if they've already been done do { algoNum = rand.Next(0, 3); progNum = rand.Next(0, 2); langNum = rand.Next(0, 3); } while (ComboDone(numTimesRun, numIterations, algoNum, progNum, langNum)); numTimesRun[algoNum, progNum, langNum]++; sortAlgos algo = (sortAlgos)algoNum; Programmers prog = (Programmers)progNum; Langs lang = (Langs)langNum; long result = RunSort(prog, lang, algo, inputPath); System.Console.Write(algo.ToString() + "\t"); System.Console.Write(prog.ToString() + "\t"); System.Console.Write(lang.ToString() + "\t"); System.Console.WriteLine(result); } System.Console.ReadKey(); System.Console.ReadKey(); System.Console.ReadKey(); }
public IActionResult Index(string searchString, string own) { RepoViewModel repos = new RepoViewModel(); if (string.IsNullOrEmpty(searchString)) { Array values = Enum.GetValues(typeof(Langs)); Random random = new Random(); Langs randomLang = (Langs)values.GetValue(random.Next(values.Length)); searchString = randomLang.ToString(); } if (!string.IsNullOrEmpty(own)) { repos = PrepareModelOwn(searchString); return(View(repos)); } try { HttpResponseMessage response = _repoService.GetByDescription(searchString).Result; if (response.IsSuccessStatusCode) { repos = response.Content.ReadAsAsync <RepoViewModel>().Result; } else { RedirectToAction("Error"); } } catch (Exception ex) { TempData["Message"] = ex.InnerException.Message; } return(View(repos)); }
public static GeneratePdfItem[] CreateCert(testResultHelper test, Langs lng) { var ci = new CultureInfo(lng.ToString().Replace('_', '-')); return XExtension.Create<GeneratePdfItem>( new GeneratePdfItem() { Name = "name", Value = string.Format("{0} {1}", test.firstName, test.lastName), IsBold = true, FontSize = 18 }, new GeneratePdfItem() { Name = "level", Value = test.score.ToString(), IsBold = true, FontSize = 18 }, new GeneratePdfItem() { Name = "level2", Value = string.Format("{0} ({1}%)", test.title, test.score), IsBold = false, FontSize = 11 }, new GeneratePdfItem() { Name = "leveldetail", Value = test.title, IsBold = true, FontSize = 18 }, new GeneratePdfItem() { Name = "start", Value = LowUtils.formatDate(test.started(), ci), IsBold = false, FontSize = 9 }, new GeneratePdfItem() { Name = "endshort", Value = test.dateTxt(ci), IsBold = false, FontSize = 11 }, new GeneratePdfItem() { Name = "end", Value = LowUtils.formatDate(test.finished(), ci), IsBold = false, FontSize = 9 }, new GeneratePdfItem() { Name = "time", Value = test.elapsedTxt(), IsBold = false, FontSize = 9 }, new GeneratePdfItem() { Name = "domain", Value = test.domain, IsBold = false, FontSize = 9 }, new GeneratePdfItem() { Name = "id", Value = test.domain + "|" + test.id.ToString(), IsBold = false, FontSize = 9 }, new GeneratePdfItem() { Name = "email", Value = test.eMail, IsBold = false, FontSize = 9 }, new GeneratePdfItem() { Name = "invitator", Value = test.company, IsBold = false, FontSize = 9 } ).Concat(test.skills.SelectMany(m => moduleCert(m, ci))).ToArray(); }
public static void setCulture(Langs lang) { setCulture(lang.ToString()); }
public static string lang2string(Langs lang) { return(lang.ToString().Replace('_', '-')); }
/// <summary> /// Pro grupu vrati zdrojovy jazyk k jazyku prekladu. Chyba je-li transLang=TransLang /// </summary> public Langs FindSrcLang(Langs transLang) { if (transLang == PrimaryLang) throw new Exception("Špatně vybarný jazyk: jazyk zdroje je roven jazyku překladu"); LocCfgTransDef res = null; if (TransDef != null) res = TransDef.Where(d => d.Trans == transLang).FirstOrDefault(); if (res != null) return res.Src; res = LocCfg.Instance().TransDef.Where(d => d.Trans == transLang).FirstOrDefault(); if (res != null) return res.Src; throw new Exception("Missing TransDef item in LocCfg for lang: " + transLang.ToString()); }
public static void tradosOper2_forLang(LocPageGroup grp, Langs transLang, bool isAutoTrans) { LocCfgPageGroupFilter group = LocCfg.Instance().findPageGroup(grp); Langs srcLang = group.FindSrcLang(transLang); foreach (int pageId in TradosDT.TradosDB.getTradosContext().Pages. Where(p => p.PageGroup == (short)grp && (p.Langs == null || p.Langs.Contains(transLang.ToString()))). Select(p => p.Id)) { TradosDT.TradosDB db = TradosDT.TradosDB.getTradosContext(); if (Machines.sb != null) Machines.sb.Length = 0; //Name vsech zdrojovych vet var srcIds = db.Sentences.Where(s => s.PageId == pageId && s.TransLang == (short)srcLang).Select(s => s.Name).ToArray(); //Vsechny doposud pripravene vety var oldSents = db.Sentences.Where(s2 => s2.PageId == pageId && s2.TransLang == (short)transLang).ToArray(); //Vymaz nepotrebne vety (neboli prelozene vety, ktere nejsou ve zdroji) db.Sentences.RemoveRange(oldSents.Where(s => !srcIds.Contains(s.Name))); //Vsechny zdroje a lookup preklady var autoTrans = db.Sentences. Where(s => s.PageId == pageId && s.TransLang == (short)srcLang && s.TransText != null). Select(s => new { name = s.Name, srcText = s.TransText, transTexts = db.Lookups.Where(l => l.SrcLang == (short)srcLang && l.TransLang == (short)transLang && l.SrcHash == s.TransHash && l.SrcText == s.TransText). Select(l => l.TransText).ToArray() }). ToArray(); //Vytvoreni novych nebo uprava starych vet foreach (string name in srcIds) { //pro vsechny potrebne vety TradosDT.Sentence sent; //if (name == "l09/a/hufex1_l09_a03/Ttrans5") // sent = null; try { sent = oldSents.Where(s => s.Name == name).SingleOrDefault(); //stara veta } catch (Exception exp) { throw new Exception(string.Format("oldSents.SingleOrDefault: name={0}, grp={1}, lang={2}", name, grp, transLang), exp); } try { var item = autoTrans.Where(at => at.name == name).SingleOrDefault(); //novy zdroj a ev. preklad z lookupu if (sent == null) { //zalozeni nove vety if (isAutoTrans && item != null && item.transTexts.Count() == 1) //existuje prave jeden lookup, dopln novy zdroj a preklad (veta DONE) TradosDT.Sentence.insert(db, pageId, name, item.srcText, (Langs)srcLang, item.transTexts.Single(), transLang); else //ne, nova veta je prezdna (TRANS) TradosDT.Sentence.insert(db, pageId, name, null, (Langs)srcLang, null, transLang); } else { //veta existuje if (isAutoTrans && item != null && item.transTexts.Count() == 1) { //existuje prave jeden lookup sent.SrcText = item.srcText; sent.TransText = item.transTexts.Single(); //aktualizuj vetu (veta DONE) sent.finish(); } } } catch (Exception exp) { throw new Exception(string.Format("autoTrans.SingleOrDefault: name={0}, grp={1}, lang={2}", name, grp, transLang), exp); } } db.SaveChanges(); } }
public static int LangToLCID(Langs l) { if (l == Langs.sp_sp) l = Langs.es_es; var cult = CultureInfo.GetCultureInfo(l.ToString().Replace('_', '-')); return cult.TextInfo.LCID; }
static string rewFileName(Langs lng, string fn) { return string.Format(Machines.basicPath + @"rew\Web4\RwBooks\Runtime\{0}\{1}", lng.ToString().Replace('_', '-'), fn); }
//K napr. sr_latn_cs_en_gb vrati Langs public static void ExtractLangs(string code, out Langs crsLang, out Langs natLang) { natLang = LowUtils.EnumGetValues<Langs>().First(l => code.StartsWith(l.ToString())); code = code.Substring(natLang.ToString().Length + 1); crsLang = LowUtils.EnumParse<Langs>(code); }
public LingeaDictFile(XElement root, Langs cl = Langs.no, Langs nl = Langs.no) { this.root = root; crsLang = LowUtils.EnumParse<Langs>(root.AttributeValue("crsLang", cl.ToString())); nativeLang = LowUtils.EnumParse<Langs>(root.AttributeValue("nativeLang", nl.ToString())); var subroot = root.Element("entries"); if (subroot != null) entryIdToEntry = subroot.Elements().ToDictionary(el => el.AttributeValue("id"), el => el); else entryIdToEntry = new Dictionary<string, XElement>(); subroot = root.Element("courseUses"); }
public static string fileName(Langs nat, Langs crs) { return Machines.rootPath + @"RwDicts\Sources\LingeaOld\lingea_" + nat.ToString() + "_" + crs.ToString() + ".xml"; }
public static LingeaSndFiles addSoundsStart(Langs lng, bool force = false) { string fn = basicPath + "\\" + lng.ToString() + ".xml"; if (!force && File.Exists(fn)) { var res = XmlUtils.FileToObject<LingeaSndFiles>(fn); //File.Delete(fn); return res; } else { var res = new LingeaSndFiles() { lng = lng }; res.files = Directory.EnumerateFiles(res.BasicPath, "*.xml").Select(f => XmlUtils.FileToObject<LingeaSndFile>(f)).ToList(); XmlUtils.ObjectToFile(fn, res); return res; } }
//obsolete static void captureLingeaOld(Langs courseLang, Langs nativeLang, string dictCode, bool updateOnly = true, bool tryNullEntries = false) { if (!DictLib.crsLangs.Contains(courseLang)) return; //if (courseLang != Langs.ru_ru) return; string fn = Machines.rootPath + @"RwDicts\Sources\LingeaOld\lingea_" + nativeLang.ToString() + "_" + courseLang.ToString() + ".xml"; _idToEntry = null; _wordToId = null; //doposud nactena entry dej do dictionary Dictionary<string, string> word_entry = File.Exists(fn) && updateOnly ? XElement.Load(fn).Elements(). SelectMany(e => e. AttributeValue("vals"). Split('#'). Select(w => DictLib.russianRemoveAkcent(courseLang, w)). Distinct(). Select(key => new { key = key.ToLower(), value = e.HasElements ? e.FirstNode.ToString() : null })). GroupBy(kv => kv.key). ToDictionary(g => g.Key, g => g.First().value) : new Dictionary<string, string>(); //v courseWords jsou slova upravena takto: lowercase, odstraneny carka nad pismeny. var allWords = courseWords[courseLang].Select(w => w.word).Distinct(); //vsechna slova ve vsech kurzech s courseLang Action save = () => { //V word_entry je: word -> null nebo word -> xmlstring XElement langRoot = new XElement("root", new XAttribute("lang", courseLang.ToString())); foreach (var grp in word_entry.Where(kv => kv.Value != null).GroupBy(kv => kv.Value)) { var vals = grp.Select(g => g.Key).Aggregate((r, i) => r + "#" + i); langRoot.Add(new XElement("w", new XAttribute("vals", vals), XElement.Parse(grp.First().Value))); } foreach (var kv in word_entry.Where(kv => kv.Value == null)) langRoot.Add(new XElement("w", new XAttribute("vals", kv.Key))); //save langRoot.Save(fn); }; int cnt = 0; foreach (var word in allWords) { string entry; if (word_entry.TryGetValue(word.ToLower(), out entry) && (entry != null || !tryNullEntries)) continue; entry = NewData.Schools.getDictWord(dictCode, courseLang == Langs.ru_ru ? DictLib.normalizeRussian(word) : word); //return; try { XElement.Parse(entry); } catch { entry = null; } word_entry.Add(word, entry); //save po 1000 heslech kvuli padu cnt++; if (cnt > 1000) { save(); cnt = 0; } } save(); }
static void captureLingea(Langs courseLang, Langs nativeLang, string dictCode) { if (!crsLangs.Contains(courseLang)) return; _lingeaWords = null; _lingeaKeys = null; //Capture XElement langRoot = new XElement("root", new XAttribute("lang", courseLang.ToString())); var words = courseWords[courseLang].Select(w => (courseLang == Langs.ru_ru ? normalizeRussian(w.word) : w.word)).Distinct().GroupBy(w => w.ToLower()).ToDictionary(g => g.Key, g => g.Aggregate((r, i) => r + "#" + i)); foreach (var word in words) { var res = NewData.Schools.getDictWord(dictCode, word.Key); var entrXml = new XElement("w", new XAttribute("key", word), new XAttribute("vals", word.Value)); langRoot.Add(entrXml); if (string.IsNullOrEmpty(res)) { entrXml.Add("???"); continue; } try { entrXml.Add(XElement.Parse(res)); } catch { entrXml.Add("?xml?"); } } //odstran duplicity var doubles = langRoot.Elements().Where(e => e.Elements().Count() == 1).Select(e => new { e, val = e.Elements().First().ToString() }).GroupBy(v => v.val).Where(g => g.Count() > 1).ToArray(); foreach (var d in doubles) { var f = d.First(); f.e.Attribute("vals").Value = d.Select(e => e.e.AttributeValue("vals")).Aggregate((r, i) => r + "#" + i); foreach (var e in d.Skip(1)) e.e.Remove(); } //save langRoot.Save(Machines.basicPath + @"rew\Web4\RwDicts\lingea_" + nativeLang.ToString() + "_" + courseLang.ToString() + ".xml"); //kontrola //var lWords = lingeaWords[nativeLang][courseLang]; //var lKeys = lingeaKeys[nativeLang][courseLang]; //Func<string, XElement> findEntry = w => { // w = courseLang == Langs.ru_ru ? normalizeRussian(w) : w; // string v; if (!lKeys.TryGetValue(w, out v)) return null; // XElement res; // return lWords.TryGetValue(v, out res) ? res : null; //}; //var wrong = courseWords[courseLang].Select(w => w.word).Where(w => findEntry(w) == null).Aggregate((r, i) => r + "\r\n" + i); //if (wrong != "") File.WriteAllText(Machines.basicPath + @"rew\Web4\RwDicts\lingeaError_" + nativeLang.ToString() + "_" + courseLang.ToString() + ".txt", wrong); }
public static string SoundBasicPath(BasicPathType basicPath, Langs lang) { if (lang == Langs.no) return getConfigPath(basicPath); #if !eTestMeManager if (basicPath == BasicPathType.Url) return (Machines.isPZComp() ? "http://download.langmaster.cz/data" : getConfigPath(basicPath)) + "/sound/" + lang.ToString(); else #endif return getConfigPath(basicPath) + '\\' + lang.ToString(); }
public static CultureInfo LangToCulture(Langs l) { if (l == Langs.sp_sp) l = Langs.es_es; return CultureInfo.GetCultureInfo(l.ToString().Replace('_', '-')); }
public static string BasicUrl(UrlType type, Langs lang) { string res = getDataPath() + "/" + type.ToString(); if (lang != Langs.no) res += "/" + lang.ToString(); return res; }
public static string UrlLocalize(string url, Domains site, Langs lng) { if (site != Domains.com && site != Domains.org) return url; int idx = url.IndexOf("pages/"); if (idx < 0) return url; string key = url.Substring(idx); return url.Substring(0, idx) + Localize(key, lng.ToString().Replace('_', '-')); }
public static void GenerateResx(Trados.TradosDataContext db, Trados.Page pg, Langs transLang) { if (pg.PageGroup == (short)LocPageGroup.newEA || pg.PageGroup == (short)LocPageGroup.fakeRussian) return; LocFileType ft = TradosLib.getFileType(pg.FileName.Replace(".resx", null)); LocPageGroup grp = (LocPageGroup)pg.PageGroup; if (ft == LocFileType.js) { //generace lokalizovaneho .JS souboru misto .RESX string fn = null; string fnContent = null; LocCfgPageGroupFilter group = LocCfg.Instance().findPageGroup(grp); switch (grp) { case LocPageGroup.EA_Code: fn = group.BasicPath + @"\framework\script\lm\tradosData." + transLang.ToString().Replace('_', '-') + ".js"; break; case LocPageGroup.rew_school: fn = group.BasicPath + @"\schools\loc\tradosData." + transLang.ToString().Replace('_', '-') + ".js"; fnContent = NewEATradosLib.locJS(db.Sentences.Where(s => s.PageId == pg.Id && s.TransLang == (short)transLang).ToDictionary(sent => sent.Name, sent => sent.TransText == null ? "###TRANS TODO###" : transFinal(sent.TransText))); fnContent = "var tradosData = " + fnContent + "; tradosData[\"forceLang\"] = \"" + transLang.ToString().Replace('_', '-') + "\";"; break; case LocPageGroup.rew_rewise: fn = group.BasicPath + @"\rewise\loc\tradosData." + transLang.ToString().Replace('_', '-') + ".js"; break; } if (fn != null) { using (StreamWriter wr = new StreamWriter(fn)) { if (fnContent != null) wr.Write(fnContent); else { wr.WriteLine("var tradosData = [];"); foreach (Trados.Sentence sent in db.Sentences.Where(s => s.PageId == pg.Id && s.TransLang == (short)transLang)) { wr.Write("tradosData['"); wr.Write(sent.Name); wr.Write("'] = '"); wr.Write(sent.TransText == null ? "###TRANS TODO###" : transFinal(sent.TransText).Replace("'", "\\'")); wr.WriteLine("';"); } } } } } else { bool isPartial = pg.Langs != null && !pg.Langs.Contains(transLang.ToString()); string fn = resxFileName(pg.FileName, transLang); Langs dbLang = isPartial ? Langs.en_gb : transLang; //Difotne je vse anglicky LowUtils.AdjustFileDir(fn); using (ResXResourceWriter wr = new ResXResourceWriter(fn)) foreach (Trados.Sentence sent in db.Sentences.Where(s => s.PageId == pg.Id && s.TransLang == (short)dbLang)) wr.AddResource(sent.Name, sent.TransText == null ? "###TRANS TODO###" : transFinal(sent.TransText).Replace("$nbsp;", " ").Replace(crlfCode, " "));/*sent.TransText.Replace(crlfCode, "\r\n"));*/ if (ft == LocFileType.lmdata && (grp == LocPageGroup.CPV || fn.ToLowerInvariant().IndexOf(@"\localizecommon\") >= 0)) { //vystup primo lokalizovaneho lmdata string lmdata = pg.FileName.Replace(".resx", null).Replace(@"app_localresources\", null); string resData = pg.FileName.Replace(".resx", null).Replace(".lmdata", "." + transLang.ToString().Replace('_', '-') + ".lmdata"); using (FileStream fs = new FileStream(resData, FileMode.Create, FileAccess.Write)) LocalizeXmlLow(lmdata, transLang, fs, false); } } }
static string dataPath(Langs lang, LocPageGroup grp) { if (grp.ToString().IndexOf("EA") == 0) { string prefix = "http://test.langmaster.cz/"; switch (lang) { case Langs.cs_cz: return prefix + "eduauthornew/"; default: string lng = lang.ToString().Substring(3); return prefix + "com" + lng + "/"; } } else { return "http://test.langmaster.cz/lmcom/com/" + lang.ToString().Replace('_', '-') + "/"; } }
public static string readFile(string dir, string fn, Langs Key) { string destFn = dir + (Key == Langs.no ? null : Key.ToString().Replace('_', '-') + "\\") + fn; return File.ReadAllText(destFn); }
static string resxFileName(string fn, Langs lang) { return fn.Replace(".resx", "." + lang.ToString().Replace('_', '-') + ".resx"); }
public static string swLang(Langs lang) { var lngStr = lang.ToString().Replace('_', '-'); return lngStr == "sp-sp" ? "es-es" : lngStr; }