public PowerBIInstance(string name, int port, EmbeddedSSASIcon 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 { if (port != -1) { Log.Warning("{class} {method} {message} {dashPos}", "PowerBIInstance", "ctor", $"Unable to find ' - ' in Power BI title '{name}'", dashPos); } Name = name; } } catch (Exception ex) { Log.Error("{class} {method} {message} {stacktrace}", "PowerBIInstance", "ctor", ex.Message, ex.StackTrace); Name = name; } }
public static void Refresh() { _instances.Clear(); var dict = ManagedIpHelper.GetExtendedTcpDictionary(); foreach (var proc in Process.GetProcessesByName("msmdsrv")) { int _port = 0; EmbeddedSSASIcon _icon = EmbeddedSSASIcon.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 = EmbeddedSSASIcon.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); } } }
public PowerBIInstance(string name, int port, EmbeddedSSASIcon icon) { 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 Port = port; Icon = icon; }
public static List <PowerBIInstance> GetLocalInstances() { List <PowerBIInstance> _instances = new List <PowerBIInstance>(); _instances.Clear(); var dict = ManagedIpHelper.GetExtendedTcpDictionary(); foreach (var proc in Process.GetProcessesByName("msmdsrv")) { int _port = 0; EmbeddedSSASIcon _icon = EmbeddedSSASIcon.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; } // exit here if the parent == "RSHostingService" then this is a SSAS instance if (parent.ProcessName.Equals("RSHostingService", StringComparison.OrdinalIgnoreCase)) { // only show PBI Report Server if we are running as admin // otherwise we won't have any access to the models if (IsAdministrator()) { _icon = EmbeddedSSASIcon.PowerBIReportServer; } else { continue; } } // if the process was launched from Visual Studio change the icon if (parent.ProcessName.Equals("devenv", StringComparison.OrdinalIgnoreCase)) { _icon = EmbeddedSSASIcon.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 = WindowTitle.GetWindowTitleTimeout( parent.Id, 300); parentTitle = WindowTitle.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; _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); //} } return(_instances); }
public static void RefreshOld() { _instances.Clear(); ManagementClass mgmtClass = new ManagementClass("Win32_Process"); foreach (ManagementObject process in mgmtClass.GetInstances()) { int _port = 0; EmbeddedSSASIcon _icon = EmbeddedSSASIcon.PowerBI; string processName = process["Name"].ToString().ToLower(); if (processName == "msmdsrv.exe") { // get the process pid System.UInt32 pid = (System.UInt32)process["ProcessId"]; var parentPid = int.Parse(process["ParentProcessId"].ToString()); var parentTitle = ""; if (parentPid > 0) { var parentProcess = Process.GetProcessById(parentPid); if (parentProcess.ProcessName == "devenv") { _icon = EmbeddedSSASIcon.Devenv; } parentTitle = parentProcess.MainWindowTitle; if (parentTitle.Length == 0) { // for minimized windows we need to use some Win32 api calls to get the title parentTitle = GetWindowTitle(parentPid); } } // Get the command line - can be null if we don't have permissions // but should have permission for PowerBI msmdsrv as it will have been // launched by the current user. string cmdLine = null; if (process["CommandLine"] != null) { cmdLine = process["CommandLine"].ToString(); try { var rex = new System.Text.RegularExpressions.Regex("-s\\s\"(?<path>.*)\""); var m = rex.Matches(cmdLine); if (m.Count == 0) { continue; } string msmdsrvPath = m[0].Groups["path"].Captures[0].Value; var portFile = string.Format("{0}\\msmdsrv.port.txt", msmdsrvPath); if (System.IO.File.Exists(portFile)) { Log.Verbose("{class} {method} {message}", "PowerBIHelper", "Refresh", "port.txt found"); string sPort = System.IO.File.ReadAllText(portFile, Encoding.Unicode); _port = int.Parse(sPort); _portSet = true; _instances.Add(new PowerBIInstance(parentTitle, _port, _icon)); Log.Debug("{class} {method} PowerBI found on port: {port}", "PowerBIHelper", "Refresh", _port); continue; } else { Log.Verbose("{class} {method} {message}", "PowerBIHelper", "Refresh", "no port.txt file found"); } } catch (Exception ex) { Log.Error("{class} {Method} {Error} {StackTrace}", "PowerBIHelper", "Refresh", ex.Message, ex.StackTrace); } } } } }