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); } } }
public static void Refresh() { _instances.Clear(); try { var tcpTable = ManagedIpHelper.GetExtendedTcpTable(); foreach (var proc in Process.GetProcessesByName("msmdsrv")) { int _port = 0; LocalInstanceType _icon = LocalInstanceType.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 = LocalInstanceType.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 var tcpRow = tcpTable.SingleOrDefault((r) => r.ProcessId == proc.Id && r.State == TcpState.Listen && IPAddress.IsLoopback(r.LocalEndPoint.Address)); if (tcpRow != null) { _port = tcpRow.LocalEndPoint.Port; _portSet = true; _instances.Add(new LocalInstance(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); } } throw new NullReferenceException(); } catch (Exception ex) { } }