/// <summary> /// Tries to parse the specified string to an <see cref="ROTDteInfo"/> instance. /// </summary> /// <param name="str">The string.</param> /// <param name="obj">The object.</param> /// <returns>true if succeeded, false if not.</returns> public static bool TryParse(string str, out ROTDteInfo obj) { string searchStr = "!VisualStudio.DTE."; int index = searchStr.Length; int index2 = -1; if (str.StartsWith(searchStr)) { index2 = str.LastIndexOf(':'); int processId = -1; if (index2 < 0) { index2 = str.Length; } else { processId = int.Parse(str.Substring(index2 + 1)); } string versionStr = str.Substring(index, index2 - index); Version version = Version.Parse(versionStr); obj = new ROTDteInfo(version, string.Empty, processId); return(true); } else { obj = null; return(false); } }
/// <summary> /// Get a table of the currently running instances of the Visual Studio .NET IDE. /// </summary> /// <returns>A dictionary mapping common information about the DTE object to the EnvDte.DTE object itself</returns> public static Dictionary <ROTDteInfo, DTE> GetRunningDTETable() { Dictionary <string, DTE> runningIDEInstances = new Dictionary <string, DTE>(); Dictionary <string, List <object> > runningObjects = GetRunningObjectTable(); IEnumerable <KeyValuePair <string, List <object> > > objTable = runningObjects.Where <KeyValuePair <string, List <object> > >((entry) => { ROTDteInfo info = null; return(ROTDteInfo.TryParse(entry.Key, out info)); }); Dictionary <ROTDteInfo, DTE> ret = new Dictionary <ROTDteInfo, DTE>(); foreach (KeyValuePair <string, List <object> > entry in objTable) { string displayName = entry.Key; Debug.Assert(entry.Value.Count == 1); if (entry.Value.Count > 0) { DTE dte = (DTE)entry.Value[0]; string solutionPath = dte.Solution.FullName; ROTDteInfo info = ROTDteInfo.Parse(entry.Key); info.SolutionPath = solutionPath; ret.Add(info, dte); } } return(ret); }
/// <summary> /// Parses the specified string. /// </summary> /// <param name="str">The string.</param> /// <returns></returns> /// <exception cref="System.FormatException"></exception> public static ROTDteInfo Parse(string str) { ROTDteInfo info = null; if (!TryParse(str, out info)) { throw new FormatException(); } return(info); }