Example #1
0
        private async Task <bool> _RowAction(IGRRow _Row)
        {
            GRRow <BookDisplay> Row = (GRRow <BookDisplay>)_Row;

            BookInstruction Payload = ( BookInstruction )Row.Source.Payload;

            if (Payload != null)
            {
                // Save the book here
                Payload.SaveInfo();

                // Reload the BookDisplay as Entry might changed from SaveInfo
                Row.Source = new BookDisplay(Payload.Entry);
            }

            SpiderBook Item = await SpiderBook.CreateSAsync(Row.Source.Entry.ZoneId, Row.Source.Entry.ZItemId, Payload?.BookSpiderDef);

            Item.PropertyChanged += Item_PropertyChanged;

            XParameter Metadata = Item.PSettings.Parameter("METADATA") ?? new XParameter("METADATA");

            Metadata.SetValue(new XKey("payload", Row.Source.Entry.Meta[AppKeys.GLOBAL_SSID]));
            Item.PSettings.SetParameter(Metadata);

            if (!Item.ProcessSuccess && Item.CanProcess)
            {
                await ItemProcessor.ProcessLocal(Item);
            }

            Item.PropertyChanged -= Item_PropertyChanged;

            (( BookDisplayPageExt )Extension).OpenItem(_Row);

            return(true);
        }
Example #2
0
 public async void ProcessItem(IGRRow DataContext)
 {
     if (DataContext is GRRow <IBookProcess> Row)
     {
         await ItemProcessor.ProcessLocal(( LocalBook )Row.Source);
     }
 }
Example #3
0
        public async void Blow()
        {
            if (LB.CanProcess)
            {
                await ItemProcessor.ProcessLocal(LB);
            }

            if (LB.ProcessSuccess)
            {
                ControlFrame.Instance.NavigateTo(
                    PageId.BOOK_INFO_VIEW
                    , () => new BookInfoView(ItemProcessor.GetBookEx(LB.ZItemId))
                    );
            }
        }
Example #4
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());
                    }
                }
            }
        }
Example #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);
        }
Example #6
0
        private async void ProcessAll(object sender, RoutedEventArgs e)
        {
            StringResources stx = StringResources.Load("AppBar", "AdvDM", "AppResources");

            if (Processing)
            {
                Terminate = !Terminate;
            }
            else
            {
                Terminate = false;
            }

            if (Terminate)
            {
                ProcessBtn.Label = stx.Text("ProcessAll");
                ProcessBtn.Icon  = new SymbolIcon(Symbol.Play);
                PTargets?
                .Where(x => !x.Processing && x.File != null)
                .ExecEach(x => x.Desc = stx.Text("Ready", "AppResources"));
            }
            else
            {
                ProcessBtn.Label = stx.Text("Pause");
                ProcessBtn.Icon  = new SymbolIcon(Symbol.Pause);
                PTargets?
                .Where(x => !x.Processing && x.File != null)
                .ExecEach(x => x.Desc = stx.Text("Waiting", "AdvDM"));
            }

            if (Processing)
            {
                return;
            }
            Processing = true;

            PTargets = ((GRTable <IBookProcess>)ViewSource.BSData.Table).Items
                       .Where(x =>
            {
                LocalBook Bk = ( LocalBook )x.Source;
                return(Bk.CanProcess && !Bk.Processed);
            })
                       .Remap(x =>
            {
                LocalBook Bk = ( LocalBook )x.Source;
                Bk.Desc      = stx.Text("Waiting", "AdvDM");
                return(Bk);
            });

            if (PTargets.Any())
            {
                if (await Shared.Conv.ConfirmTranslate("__ALL__", "All"))
                {
                    Shared.Conv.SetPrefs(PTargets);
                }

                foreach (LocalBook b in PTargets)
                {
                    await ItemProcessor.ProcessLocal(b);

                    if (Terminate)
                    {
                        break;
                    }
                }
            }

            ProcessBtn.Label = stx.Text("ProcessAll");
            ProcessBtn.Icon  = new SymbolIcon(Symbol.Play);
            PTargets         = null;
            Terminate        = false;
            Processing       = false;
        }
Example #7
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) { }
            }
        }