public async void Save(BoardViewModel boardViewModel)
{
if (!EnsureUnsnapped())
return;
if (boardViewModel == null)
boardViewModel = ActiveBoard;
var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary };
// Dropdown of file types the user can save the file as
savePicker.FileTypeChoices.Add("LiveBoard file", new List<string>() { ".lvbd" });
// Default file name if the user does not type one in or select a file to replace
savePicker.SuggestedFileName = BoardViewModel.CreateNewFilename();
savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
StorageFile file = await savePicker.PickSaveFileAsync();
if (file == null)
{
PopupMessage = "Operation cancelled.";
}
else
{
// Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
CachedFileManager.DeferUpdates(file);
// write to file
String content = boardViewModel.Board.ToXml().ToString();
await FileIO.WriteTextAsync(file, content, UnicodeEncoding.Utf8);
// 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.
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
StorageApplicationPermissions.MostRecentlyUsedList.Add(file, file.Path);
// TODO: 완료 팝업. 아직 안함.
if (status == FileUpdateStatus.Complete)
{
PopupMessage = "File " + file.Name + " was saved.";
}
else
{
PopupMessage = "File " + file.Name + " couldn't be saved.";
}
}
}