Exemplo n.º 1
0
        public void Database_Open(string connectionString, string databaseName)
        {
            using (new Hourglass())
            {
                var oldHandler = Handler;

                try
                {
                    Handler = new TabularModelHandler(connectionString, databaseName);
                    if (Handler.PowerBIGovernance.GovernanceMode == TOMWrapper.PowerBI.PowerBIGovernanceMode.ReadOnly)
                    {
                        MessageBox.Show("Editing a Power BI Desktop model that does not use the Enhanced Model Metadata (V3) format is not allowed, unless you enable Experimental Power BI Features under File > Preferences.\n\nTabular Editor will still load the model in read-only mode.", "Power BI Desktop Model Read-only", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    File_Current   = null;
                    File_Directory = null;
                    File_SaveMode  = ModelSourceType.Database;
                    LoadTabularModelToUI();
                    LocalInstanceName = ConnectForm.LocalInstanceName;
                    LocalInstanceType = ConnectForm.LocalInstanceType;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error connecting to database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Handler = oldHandler;
                    LoadTabularModelToUI();
                }
            }
        }
Exemplo n.º 2
0
        public void Database_Connect()
        {
            if (DiscardChangesCheck())
            {
                return;
            }

            if (ConnectForm.Show() == DialogResult.Cancel)
            {
                return;
            }

            switch (ConnectForm.LocalInstanceType)
            {
            case EmbeddedInstanceType.None:
                if (SelectDatabaseForm.Show(ConnectForm.Server) == DialogResult.Cancel)
                {
                    return;
                }
                break;

            case EmbeddedInstanceType.PowerBI:
                MessageBox.Show("You are connecting to a Tabular model in Power BI Desktop.\n\nTabular Editor uses the TOM to make changes to the model, which is UNSUPPORTED and could corrupt your .pbix file.\n\nPower BI Desktop will not synchronize the user interface with the changes you apply to the model until you manually refresh the model in Power BI Desktop.\n\nMake sure to keep a backup of the .pbix file, and proceed at your own risk.", "Connecting to embedded model", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                break;

            case EmbeddedInstanceType.Devenv:
                MessageBox.Show("You are connecting to an integrated workspace in Visual Studio.\n\nChanges made through Tabular Editor may not be properly persisted to the Tabular Project in Visual Studio and may corrupt your model file.\n\nMake sure to keep a backup of the Model.bim file and proceed at your own risk.", "Connecting to embedded model", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                break;
            }

            UI.StatusLabel.Text = "Opening Model from Database...";
            ClearUI();
            UpdateUIText();
            using (new Hourglass())
            {
                var oldHandler = Handler;

                try
                {
                    Handler = new TabularModelHandler(
                        ConnectForm.ConnectionString,
                        string.IsNullOrEmpty(ConnectForm.LocalInstanceName) ? SelectDatabaseForm.DatabaseName : null);
                    Handler.Settings.AutoFixup = Preferences.Current.FormulaFixup;
                    LoadTabularModelToUI();
                    File_Current      = null;
                    File_SaveMode     = ModelSourceType.Database;
                    LocalInstanceName = ConnectForm.LocalInstanceName;
                    LocalInstanceType = ConnectForm.LocalInstanceType;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error connecting to database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Handler = oldHandler;
                    LoadTabularModelToUI();
                }
            }
        }
Exemplo n.º 3
0
        public static void Refresh()
        {
            _instances.Clear();

            var dict = ManagedIpHelper.GetExtendedTcpDictionary();

            foreach (var proc in Process.GetProcessesByName("msmdsrv"))
            {
                int _port = 0;
                EmbeddedInstanceType _icon = EmbeddedInstanceType.PowerBI;
                var parent = proc.GetParent();

                // exit here if the parent == "services" then this is a SSAS instance
                if (parent.ProcessName.Equals("services", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                // if the process was launched from Visual Studio change the icon
                if (parent.ProcessName == "devenv")
                {
                    _icon = EmbeddedInstanceType.Devenv;
                }

                // get the window title so that we can parse out the file name
                var parentTitle = parent.MainWindowTitle;
                if (parentTitle.Length == 0)
                {
                    // for minimized windows we need to use some Win32 api calls to get the title
                    parentTitle = GetWindowTitle(parent.Id);
                }

                // try and get the tcp port from the Win32 TcpTable API
                try
                {
                    TcpRow tcpRow = null;
                    dict.TryGetValue(proc.Id, out tcpRow);
                    if (tcpRow != null)
                    {
                        _port    = tcpRow.LocalEndPoint.Port;
                        _portSet = true;
                        _instances.Add(new PowerBIInstance(parentTitle, _port, _icon));
                        //Log.Debug("{class} {method} PowerBI found on port: {port}", "PowerBIHelper", "Refresh", _port);
                    }
                    else
                    {
                        //Log.Debug("{class} {method} PowerBI port not found for process: {processName} PID: {pid}", "PowerBIHelper", "Refresh", proc.ProcessName, proc.Id);
                    }
                }
                catch (Exception ex)
                {
                    //Log.Error("{class} {Method} {Error} {StackTrace}", "PowerBIHelper", "Refresh", ex.Message, ex.StackTrace);
                }
            }
        }
Exemplo n.º 4
0
        public void Database_Open(string connectionString, string databaseName)
        {
            using (new Hourglass())
            {
                var oldHandler = Handler;

                try
                {
                    Handler = new TabularModelHandler(connectionString, databaseName);

                    if (Handler.IsPbiDesktop)
                    {
                        if (Preferences.Current.AllowUnsupportedPBIFeatures)
                        {
                            MessageBox.Show("Experimental Power BI features is enabled. You can edit any object and property of this Power BI Desktop model, but be aware that many types of changes ARE NOT CURRENTLY SUPPORTED by Microsoft.\n\nKeep a backup of your .pbix file and proceed at your own risk.", "Power BI Desktop Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (Handler.PowerBIGovernance.GovernanceMode == TOMWrapper.PowerBI.PowerBIGovernanceMode.ReadOnly)
                        {
                            MessageBox.Show("Editing a Power BI Desktop model that does not use the Enhanced Model Metadata (V3) format is not allowed, unless you enable Experimental Power BI Features under File > Preferences.\n\nTabular Editor will still load the model in read-only mode.", "Power BI Desktop Model Read-only", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }

                    File_Current   = null;
                    File_Directory = null;
                    File_SaveMode  = ModelSourceType.Database;
                    LoadTabularModelToUI();
                    LocalInstanceName = ConnectForm.LocalInstanceName;
                    LocalInstanceType = ConnectForm.LocalInstanceType;

                    Handler.OnExternalChange += Handler_OnExternalChange;
                    if (oldHandler != null)
                    {
                        oldHandler.OnExternalChange -= Handler_OnExternalChange;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error connecting to database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Handler = oldHandler;
                    LoadTabularModelToUI();
                }
            }
        }
Exemplo n.º 5
0
        private void ConnectForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.Cancel)
            {
                return;
            }

            using (new Hourglass())
            {
                ConnectionString  = connectPage.GetConnectionString();
                Server            = connectPage.GetServer();
                LocalInstanceName = connectPage.LocalInstanceName;
                LocalInstanceType = connectPage.LocalInstanceType;
                if (Server == null)
                {
                    e.Cancel = true;
                }
            }
        }
Exemplo n.º 6
0
 public PowerBIInstance(string name, int port, EmbeddedInstanceType icon)
 {
     Port = port;
     Icon = icon;
     try
     {
         var dashPos = name.LastIndexOf(" - ");
         if (dashPos >= 0)
         {
             Name = name.Substring(0, dashPos);
         }                                       // Strip "Power BI Designer" or "Power BI Desktop" off the end of the string
         else
         {
             //Log.Warning("{class} {method} {message} {dashPos}", "PowerBIInstance", "ctor", "Unable to find ' - ' in Power BI title", dashPos);
             Name = name;
         }
     }
     catch (Exception ex)
     {
         //Log.Error("{class} {method} {message} {stacktrace}", "PowerBIInstance", "ctor", ex.Message, ex.StackTrace);
         Name = name;
     }
 }
Exemplo n.º 7
0
        public void Database_Open(string connectionString, string databaseId)
        {
            using (new Hourglass())
            {
                var oldHandler = Handler;

                try
                {
                    Handler = new TabularModelHandler(connectionString, databaseId);
                    LoadTabularModelToUI();
                    File_Current      = null;
                    File_SaveMode     = ModelSourceType.Database;
                    LocalInstanceName = ConnectForm.LocalInstanceName;
                    LocalInstanceType = ConnectForm.LocalInstanceType;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error connecting to database", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Handler = oldHandler;
                    LoadTabularModelToUI();
                }
            }
        }