public void AggregateStatsTest()
        {
            int    PrevCount = DataBaseHelper.GetTotalDownCount();
            string packageId = DateTime.Now.Ticks.ToString();

            PackageHelper.UploadNewPackage(packageId);
            PackageHelper.DownloadPackage(packageId);
            TaskInvocationHelper.InvokeAggregateStatsTask();
            int currentCount = DataBaseHelper.GetTotalDownCount();

            //Instead of increasing by 1, we need to get the count of new rows in package statistics.
            Assert.IsTrue((currentCount == PrevCount + 1), "The total download count did not increase by one after executing the aggregate stats task");
        }
        private async void Download_Click(object sender, RoutedEventArgs e)
        {
            InstallButton.IsEnabled = false;
            var    culture   = CultureInfo.CurrentUICulture;
            string productId = ViewModel.Product.ProductId;

            var dialog = new ProgressDialog()
            {
                Title = ViewModel.Product.Title,
                Body  = "Fetching packages..."
            };

            dialog.ShowAsync();

            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(culture, true));
            await dcathandler.QueryDCATAsync(productId);

            var packs = await dcathandler.GetPackagesForProductAsync();

            string packageFamilyName = dcathandler.ProductListing.Product.Properties.PackageFamilyName;

            dialog.Hide();
            if (packs != null)// && packs.Count > 0)
            {
                var package = PackageHelper.GetLatestDesktopPackage(packs.ToList(), packageFamilyName, ViewModel.Product);
                if (package == null)
                {
                    var noPackagesDialog = new ContentDialog()
                    {
                        Title             = ViewModel.Product.Title,
                        Content           = "No available packages for this product.",
                        PrimaryButtonText = "Ok"
                    };
                    await noPackagesDialog.ShowAsync();

                    return;
                }
                else
                {
                    var file = (await PackageHelper.DownloadPackage(package, ViewModel.Product)).Item1;

                    var toast = PackageHelper.GenerateDownloadSuccessToast(package, ViewModel.Product, file);
                    Windows.UI.Notifications.ToastNotificationManager.GetDefault().CreateToastNotifier().Show(toast);
                }
            }

            InstallButton.IsEnabled = true;
        }
        public void ReplicatePackageStatisticsTaskBasicTest()
        {
            //Create a new DB and create artifacts in it.
            string warehouseDbName = "Warehouse" + DateTime.Now.Ticks.ToString();

            base.CreateAndVerifyNewWareHouseDb(warehouseDbName);
            //Invoke the replicate task initially.
            int count = TaskInvocationHelper.InvokeReplicatePackageStatisticsTask(DataBaseHelper.GetConnectionStringForDataBase(warehouseDbName));
            //upload a new package and download it.
            string packageId = DateTime.Now.Ticks.ToString();

            PackageHelper.UploadNewPackage(packageId);
            PackageHelper.DownloadPackage(packageId);
            //invoke the task again.
            count = TaskInvocationHelper.InvokeReplicatePackageStatisticsTask(DataBaseHelper.GetConnectionStringForDataBase(warehouseDbName));
            //Check that the count of rows replicated is one now.
            //TDB : This might not be one always ( in case if there is some additional download. The test assumes that no one else is using the BVT environment).
            Assert.IsTrue((count == 1), "The count of packages being replicated after downloading one package is not one. Actual count : {1}", count);
        }
        private async void Download_Click(object sender, RoutedEventArgs e)
        {
            InstallButton.IsEnabled = false;

            var gettingPackagesDialog = new ProgressDialog()
            {
                Title = ViewModel.Product.Title,
                Body  = "Fetching packages..."
            };
            await PackageHelper.DownloadPackage(ViewModel.Product,
                                                gettingPackagesCallback : product =>
            {
                gettingPackagesDialog.ShowAsync();
            },
                                                noPackagesCallback : async product =>
            {
                var noPackagesDialog = new ContentDialog()
                {
                    Title             = product.Title,
                    Content           = "No available packages for this product.",
                    PrimaryButtonText = "Ok"
                };
                await noPackagesDialog.ShowAsync();
            },
                                                packagesLoadedCallback : product =>
            {
                gettingPackagesDialog.Hide();
            },
                                                packageDownloadedCallback : async(product, details, file, toast) =>
            {
                var savePicker = new Windows.Storage.Pickers.FileSavePicker();
                savePicker.SuggestedStartLocation =
                    Windows.Storage.Pickers.PickerLocationId.Downloads;
                if (file.FileType.EndsWith("bundle"))
                {
                    savePicker.FileTypeChoices.Add("Windows App Bundle", new string[] { file.FileType });
                }
                else
                {
                    savePicker.FileTypeChoices.Add("Windows App Package", new string[] { file.FileType });
                }
                savePicker.SuggestedFileName = file.DisplayName;
                savePicker.SuggestedSaveFile = file;
                var userFile = await savePicker.PickSaveFileAsync();
                if (userFile != null)
                {
                    await file.MoveAndReplaceAsync(userFile);
                }
            });

            InstallButton.IsEnabled = true;
            return;

            var    culture   = CultureInfo.CurrentUICulture;
            string productId = ViewModel.Product.ProductId;



            DisplayCatalogHandler dcathandler = new DisplayCatalogHandler(DCatEndpoint.Production, new Locale(culture, true));
            await dcathandler.QueryDCATAsync(productId);

            var packs = await dcathandler.GetMainPackagesForProductAsync();

            string packageFamilyName = dcathandler.ProductListing.Product.Properties.PackageFamilyName;

            gettingPackagesDialog.Hide();
            if (packs != null)// && packs.Count > 0)
            {
                var package = PackageHelper.GetLatestDesktopPackage(packs.ToList(), packageFamilyName, ViewModel.Product);
                if (package == null)
                {
                    return;
                }
                else
                {
                    var file = (await PackageHelper.DownloadPackage(package, ViewModel.Product)).Item1;

                    var toast = PackageHelper.GenerateDownloadSuccessToast(package, ViewModel.Product, file);
                    Windows.UI.Notifications.ToastNotificationManager.GetDefault().CreateToastNotifier().Show(toast);
                }
            }

            InstallButton.IsEnabled = true;
        }