/// <inheritdoc /> public async Task ExecuteUserActionAsync() { // Create a json array object JArray jsonArray = new JArray(); // Use the visitor pattern to create a json array object ShapeList.ForEach(paintBase => { paintBase.Accept(new WriteFileVisitor(jsonArray)); }); // Convert jsonarray object to string string shapeListJson = jsonArray.ToString(); // Get save location from user FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; savePicker.FileTypeChoices.Add("JSON File", new List <string>() { ".json" }); StorageFile file = await savePicker.PickSaveFileAsync(); if (file != null) { // Try to write file to the disk CachedFileManager.DeferUpdates(file); await FileIO.WriteTextAsync(file, shapeListJson); // Give dialog dependent on success FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file); if (status == FileUpdateStatus.Complete) { ContentDialog dialog = new ContentDialog() { Title = "File save success", Content = "The file was saved successfully", CloseButtonText = "Ok" }; await dialog.ShowAsync(); } else { ContentDialog dialog = new ContentDialog() { Title = "File save failed", Content = "An error occured while trying to save the file", CloseButtonText = "Close" }; await dialog.ShowAsync(); } } else { ContentDialog dialog = new ContentDialog() { Title = "File save failed", Content = "An error occured while trying to save the file", CloseButtonText = "Close" }; await dialog.ShowAsync(); } }
public void DrawShapesInto(ShapeList shapes, TextWriter writer) => shapes.ForEach(s => DrawShapeInto(s, writer));