public async Task Load(string folderUrl, string url)
        {
            var rect = new Rect(0, 0, 500, 300);

            if (DownloadManager.IsImage(url))
            {
                slideShow = new SlideShow();
                await slideShow.SetRect(rect, folderUrl, url, 1f);

                progressLoad.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                frame.Children.Add(slideShow);
            }
            else if (DownloadManager.IsVideo(url))
            {
                rect        = new Rect(0, 0, Window.Current.Bounds.Width, Window.Current.Bounds.Height);
                videoPlayer = new VideoPlayer();
                videoPlayer.SetRect(rect, folderUrl, url, 1f);
                progressLoad.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                frame.Children.Add(videoPlayer);
            }
        }
Пример #2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override async void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            var app    = Application.Current as App;
            var loader = new ResourceLoader();

            if (app.needToDownload == false)
            {
                needtoGoBack = true; return;
            }

            app.needToDownload = false;

            var item = navigationParameter as DownloadMagazine;

            if (item != null)
            {
                statusText.Text = loader.GetString("download_progress");

                var url = item.url;

                LoadSnappedSource();
                //magList.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                downloadView.Visibility = Windows.UI.Xaml.Visibility.Visible;

                try
                {
                    var folder = await app.Manager.AddMagazineFolderStructure(url);

                    Windows.UI.Xaml.Media.Imaging.BitmapSource bitmap = null;
                    try
                    {
                        bitmap = await app.Manager.DownloadThumbnailAsync(url, folder);
                    }
                    catch { }
                    if (bitmap == null)
                    {
                        var messageDialog = new MessageDialog(loader.GetString("download_failed"));
                        var commands      = new List <UICommand>();
                        var close         = new UICommand(loader.GetString("close"));
                        close.Invoked = closeCommandHandler;
                        messageDialog.Commands.Clear();
                        messageDialog.Commands.Add(close);
                        var task = messageDialog.ShowAsync().AsTask();
                        return;
                    }
                    pdfThumbnail.Width  = bitmap.PixelWidth * pdfThumbnail.Height / bitmap.PixelHeight;
                    pdfThumbnail.Source = bitmap;

                    pRing.IsActive = false;

                    var progressIndicator = new Progress <int>((value) =>
                    {
                        if (statusText.Text != app.Manager.StatusText)
                        {
                            statusText.Text = app.Manager.StatusText;
                        }
                        progressBar.Value = value;
                    });
                    cts = new CancellationTokenSource();

                    IRandomAccessStream stream = null;
                    if (item.redirectUrl == null)
                    {
                        stream = await app.Manager.DownloadMagazineAsync(url, folder, item.IsSampleDownloaded, progressIndicator, cts.Token);
                    }
                    else
                    {
                        stream = await app.Manager.DownloadMagazineAsync(url, item.redirectUrl, folder, item.IsSampleDownloaded, progressIndicator, cts.Token);
                    }
                    if (stream == null)
                    {
                        return;
                    }
                    statusText.Text = loader.GetString("done");
                    await app.Manager.MarkAsDownloaded(url, folder, item.IsSampleDownloaded);

                    await Task.Delay(1000);

                    var mag = DownloadManager.GetLocalUrl(app.Manager.MagazineLocalUrl, url.FullName);
                    this.Frame.Navigate(typeof(PdfViewPage), new MagazineData()
                    {
                        stream = stream, folderUrl = mag.FolderPath
                    });
                }
                catch (Exception ex)
                {
                    statusText.Text = "Error";
                    if (ex.Message == "Response status code does not indicate success: 403 (Forbidden).")
                    {
                        var messageDialog = new MessageDialog(loader.GetString("download_failed"));
                        var commands      = new List <UICommand>();
                        var close         = new UICommand(loader.GetString("close"));
                        close.Invoked = closeCommandHandler;
                        messageDialog.Commands.Clear();
                        messageDialog.Commands.Add(close);
                        var task = messageDialog.ShowAsync().AsTask();
                        return;
                    }
                    else if (ex.Message == "The operation was canceled.")
                    {
                        var messageDialog = new MessageDialog(loader.GetString("download_failed"));
                        var commands      = new List <UICommand>();
                        var close         = new UICommand(loader.GetString("close"));
                        close.Invoked = closeCommandHandler;
                        messageDialog.Commands.Clear();
                        messageDialog.Commands.Add(close);
                        var task = messageDialog.ShowAsync().AsTask();
                        return;
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Unexpected error");
                        var commands      = new List <UICommand>();
                        var close         = new UICommand(loader.GetString("close"));
                        close.Invoked = closeCommandHandler;
                        messageDialog.Commands.Clear();
                        messageDialog.Commands.Add(close);
                        var task = messageDialog.ShowAsync().AsTask();
                        return;
                    }
                }
            }
            else
            {
                //string s = navigationParameter as string;
                //if (s == "test")
                //{
                //    testView.Visibility = Windows.UI.Xaml.Visibility.Visible;
                //}
                //else
                //{
                //    needtoGoBack = true;
                //}
            }
        }
Пример #3
0
        //private async Task<StorageFile> CreateMetadataFile(string name)
        //{
        //    //var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder;
        //    var roamingFolder = KnownFolders.DocumentsLibrary;
        //    var file = await roamingFolder.CreateFileAsync(name + ".pmd", CreationCollisionOption.ReplaceExisting);
        //    folder = await roamingFolder.CreateFolderAsync(name, CreationCollisionOption.GenerateUniqueName);
        //    var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

        //    using (var outputStream = stream.GetOutputStreamAt(0))
        //    using (var dataWriter = new DataWriter(outputStream))
        //    {
        //        string data = name + "\r\n" + DateTime.Today.Month.ToString() + "/" + DateTime.Today.Day.ToString() + "/" + DateTime.Today.Year.ToString() + "\r\n";

        //        dataWriter.WriteString(data);

        //        await dataWriter.StoreAsync();
        //        await outputStream.FlushAsync();
        //    }

        //    return file;
        //}

        //private async Task<IRandomAccessStream> DownloadFileAsyncWithProgress(string url, StorageFile pdfFile, IProgress<int> progress = null, CancellationToken cancelToken = default(CancellationToken))
        //{
        //    HttpClient client = new HttpClient();

        //    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

        //    int read = 0;
        //    int offset = 0;
        //    byte[] responseBuffer = new byte[1024];

        //    var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancelToken);
        //    var length = response.Content.Headers.ContentLength;

        //    cancelToken.ThrowIfCancellationRequested();

        //    var stream = new InMemoryRandomAccessStream();

        //    using (var responseStream = await response.Content.ReadAsStreamAsync())
        //    {
        //        do
        //        {
        //            cancelToken.ThrowIfCancellationRequested();

        //            read = await responseStream.ReadAsync(responseBuffer, 0, responseBuffer.Length);

        //            cancelToken.ThrowIfCancellationRequested();

        //            await stream.AsStream().WriteAsync(responseBuffer, 0, read);

        //            offset += read;
        //            int val = (int)(offset * 100 / length);
        //            progress.Report(val);
        //        }
        //        while (read != 0);
        //    }

        //    await stream.FlushAsync();

        //    using (var protectedStream = await DownloadManager.ProtectPDFStream(stream))
        //    using (var fileStream = await pdfFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
        //    //using (var unprotectedStream = await UnprotectPDFStream(protectedStream))
        //    {

        //        await RandomAccessStream.CopyAsync(protectedStream, fileStream.GetOutputStreamAt(0));

        //        await fileStream.FlushAsync();
        //    }

        //    return stream;
        //}

        //private async Task GetUrlsFromPDF(IRandomAccessStream stream)
        //{
        //    using (var dataReader = new DataReader(stream.GetInputStreamAt(0)))
        //    {
        //        uint u = await dataReader.LoadAsync((uint)stream.Size);
        //        IBuffer buffer = dataReader.ReadBuffer(u);

        //        GetPDFLinks(buffer);

        //        TimeSpan t = new TimeSpan(0, 0, 1);
        //        await Task.Delay(t);
        //    }
        //}

        //private void GetPDFLinks(IBuffer buffer)
        //{
        //    var document = Document.Create(
        //                buffer, // - file
        //                DocumentType.PDF, // type
        //                72 // - dpi
        //              );

        //    var linkVistor = new LinkInfoVisitor();
        //    linkVistor.OnURILink += linkVistor_OnURILink;

        //    for (int i = 0; i < document.PageCount; i++)
        //    {
        //        var links = document.GetLinks(i);

        //        for (int j = 0; j < links.Count; j++)
        //        {
        //            links[j].AcceptVisitor(linkVistor);

        //        }
        //    }
        //}

        //void linkVistor_OnURILink(LinkInfoVisitor __param0, LinkInfoURI __param1)
        //{
        //    string str = __param1.URI;
        //    if (str.Contains("localhost"))
        //    {
        //        links.Add(str);
        //    }
        //}

        //private async Task DownloadAssetsAsync(StorageFile metadataFile)
        //{
        //    var absLinks = new List<string>();

        //    foreach (var link in links)
        //    {
        //        string absLink = link;
        //        var pos = absLink.IndexOf('?');
        //        if (pos >= 0) absLink = link.Substring(0, pos);
        //        string fileName = absLink.Replace("http://localhost/", "");
        //        string linkString = "";
        //        linkString = folder.Path + "\\" + absLink.Replace("http://localhost/", "") + "\r\n";
        //        absLink = absLink.Replace("http://localhost/", "http://librelio-europe.s3.amazonaws.com/niveales/wind/windfree_albeau2012/");
        //        absLinks.Add(absLink);

        //        var progressIndicator = new Progress<int>((value) => progressBar.Value = value);
        //        cts = new CancellationTokenSource();

        //        var sampleFile = await folder.CreateFileAsync(fileName + ".pmd", CreationCollisionOption.ReplaceExisting);

        //        await DownloadFileAsyncWithProgress(absLink, sampleFile, progressIndicator, cts.Token);

        //        using (var fileStream = await metadataFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
        //        using (var dataReader = new DataReader(fileStream.GetInputStreamAt(0)))
        //        using (var dataWriter = new DataWriter(fileStream.GetOutputStreamAt(0)))
        //        {
        //            var len = await dataReader.LoadAsync((uint)fileStream.Size);
        //            var data = dataReader.ReadString((uint)len);
        //            var size = dataWriter.WriteString(data + linkString);
        //            await fileStream.FlushAsync();
        //            await dataWriter.StoreAsync();
        //        }
        //    }
        //}

        private async void itemListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            Item item = (Item)e.ClickedItem;

            var loader = new ResourceLoader();

            statusText.Text = loader.GetString("download_progress");

            var app = Application.Current as App;

            foreach (var url in app.Manager.MagazineUrl)
            {
                if (url.FullName == item.FullName)
                {
                    //magList.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    downloadView.Visibility = Windows.UI.Xaml.Visibility.Visible;

                    var folder = await app.Manager.AddMagazineFolderStructure(url);

                    var bitmap = await app.Manager.DownloadThumbnailAsync(url, folder);

                    pdfThumbnail.Width  = bitmap.PixelWidth * pdfThumbnail.Height / bitmap.PixelHeight;
                    pdfThumbnail.Source = bitmap;

                    pRing.IsActive = false;

                    var progressIndicator = new Progress <int>((value) =>
                    {
                        if (statusText.Text != app.Manager.StatusText)
                        {
                            statusText.Text = app.Manager.StatusText;
                        }
                        progressBar.Value = value;
                    });
                    cts = new CancellationTokenSource();

                    try
                    {
                        var stream = await app.Manager.DownloadMagazineAsync(url, folder, false, progressIndicator, cts.Token);

                        if (stream == null)
                        {
                            return;
                        }
                        statusText.Text = loader.GetString("done");
                        await app.Manager.MarkAsDownloaded(url, folder, false);

                        await Task.Delay(1000);

                        var mag = DownloadManager.GetLocalUrl(app.Manager.MagazineLocalUrl, item.FullName);
                        this.Frame.Navigate(typeof(PdfViewPage), new MagazineData()
                        {
                            stream = stream, folderUrl = mag.FolderPath
                        });
                    }
                    catch (Exception ex)
                    {
                        statusText.Text = "Error";
                        if (ex.Message == "Response status code does not indicate success: 403 (Forbidden).")
                        {
                            var messageDialog = new MessageDialog(loader.GetString("download_failed"));
                            var commands      = new List <UICommand>();
                            var close         = new UICommand(loader.GetString("close"));
                            close.Invoked = closeCommandHandler;
                            messageDialog.Commands.Clear();
                            messageDialog.Commands.Add(close);
                            var task = messageDialog.ShowAsync().AsTask();
                            return;
                        }
                        else if (ex.Message == "The operation was canceled.")
                        {
                            var messageDialog = new MessageDialog(loader.GetString("download_failed"));
                            var commands      = new List <UICommand>();
                            var close         = new UICommand(loader.GetString("close"));
                            close.Invoked = closeCommandHandler;
                            messageDialog.Commands.Clear();
                            messageDialog.Commands.Add(close);
                            var task = messageDialog.ShowAsync().AsTask();
                            return;
                        }
                        else
                        {
                            var messageDialog = new MessageDialog("Unexpected error");
                            var commands      = new List <UICommand>();
                            var close         = new UICommand(loader.GetString("close"));
                            close.Invoked = closeCommandHandler;
                            messageDialog.Commands.Clear();
                            messageDialog.Commands.Add(close);
                            var task = messageDialog.ShowAsync().AsTask();
                            return;
                        }
                    }

                    return;
                }
            }
        }
Пример #4
0
        private async void buyMag_Click(object sender, RoutedEventArgs e)
        {
            if (licenseInformation == null)
            {
                return;
            }
            var loader = new ResourceLoader();

            if (!licenseInformation.ProductLicenses[product_id].IsActive)
            {
                try
                {
                    // The customer doesn't own this feature, so
                    // show the purchase dialog.

                    var receipt = await CurrentApp.RequestProductPurchaseAsync(product_id, true);

                    if (!licenseInformation.ProductLicenses[product_id].IsActive || receipt == "")
                    {
                        return;
                    }
                    await DownloadManager.StoreReceiptAsync(product_id, receipt);

                    // the in-app purchase was successful

                    // TEST ONLY
                    // =================================================
                    //var f = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\test\receipt.pmd");
                    //var xml = new XmlDocument();
                    //xml = await XmlDocument.LoadFromFileAsync(f);
                    //var item = xml.GetElementsByTagName("ProductReceipt")[0] as XmlElement;
                    //item.SetAttribute("ProductId", product_id);
                    //var date = new DateTimeOffset(DateTime.Now);
                    //date = date.AddMinutes(3);
                    //var str = date.ToString("u");
                    //str = str.Replace(" ", "T");
                    //item.SetAttribute("ExpirationDate", str);
                    //receipt = xml.GetXml();
                    //if (DownloadManager.ReceiptExpired(receipt)) return;
                    // =================================================

                    buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        Bought(this, DownloadManager.GetUrl(product_id, receipt, relativePath, app.ClientName, app.MagazineName));
                        this.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    }
                    else
                    {
                        var messageDialog = new MessageDialog(loader.GetString("purchase_successfull"));
                        var task          = messageDialog.ShowAsync().AsTask();
                    }
                }
                catch (Exception)
                {
                    // The in-app purchase was not completed because
                    // an error occurred.
                    var messageDialog = new MessageDialog("Unexpected error");
                    var task          = messageDialog.ShowAsync().AsTask();
                }
            }
            else
            {
                var messageDialog = new MessageDialog(loader.GetString("already_subscribed"));
                var task          = messageDialog.ShowAsync().AsTask();
            }
        }
Пример #5
0
        public async Task Init(Data.MagazineViewModel mag, bool local = false, bool intern = false)
        {
            bool needToUpdateImage = false;

            if (mag.Image != null)
            {
                thumbnail.Source = mag.Image;
            }
            else
            {
                needToUpdateImage = true;
            }

            title.Text    = mag.Title;
            subtitle.Text = mag.Subtitle;
            var loader = new ResourceLoader();

            if (local)
            {
                _item = mag;

                noOptions.Visibility              = Windows.UI.Xaml.Visibility.Collapsed;
                noOptions.Text                    = loader.GetString("no_options");
                subscribeBtnContainer.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
                subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                buyMagContainer.Visibility        = Windows.UI.Xaml.Visibility.Collapsed;
                getSampleContainer.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;

                open.Text = loader.GetString("read");
                openContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                delete.Text = loader.GetString("delete");
                deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;

                if (_item.IsSampleDownloaded)
                {
                    subtitle.Text += " SAMPLE";
                }

                this.Visibility = Windows.UI.Xaml.Visibility.Visible;

                return;
            }

            if (mag.IsSampleDownloaded)
            {
                getSample.Text          = loader.GetString("open_sample");
                getSampleButton.Content = "\xe16f";
            }
            else
            {
                getSample.Text          = loader.GetString("download_sample");
                getSampleButton.Content = "\xe118";
            }

            _item              = mag;
            product_id         = mag.FileName.Replace("_.pdf", "");
            relativePath       = mag.RelativePath;
            licenseInformation = CurrentApp.LicenseInformation;
            IReadOnlyDictionary <string, ProductListing> productListings = null;

            try
            {
                var appListing = await CurrentApp.LoadListingInformationAsync();

                productListings = appListing.ProductListings;
            }
            catch
            {
                subscribeBtnContainer.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
                subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                buyMagContainer.Visibility        = Windows.UI.Xaml.Visibility.Collapsed;
                if (!intern)
                {
                    getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
                else
                {
                    getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                }
                openContainer.Visibility   = Windows.UI.Xaml.Visibility.Collapsed;
                deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                noOptions.Visibility       = Windows.UI.Xaml.Visibility.Visible;
                noOptions.Text             = loader.GetString("no_options");
                this.Visibility            = Windows.UI.Xaml.Visibility.Visible;

                if (needToUpdateImage)
                {
                    var task = LoadImage(mag);
                }

                return;
            }

            ProductListing product = null;

            //statusContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            //buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtnContainer.Visibility  = Windows.UI.Xaml.Visibility.Collapsed;
            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            buyMagContainer.Visibility        = Windows.UI.Xaml.Visibility.Collapsed;
            if (!intern)
            {
                getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                getSampleContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            openContainer.Visibility   = Windows.UI.Xaml.Visibility.Collapsed;
            deleteContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            this.Visibility = Windows.UI.Xaml.Visibility.Visible;

            try
            {
                product = productListings[product_id];
            }
            catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentApp.GetAppReceiptAsync().AsTask();

                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);
                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync(product_id, receipt);

                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl(product_id, receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility       = Windows.UI.Xaml.Visibility.Collapsed;
                            buyMag.Text                = loader.GetString("buy_number") + " " + product.FormattedPrice;
                            buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl(product_id, relativePath, app.ClientName, app.MagazineName);

                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility       = Windows.UI.Xaml.Visibility.Collapsed;
                            buyMag.Text                = loader.GetString("buy_number") + " " + product.FormattedPrice;
                            buyMagContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl(product_id, relativePath, app.ClientName, app.MagazineName);

                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentApp.GetAppReceiptAsync().AsTask();
                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync(product_id, receipt);

                                url = DownloadManager.GetUrl(product_id, receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task          = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task          = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog(loader.GetString("purchase_successfull"));
                        var task          = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            product = null;

            try {
                product = productListings["yearlysubscription"];
            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try {
                        receipt = await CurrentApp.GetAppReceiptAsync().AsTask();

                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);
                    } catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("yearlysubscription", receipt);

                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl("yearlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility             = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn.Text                = loader.GetString("subscribe_one_year") + " " + product.FormattedPrice;
                            subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("yearlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility             = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn.Text                = loader.GetString("subscribe_one_year") + " " + product.FormattedPrice;
                            subscribeBtnContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    //var productLicense1 = licenseInformation.ProductLicenses["Subscription1"];
                    //var longdateTemplate = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longdate");
                    //var text = "Subscription1 expires on: " + longdateTemplate.Format(productLicense1.ExpirationDate);
                    //var remainingDays = (productLicense1.ExpirationDate - DateTime.Now).Days;
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("yearlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try {
                                receipt = await CurrentApp.GetAppReceiptAsync().AsTask();
                            }  catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("yearlysubscription", receipt);

                                url = DownloadManager.GetUrl("yearlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task          = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task          = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog(loader.GetString("purchase_successfull"));
                        var task          = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            product = null;

            try {
                product = productListings["monthlysubscription"];
            } catch { }

            if (product != null)
            {
                if (!licenseInformation.ProductLicenses[product.ProductId].IsActive)
                {
                    string receipt = "";
                    try
                    {
                        receipt = await CurrentApp.GetAppReceiptAsync().AsTask();

                        receipt = DownloadManager.GetProductReceiptFromAppReceipt(product.ProductId, receipt);
                    }
                    catch { }
                    if (receipt != "")
                    {
                        await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);

                        var app = Application.Current as App;
                        var url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn1.Text   = loader.GetString("subscribe_one_month") + " " + product.FormattedPrice;
                            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                    else
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (!url.Equals("NoReceipt"))
                        {
                            Bought(this, url);
                            return;
                        }
                        else
                        {
                            noOptions.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                            subscribeBtn1.Text   = loader.GetString("subscribe_one_month") + " " + product.FormattedPrice;
                            subscribeBtn1Container.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                    }
                }
                else
                {
                    if (Bought != null)
                    {
                        var app = Application.Current as App;
                        var url = await DownloadManager.GetUrl("monthlysubscription", relativePath, app.ClientName, app.MagazineName);

                        if (url.Equals("NoReceipt"))
                        {
                            string receipt = "";
                            try
                            {
                                receipt = await CurrentApp.GetAppReceiptAsync().AsTask();
                            }
                            catch { }
                            if (receipt != "")
                            {
                                await DownloadManager.StoreReceiptAsync("monthlysubscription", receipt);

                                url = DownloadManager.GetUrl("monthlysubscription", receipt, relativePath, app.ClientName, app.MagazineName);
                                if (!url.Equals("NoReceipt"))
                                {
                                    Bought(this, url);
                                    return;
                                }
                                else
                                {
                                    var messageDialog = new MessageDialog("No Receipt");
                                    var task          = messageDialog.ShowAsync().AsTask();
                                }
                            }
                            else
                            {
                                var messageDialog = new MessageDialog("No Receipt");
                                var task          = messageDialog.ShowAsync().AsTask();
                            }
                        }
                        else
                        {
                            Bought(this, url);
                            return;
                        }
                    }
                    else
                    {
                        var messageDialog = new MessageDialog(loader.GetString("purchase_successfull"));
                        var task          = messageDialog.ShowAsync().AsTask();
                    }
                }
            }

            if (buyMagContainer.Visibility == Windows.UI.Xaml.Visibility.Collapsed)
            {
                if (subscribeBtnContainer.Visibility == Windows.UI.Xaml.Visibility.Visible)
                {
                    //subscribeBtnContainer.Margin = new Thickness(0, 22, 0, 10);
                }
                else if (subscribeBtn1Container.Visibility == Windows.UI.Xaml.Visibility.Visible)
                {
                    //subscribeBtn1.Margin = new Thickness(0, 22, 0, 10);
                }
                else
                {
                    noOptions.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    noOptions.Text       = loader.GetString("no_options");
                }
            }

            if (needToUpdateImage)
            {
                await LoadImage(mag);
            }

            //statusContainer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            //buttonContainer.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
Пример #6
0
        private async void frame_Loaded(object sender, RoutedEventArgs e)
        {
            init = true;

            if (!DownloadManager.IsFullScreenAsset(_url))
            {
                this.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                this.VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Top;
                this.Margin = new Thickness(_rect.Left * _offset, (_rect.Top + 1.5) * _offset, 0, 0);
                this.Width  = _rect.Width * _offset;
                this.Height = _rect.Height * _offset;
            }
            else
            {
                this.Width  = _rect.Width;
                this.Height = _rect.Height;
                this.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
                this.VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Center;
                btnFullScreen.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            videoPlayer.Width  = this.Width;
            videoPlayer.Height = this.Height;

            webView.Width  = this.Width;
            webView.Height = this.Height;

            if (DownloadManager.IsLocalAsset(_url))
            {
                StorageFolder folder = null;
                try
                {
                    folder = await StorageFolder.GetFolderFromPathAsync(_folderUrl);
                }
                catch
                {
                    error = true;
                    noAsset.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    if (DownloadManager.IsFullScreenAsset(_url) || DownloadManager.IsAutoPlay(_url))
                    {
                        Start();
                    }
                    return;
                }

                var pos = _url.IndexOf(".mp4");

                StorageFile file = null;
                try
                {
                    var str = folder.Path + "\\" + _url.Substring(0, pos).Replace("http://localhost/", "") + ".mp4";
                    file = await StorageFile.GetFileFromPathAsync(str);

                    var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    var unprotected = await DownloadManager.UnprotectPDFStream(stream);

                    var tmp = await ApplicationData.Current.LocalFolder.CreateFileAsync("tmp.mp4", CreationCollisionOption.ReplaceExisting);

                    using (var tmpStream = await tmp.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await RandomAccessStream.CopyAndCloseAsync(unprotected.GetInputStreamAt(0), tmpStream.GetOutputStreamAt(0));

                        await tmpStream.FlushAsync();
                    }
                    tmp = null;
                    tmp = await ApplicationData.Current.LocalFolder.GetFileAsync("tmp.mp4");

                    stream = await tmp.OpenAsync(FileAccessMode.Read);

                    videoPlayer.SetSource(stream, file.ContentType);

                    if (DownloadManager.IsFullScreenAsset(_url) || DownloadManager.IsAutoPlay(_url))
                    {
                        Start();
                    }
                }
                catch (Exception)
                {
                    error = true;
                    noAsset.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    if (DownloadManager.IsFullScreenAsset(_url) || DownloadManager.IsAutoPlay(_url))
                    {
                        Start();
                    }
                    return;
                }
            }
            else
            {
                Start();
                videoPlayer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                webView.Visibility     = Windows.UI.Xaml.Visibility.Visible;
                webView.Navigate(new Uri(_url));
                HideUI();
            }
        }
Пример #7
0
        public async Task SetRect(Rect rect, string folderUrl, string url, float offset)
        {
            var loader = new ResourceLoader();

            textInfo.Text = loader.GetString("slide_show_inf");
            if (!DownloadManager.IsFullScreenAsset(url))
            {
                this.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                this.VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Top;
                this.Margin = new Thickness(rect.Left * offset, (rect.Top + 1.5) * offset, 0, 0);
                this.Width  = rect.Width * offset;
                this.Height = rect.Height * offset;
            }
            else
            {
                info.Visibility          = Windows.UI.Xaml.Visibility.Visible;
                this.Width               = Window.Current.Bounds.Width;
                this.Height              = Window.Current.Bounds.Height;
                this.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
                this.VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Center;

                enabled    = true;
                fullScreen = true;
            }

            string startMame = null;
            string endName   = null;

            //if (!DownloadManager.IsFullScreenAsset(url))
            //{
            //    images.Add(new ImageData() { Image = null, Width = this.Width, Height = this.Height });
            //}

            StorageFolder folder = null;

            try
            {
                folder = await StorageFolder.GetFolderFromPathAsync(folderUrl);

                int start = 0;
                int end   = 0;
                if (url.Contains(".jpg"))
                {
                    start = url.IndexOf('_');
                    end   = url.IndexOf(".jpg");

                    startMame = url.Substring(0, start + 1);
                    startMame = startMame.Replace("http://localhost/", "");
                    endName   = ".jpg";
                }
                else if (url.Contains(".png"))
                {
                    start = url.IndexOf('_');
                    end   = url.IndexOf(".png");

                    startMame = url.Substring(0, start + 1);
                    endName   = ".png";
                }

                if (start == -1 || end == -1)
                {
                    throw new Exception();
                }

                var test = url.Substring(start + 1, end - start);
                length = Convert.ToInt32(url.Substring(start + 1, end - start - 1));
            }
            catch
            {
                //if (!DownloadManager.IsFullScreenAsset(url))
                //{
                //    images.Add(new ImageData() { Image = null, Width = this.Width, Height = this.Height });
                //}

                for (int p = 0; p < 1; p++)
                {
                    images.Add(new ImageData()
                    {
                        Image = null, NotDownloaded = true, Width = this.Width, Height = this.Height
                    });
                }
                //progressLoad.IsActive = false;
                return;
            }

            var maxWidth  = this.Width;
            var maxHeight = this.Height;

            for (int i = 1; i <= length; i++)
            {
                StorageFile file = null;
                try
                {
                    var str = folder.Path + "\\" + startMame + i + endName;
                    file = await StorageFile.GetFileFromPathAsync(folder.Path + "\\" + startMame + i + endName);

                    using (var stream = await file.OpenAsync(FileAccessMode.Read))
                    {
                        var unprotected = await DownloadManager.UnprotectPDFStream(stream);

                        var bitmap = new BitmapImage();
                        await bitmap.SetSourceAsync(unprotected);

                        if (DownloadManager.IsFullScreenAsset(url))
                        {
                            maxWidth  = maxWidth < bitmap.PixelWidth ? bitmap.PixelWidth : maxWidth;
                            maxHeight = maxHeight < bitmap.PixelHeight ? bitmap.PixelHeight : maxHeight;
                            images.Add(new ImageData()
                            {
                                Image = bitmap, ImgStretch = Stretch.Uniform, Hidden = true, Width = this.Width, Height = this.Height
                            });
                        }
                        else
                        {
                            images.Add(new ImageData()
                            {
                                Image = bitmap, ImgStretch = Stretch.Uniform, Hidden = true, Width = this.Width, Height = this.Height
                            });
                        }
                    }
                }
                catch
                {
                    images.Add(new ImageData()
                    {
                        Image = null, NotDownloaded = true, Width = this.Width, Height = this.Height
                    });
                    //progressLoad.IsActive = false;
                }
            }

            //if (!DownloadManager.IsFullScreenAsset(url))
            //{
            //    images.Add(new ImageData() { Image = null, Width = this.Width, Height = this.Height });
            //}
            //else
            //{
            //if (maxHeight > Window.Current.Bounds.Height)
            //{
            //    maxWidth = maxWidth * (Window.Current.Bounds.Height) / maxHeight;
            //    maxHeight = Window.Current.Bounds.Height;
            //}
            //this.Width = maxWidth;
            //this.Height = maxHeight;
            //foreach (var image in images)
            //{
            //    image.Width = maxWidth;
            //    image.Height = maxHeight;
            //}
            //}
            itemListView.ItemsSource = images;

            if (DownloadManager.IsAutoPlay(url))
            {
                autoSlide = true;

                enabled = true;
            }

            if (DownloadManager.IsNoTransitions(url))
            {
                noTranstions = true;

                enabled = true;
            }

            if (url.Contains("wadelay="))
            {
                var pp = url.IndexOf("wadelay=");
                interval = Convert.ToInt32(url.Substring(pp + 8, 3));
            }

            //progressLoad.IsActive = false;
        }