public static Admin.DictEntryRes processCommand(Admin.DictEntryCmd cmd) { Func<Langs, Langs, IEnumerable<ByHand>> getHands = (crsL, natL) => { var fn = Machines.rootPath + string.Format(@"RwDicts\Sources\LingeaOld\design\byHand_{0}_{1}.xml", crsL, natL); IEnumerable<string> fns = File.Exists(fn) ? XExtension.Create(fn) : Directory.EnumerateFiles(Machines.rootPath + @"RwDicts\Sources\LingeaOld\design", string.Format("byHand_{0}_{1}*.xml", crsL, natL)); return fns.SelectMany(f => XmlUtils.FileToObject<List<ByHand>>(f)); }; var hands = getHands(cmd.crsLang, cmd.natLang).ToDictionary(bh => bh.id(), bh => bh); var handFn = Machines.rootPath + string.Format(@"RwDicts\Sources\LingeaOld\design\byHand_{0}_{1}.xml", cmd.crsLang, cmd.natLang); ByHand edited; if (entries == null) entries = LingeaDictionary.getOldLingeaEntries(); if (dictEntries == null) dictEntries = XmlUtils.FileToObject<LingeaDictionary.DictEntry[]>(Machines.rootPath + @"RwDicts\Sources\LingeaOld\design\entriesInfo.xml"); switch (cmd.type) { case Admin.DictEntryCmdType.loadDict: Func<LingeaDictionary.DictEntry, Langs> getHand = de => hands.TryGetValue(de.id(), out edited) ? edited.okCrs : Langs.no; var res = dictEntries. //Where(de => cmd.crsLang == de.crsLang && cmd.natLang == de.natLang). Where(de => de.okCrs == Langs.no && cmd.crsLang == de.crsLang && cmd.natLang == de.natLang). Select(de => new DictEntryCmd { entryId = de.entryId, soundMaster = de.soundMaster, html = entries[de.crsLang][de.natLang].entryIdToEntry[de.entryId].ToString(), okCrs = getHand(de), }).ToArray(); //return new Admin.DictEntryRes { entries = res2.Length > 1000 ? res2.Where(de => de.okCrsMaybe == Langs.no).Take(1000).ToArray() : res2 }; return new Admin.DictEntryRes { entries = res }; case Admin.DictEntryCmdType.saveEntry: if (!hands.TryGetValue(cmd.id(), out edited)) { edited = new ByHand { entryId = cmd.entryId /*, crsLang = cmd.crsLang, natLang = cmd.natLang, okCrsReason = cmd.okCrsReason*/ }; hands.Add(edited.id(), edited); } edited.okCrs = cmd.okCrs; XmlUtils.ObjectToFile(handFn, hands.Values.ToList()); return new Admin.DictEntryRes(); case DictEntryCmdType.statistics: var files0 = dictEntries.Where(de => de.okCrs == Langs.no); var files1 = files0.GroupBy(de => new { de.crsLang, de.natLang }).Where(g => g.Count() > 0).Select(g => new { g.Key, count = g.Count() }); var files2 = files1. Select(g => new { g.Key, count = g.count }); var files3 = files2.Select(fc => new DictEntryCmd { allCount = fc.count, todoCount = fc.count - getHands(fc.Key.crsLang, fc.Key.natLang).Where(d => d.okCrs != Langs.no).Count(), crsLang = fc.Key.crsLang, natLang = fc.Key.natLang, }). ToArray(); return new Admin.DictEntryRes { entries = files3 }; default: throw new NotImplementedException(); } }
private void Register() { Console.Clear(); ConsoleKeyInfo cki; WindowSize size = new WindowSize(); int cItem = 0; string[] items = new string[] { " USERNAME ", " EMAIL ", " PHONE ", " PASSWORD ", " SIGN UP " }; string[] variables = new string[] { "", "", "", "" }; int X = size.BWidth + 3, Y = (size.Height / 2) - (items.Length + 2); Point point = new Point(size.BWidth, size.BHeight); ConsoleRectangle rectangle = new ConsoleRectangle(size.aWidth, size.aHeight, point, ConsoleColor.DarkRed); rectangle.Draw(); while (true) { int index = 0; ; for (index = 0; index < items.Length; index++) { Y += 2; Console.SetCursorPosition(X, Y); if (index != items.Length - 1) { if (index == cItem) { Background.WriteLine(items[index]); } else { Console.Write(items[index]); } Console.SetCursorPosition(size.Width - size.BWidth - 24, Y); Background.WriteLine(" "); if (index == 3) { for (int j = 0; j < variables[index].Length; j++) { Background.WriteLine("*"); } } else { Background.WriteLine(variables[index]); } Console.SetCursorPosition(size.Width - size.BWidth - 23 + variables[index].Length, Y); for (int z = 0; z < 22 - variables[index].Length; z++) { Background.WriteLine(" "); } } else { Console.SetCursorPosition(size.Average - (items[index].Length / 2), Y + 2); if (index == cItem) { Background.WriteLine(items[index]); } else { Console.WriteLine(items[index]); } } } Y = (size.Height / 2) - (items.Length + 2); do { cki = Console.ReadKey(true); } while (cki.Key != ConsoleKey.UpArrow && cki.Key != ConsoleKey.DownArrow && cki.Key != ConsoleKey.Enter && cki.Key != ConsoleKey.Escape); switch (cki.Key) { case ConsoleKey.UpArrow: cItem--; if (cItem < 0) { cItem = items.Length - 1; } break; case ConsoleKey.DownArrow: cItem++; if (cItem > items.Length - 1) { cItem = 0; } break; case ConsoleKey.Enter: if (cItem != items.Length - 1) { Console.SetCursorPosition(size.Width - size.BWidth - 23 + variables[cItem].Length, Y + (cItem * 2 + 2)); if (cItem == 3) { variables[cItem] = Background.InputString(variables[cItem], '*'); } else { variables[cItem] = Background.InputString(variables[cItem]); } } else { Console.SetCursorPosition(size.Average - 4, Y + 12); Console.WriteLine(" Sign Up "); if (Check.CheckUsername(variables[0], size.Average, Y + 14) && Check.CheckEmail(variables[1], size.Average, Y + 14) && Check.CheckPhone(variables[2], size.Average, Y + 14) && Check.CheckPassword(variables[3], size.Average, Y + 14)) { string filePath = "admins.json"; Admin newAdmin = new Admin() { UserName = variables[0], Email = variables[1], Phone = variables[2], Password = variables[3] }; if (File.Exists(filePath)) { var jsonData = File.ReadAllText(filePath); var adminList = JsonConvert.DeserializeObject <List <Admin> >(jsonData) ?? new List <Admin>(); adminList.Add(newAdmin); jsonData = JsonConvert.SerializeObject(adminList); File.WriteAllText(filePath, jsonData); } else { var adminList = new List <Admin>(); adminList.Add(newAdmin); var jsonData = JsonConvert.SerializeObject(adminList); File.WriteAllText(filePath, jsonData); } Background.DisplayMsg(" SUCCESSFULLY ", size.Average, Y + 14); Login(); } } break; case ConsoleKey.Escape: AdminPanel(); break; default: break; } } }