コード例 #1
0
        public async Task BeforeTest()
        {
            await WinIsolatedStorage.DeleteAsync("2day.db");

            CreateWorkbook(out this.persistence, out this.workbook);
            this.workbook.RemoveAll();
            this.persistence.Save();

            this.workbook.AddFolder("f1");
            this.workbook.AddContext("c1");
            this.persistence.Save();

            CreateWorkbook(out this.backgroundPersistence, out this.backgroundWorkbook);
            if (Ioc.HasType <ISynchronizationManager>())
            {
                Ioc.RemoveInstance <ISynchronizationManager>();
            }

            var trackingManager = new TestTrackingManager();
            var syncManager     = new SynchronizationManager(new TestPlatformService(), trackingManager, "test", false);

            Ioc.RegisterInstance <ISynchronizationManager, SynchronizationManager>(syncManager);

            this.manager = new BackgroundSynchronizationManager(this.workbook, trackingManager, (s) => { });
        }
コード例 #2
0
        public async Task CreateBackupAsync()
        {
            this.trackingManager.TagEvent("Create backup start", new Dictionary <string, string>());

            try
            {
                var localFolder = ApplicationData.Current.LocalFolder;

                // get file pointer to database and sync metadata
                var dbFile = await localFolder.CreateFileAsync(this.persistenceLayer.DatabaseFilename, CreationCollisionOption.OpenIfExists);

                var syncMetadataFile = await localFolder.CreateFileAsync(SynchronizationMetadata.Filename, CreationCollisionOption.OpenIfExists);

                // create backup folder where we'll zip appropriate files
                await WinIsolatedStorage.DeleteFolderAsync(BackupFolderName);

                await WinIsolatedStorage.DeleteAsync(BackupFileName);

                var backupFolder = await localFolder.CreateFolderAsync(BackupFolderName, CreationCollisionOption.OpenIfExists);

                // copy database and sync metadata
                await dbFile.CopyAsync(backupFolder, this.persistenceLayer.DatabaseFilename, NameCollisionOption.ReplaceExisting);

                await syncMetadataFile.CopyAsync(backupFolder, SynchronizationMetadata.Filename, NameCollisionOption.ReplaceExisting);

                // save all settings in a json file
                var settings    = new Dictionary <string, object>();
                var settingKeys = typeof(CoreSettings).GetFields(BindingFlags.Static | BindingFlags.Public).Select(p => p.Name).ToList();
                foreach (string settingKey in settingKeys)
                {
                    object settingValue = ApplicationData.Current.LocalSettings.Values[settingKey];
                    if (settingValue != null)
                    {
                        settings.Add(settingKey, settingValue);
                    }
                }
                string jsonSettings = JsonConvert.SerializeObject(settings);
                var    settingsFile = await backupFolder.CreateFileAsync(BackupSettingsFileName, CreationCollisionOption.ReplaceExisting);

                await WinIsolatedStorage.WriteTextInFileAsync(settingsFile, jsonSettings);

                // zip the backup folder
                ZipFile.CreateFromDirectory(backupFolder.Path, Path.Combine(localFolder.Path, BackupFileName));

                // let users pick a place where to save the backup
                var picker = new FileSavePicker();
                picker.FileTypeChoices.Add("2Day Backup", new List <string> {
                    BackupFileExtension
                });

                var backupFile = await picker.PickSaveFileAsync();

                if (backupFile == null)
                {
                    return;
                }

                // copy the newly created zip file to the user location
                var savedBackupFile = await localFolder.CreateFileAsync(BackupFileName, CreationCollisionOption.OpenIfExists);

                await savedBackupFile.CopyAndReplaceAsync(backupFile);

                this.trackingManager.TagEvent("Create backup success", new Dictionary <string, string>());
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, "CreateBackupAsync");
                this.trackingManager.TagEvent("Create backup exception", new Dictionary <string, string> {
                    { "exception", ex.GetType().Name }
                });

                await this.messageBoxService.ShowAsync(StringResources.General_LabelError, ex.Message);
            }
        }
コード例 #3
0
        public async Task DeleteAsync(string filename)
        {
            await WinIsolatedStorage.DeleteAsync(filename);

            await WinIsolatedStorage.AppendTextAsync(filename, string.Empty);
        }