예제 #1
0
        private List <AppData> getAppDatas()
        {
            List <AppData> list = new List <AppData>();

            foreach (CompactAppData c in backup.Apps)
            {
                AppData data = AppDataExtension.FindAppData(c.FamilyName);
                if (data != null)
                {
                    list.Add(data);
                }
            }
            return(list);
        }
예제 #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            displayRequest = new DisplayRequest();
            displayRequest.RequestActive();

            var message = Newtonsoft.Json.JsonConvert.DeserializeObject <BackupProgressMessage>(e.Parameter.ToString());

            if (message.IsRestore)
            {
                HeaderText.Visibility      = Visibility.Collapsed;
                HeaderText2.Visibility     = Visibility.Visible;
                WarningMessage.Visibility  = Visibility.Collapsed;
                WarningMessage2.Visibility = Visibility.Visible;

                List <CompactAppData> skipApps = new List <CompactAppData>();

                try
                {
                    backup = message.backup;

                    ((App)App.Current).BackRequested += BackupProgress_BackRequested;
                    backupManager.BackupProgress     += BackupManager_BackupProgress;

                    LogsView.ItemsSource = log;

                    string notAvailableNames = "";
                    foreach (var item in backup.Apps)
                    {
                        if (LoadAppData.appsData.Count(x => x.FamilyName == item.FamilyName) == 0)
                        {
                            skipApps.Add(item);
                            if (notAvailableNames.Length > 0)
                            {
                                notAvailableNames += "\r\n";
                            }
                            notAvailableNames += item.DisplayName;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageDialog md = new MessageDialog("1" + ex.Message);
                    await md.ShowAsync();
                }

                try
                {
                    foreach (var item in backup.Apps)
                    {
                        if (!skipApps.Contains(item))
                        {
                            AppData appd = AppDataExtension.FindAppData(item.FamilyName);
                            if (appd.PackageId != item.PackageId)
                            {
                                MessageDialog md = new MessageDialog("Current installed version doesn't match the version backup was created from.\r\n\r\n" +
                                                                     "Current installed version: " + appd.PackageId + "\r\n\r\n" +
                                                                     "Backup: " + item.PackageId + "\r\n\r\n\r\n" +
                                                                     "Do you want to restore this app?",
                                                                     appd.DisplayName + ": Version mismatch");
                                md.Commands.Add(new UICommand("Restore")
                                {
                                    Id = 1
                                });
                                md.Commands.Add(new UICommand("Don't restore")
                                {
                                    Id = 0
                                });
                                md.DefaultCommandIndex = 1;
                                md.CancelCommandIndex  = 0;

                                var result = await md.ShowAsync();

                                if (((int)result.Id) == 0)
                                {
                                    skipApps.Add(item);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageDialog md = new MessageDialog("2" + ex.Message);
                    await md.ShowAsync();
                }

                try
                {
                    cleanedCount   = -1;
                    totalAppsCount = backup.Apps.Count;
                }
                catch (Exception ex)
                {
                    MessageDialog md = new MessageDialog("3" + ex.Message);
                    await md.ShowAsync();
                }

                await backupManager.Restore(backup, skipApps);

                progressBar1.Value         = 100.0;
                messageTextBlock.Text      = "Restore completed.";
                HeaderText2.Text           = "DONE";
                WarningMessage2.Visibility = Visibility.Collapsed;
                FinalMessage.Visibility    = Visibility.Visible;
                progressRing.IsActive      = false;
                progressRing.Visibility    = Visibility.Collapsed;
            }
            else
            {
                backup = message.backup;

                ((App)App.Current).BackRequested += BackupProgress_BackRequested;
                backupManager.BackupProgress     += BackupManager_BackupProgress;

                LogsView.ItemsSource = log;

                List <AppData> appDatas = (from CompactAppData c in backup.Apps
                                           select AppDataExtension.FindAppData(c.FamilyName)).ToList();

                await backupManager.CreateBackup(appDatas, backup.Name);

                progressBar1.Value        = 100.0;
                messageTextBlock.Text     = "Backup completed.";
                HeaderText.Text           = "DONE";
                WarningMessage.Visibility = Visibility.Collapsed;
                FinalMessage.Visibility   = Visibility.Visible;
                progressRing.IsActive     = false;
                progressRing.Visibility   = Visibility.Collapsed;
            }

            ((App)App.Current).BackRequested -= BackupProgress_BackRequested;
            displayRequest.RequestRelease();
        }