예제 #1
0
        public static SaveAsDialog CreateFolderDialog(bool showSfaCheckbox)
        {
            var result = new SaveAsDialog();

            result.dlg = new CommonOpenFileDialog();
            if (showSfaCheckbox)
            {
                result.AddSfaCheckbox();
            }
            (result.dlg as CommonOpenFileDialog).IsFolderPicker = true;

            return(result);
        }
예제 #2
0
        public static SaveAsDialog CreateFileDialog(bool showSfaCheckbox, string defaultFileName, bool allowPbit)
        {
            var result = new SaveAsDialog();

            result.dlg = new CommonSaveFileDialog();
            if (showSfaCheckbox)
            {
                result.AddSfaCheckbox();
            }
            result.dlg.DefaultFileName = defaultFileName;
            result.dlg.Filters.Clear();
            if (allowPbit)
            {
                result.dlg.Filters.Add(new CommonFileDialogFilter("Power BI Template", "*.pbit"));
            }
            result.dlg.Filters.Add(new CommonFileDialogFilter("Tabular Model Files", "*.bim"));
            result.dlg.Filters.Add(new CommonFileDialogFilter("All files", "*.*"));

            return(result);
        }
예제 #3
0
        public void File_SaveAs_ToFolder()
        {
            ExpressionEditor_AcceptEdit();

            // Save as a Folder structure:
            var saveFormat = SaveFormat.TabularEditorFolder;

            // This flag indicates whether we're currently connected to a database:
            var connectedToDatabase = Handler.SourceType == ModelSourceType.Database;

            // This flag indicates whether the "Current File" pointer should be set to the new file location, which
            // is the typical behaviour of Windows applications when choosing "Save As...". However, when connected
            // to a database, we do not want to do this, as users will probably want to keep working on the existing
            // connection.
            var changeFilePointer = !connectedToDatabase;

            // This flag indicates whether we should reset the undo-checkpoint after saving the model.
            // The purpose of resetting the checkpoint is to visually indicate to the user, that no
            // changes have been made to the model since the last save. We do this, only when changing
            // the "Current File" pointer:
            var resetCheckPoint = changeFilePointer;

            // This flag indicates whether the SerializationOptions annotations on the currently loaded
            // model will be restored to its original value, after the model is saved (possibly using
            // different serialization options, depending on the other arguments of the Save() method).
            // We should always restore when connected to a database, as we don't want our serialization
            // options to be saved to the database - only to the file/folder that we're currently saving to.
            var restoreSerializationOptions = connectedToDatabase;

            // The serialization options to use when saving (unless users check the "Use serialization settings from annotations" checkbox):
            var serializationOptions = Preferences.Current.GetSerializeOptions(LocalInstance?.Type == LocalInstanceType.PowerBI ? LocalInstance.Name : null);

            // Only show the "Use serialize options from annotations" checkbox when the current model has these annotations:
            var showSfa = Handler.HasSerializeOptions;

            using (var dialog = SaveAsDialog.CreateFolderDialog(showSfa))
            {
                var res = dialog.ShowDialog();
                if (res == CommonFileDialogResult.Ok && !string.IsNullOrWhiteSpace(dialog.FileName))
                {
                    using (new Hourglass())
                    {
                        UI.StatusLabel.Text = "Saving...";

                        try
                        {
                            Handler.Save(dialog.FileName,
                                         saveFormat,
                                         serializationOptions,
                                         dialog.UseSerializationFromAnnotations,
                                         resetCheckPoint,
                                         restoreSerializationOptions);

                            RecentFiles.Add(dialog.FileName);
                            RecentFiles.Save();
                            UI.FormMain.PopulateRecentFilesList();

                            // If working with a file, change the current file pointer:
                            if (changeFilePointer)
                            {
                                File_SaveMode  = ModelSourceType.Folder;
                                File_Current   = dialog.FileName;
                                File_Directory = FileSystemHelper.DirectoryFromPath(File_Current);
                                File_LastWrite = GetLastDirChange(File_Current);
                            }
                        }
                        catch (Exception e)
                        {
                            HandleError("Could not save metadata to folder", e);
                        }
                        UpdateUIText();
                    }
                }
            }
        }
예제 #4
0
        public void File_SaveAs()
        {
            ExpressionEditor_AcceptEdit();

            // Only show the "Use serialize options from annotations" checkbox when the current model has these annotations,
            // and not when switching between file/folder:
            var showSfa = Handler.HasSerializeOptions;

            // If the model is currently loaded from a database or a folder structure, use the default "Model.bim" as a file
            // name. Otherwise, use the name of the current file:
            var defaultFileName = (Handler.SourceType == ModelSourceType.Database || Handler.SourceType == ModelSourceType.Folder) ? "Model.bim" : File_Current;

            // We only allow saving as a Power BI Template, if the current model was loaded from a template:
            var allowPbit = Handler.SourceType == ModelSourceType.Pbit;

            // This flag indicates whether we're currently connected to a database:
            var connectedToDatabase = Handler.SourceType == ModelSourceType.Database;

            // This flag indicates whether the "Current File" pointer should be set to the new file location, which
            // is the typical behaviour of Windows applications when choosing "Save As...". However, when connected
            // to a database, we do not want to do this, as users will probably want to keep working on the existing
            // connection.
            var changeFilePointer = !connectedToDatabase;

            // This flag indicates whether we should reset the undo-checkpoint after saving the model.
            // The purpose of resetting the checkpoint is to visually indicate to the user, that no
            // changes have been made to the model since the last save. We do this, only when changing
            // the "Current File" pointer:
            var resetCheckPoint = changeFilePointer;

            // This flag indicates whether the SerializationOptions annotations on the currently loaded
            // model will be restored to its original value, after the model is saved (possibly using
            // different serialization options, depending on the other arguments of the Save() method).
            // We should always restore when connected to a database, as we don't want our serialization
            // options to be saved to the database - only to the file/folder that we're currently saving to.
            var restoreSerializationOptions = connectedToDatabase;

            // The serialization options to use when saving (unless users check the "Use serialization settings from annotations" checkbox):
            var serializationOptions = Preferences.Current.GetSerializeOptions(LocalInstance?.Type == LocalInstanceType.PowerBI ? LocalInstance.Name : null);

            using (var dialog = SaveAsDialog.CreateFileDialog(showSfa, defaultFileName, allowPbit))
            {
                var res = dialog.ShowDialog();

                if (res == CommonFileDialogResult.Ok && !string.IsNullOrWhiteSpace(dialog.FileName))
                {
                    using (new Hourglass())
                    {
                        UI.StatusLabel.Text = "Saving...";

                        // Save as a Power BI Template, if that's the type of file chosen in the dialog:
                        var saveFormat = dialog.FileType == "pbit" ? SaveFormat.PowerBiTemplate : SaveFormat.ModelSchemaOnly;

                        var fileName = dialog.FileName;
                        if (dialog.FileType == "pbit" && !fileName.EndsWith(".pbit"))
                        {
                            fileName += ".pbit";
                        }
                        else if (dialog.FileType == "bim" && !fileName.EndsWith(".bim"))
                        {
                            fileName += ".bim";
                        }

                        try
                        {
                            Handler.Save(fileName,
                                         saveFormat,
                                         serializationOptions,
                                         dialog.UseSerializationFromAnnotations,
                                         resetCheckPoint,
                                         restoreSerializationOptions);

                            RecentFiles.Add(fileName);
                            RecentFiles.Save();
                            UI.FormMain.PopulateRecentFilesList();

                            // If not connected to a database, change the current working file:
                            if (changeFilePointer)
                            {
                                File_Current   = fileName;
                                File_Directory = FileSystemHelper.DirectoryFromPath(File_Current);
                                File_LastWrite = File.GetLastWriteTime(File_Current);
                                File_SaveMode  = dialog.FileType == "pbit" ? ModelSourceType.Pbit : ModelSourceType.File;
                            }
                        }
                        catch (Exception e)
                        {
                            HandleError("Could not save metadata to file", e);
                        }

                        UpdateUIText();
                    }
                }
            }
        }