Пример #1
0
        /// <summary>
        /// Loads an Analysis Services tabular database (Compatibility Level 1200 or newer) from a file
        /// or folder.
        /// </summary>
        /// <param name="path"></param>
        public TabularModelHandler(string path, TabularModelHandlerSettings settings = null)
        {
            _disableUpdates = true;

            Singleton = this;
            Settings  = settings ?? TabularModelHandlerSettings.Default;

            var file = new FileInfo(path);

            // If the file extension is .pbit, assume Power BI template:
            if (file.Exists && file.Extension.EqualsI(".pbit"))
            {
                LoadPowerBiTemplateFile(path);
            }

            // If the file name is "database.json" or path is a directory, assume Split Model:
            else if ((file.Exists && file.Name.EqualsI("database.json")) || Directory.Exists(path))
            {
                LoadSplitModelFiles(path);
            }

            // In any other case, assume this is just a regular Model.bim file:
            else
            {
                LoadModelFile(path);
            }

            Model.ClearTabularEditorAnnotations();
            _disableUpdates = false;

            UndoManager.Enabled = true;
        }
        /// <summary>
        /// Loads an Analysis Services tabular database (Compatibility Level 1200 or newer) from a file
        /// or folder.
        /// </summary>
        /// <param name="path"></param>
        public TabularModelHandler(string path, TabularModelHandlerSettings settings = null) : this(settings)
        {
            _disableUpdates = true;

            var file = new FileInfo(path);

            // If the file extension is .pbit, assume Power BI template:
            if (file.Exists && file.Extension.EqualsI(".pbit"))
            {
                LoadPowerBiTemplateFile(path);
            }

            // If the file name is "database.json" or path is a directory, assume Split Model:
            else if ((file.Exists && file.Name.EqualsI("database.json")) || Directory.Exists(path))
            {
                LoadSplitModelFiles(path);
            }

            // In any other case, assume this is just a regular Model.bim file:
            else
            {
                LoadModelFile(path);
            }

            UndoManager.Suspend();
            Model.ClearTabularEditorAnnotations();
            _disableUpdates = false;

            UndoManager.Resume();
            PowerBIGovernance.UpdateGovernanceMode();
        }
Пример #3
0
        /// <summary>
        /// Creates a new blank Tabular Model
        /// </summary>
        public TabularModelHandler(int compatibilityLevel = 1200, TabularModelHandlerSettings settings = null, bool pbiDatasetModel = false)
        {
            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = null;

            database = new TOM.Database("SemanticModel")
            {
                CompatibilityLevel = compatibilityLevel,
                CompatibilityMode  = pbiDatasetModel ? Microsoft.AnalysisServices.CompatibilityMode.PowerBI : Microsoft.AnalysisServices.CompatibilityMode.AnalysisServices
            };
            CompatibilityLevel = compatibilityLevel;
            database.Model     = new TOM.Model();
            if (pbiDatasetModel)
            {
                database.Model.DefaultPowerBIDataSourceVersion = TOM.PowerBIDataSourceVersion.PowerBI_V3;
            }

            SourceType = ModelSourceType.File;
            Source     = "Model.bim";

            Status = "Succesfully created new model.";
            Init();

            UndoManager.Enabled = true;
            PowerBIGovernance.UpdateGovernanceMode(this);
        }
        /// <summary>
        /// Connects to a SQL Server 2016 Analysis Services instance and loads a tabular model
        /// from one of the deployed databases on the instance.
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="databaseName"></param>
        public TabularModelHandler(string serverName, string databaseName, TabularModelHandlerSettings settings = null)
        {
            this.serverName = serverName;
            _disableUpdates = true;

            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = new TOM.Server();

            var connectionString = TabularConnection.GetConnectionString(serverName, applicationName);

            server.Connect(connectionString);

            if (databaseName == null)
            {
                if (server.Databases.Count >= 1)
                {
                    database = server.Databases[0];
                }
                else
                {
                    throw new InvalidOperationException("This instance does not contain any databases, or the user does not have access.");
                }
            }
            else
            {
                database = server.Databases.GetByName(databaseName);
            }
            if (CompatibilityLevel < 1200)
            {
                throw new InvalidOperationException("Only databases with Compatibility Level 1200 or higher can be loaded in Tabular Editor.");
            }

            SourceType = ModelSourceType.Database;
            Source     = database.Server.Name + "." + database.Name;

            Status  = "Connected succesfully.";
            Version = database.Version;
            Init();

            Model.ClearTabularEditorAnnotations();

            _disableUpdates     = false;
            UndoManager.Enabled = true;
            PowerBIGovernance.UpdateGovernanceMode(this);
            CheckErrors();

            trace = new ExternalChangeTrace(database, applicationName, XEventCallback);
            if (Settings.ChangeDetectionLocalServers)
            {
                trace.Start();
            }
        }
Пример #5
0
        /// <summary>
        /// Connects to a SQL Server 2016 Analysis Services instance and loads a tabular model
        /// from one of the deployed databases on the instance.
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="databaseId"></param>
        public TabularModelHandler(string serverName, string databaseId, TabularModelHandlerSettings settings = null)
        {
            this.serverName = serverName;
            _disableUpdates = true;

            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = new TOM.Server();
            server.Connect(serverName);

            if (databaseId == null)
            {
                if (server.Databases.Count >= 1)
                {
                    database = server.Databases[0];
                }
                else
                {
                    throw new InvalidOperationException("This instance does not contain any databases, or the user does not have access.");
                }
            }
            else
            {
                database = server.Databases[databaseId];
            }
            database.RemoveTabularEditorTag();
            CompatibilityLevel = database.CompatibilityLevel;

            if (CompatibilityLevel < 1200)
            {
                throw new InvalidOperationException("Only databases with Compatibility Level 1200 or higher can be loaded in Tabular Editor.");
            }

            SourceType = ModelSourceType.Database;
            Source     = database.Server.Name + "." + database.Name;

            Status  = "Connected succesfully.";
            Version = database.Version;
            Init();

            Model.ClearTabularEditorAnnotations();

            _disableUpdates     = false;
            UndoManager.Enabled = true;
            PowerBIGovernance.UpdateGovernanceMode(this);
        }
        /// <summary>
        /// Creates a new blank Tabular Model
        /// </summary>
        public TabularModelHandler(int compatibilityLevel = 1200, TabularModelHandlerSettings settings = null)
        {
            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = null;

            database = new TOM.Database("New Tabular Database")
            {
                CompatibilityLevel = compatibilityLevel
            };
            CompatibilityLevel = compatibilityLevel;
            database.Model     = new TOM.Model();

            SourceType = ModelSourceType.File;
            Source     = "Model.bim";

            Status = "Succesfully created new model.";
            Init();
        }
Пример #7
0
        /// <summary>
        /// Creates a new blank Tabular Model
        /// </summary>
        public TabularModelHandler(int compatibilityLevel = 1200, TabularModelHandlerSettings settings = null)
        {
            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = null;

            database = new TOM.Database("SemanticModel")
            {
                CompatibilityLevel = compatibilityLevel
            };
            CompatibilityLevel = compatibilityLevel;
            database.Model     = new TOM.Model();

            SourceType = ModelSourceType.File;
            Source     = "Model.bim";

            Status = "Succesfully created new model.";
            Init();

            UndoManager.Enabled = true;
            PowerBIGovernance.UpdateGovernanceMode(this);
        }
        /// <summary>
        /// Connects to a SQL Server 2016 Analysis Services instance and loads a tabular model
        /// from one of the deployed databases on the instance.
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="databaseId"></param>
        public TabularModelHandler(string serverName, string databaseId, TabularModelHandlerSettings settings = null)
        {
            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = new TOM.Server();
            server.Connect(serverName);

            if (databaseId == null)
            {
                if (server.Databases.Count >= 1)
                {
                    database = server.Databases[0];
                }
                else
                {
                    throw new InvalidOperationException("This instance does not contain any databases, or the user does not have access.");
                }
            }
            else
            {
                database = server.Databases[databaseId];
            }
            CompatibilityLevel = database.CompatibilityLevel;

            if (CompatibilityLevel < 1200)
            {
                throw new InvalidOperationException("Only databases with Compatibility Level 1200 or higher can be loaded in Tabular Editor.");
            }

            SourceType = ModelSourceType.Database;
            Source     = database.Server.Name + "." + database.Name;

            Status  = "Connected succesfully.";
            Version = database.Version;
            Init();
        }
Пример #9
0
        /// <summary>
        /// Connects to a SQL Server 2016 Analysis Services instance and loads a tabular model
        /// from one of the deployed databases on the instance.
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="databaseName"></param>
        public TabularModelHandler(string serverName, string databaseName, TabularModelHandlerSettings settings = null) : this(settings)
        {
            this.serverName = serverName;
            _disableUpdates = true;

            server = new TOM.Server();

            var connectionString = TabularConnection.GetConnectionString(serverName, applicationName);
            server.Connect(connectionString);

            if (string.IsNullOrEmpty(databaseName))
            {
                if (server.Databases.Count >= 1)
                {
                    database = server.Databases[0];
                }
                else
                {
                    throw new InvalidOperationException("This instance does not contain any databases, or the user does not have access.");
                }
            }
            else
            {
                database = server.Databases.FindByName(databaseName);
                if (database == null)
                {
                    database = server.Databases[databaseName];
                }
            }
            if (CompatibilityLevel < 1200)
            {
                throw new InvalidOperationException("Only databases with Compatibility Level 1200 or higher can be loaded in Tabular Editor.");
            }

            SourceType = ModelSourceType.Database;
            Source     = database.Server.Name + "." + database.Name;

            Status  = "Connected successfully.";
            Version = database.Version;
            Init();
            UndoManager.Suspend();

            Model.ClearTabularEditorAnnotations();

            _disableUpdates = false;
            UndoManager.Resume();
            PowerBIGovernance.UpdateGovernanceMode();
            CheckErrors();

            try
            {
                ExternalChangeTrace.Cleanup();
                trace = new ExternalChangeTrace(database, applicationName, XEventCallback);
                if (Settings.ChangeDetectionLocalServers)
                {
                    trace.Start();
                }
            }
            catch (Exception ex)
            {
                Log("Exception while configuring AS trace: " + ex.Message);
            }
        }
Пример #10
0
 private TabularModelHandler(TabularModelHandlerSettings settings)
 {
     this.PowerBIGovernance = new PowerBIGovernance(this);
     Settings  = settings ?? TabularModelHandlerSettings.Default;
     Singleton = this;
 }
        /// <summary>
        /// Loads an Analysis Services tabular database (Compatibility Level 1200 or newer) from a file
        /// or folder.
        /// </summary>
        /// <param name="path"></param>
        public TabularModelHandler(string path, TabularModelHandlerSettings settings = null)
        {
            Settings = settings ?? TabularModelHandlerSettings.Default;

            Singleton = this;
            server    = null;

            var    fi = new FileInfo(path);
            string data;

            if (fi.Exists && fi.Extension == ".pbit")
            {
                pbit       = new PowerBiTemplate(path);
                data       = pbit.ModelJson;
                SourceType = ModelSourceType.Pbit;
                Source     = path;
            }
            else

            if (!fi.Exists || fi.Name == "database.json")
            {
                if (fi.Name == "database.json")
                {
                    path = fi.DirectoryName;
                }

                if (Directory.Exists(path))
                {
                    data = CombineFolderJson(path);
                }
                else
                {
                    throw new FileNotFoundException();
                }

                SourceType = ModelSourceType.Folder;
                Source     = path;
            }
            else
            {
                data       = File.ReadAllText(path);
                SourceType = ModelSourceType.File;
                Source     = path;
            }
            database           = TOM.JsonSerializer.DeserializeDatabase(data);
            CompatibilityLevel = database.CompatibilityLevel;

            Status = "File loaded succesfully.";
            Init();

            var serializeOptionsAnnotation = Model.GetAnnotation("TabularEditor_SerializeOptions");

            if (serializeOptionsAnnotation != null)
            {
                SerializeOptions = JsonConvert.DeserializeObject <SerializeOptions>(serializeOptionsAnnotation);
            }

            // Check if translations / perspectives are stored locally in the model:
            if (SourceType == ModelSourceType.Folder && (SerializeOptions.LocalTranslations || SerializeOptions.LocalPerspectives))
            {
                UndoManager.Enabled = false;
                BeginUpdate("Apply translations and perspectives from annotations");

                var translationsJson = Model.GetAnnotation("TabularEditor_Cultures");
                if (SerializeOptions.LocalTranslations && translationsJson != null)
                {
                    Model.Cultures.FromJson(translationsJson);

                    foreach (var item in AllTranslatableObjects)
                    {
                        item.LoadTranslations();
                    }
                }

                var perspectivesJson = Model.GetAnnotation("TabularEditor_Perspectives");
                if (SerializeOptions.LocalPerspectives && perspectivesJson != null)
                {
                    Model.Perspectives.FromJson(perspectivesJson);

                    foreach (var item in AllPerspectiveObjects)
                    {
                        item.LoadPerspectives();
                    }
                }

                EndUpdate();
                UndoManager.Enabled = true;
            }
        }