Exemplo n.º 1
0
        public async void ProcessItem(IGRRow DataContext)
        {
            if (DataContext is GRRow <IBookProcess> Row)
            {
                SpiderBook BkProc = ( SpiderBook )Row.Source;
                if (!BkProc.Processing)
                {
                    await ItemProcessor.ProcessLocal(BkProc);

                    if (BkProc.GetBook().Packed == true)
                    {
                        new VolumeLoader((x) => { }).Load(BkProc.GetBook());
                    }
                }
            }
        }
Exemplo n.º 2
0
        private async void LoadInstruction(BookInstruction B, bool useCache)
        {
            if (!BookInstruction.OpLocks.AcquireLock(B.GID, out AsyncLocks <string, bool> .QueueToken QT))
            {
                await QT.Task;
            }

            SpiderBook SBook = await SpiderBook.CreateSAsync(B.ZoneId, B.ZItemId, B.BookSpiderDef);

            if (Shared.Storage.FileExists(SBook.MetaLocation))
            {
                B.LastCache = Shared.Storage.FileTime(SBook.MetaLocation).LocalDateTime;
            }

            if (useCache && (B.Packed == true || Shared.BooksDb.Volumes.Any(x => x.Book == B.Entry)))
            {
                if (B.Packed != true)
                {
                    B.PackSavedVols(SBook.PSettings);
                }
            }
            else
            {
                bool UpdateFailed = true;

                await SBook.Process();

                if (SBook.Processed && SBook.ProcessSuccess)
                {
                    B.LastCache = DateTime.Now;
                    BookInstruction BUpdate = SBook.GetBook();

                    if (BUpdate.Packable && BUpdate.Packed != true)
                    {
                        BUpdate.PackVolumes(SBook.GetPPConvoy());
                        B.Update(BUpdate);
                        UpdateFailed = false;
                    }
                }

                // Cannot download content, use cache if available
                if (UpdateFailed && Shared.BooksDb.Volumes.Any(x => x.Book == B.Entry))
                {
                    Logger.Log(ID, "Spider failed to produce instructions, using cache instead", LogType.WARNING);
                    B.PackSavedVols(SBook.PSettings);
                }
            }

            QT.TrySetResult(true);
            OnComplete(B);
        }
Exemplo n.º 3
0
 public void ProcessOrOpenItem(IGRRow DataContext)
 {
     if (DataContext is GRRow <IBookProcess> Row)
     {
         SpiderBook BkProc = ( SpiderBook )Row.Source;
         if (BkProc.Processed && BkProc.ProcessSuccess)
         {
             BookItem BkItem = BkProc.GetBook();
             ControlFrame.Instance.NavigateTo(PageId.BOOK_INFO_VIEW, () => new wenku10.Pages.BookInfoView(BkItem));
         }
         else
         {
             ProcessItem(DataContext);
         }
     }
 }
Exemplo n.º 4
0
        private async void PinItemToStart(object sender, RoutedEventArgs e)
        {
            SpiderBook B = ( SpiderBook )(( FrameworkElement )sender).DataContext;

            if (B.ProcessSuccess)
            {
                BookInstruction Book   = B.GetBook();
                string          TileId = await PageProcessor.PinToStart(Book);

                if (!string.IsNullOrEmpty(TileId))
                {
                    PinManager PM = new PinManager();
                    PM.RegPin(Book, TileId, true);

                    await PageProcessor.RegLiveSpider(B, Book, TileId);
                }
            }
        }
Exemplo n.º 5
0
        private async void OpenSpider(HubScriptItem HSI)
        {
            BookItem Book = null;

            try
            {
                SpiderBook SBook = await SpiderBook.ImportFile(await HSI.ScriptFile.ReadString(), true);

                if (SBook.CanProcess && !SBook.Processed)
                {
                    await ItemProcessor.ProcessLocal(SBook);

                    Book = SBook.GetBook();
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ID, ex.Message, LogType.WARNING);
            }

            // Should be outside of try..catch block
            OpenBook(Book);
        }
Exemplo n.º 6
0
        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) { }
            }
        }