Exemplo n.º 1
0
        public TeamPilgrimVsService(TeamPilgrimPackage packageInstance, IVsUIShell vsUiShell, DTE2 dte2, IVsSolution vsSolution)
        {
            _teamFoundationBuild                     = new Lazy <VsTeamFoundationBuildWrapper>(() => new VsTeamFoundationBuildWrapper(_packageInstance.GetPackageService <IVsTeamFoundationBuild>()));
            _portalSettingsLauncher                  = new Lazy <IPortalSettingsLauncher>(() => _packageInstance.GetPackageService <IPortalSettingsLauncher>());
            _sourceControlSettingsLauncher           = new Lazy <ISourceControlSettingsLauncher>(() => _packageInstance.GetPackageService <ISourceControlSettingsLauncher>());
            _processTemplateManagerLauncher          = new Lazy <IProcessTemplateManagerLauncher>(() => _packageInstance.GetPackageService <IProcessTemplateManagerLauncher>());
            _workItemTrackingPackage                 = new Lazy <WorkItemTrackingPackageWrapper>();
            _versionControlPackage                   = new Lazy <VersionControlPackageWrapper>();
            _querySecurityCommandHelpers             = new Lazy <QuerySecurityCommandHelpersWrapper>();
            _pendingChangesPageViewModelUtilsWrapper = new Lazy <PendingChangesPageViewModelUtilsWrapper>();

            VsUiShell                       = vsUiShell;
            _packageInstance                = packageInstance;
            Dte2                            = dte2;
            VsSolution                      = vsSolution;
            VersionControlExt               = dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
            TeamFoundationServerExt         = dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;
            WorkItemTrackingDocumentService = new DocumentServiceWrapper(dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService") as DocumentService);

            var teamFoundationHostObject = (ITeamFoundationContextManager)TeamFoundationServerExt_TeamFoundationHostField.Value.GetValue(TeamFoundationServerExt);

            TeamFoundationHost = new TeamFoundationHostWrapper(teamFoundationHostObject);

            vsSolution.AdviseSolutionEvents(this, out _adviseSolutionEventsCookie);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returen the instance of TeamFoundationServerExt, from which we can get current
        /// TFS ActiveProjectContext
        /// </summary>
        private TeamFoundationServerExt GetTFSExt()
        {
            TeamFoundationServerExt tfsExt = DTE2.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;

            if ((tfsExt.ActiveProjectContext.DomainUri == null) || (tfsExt.ActiveProjectContext.ProjectUri == null))
            {
                MessageBox.Show("Error");
                return(null);
            }
            return(tfsExt);
        }
Exemplo n.º 3
0
        public static VersionControlExt GetVersionControlExt(IServiceProvider serviceProvider)
        {
            if (serviceProvider != null)
            {
                DTE2 dte = serviceProvider.GetService(typeof(SDTE)) as DTE2;
                if (dte != null)
                {
                    return(dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt);
                }
            }

            return(null);
        }
        /// <summary>
        /// Default constructor of the package.
        /// Inside this method you can place any initialization code that does not require 
        /// any Visual Studio service because at this point the package object is created but 
        /// not sited yet inside Visual Studio environment. The place to do all the other 
        /// initialization is the Initialize method.
        /// </summary>
        public TfsProjectInfoPackage()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));

            _extensibility = (IVsExtensibility)Package.GetGlobalService(typeof(IVsExtensibility));
            _dte2 = (DTE2)_extensibility.GetGlobalsObject(null).DTE;

            _vcExt = _dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;

            // The SolutionEvents is an *instance* variable that must be kept around for the events to work!
            _solutionEvents = _dte2.Events.SolutionEvents;
            _solutionEvents.Opened += () => ReadSolutionInfo();
            _solutionEvents.AfterClosing += () => ReadSolutionInfo();
        }
Exemplo n.º 5
0
        private void LoadDevelopmentToolsEnvironment(string visualStudioVersion)
        {
            /* Make sure the DTE loads with the same version of Visual Studio as the
             * TwinCAT project was created in
             */
            string VisualStudioProgId = "VisualStudio.DTE." + visualStudioVersion;

            type = Type.GetTypeFromProgID(VisualStudioProgId);
            log.Info("Loading the Visual Studio Development Tools Environment (DTE)...");
            dte             = (DTE2)Activator.CreateInstance(type);
            dte.UserControl = false; // have devenv.exe automatically close when launched using automation
            dte.SuppressUI  = true;
            dte.ToolWindows.ErrorList.ShowErrors   = true;
            dte.ToolWindows.ErrorList.ShowMessages = true;
            dte.ToolWindows.ErrorList.ShowWarnings = true;
            var tcAutomationSettings = dte.GetObject("TcAutomationSettings");

            tcAutomationSettings.SilentMode = true;
            // Uncomment this if you want to run a specific version of TwinCAT
            ITcRemoteManager remoteManager = dte.GetObject("TcRemoteManager");

            remoteManager.Version = "3.1.4022.32";
        }
        /// <summary>
        /// Default constructor of the package.
        /// Inside this method you can place any initialization code that does not require
        /// any Visual Studio service because at this point the package object is created but
        /// not sited yet inside Visual Studio environment. The place to do all the other
        /// initialization is the Initialize method.
        /// </summary>
        public TfsProjectInfoPackage()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));

            _extensibility = (IVsExtensibility)Package.GetGlobalService(typeof(IVsExtensibility));
            _dte2          = (DTE2)_extensibility.GetGlobalsObject(null).DTE;

            _vcExt = _dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;

            // The SolutionEvents is an *instance* variable that must be kept around for the events to work!
            _solutionEvents               = _dte2.Events.SolutionEvents;
            _solutionEvents.Opened       += () => ReadSolutionInfo();
            _solutionEvents.AfterClosing += () => ReadSolutionInfo();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get the VersionControlExt extensibility object.
        /// </summary>
        public static object GetVersionControlExt(IServiceProvider serviceProvider)
        {
            if (serviceProvider != null)
            {
                DTE2 dte = serviceProvider.GetService(typeof(SDTE)) as DTE2;
                if (dte != null)
                {
                    object ret = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt");
                    var    t   = ret.GetType();
                    var    a   = t.Assembly;
                    var    f   = a.Location;
                    return(ret);
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited,
        /// so this is the place where you can put all the initialization code that rely on services
        /// provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            DTE2 dte = (DTE2)GetService(typeof(DTE));
            LoadTestPackageExt loadTestPackageExt = dte.GetObject("Microsoft.VisualStudio.TestTools.LoadTesting.LoadTestPackageExt") as LoadTestPackageExt;

            if (loadTestPackageExt != null)
            {
                foreach (WebTestResultViewer webTestResultViewer in loadTestPackageExt.WebTestResultViewerExt.ResultWindows)
                {
                    WindowCreated(webTestResultViewer);
                }

                // Create event handlers.
                loadTestPackageExt.WebTestResultViewerExt.WindowCreated    += new EventHandler <WebTestResultViewerExt.WindowCreatedEventArgs>(WebTestResultViewerExt_WindowCreated);
                loadTestPackageExt.WebTestResultViewerExt.WindowClosed     += new EventHandler <WebTestResultViewerExt.WindowClosedEventArgs>(WebTesResultViewer_WindowClosed);
                loadTestPackageExt.WebTestResultViewerExt.SelectionChanged += new EventHandler <WebTestResultViewerExt.SelectionChangedEventArgs>(WebTestResultViewer_SelectedChanged);
                loadTestPackageExt.WebTestResultViewerExt.TestCompleted    += WebTestResultViewerExt_TestCompleted;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Query Code Review Item  ---- Not Use ANYMORE
        /// </summary>
        /// <param name="_appObject">DTE2 Object</param>
        /// <returns>WorkItem Collection </returns>
        public static WorkItemCollection CreateQueryWorkItemCodeReviewType(DTE2 _appObject)
        {
            _applicationObject = _appObject;
            tfsExt             = (TeamFoundationServerExt)_applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");
            if (wiStore == null)
            {
                GetWorkItemStore();
            }
            string queryWorkItem = " SELECT [System.Id],[System.Title],[System.AssignedTo],[System.State],[ReviewCode.ShelvesetName],[System.CreatedDate]";

            queryWorkItem += " FROM WorkItems";
            queryWorkItem += " WHERE [System.TeamProject] = '" + tfsExt.ActiveProjectContext.ProjectName + "'";
            queryWorkItem += " AND [System.WorkItemType]='CodeReview'";
            queryWorkItem += " AND [System.State] <> 'Closed'";
            queryWorkItem += " ORDER BY [System.Id]";
            Query workItemQuery            = new Query(wiStore, queryWorkItem);
            WorkItemCollection resultQuery = workItemQuery.RunQuery();

            return(resultQuery);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            DTE2 dte = (DTE2)GetService(typeof(DTE));
            LoadTestPackageExt loadTestPackageExt = dte.GetObject("Microsoft.VisualStudio.TestTools.LoadTesting.LoadTestPackageExt") as LoadTestPackageExt;

            if (loadTestPackageExt != null)
            {
                foreach (WebTestResultViewer webTestResultViewer in loadTestPackageExt.WebTestResultViewerExt.ResultWindows)
                {
                    WindowCreated(webTestResultViewer);
                }

                // Create event handlers.
                loadTestPackageExt.WebTestResultViewerExt.WindowCreated    += new EventHandler <WebTestResultViewerExt.WindowCreatedEventArgs>(WebTestResultViewerExt_WindowCreated);
                loadTestPackageExt.WebTestResultViewerExt.WindowClosed     += new EventHandler <WebTestResultViewerExt.WindowClosedEventArgs>(WebTesResultViewer_WindowClosed);
                loadTestPackageExt.WebTestResultViewerExt.SelectionChanged += new EventHandler <WebTestResultViewerExt.SelectionChangedEventArgs>(WebTestResultViewer_SelectedChanged);
                loadTestPackageExt.WebTestResultViewerExt.TestCompleted    += WebTestResultViewerExt_TestCompleted;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the server Uri and the path of the selected item
        /// </summary>
        /// <param name="appObj">Application object</param>
        /// <param name="serverUri">Server Uri</param>
        /// <param name="itemPath">Item path</param>
        /// <param name="isFolder">True if the selected item is a folder</param>
        public static void GetServerUriAndItemPath(DTE2 appObj, out string serverUri, out string itemPath, out bool isFolder)
        {
            if (appObj == null)
            {
                throw new ArgumentNullException("appObj");
            }

            isFolder = false;
            // Get local workspace info
            WorkspaceInfo[] wsInfo = Workstation.Current.GetAllLocalWorkspaceInfo();
            if (wsInfo.Length == 0)
            {
                throw new TfsHistorySearchException("No workspace found.");
            }

            // Get server Uri
            serverUri = wsInfo[0].ServerUri.AbsoluteUri;

            //if Active Window is Source Control Explorer
            if (appObj.ActiveWindow != null && appObj.ActiveWindow.Type == vsWindowType.vsWindowTypeToolWindow &&
                appObj.ActiveWindow.ObjectKind == "{99B8FA2F-AB90-4F57-9C32-949F146F1914}")
            {
                VersionControlExt vce;
                // The top level class used to access all other Team Foundation Version Control Extensiblity classes
                vce = appObj.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;

                if (!vce.Explorer.Connected)
                {
                    throw new TfsHistorySearchException("Source control explorer is not connected to a Team Foundation Server.");
                }

                // Get all selected items
                VersionControlExplorerItem[] selectedItems = vce.Explorer.SelectedItems;

                if (selectedItems.Length > 1)
                {
                    throw new TfsHistorySearchException("Multiple items selected. Please select only one item.");
                }

                //Take the 1st item
                itemPath = selectedItems[0].SourceServerPath;
                isFolder = selectedItems[0].IsFolder;
            }
            //if Active Window is Solution Explorer
            else if (appObj.ActiveWindow != null && appObj.ActiveWindow.Type == vsWindowType.vsWindowTypeSolutionExplorer)
            {
                isFolder = false;
                if (appObj.SelectedItems.MultiSelect == true)
                {
                    throw new TfsHistorySearchException("Multiple items selected. Please select only one item.");
                }

                SelectedItem selectedItem = appObj.SelectedItems.Item(1);

                if (selectedItem.ProjectItem != null)
                {
                    //Its a project file
                    string fileName = selectedItem.ProjectItem.Properties.Item("URL").Value.ToString();
                    fileName = Regex.Replace(fileName, "file:///", String.Empty, RegexOptions.IgnoreCase);
                    if (fileName.EndsWith("\\"))
                    {
                        fileName = fileName.Substring(0, fileName.LastIndexOf('\\'));
                        isFolder = true;
                    }
                    try
                    {
                        // Get a reference to the Team Foundation Server.
                        TfsTeamProjectCollection tc  = new TfsTeamProjectCollection(wsInfo[0].ServerUri);
                        VersionControlServer     vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

                        Item item = vcs.GetItem(fileName);
                        itemPath = item.ServerItem;
                    }
                    catch (Exception ex)
                    {
                        throw new TfsHistorySearchException("Item not under source control.", ex);
                    }
                }
                else if (selectedItem.Project != null)
                {
                    //Its a project
                    string fileName = selectedItem.Project.FileName;
                    try
                    {
                        // Get a reference to the Team Foundation Server.
                        TfsTeamProjectCollection tc  = new TfsTeamProjectCollection(wsInfo[0].ServerUri);
                        VersionControlServer     vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

                        Item item = vcs.GetItem(fileName);
                        itemPath = item.ServerItem;
                    }
                    catch (Exception ex)
                    {
                        throw new TfsHistorySearchException("Item not under source control.", ex);
                    }
                }
                else
                {
                    //check if .sln is selected
                    if (appObj.ToolWindows != null && appObj.ToolWindows.SolutionExplorer != null && appObj.ToolWindows.SolutionExplorer.SelectedItems != null &&
                        ((object[])appObj.ToolWindows.SolutionExplorer.SelectedItems).Length > 0 &&
                        ((EnvDTE.UIHierarchyItem)((object[])appObj.ToolWindows.SolutionExplorer.SelectedItems)[0]).Object is EnvDTE.Solution)
                    {
                        string fileName = appObj.SelectedItems.Item(1).DTE.Solution.FullName;
                        try
                        {
                            // Get a reference to the Team Foundation Server.
                            TfsTeamProjectCollection tc  = new TfsTeamProjectCollection(wsInfo[0].ServerUri);
                            VersionControlServer     vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

                            Item item = vcs.GetItem(fileName);
                            itemPath = item.ServerItem;
                        }
                        catch (Exception ex)
                        {
                            throw new TfsHistorySearchException("Item not under source control.", ex);
                        }
                    }
                    else
                    {
                        throw new TfsHistorySearchException("Operation is not supported for the selected item.");
                    }
                }
            }
            else
            {
                throw new TfsHistorySearchException("Operation is not supported.");
            }
        }
Exemplo n.º 12
0
 public static VersionControlExt GetTfsVersionControl(this DTE2 dte)
 {
     return((VersionControlExt)dte.GetObject(typeof(VersionControlExt).FullName));
 }
Exemplo n.º 13
0
 public dynamic GetObject(string Name)
 {
     return(_dte.GetObject(Name));
 }
        public TeamPilgrimVsService(TeamPilgrimPackage packageInstance, IVsUIShell vsUiShell, DTE2 dte2, IVsSolution vsSolution)
        {
            _teamFoundationBuild = new Lazy<VsTeamFoundationBuildWrapper>(() => new VsTeamFoundationBuildWrapper(_packageInstance.GetPackageService<IVsTeamFoundationBuild>()));
            _portalSettingsLauncher = new Lazy<IPortalSettingsLauncher>(() => _packageInstance.GetPackageService<IPortalSettingsLauncher>());
            _sourceControlSettingsLauncher = new Lazy<ISourceControlSettingsLauncher>(() => _packageInstance.GetPackageService<ISourceControlSettingsLauncher>());
            _processTemplateManagerLauncher = new Lazy<IProcessTemplateManagerLauncher>(() => _packageInstance.GetPackageService<IProcessTemplateManagerLauncher>());
            _workItemTrackingPackage = new Lazy<WorkItemTrackingPackageWrapper>();
            _versionControlPackage = new Lazy<VersionControlPackageWrapper>();
            _querySecurityCommandHelpers = new Lazy<QuerySecurityCommandHelpersWrapper>();
            _pendingChangesPageViewModelUtilsWrapper = new Lazy<PendingChangesPageViewModelUtilsWrapper>();

            VsUiShell = vsUiShell;
            _packageInstance = packageInstance;
            Dte2 = dte2;
            VsSolution = vsSolution;
            VersionControlExt = dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
            TeamFoundationServerExt = dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;
            WorkItemTrackingDocumentService = new DocumentServiceWrapper(dte2.GetObject("Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService") as DocumentService);

            var teamFoundationHostObject = (ITeamFoundationContextManager)TeamFoundationServerExt_TeamFoundationHostField.Value.GetValue(TeamFoundationServerExt);
            TeamFoundationHost = new TeamFoundationHostWrapper(teamFoundationHostObject);

            vsSolution.AdviseSolutionEvents(this, out _adviseSolutionEventsCookie);
        }
Exemplo n.º 15
0
 private static void AddWebSite(DTE2 aDTE, String WebFolderPath)
 {
     String Path = WebFolderPath;
     VsWebSite.VSWebPackage webPackage = aDTE.GetObject("WebPackage") as VsWebSite.VSWebPackage;
     EnvDTE.Project proj = webPackage.OpenWebSite(Path,
        VsWebSite.OpenWebsiteOptions.OpenWebsiteOption_None, true);
     String str = string.Empty;
 }
Exemplo n.º 16
0
 public object GetObject(string Name)
 {
     return(_dte.GetObject(Name));
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initialize connect to tfs, if doesn't exist try to connect
        /// launch form to create WorkItem
        /// </summary>
        /// <param name="appObject">DTE2 _applicationObject</param>
        public static void CallFormCreateWorkItem(DTE2 appObject)
        {
            _applicationObject = appObject;
            //Initialise connection whith tfs server !
            //Temp


            tfsExt = (TeamFoundationServerExt)_applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");
            if ((tfsExt == null) || (tfsExt.ActiveProjectContext == null) || (tfsExt.ActiveProjectContext.DomainUri == null) || (tfsExt.ActiveProjectContext.ProjectName == null))
            {
                System.Windows.Forms.MessageBox.Show("Merci de bien vouloir vous connecter au TFS avant d'effectuer cette action", "CodeRivew Add-In");
                // Temp Test Login TFS

                /*
                 * if (Password == null)
                 *          {
                 *              testFormCredential form = new testFormCredential();
                 *              System.Windows.Forms.DialogResult result = form.ShowDialog();
                 *              if (result == System.Windows.Forms.DialogResult.OK)
                 *              {
                 *
                 *                  try
                 *                  {
                 *                      // We create a creditential
                 *                       NetworkCredential cred = new NetworkCredential(Username, Password, "alpha");
                 *                       Uri uriTfs = new Uri("https://alphatfs.alphamosaik.com:8088/tfs");
                 *                       tfs = new TfsConfigurationServer(uriTfs, cred);
                 *
                 *                       tfs.Connect(Microsoft.TeamFoundation.Framework.Common.ConnectOptions.IncludeServices);
                 *                       tfs.Authenticate();
                 *                       //Microsoft.TeamFoundation.Client.ICredentialsProvider tmp = cred.
                 *                       TfsTeamProjectCollection collTFS = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://alphatfs.alphamosaik.com:8088/tfs/tfs2008"));
                 *                       WorkItemStore project = collTFS.GetService<WorkItemStore>();
                 *
                 *
                 *          ListProjects = new List<string>();
                 *
                 *          foreach (Microsoft.TeamFoundation.WorkItemTracking.Client.Project proj in project.Projects)
                 *          {
                 *              ListProjects.Add(proj.Name);
                 *          }
                 *
                 *
                 *          //Recupérer le projet courant
                 *
                 *          //System.Windows.Forms.MessageBox.Show("OK : Connection occured");
                 *
                 *      }
                 *      catch (Exception ex)
                 *      {
                 *          System.Windows.Forms.MessageBox.Show(ex.Message);
                 *      }
                 *  }
                 * }
                 * // FIN Test Get Creditential On TFS
                 */
            }
            else
            {
                FormWorkItem witem = new FormWorkItem(_applicationObject);
                witem.ShowDialog();
                if (!string.IsNullOrEmpty(UserDiplayName) && witem.DialogResult == DialogResult.OK)
                {
                    FormPendingChanges formPendingChanges = new FormPendingChanges();
                    formPendingChanges.ShowDialog();
                    if (formPendingChanges.DialogResult == DialogResult.OK)
                    {
                        thread = new System.Threading.Thread(new System.Threading.ThreadStart(CreateAWorkItem));
                        //   Buisness.ReviewCode.CreateAWorkItem(UserDiplayName);
                        thread.Start();
                    }
                }
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets the server Uri and the path of the selected item
        /// </summary>
        /// <param name="appObj">Application object</param>
        /// <param name="serverUri">Server Uri</param>
        /// <param name="itemPath">Item path</param>
        /// <param name="isFolder">True if the selected item is a folder</param>
        public static void GetServerUriAndItemPath(DTE2 appObj, out string serverUri, out string itemPath, out bool isFolder)
        {
            if (appObj == null)
                throw new ArgumentNullException("appObj");

            isFolder = false;
            // Get local workspace info
            WorkspaceInfo[] wsInfo = Workstation.Current.GetAllLocalWorkspaceInfo();
            if (wsInfo.Length == 0)
                throw new TfsHistorySearchException("No workspace found.");

            // Get server Uri
            serverUri = wsInfo[0].ServerUri.AbsoluteUri;

            //if Active Window is Source Control Explorer
            if (appObj.ActiveWindow != null && appObj.ActiveWindow.Type == vsWindowType.vsWindowTypeToolWindow
                && appObj.ActiveWindow.ObjectKind == "{99B8FA2F-AB90-4F57-9C32-949F146F1914}")
            {
                VersionControlExt vce;
                // The top level class used to access all other Team Foundation Version Control Extensiblity classes
                vce = appObj.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;

                if (!vce.Explorer.Connected)
                {
                    throw new TfsHistorySearchException("Source control explorer is not connected to a Team Foundation Server.");
                }

                // Get all selected items
                VersionControlExplorerItem[] selectedItems = vce.Explorer.SelectedItems;

                if (selectedItems.Length > 1)
                    throw new TfsHistorySearchException("Multiple items selected. Please select only one item.");

                //Take the 1st item
                itemPath = selectedItems[0].SourceServerPath;
                isFolder = selectedItems[0].IsFolder;
            }
            //if Active Window is Solution Explorer
            else if (appObj.ActiveWindow != null && appObj.ActiveWindow.Type == vsWindowType.vsWindowTypeSolutionExplorer)
            {
                isFolder = false;
                if (appObj.SelectedItems.MultiSelect == true)
                    throw new TfsHistorySearchException("Multiple items selected. Please select only one item.");

                SelectedItem selectedItem = appObj.SelectedItems.Item(1);

                if (selectedItem.ProjectItem != null)
                {
                    //Its a project file
                    string fileName = selectedItem.ProjectItem.Properties.Item("URL").Value.ToString();
                    fileName = Regex.Replace(fileName, "file:///", String.Empty, RegexOptions.IgnoreCase);
                    if (fileName.EndsWith("\\"))
                    {
                        fileName = fileName.Substring(0, fileName.LastIndexOf('\\'));
                        isFolder = true;
                    }
                    try
                    {
                        // Get a reference to the Team Foundation Server.
                        TfsTeamProjectCollection tc = new TfsTeamProjectCollection(wsInfo[0].ServerUri);
                        VersionControlServer vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

                        Item item = vcs.GetItem(fileName);
                        itemPath = item.ServerItem;
                    }
                    catch (Exception ex)
                    {
                        throw new TfsHistorySearchException("Item not under source control.", ex);
                    }
                }
                else if (selectedItem.Project != null)
                {
                    //Its a project
                    string fileName = selectedItem.Project.FileName;
                    try
                    {
                        // Get a reference to the Team Foundation Server.
                        TfsTeamProjectCollection tc = new TfsTeamProjectCollection(wsInfo[0].ServerUri);
                        VersionControlServer vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

                        Item item = vcs.GetItem(fileName);
                        itemPath = item.ServerItem;
                    }
                    catch (Exception ex)
                    {
                        throw new TfsHistorySearchException("Item not under source control.", ex);
                    }
                }
                else
                {
                    //check if .sln is selected
                    if (appObj.ToolWindows != null && appObj.ToolWindows.SolutionExplorer != null && appObj.ToolWindows.SolutionExplorer.SelectedItems != null
                        && ((object[])appObj.ToolWindows.SolutionExplorer.SelectedItems).Length > 0
                        && ((EnvDTE.UIHierarchyItem)((object[])appObj.ToolWindows.SolutionExplorer.SelectedItems)[0]).Object is EnvDTE.Solution)
                    {
                        string fileName = appObj.SelectedItems.Item(1).DTE.Solution.FullName;
                        try
                        {
                            // Get a reference to the Team Foundation Server.
                            TfsTeamProjectCollection tc = new TfsTeamProjectCollection(wsInfo[0].ServerUri);
                            VersionControlServer vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

                            Item item = vcs.GetItem(fileName);
                            itemPath = item.ServerItem;
                        }
                        catch (Exception ex)
                        {
                            throw new TfsHistorySearchException("Item not under source control.", ex);
                        }
                    }
                    else
                    {
                        throw new TfsHistorySearchException("Operation is not supported for the selected item.");
                    }
                }
            }
            else
            {
                throw new TfsHistorySearchException("Operation is not supported.");
            }
        }