private void M0005_ReadingHistory() { XRegistry XReg = new XRegistry("<n/>", FileLinks.ROOT_SETTING + "ReadingHistory.xml"); XParameter[] XParams = XReg.Parameters(); foreach (XParameter XParam in XParams) { string Id = XParam.Id; string Name = XParam.GetValue("name"); string Date = XParam.GetValue("date"); if (int.TryParse(Id, out int aid)) { BookItem Bk = X.Instance <BookItem>(XProto.BookItemEx, Id); Bk.Title = Name; if (DateTime.TryParse(Date, out DateTime dt)) { Bk.Entry.LastAccess = dt; } } } Shared.BooksDb.SaveChanges(); }
private void GotServerList(DRequestCompletedEventArgs e, string key) { IEnumerable <ServerChoice> SC = null; XParameter[] Params = ServerReg.Parameters("uri"); try { IEnumerable <string> Servers = X.Call <IEnumerable <string> >(XProto.ServerSelector, "ExtractList", e.ResponseString); SC = Servers.Remap(x => { string[] s = x.Split(new char[] { ',' }); return(new ServerChoice(s[0], s[1])); }); var j = Task.Run(async() => { await X.Call <Task>(XProto.ServerSelector, "ProcessList", Servers); foreach (ServerChoice C in SC) { C.Preferred = X.Static <IEnumerable <Weight <string> > >(XProto.ServerSelector, "ServerList").Any(x => { if (x.Freight == C.Name) { C.Desc = x.Factor + ""; return(true); } return(false); }); C.IsLoading = false; } }); } catch (Exception ex) { Logger.Log(ID, ex.Message, LogType.ERROR); } Worker.UIInvoke(() => AvailableServers.ItemsSource = SC); }
private async Task M0004_Books_TypeL() { string LRoot = "shared/transfers/LVolumes/"; if (!Shared.Storage.DirExist(LRoot)) { return; } string[] Ids = Shared.Storage.ListDirs(LRoot); int l = Ids.Length; List <Book> Entries = new List <Book>(); await Ids.ExecEach(async ( Id, i ) => { MesgR(stx.Text("MightTakeAWhile") + string.Format("{1}/{2} ( {0} )", Id, i + 1, l)); Book Entry = null; if (int.TryParse(Id, out int k) && X.Exists) { BookItem Item = X.Instance <BookItem>(XProto.BookItemEx, Id); Entry = Item.Entry; Entry.Type = Entry.Type | BookType.L; } else { BookItem Item = new LocalTextDocument(Id); Entry = Item.Entry; } await Shared.BooksDb.LoadCollectionAsync(Entry, x => x.Volumes, x => x.Index); Entry.Volumes.Clear(); string BRoot = LRoot + Id + "/"; string MetaLoc = BRoot + "METADATA.xml"; XRegistry XMeta = new XRegistry("<Meta />", MetaLoc); XParameter[] VolDefs = XMeta.Parameters("vid"); VolDefs.ExecEach((VolDef, vi) => { Volume Vol = new Volume() { Book = Entry, Title = VolDef.GetValue("name"), Chapters = new List <Chapter>(), Index = vi }; Vol.Meta[AppKeys.GLOBAL_VID] = VolDef.Id; XRegistry ChReg = new XRegistry("<ch />", BRoot + VolDef.Id + ".vol"); XParameter[] ChDefs = ChReg.Parameters("cid"); ChDefs.ExecEach((ChDef, ei) => { Chapter Ch = new Chapter() { Book = Entry, Volume = Vol, Title = ChDef.GetValue("name"), Index = ei }; Ch.Meta[AppKeys.GLOBAL_CID] = ChDef.Id; string ChLocation = BRoot + VolDef.Id + "/" + ChDef.Id + ".txt"; if (Shared.Storage.FileExists(ChLocation)) { ChapterContent ChCont = new ChapterContent() { Chapter = Ch, }; ChCont.Data.BytesValue = Shared.Storage.GetBytes(ChLocation); Shared.BooksDb.ChapterContents.Add(ChCont); } Vol.Chapters.Add(Ch); }); Entry.Volumes.Add(Vol); }); Entries.Add(Entry); }); MesgR(stx.Text("SavingRecords")); Shared.BooksDb.SaveBooks(Entries.ToArray()); Purge(LRoot); }
private async Task UpdateSpiders() { try { XReg.SetParameter(TASK_START, CustomAnchor.TimeKey); XReg.Save(); IEnumerable <XParameter> Updates; List <string> Exists = new List <string>(); if (Retrying) { Updates = XReg.Parameters(AppKeys.BTASK_SPIDER).Where(x => { int r = x.GetSaveInt(AppKeys.BTASK_RETRY); return(0 < r && r < MaxRetry); }); } else { Updates = XReg.Parameters(AppKeys.BTASK_SPIDER).Where(x => { int r = x.GetSaveInt(AppKeys.BTASK_RETRY); if (r == 0 || MaxRetry <= r) { return(true); } else { // Consider Retry Timer dead if LastUpdate is 20 < minutes DateTime LastRun = DateTime.FromFileTimeUtc(x.GetSaveLong(AppKeys.LBS_TIME)); return(30 < DateTime.Now.Subtract(LastRun).TotalMinutes); } }); } foreach (XParameter UpdateParam in Updates) { string TileId = UpdateParam.GetValue("tileId"); if (!SecondaryTile.Exists(TileId)) { UpdateParam.SetValue(new XKey[] { new XKey(AppKeys.SYS_EXCEPTION, "App Tile is missing") , CustomAnchor.TimeKey }); XReg.SetParameter(UpdateParam); continue; } string[] Keys = UpdateParam.Id.Split('.'); if (Keys.Length != 3) { XReg.RemoveParameter(UpdateParam.Id); continue; } SpiderBook SBook = await SpiderBook.CreateSAsync(Keys[0], Keys[2], null); if (!SBook.CanProcess) { XReg.RemoveParameter(UpdateParam.Id); continue; } SBook.MarkUnprocessed(); string OHash = null, NHash = null; SBook.GetBook()?.Entry.Meta.TryGetValue("TOCHash", out OHash); await ItemProcessor.ProcessLocal(SBook); if (SBook.ProcessSuccess) { BookInstruction NBook = SBook.GetBook(); NBook?.Entry.Meta.TryGetValue("TOCHash", out NHash); if (NBook.Packed == true && (NBook.NeedUpdate || OHash != NHash)) { await LiveTileService.UpdateTile(CanvasDevice, NBook, TileId); } UpdateParam.SetValue(new XKey[] { new XKey(AppKeys.SYS_EXCEPTION, false) , new XKey(AppKeys.BTASK_RETRY, 0) , CustomAnchor.TimeKey }); } else { CreateRetryTimer(); int NRetries = UpdateParam.GetSaveInt(AppKeys.BTASK_RETRY); UpdateParam.SetValue(new XKey[] { new XKey(AppKeys.SYS_EXCEPTION, true) , new XKey(AppKeys.BTASK_RETRY, NRetries + 1) , CustomAnchor.TimeKey }); } XReg.SetParameter(UpdateParam); XReg.Save(); } XReg.SetParameter(TASK_END, CustomAnchor.TimeKey); XReg.Save(); } catch (Exception ex) { try { XReg.SetParameter(AppKeys.SYS_EXCEPTION, new XKey(AppKeys.SYS_MESSAGE, ex.Message)); XReg.Save(); } catch (Exception) { } } }