public void Save()

in Clients/Xamarin.Interactive.Client/Workbook/Models/WorkbookPackage.cs [425:501]


        public void Save (IWorkbookSaveOperation operation)
        {
            var saveOperation = operation as SaveOperation;
            if (saveOperation == null)
                throw new ArgumentNullException (nameof (operation));

            LogicalPath = operation.Destination;
            SaveOptions = WorkbookSaveOptions.None;

            if (IndexPage != null && IndexPage.IsUntitled)
                IndexPage.Title = LogicalPath.NameWithoutExtension;

            if (saveOperation.OnlyPage != null &&
                !saveOperation.OnlyPageHasDependencies &&
                !openedFromDirectory) {
                // The workbook package has only a single page with no relative
                // dependencies. If the original path was a workbook directory,
                // keep that format. If we originally opened from a workbook
                // directory and our target save path is not a directory, keep
                // that format. Otherwise, save the page as a single file.
                var writePath = logicalPath.DirectoryExists
                    ? logicalPath.Combine (saveOperation.OnlyPage.Path)
                    : logicalPath;

                using (var writer = new StreamWriter (writePath))
                    saveOperation.OnlyPage.Write (writer, Packages);

                WorkingPath = logicalPath;
                return;
            }

            var sourceBasePath = WorkingBasePath;

            if (saveOperation.OnlyPage != null)
                saveOperation.OnlyPage.Path = indexPageFileName;

            if (logicalPath.FileExists)
                File.Delete (logicalPath);

            logicalPath.CreateDirectory ();

            if (WorkingPath.DirectoryExists && WorkingPath.Extension == dottedExtension)
                CopyDirectoryContents (WorkingPath, logicalPath);

            foreach (var page in saveOperation.AllDependencies) {
                using (var writer = new StreamWriter (logicalPath.Combine (page.Key.Path)))
                    page.Key.Write (writer, Packages);

                foreach (var dep in page.Value) {
                    var sourcePath = sourceBasePath.Combine (dep);
                    if (!sourcePath.FileExists)
                        continue;

                    // FIXME: if the dep is not a child of the baseSourcePath this
                    // copy will result in the file not being located in the actual
                    // workbook package (e.g. the dep is something like '../foo.jpg').
                    // Adjust the dest path so that it will be copied into the package,
                    // but the workbook content itself will be broken until we can
                    // actually fix this up in the markdown.
                    var destPath = logicalPath.Combine (dep);
                    if (destPath.IsChildOfDirectory (logicalPath) && destPath != sourcePath) {
                        destPath.ParentDirectory.CreateDirectory ();
                        File.Copy (sourcePath, destPath, true);
                    }
                }
            }

            if (saveOperation.Options.HasFlag (WorkbookSaveOptions.Archive))
                ArchiveDirectory (logicalPath);

            // For overwrite saves of archives, WorkingPath should continue
            // to point to the extracted directory in temp
            if (!saveOperation.Options.HasFlag (WorkbookSaveOptions.Archive) ||
                WorkingPath == null ||
                !WorkingPath.Exists)
                WorkingPath = logicalPath;
        }