Exemple #1
0
        public Task InstallDlBook(DlBook dlBook, string symmetricKey, CancellationToken cancelToken)
        {
            return(Task.Run(async() =>
            {
                InstallResultEnum installResult = InstallResultEnum.Failure;
                PublicationContent publicationContent = null;
                try
                {
                    var contentKey = await dlBook.GetContentKey(symmetricKey).WithCancellation <byte[]>(cancelToken);
                    publicationContent = new PublicationContent(dlBook, contentKey);

                    bool hasNotInstalled = (!await publicationContent.DlBook.IsSqliteDecryped());
                    if (hasNotInstalled)
                    {
                        await publicationContent.DlBook.UnZipFile(cancelToken);
                        if (cancelToken.IsCancellationRequested)
                        {
                            cancelToken.ThrowIfCancellationRequested();
                        }
                        await publicationContent.DecryptDataBase();
                        await publicationContent.DlBook.DeleteOriginalSqlite();
                        installResult = InstallResultEnum.Success;
                    }
                    else
                    {//has been installed
                        installResult = InstallResultEnum.Success;
                    }
                }
                catch (OperationCanceledException ex)
                {
                    if (cancelToken.IsCancellationRequested)
                    {
                        installResult = InstallResultEnum.Cancel;
                    }
                    throw ex;
                }
                catch (Exception ex)
                {
                    Logger.Log("Install error:" + ex.ToString());
                    installResult = InstallResultEnum.Failure;
                    throw ex;
                }
                finally
                {
                    if (publicationContent != null && installResult != InstallResultEnum.Success)
                    {
                        publicationContent.DlBook.DeleteDlBookInstallFile().Wait();
                    }
                }
            }));
        }
        async void InstallCurrentBook()
        {
            var cancelTokenSource = new CancellationTokenSource();

            InstallResultEnum installResult = await PublicationUtil.Instance.Install(BookInfo.BookId, cancelTokenSource.Token);

            switch (installResult)
            {
            case InstallResultEnum.Cancel:
                ShowInstallErrorAlert();
                break;

            case InstallResultEnum.Failure:
                ShowInstallErrorAlert();
                break;

            case InstallResultEnum.Success:
                break;
            }
        }