예제 #1
0
        private async void MenuFlyoutItem_Click_8(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker();
            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

            savePicker.FileTypeChoices.Add("Rich Text", new List <string>()
            {
                ".rtf"
            });

            savePicker.SuggestedFileName = "New Document";

            file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                Windows.Storage.CachedFileManager.DeferUpdates(file);
                randAccStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                flextextwrite.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);


                Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                if (status != Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    Windows.UI.Popups.MessageDialog errorBox =
                        new Windows.UI.Popups.MessageDialog("File " + file.Name + " couldn't be saved.");
                    await errorBox.ShowAsync();
                }
            }
        }
예제 #2
0
        private async void SaveButtonPressed(ChartControlFull sender)
        {
            // if (sender == chartControlOne)
            // {
            // string dataToSave = chartControlOne.getDataString();
            // if (dataToSave == null)
            //{
            //  ShowErrorDialog("Chart returned no data, please try again later.", "No data to save");
            //  return;
            //}

            var savePicker = new Windows.Storage.Pickers.FileSavePicker();

            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Plain Text", new List <string>()
            {
                ".txt"
            });
            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "HeartBeat";

            StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                CachedFileManager.DeferUpdates(file);
                //  await FileIO.WriteTextAsync(file, dataToSave);

                Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);

                if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    ShowErrorDialog("File " + file.Name + " was saved.", "Save to file");
                }
                else
                {
                    ShowErrorDialog("File " + file.Name + " couldn't be saved.", "Save to file");
                }
                //}
            }
        }
예제 #3
0
    private async void SaveFileAsync(string fileName, string pathToSave, string pathToMedia)
    {
        UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
        {
            FileSavePicker savePicker         = new FileSavePicker();
            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Archieved Expert Data with Media", new List <string>()
            {
                ".zip"
            });

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = fileName + ".zip";

            StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                InstructionManager.Instance.Instruction.Name = file.DisplayName;
                InstructionManager.Instance.Save(true, pathToSave);

                ShowWaitingDialog();
                using (Stream zipFileToSave = await file.OpenStreamForWriteAsync())
                {
                    // do export async
                    await Task.Run(() =>
                    {
                        //open acces to zip file
                        //todo: check mode
                        using (ZipArchive archive = new ZipArchive(zipFileToSave, ZipArchiveMode.Update))
                        {
                            archive.CreateEntryFromFile(Path.Combine(pathToSave, InstructionManager.Instance.Instruction.Name + ".save"), InstructionManager.Instance.Instruction.Name + ".save");

                            foreach (var step in InstructionManager.Instance.Instruction.Steps)
                            {
                                foreach (var mediaFile in step.MediaFiles)
                                {
                                    archive.CreateEntryFromFile(Path.Combine(pathToMedia, mediaFile.FileName), @"media\" + mediaFile.FileName);
                                }
                            }
                        }
                    });
                }

                // 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)
                {
                    ExportCompleted?.Invoke(this, true);
                }
                else
                {
                    ExportCompleted?.Invoke(this, false);
                }
            }
            else
            {
                ExportCompleted?.Invoke(this, false);
            }

            ChangeWaitingDialogText();
            //EnableUI();
        }, false);
    }