예제 #1
0
        internal static async Task SaveAppStateToUserDefinedLocation(AppState appState)
        {
            var savePicker = new Windows.Storage.Pickers.FileSavePicker();

            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            savePicker.FileTypeChoices.Add("Plain Text", new List <string>()
            {
                ".xml"
            });
            savePicker.SuggestedFileName = "HomeAutomationSettings";

            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                var token = StorageApplicationPermissions.FutureAccessList.Add(file, _userDefinedSettingsToken);
                LocalSettings.Values[_userDefinedSettingsToken] = token;

                // Prevent updates to the remote version of the file until
                // we finish making changes and call CompleteUpdatesAsync.
                //Windows.Storage.CachedFileManager.DeferUpdates(file);  crashes when used with dropbox
                // write to file
                await XMLStorage.SaveObjectToXmlByFile(appState, file);

                // Let Windows know that we're finished changing the file so
                // the other app can update the remote version of the file.
                // Completing updates may require Windows to ask for user input.
                Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    Debug.WriteLine("File " + file.Name + " was saved.");
                }
                else
                {
                    Debug.WriteLine("File " + file.Name + " couldn't be saved.");
                }
            }
            else
            {
                Debug.WriteLine("Saving file was cancelled.");
            }
        }
예제 #2
0
        public static async Task StoreAppState(AppState state)
        {
            var configFile = await TryLoadConfigFile();

            await XMLStorage.SaveObjectToXmlByFile(state, configFile);
        }