public ExportController(IConfiguration config, ILoggerFactory loggerFactory, SqlDict dict) { this.config = config; mut = config["MUTATION"] == "HDD" ? Mutation.HDD : Mutation.CHD; logger = loggerFactory.CreateLogger("ExportController"); this.dict = dict; }
public IActionResult GetPastChanges([FromQuery] string entryId, [FromQuery] string lang) { if (entryId == null || lang == null) { return(StatusCode(400, "Missing parameter(s).")); } int idVal = EntryId.StringToId(entryId); string hw, trg; EntryStatus status; SqlDict.GetEntryById(idVal, out hw, out trg, out status); var changes = SqlDict.GetEntryChanges(idVal); // Remove first item (most recent change). But first, backprop potential trg and status change if (changes[0].HeadBefore != null) { hw = changes[0].HeadBefore; } if (changes[0].BodyBefore != null) { trg = changes[0].BodyBefore; } if (changes[0].StatusBefore != 99) { status = (EntryStatus)changes[0].StatusBefore; } changes.RemoveAt(0); StringBuilder sb = new StringBuilder(); HistoryRenderer.RenderPastChanges(sb, entryId, hw, trg, status, changes, lang); return(new ObjectResult(sb.ToString())); }
/// <summary> /// Ctor: init controller within app environment. /// </summary> public SmartsController(CountryResolver cres, LangRepo langRepo, SqlDict dict, QueryLogger qlog, IConfiguration config) { this.cres = cres; this.langRepo = langRepo; this.dict = dict; this.qlog = qlog; }
/// <summary> /// Ctor: infuse dependencies. /// </summary> public IndexController(PageProvider pageProvider, IConfiguration config, ILoggerFactory loggerFactory, Auth auth, SqlDict dict) { mut = config["MUTATION"] == "HDD" ? Mutation.HDD : Mutation.CHD; baseUrl = config["baseUrl"]; dpc = new DynpageController(pageProvider, config, loggerFactory, auth, dict, null, null, null, null); gaCode = config["gaCode"]; captchaSiteKey = config["captchaSiteKey"]; }
/// <summary> /// Ctor: Infuse app services. /// </summary> /// <remarks> /// Default null values make controller accessible to <see cref="IndexController"/>. /// That way, functionality is limited to serving static pages. /// </remarks> public DynpageController(PageProvider pageProvider, IConfiguration config, ILoggerFactory loggerFactory, Auth auth, SqlDict dict, CountryResolver cres, QueryLogger qlog, Sphinx sphinx, LangRepo langRepo) { this.cres = cres; this.pageProvider = pageProvider; this.dict = dict; this.sphinx = sphinx; this.qlog = qlog; this.config = config; this.logger = loggerFactory.CreateLogger("DynpageController"); this.auth = auth; this.langRepo = langRepo; }
private void doExport() { string exportFileName = Path.Combine(config["exportFolder"], config["exportFileNameRaw"]); bool fileUpToDate = false; if (System.IO.File.Exists(exportFileName)) { FileInfo fi = new FileInfo(exportFileName); DateTime dtFile = fi.LastWriteTimeUtc; DateTime dtData = SqlDict.GetLatestChangeUtc(); fileUpToDate = dtFile > dtData; } if (fileUpToDate) { return; } using (FileStream fs = new FileStream(exportFileName, FileMode.Create, FileAccess.ReadWrite)) using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) using (SqlDict.Exporter exporter = new SqlDict.Exporter()) { // #20 Dictionary export mixes \r\n and \n sw.NewLine = "\n"; writePrologue(sw); EntryBlockWriter ebw = new EntryBlockWriter(sw); while (true) { List <EntryVersion> history; int entryId; exporter.GetNext(out history, out entryId); if (history == null) { break; } //// DBG: reduced export //DateTime limit = new DateTime(2016, 11, 1); //if (history[history.Count - 1].Timestamp < limit) continue; ebw.WriteBlock(entryId, history); } } }
public IActionResult GetHistoryItem([FromQuery] string entryId, [FromQuery] string lang) { if (entryId == null || lang == null) { return(StatusCode(400, "Missing parameter(s).")); } int idVal = EntryId.StringToId(entryId); string hw, trg; EntryStatus status; SqlDict.GetEntryById(idVal, out hw, out trg, out status); StringBuilder sb = new StringBuilder(); List <ChangeItem> changes = SqlDict.GetEntryChanges(idVal); ChangeItem ci = changes[0]; ci.EntryBody = trg; ci.EntryHead = hw; ci.EntryStatus = status; HistoryRenderer.RenderItem(sb, trg, status, changes[0], lang); return(new ObjectResult(sb.ToString())); }
public IActionResult GetEditEntryData([FromQuery] string entryId, [FromQuery] string lang) { if (entryId == null || lang == null) { return(StatusCode(400, "Missing parameter(s).")); } // The data we'll return. EditEntryData res = new EditEntryData(); // Is this an authenticated user? int userId; string userName; auth.CheckSession(HttpContext.Request.Headers, out userId, out userName); // Can she approve entries? if (userId != -1) { res.CanApprove = auth.CanApprove(userId); } // Retrieve entry int idVal = EntryId.StringToId(entryId); string hw, trg; EntryStatus status; SqlDict.GetEntryById(idVal, out hw, out trg, out status); CedictParser parser = new CedictParser(); CedictEntry entry = parser.ParseEntry(hw + " " + trg, 0, null); res.Status = status.ToString().ToLowerInvariant(); res.HeadSimp = entry.ChSimpl; res.HeadTrad = entry.ChTrad; res.HeadPinyin = ""; for (int i = 0; i != entry.PinyinCount; ++i) { if (res.HeadPinyin.Length > 0) { res.HeadPinyin += " "; } var pys = entry.GetPinyinAt(i); res.HeadPinyin += pys.GetDisplayString(false); } res.TrgTxt = trg.Trim('/').Replace('/', '\n').Replace('\\', '/'); // Entry HTML entry.Status = status; EntryRenderer er = new EntryRenderer(lang, entry, true, "mainEntry"); er.OneLineHanziLimit = 12; StringBuilder sb = new StringBuilder(); er.Render(sb, null); res.EntryHtml = sb.ToString(); // Entry history List <ChangeItem> changes = SqlDict.GetEntryChanges(idVal); sb.Clear(); HistoryRenderer.RenderEntryChanges(sb, hw, trg, status, changes, lang); res.HistoryHtml = sb.ToString(); return(new ObjectResult(res)); }
public EditController(LangRepo langRepo, SqlDict dict, Auth auth) { this.langRepo = langRepo; this.dict = dict; this.auth = auth; }
public IActionResult VerifyHead([FromQuery] string lang, [FromQuery] string simp, [FromQuery] string trad, [FromQuery] string pinyin) { if (simp == null) { return(StatusCode(400, "Missing 'simp' parameter.")); } if (trad == null) { return(StatusCode(400, "Missing 'trad' parameter.")); } if (pinyin == null) { return(StatusCode(400, "Missing 'pinyin' parameter.")); } NewEntryVerifyHeadResult res = new NewEntryVerifyHeadResult(); StringBuilder sb = new StringBuilder(); // Prepare pinyin as list of proper syllables List <PinyinSyllable> pyList = new List <PinyinSyllable>(); string[] pyRawArr = pinyin.Split(' '); foreach (string pyRaw in pyRawArr) { PinyinSyllable syll = PinyinSyllable.FromDisplayString(pyRaw); if (syll == null) { syll = new PinyinSyllable(pyRaw, -1); } pyList.Add(syll); } string pyInOne = ""; foreach (var syll in pyList) { if (pyInOne != "") { pyInOne += " "; } pyInOne += syll.GetDisplayString(false); } // Is this a dupe? string head = trad + " " + simp + " [" + pyInOne + "]"; CedictEntry existingEntry = SqlDict.GetEntryByHead(head); if (existingEntry != null) { res.Duplicate = true; res.ExistingEntryId = EntryId.IdToString(existingEntry.StableId); EntryRenderer er = new EntryRenderer(lang, existingEntry, true); er.Render(sb, null); res.ExistingEntry = sb.ToString(); return(new ObjectResult(res)); } // OK, we're good. res.Duplicate = false; // Return all entries, CEDICT and HanDeDict, rendered as HTML CedictEntry[] ced, hdd; langRepo.GetEntries(simp, out ced, out hdd); sb.Append("<div id='newEntryRefCED'>"); foreach (CedictEntry entry in ced) { EntryRenderer er = new EntryRenderer(lang, entry, trad, pyList); er.Render(sb, null); } sb.Append("</div>"); sb.Append("<div id='newEntryRefHDD'>"); foreach (CedictEntry entry in hdd) { EntryRenderer er = new EntryRenderer(lang, entry, trad, pyList); er.Render(sb, null); } sb.Append("</div>"); res.RefEntries = sb.ToString(); // Tell our caller return(new ObjectResult(res)); }
public NewEntryController(LangRepo langRepo, SqlDict dict) { this.langRepo = langRepo; this.dict = dict; }