Ejemplo n.º 1
0
        /// <summary>
        /// Called when [plan work item].
        /// </summary>
        /// <param name="workItemIds">The work item ids.</param>
        public void OnPlanWorkItem(int[] workItemIds, bool areWorkItemsSelected = true)
        {
            var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            if (dteService == null)
            {
                Debug.WriteLine("[PlanWorkItemController] DTE Service is null.");
                return;
            }

            var teamExplorer = (ITeamExplorer)(Package.GetGlobalService(typeof(ITeamExplorer)));

            teamFoundationServerExt = (dteService.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt);

            TfsClient tfsClient = new TfsClient(teamFoundationServerExt);

            teamExplorer.NavigateToPage(new Guid(PlanWorkItemPage.PageId), new PlanWorkItemPageModel()
            {
                WorkItemIds                = workItemIds,
                UsersAvailableForAssign    = tfsClient.GetUsers(),
                ConfigurationFilePath      = TFSScrumExtensionsPackage.ConfigurationFilePath,
                AvailableWorkItemTypes     = tfsClient.GetWorkItemsTypes(),
                AvailableWorkItemLinkTypes = tfsClient.GetWorkItemLinkTypes(),
                TfsClient            = tfsClient,
                AreWorkItemsSelected = areWorkItemsSelected
            });
        }
Ejemplo n.º 2
0
        internal VsTfsConnectionInfoProvider()
        {
            var dte = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            TeamFoundationServerExt tfse = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;

            tfse.ProjectContextChanged += VsTfsProjectContextChanged;
        }
        /// <summary>
        /// Creates a <see cref="MarginCore"/> for a given <see cref="IWpfTextView"/>.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param>
        /// <param name="textDocumentFactoryService">Service that creates, loads, and disposes text documents.</param>
        /// <param name="vsServiceProvider">Visual Studio service provider.</param>
        /// <param name="formatMapService">Service that provides the <see cref="IEditorFormatMap"/>.</param>
        /// <param name="scrollMapFactoryService">Factory that creates or reuses an <see cref="IScrollMap"/> for an <see cref="ITextView"/>.</param>
        public MarginCore(IWpfTextView textView, ITextDocumentFactoryService textDocumentFactoryService, SVsServiceProvider vsServiceProvider, IEditorFormatMapService formatMapService, IScrollMapFactoryService scrollMapFactoryService)
        {
            Debug.WriteLine("Entering constructor.", Properties.Resources.ProductName);

            _textView = textView;
            if (!textDocumentFactoryService.TryGetTextDocument(_textView.TextDataModel.DocumentBuffer, out _textDoc))
            {
                Debug.WriteLine("Can not retrieve TextDocument. Margin is disabled.", Properties.Resources.ProductName);
                _isEnabled = false;
                return;
            }

            _formatMap      = formatMapService.GetEditorFormatMap(textView);
            _marginSettings = new MarginSettings(_formatMap);

            _scrollMap = scrollMapFactoryService.Create(textView);

            var dte = (DTE2)vsServiceProvider.GetService(typeof(DTE));

            _tfExt = (TeamFoundationServerExt)dte.GetObject(typeof(TeamFoundationServerExt).FullName);
            Debug.Assert(_tfExt != null, "_tfExt is null.");
            _tfExt.ProjectContextChanged += OnTfExtProjectContextChanged;

            UpdateMargin();
        }
Ejemplo n.º 4
0
        /// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary>
        /// <param term='commandName'>The name of the command to execute.</param>
        /// <param term='executeOption'>Describes how the command should be run.</param>
        /// <param term='varIn'>Parameters passed from the caller to the command handler.</param>
        /// <param term='varOut'>Parameters passed from the command handler to the caller.</param>
        /// <param term='handled'>Informs the caller if the command was handled or not.</param>
        /// <seealso class='Exec' />
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if(commandName == "VS2010TestResultPublisher.Connect.VS2010TestResultPublisher")
                {
                    handled = true;
                    try
                    {
                        _tfsExt = _applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;
                    }
                    catch { }

                    MainPublisherForm mainForm = null;

                    if (_tfsExt == null)
                    {
                        mainForm = new MainPublisherForm(_applicationObject.Solution.FileName);
                    }
                    else
                    {

                        mainForm = new MainPublisherForm(_applicationObject.Solution.FileName, new ProjectSettings(_tfsExt.ActiveProjectContext));
                    }

                    mainForm.Show();
                    return;
                }
            }
        }
Ejemplo n.º 5
0
        private static void WriteUnableToLoadLogEntry(TeamFoundationServerExt tfse)
        {
            var message = "Unable to load Project Context Properties";

            if (tfse.ActiveProjectContext != null && tfse.ActiveProjectContext.ProjectName != null)
            {
                message += " on Project '" + tfse.ActiveProjectContext.ProjectName + "'.";
            }
            SimpleLogger.Log(SimpleLogLevel.Error, message);
            if (tfse.ActiveProjectContext == null)
            {
                SimpleLogger.Log(SimpleLogLevel.Error, "ActiveProjectContext null");
            }
            if (tfse.ActiveProjectContext != null && tfse.ActiveProjectContext.DomainUri == null)
            {
                SimpleLogger.Log(SimpleLogLevel.Error, "ActiveProjectContext.DomainUri null");
            }
            if (tfse.ActiveProjectContext != null && tfse.ActiveProjectContext.ProjectName == null)
            {
                SimpleLogger.Log(SimpleLogLevel.Error, "ProjectName null");
            }
            if (Repository.Instance.TfsBridgeProvider == null)
            {
                SimpleLogger.Log(SimpleLogLevel.Error, "TfsBridgeProvider null");
            }
            if (Repository.Instance.TfsBridgeProvider != null &&
                Repository.Instance.TfsBridgeProvider.VersionControlServer == null)
            {
                SimpleLogger.Log(SimpleLogLevel.Error, "TfsBridgeProvider.VersionControlServer null");
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GeneralSettingsEditorViewModel"/> class.
 /// </summary>
 /// <param name="teamFoundationServer">
 /// The team foundation server.
 /// </param>
 /// <param name="resolverTypes">
 /// The resolver Types.
 /// </param>
 public PersonalSettingsEditorViewModel(TeamFoundationServerExt teamFoundationServer)
 {
     SaveCommand = new DelegateCommand(Save, CanSave);
     this._teamFoundationServer = teamFoundationServer;
     this._teamFoundationServer.ProjectContextChanged += (s, a) => LoadSettings();
     LoadSettings();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GeneralSettingsEditorViewModel"/> class.
        /// </summary>
        /// <param name="teamFoundationServer">
        /// The team foundation server.
        /// </param>
        /// <param name="resolverTypes">
        /// The resolver Types.
        /// </param>
        public GeneralSettingsEditorViewModel(TeamFoundationServerExt teamFoundationServer, IEnumerable <IDependencyResolverType> resolverTypes)
        {
            ResolverTypes = new ObservableCollection <ResolverTypeViewModel>(resolverTypes.Select(x => new ResolverTypeViewModel(x)));

            SaveCommand = new DelegateCommand(Save, CanSave);
            this._teamFoundationServer = teamFoundationServer;
            this._teamFoundationServer.ProjectContextChanged += (s, a) => LoadSettings();
            LoadSettings();
        }
Ejemplo n.º 8
0
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <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();

            var dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            TeamFoundationServerExt ext = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;

            ext.ProjectContextChanged += ext_ProjectContextChanged;
        }
 /// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary>
 /// <param name='disconnectMode'>Describes how the Add-in is being unloaded.</param>
 /// <param name='custom'>Array of parameters that are host application specific.</param>
 /// <seealso class='IDTExtensibility2' />
 public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
 {
     // Unhook the ProjectContextChanged event handler.
     if (null != m_tfsExt)
     {
         m_tfsExt.ProjectContextChanged -= TfsExt_ProjectContextChanged;
         m_tfsExt = null;
     }
 }
 public VSExtensionContext(TeamFoundationServerExt ext, IVsTeamFoundationBuild buildExt)
 {
     this.ext = ext;
     this.buildExt = buildExt;
     if (ext != null)
     {
         this.currentConnectionUri = ext.ActiveProjectContext.DomainUri;
         ext.ProjectContextChanged += this.OnSelectedProjectChanged;
     }
 }
 public VSExtensionContext(TeamFoundationServerExt ext, IVsTeamFoundationBuild buildExt)
 {
     this.ext      = ext;
     this.buildExt = buildExt;
     if (ext != null)
     {
         this.currentConnectionUri  = ext.ActiveProjectContext.DomainUri;
         ext.ProjectContextChanged += this.OnSelectedProjectChanged;
     }
 }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get WorkItemStore
        /// </summary>
        /// <returns>WorkItemStore</returns>
        public static WorkItemStore GetWorkItemStore()
        {
            if (tfsExt == null)
            {
                tfsExt = (Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt)_applicationObject.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");
            }
            tfsColl = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsExt.ActiveProjectContext.DomainUri));
            wiStore = tfsColl.GetService <WorkItemStore>();

            return(wiStore);
        }
Ejemplo n.º 14
0
        private void ConnectToTFS()
        {
            if (TfsExt != null)  // Already connected
            {
                return;
            }
            var dte = (DTE2)this.BasicHelper.GetService <IVsExtensibility>().GetGlobalsObject(null).DTE;

            TfsExt =
                dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as
                TeamFoundationServerExt;

            TfsExt.ProjectContextChanged += TfsContextChanged;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PlanWorkItemController"/> class.
        /// </summary>
        public PlanWorkItemController()
        {
            var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            if (dteService == null)
            {
                Debug.WriteLine("[PlanWorkItemController] DTE Service is null.");
                return;
            }

            var teamExplorer = (ITeamExplorer)(Package.GetGlobalService(typeof(ITeamExplorer)));

            teamFoundationServerExt = (dteService.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt);
            teamFoundationServerExt.ProjectContextChanged +=teamFoundationServerExt_ProjectContextChanged;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlanWorkItemController"/> class.
        /// </summary>
        public PlanWorkItemController()
        {
            var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            if (dteService == null)
            {
                Debug.WriteLine("[PlanWorkItemController] DTE Service is null.");
                return;
            }

            var teamExplorer = (ITeamExplorer)(Package.GetGlobalService(typeof(ITeamExplorer)));

            teamFoundationServerExt = (dteService.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt);
            teamFoundationServerExt.ProjectContextChanged += teamFoundationServerExt_ProjectContextChanged;
        }
        /// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary>
        public TeamExplorerIntergator(EnvDTE.IVsExtensibility extensibility, IVsTeamExplorer te)
        {
            IvsTeamExpl = te;

            // get IDE Globals object and DTE from that
            EnvDTE80.DTE2 dte2 = extensibility.GetGlobalsObject(null).DTE as EnvDTE80.DTE2;
            _applicationobject = dte2;

            Debug.Assert(dte2 != null, "No DTE2");

            TeamFoundationServerExt tfsExt = (TeamFoundationServerExt)dte2.Application.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");

            this.srcCtrlExplorer = (VersionControlExt)dte2.Application.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt");

            DoConnect(tfsExt);
        }
Ejemplo n.º 18
0
        private TfsHelper()
        {
            Project = new ProjectData();
            var dte2 = (DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE));

            m_FoundationServerExt =
                dte2.GetObject(s_TeamFoundationServerExtString) as
                TeamFoundationServerExt;

            //register on the ProjectContextChanged event
            if (m_FoundationServerExt != null)
            {
                m_FoundationServerExt.ProjectContextChanged +=
                    FoundationServerExt_ProjectContextChanged;
            }
        }
        /// <summary>
        /// Determines whether this instance is connected.
        /// </summary>
        /// <returns></returns>
        public bool IsConnected()
        {
            var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            if (dteService == null)
            {
                Debug.WriteLine("[PlanWorkItemController] DTE Service is null.");
                return false;
            }

            var teamExplorer = (ITeamExplorer)(Package.GetGlobalService(typeof(ITeamExplorer)));

            teamFoundationServerExt = (dteService.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt);
            TfsClient tfsClient = new TfsClient(teamFoundationServerExt);

            return tfsClient.IsTeamProjectConnnected();
        }
Ejemplo n.º 20
0
        private void LoadUriAndProject(TeamFoundationServerExt tfse)
        {
            var newUri = new Uri(tfse.ActiveProjectContext.DomainUri);

            SetUri(newUri);
            if (Repository.Instance.TfsBridgeProvider != null &&
                Repository.Instance.TfsBridgeProvider.VersionControlServer != null)
            {
                var newProject = Repository.Instance.TfsBridgeProvider.VersionControlServer.GetTeamProject(tfse.ActiveProjectContext.ProjectName);
                SetProject(newProject);
                Repository.Instance.TfsBridgeProvider.ActiveTeamProject = newProject;
            }
            else
            {
                WriteUnableToLoadLogEntry(tfse);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Determines whether this instance is connected.
        /// </summary>
        /// <returns></returns>
        public bool IsConnected()
        {
            var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            if (dteService == null)
            {
                Debug.WriteLine("[PlanWorkItemController] DTE Service is null.");
                return(false);
            }

            var teamExplorer = (ITeamExplorer)(Package.GetGlobalService(typeof(ITeamExplorer)));

            teamFoundationServerExt = (dteService.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt);
            TfsClient tfsClient = new TfsClient(teamFoundationServerExt);

            return(tfsClient.IsTeamProjectConnnected());
        }
Ejemplo n.º 22
0
        private void ReloadProjectContextProperties()
        {
            var dte = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            TeamFoundationServerExt tfse = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;

            if (tfse.ActiveProjectContext != null &&
                tfse.ActiveProjectContext.DomainUri != null &&
                !String.IsNullOrEmpty(tfse.ActiveProjectContext.ProjectName))
            {
                Uri     = new Uri(tfse.ActiveProjectContext.DomainUri);
                Project = Repository.Instance.TfsBridgeProvider.VersionControlServer.GetTeamProject(tfse.ActiveProjectContext.ProjectName);
            }
            else
            {
                Uri     = null;
                Project = null;
            }
        }
Ejemplo n.º 23
0
        void ext_ProjectContextChanged(object sender, EventArgs e)
        {
            var dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            TeamFoundationServerExt ext = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;

            if (ext != null && ext.ActiveProjectContext != null && ext.ActiveProjectContext.DomainUri != null)
            {
                var coll = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(ext.ActiveProjectContext.DomainUri));
                var vcs  = coll.GetService <VersionControlServer>();

                if (vcs != null)
                {
                    vcs.UnshelveShelveset -= vcs_UnshelveShelveset;
                    vcs.CommitShelveset   -= vcs_CommitShelveset;
                    vcs.UnshelveShelveset += vcs_UnshelveShelveset;
                    vcs.CommitShelveset   += vcs_CommitShelveset;
                }
            }
        }
Ejemplo n.º 24
0
 private void EnsurePendingChangesService()
 {
     if (_pendingChangesExt == null)
     {
         var dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
         TeamFoundationServerExt ext = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;
         _pendingChangesExt = GetService <IPendingChangesExt>();
         if (_pendingChangesExt == null)
         {
             //var dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
             VersionControlExt ex = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
             _pendingChangesExt = ex.PendingChanges;
         }
         if (_pendingChangesExt != null)
         {
             _pendingChangesExt.PropertyChanged += svc_PropertyChanged;
         }
     }
 }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
 internal VsTfsConnectionInfoProvider()
 {
     try
     {
         var dte = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
         var obj = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt");
         if (obj == null)
         {
             SimpleLogger.Log(SimpleLogLevel.Error,
                              "Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt is null");
         }
         else
         {
             TeamFoundationServerExt tfse =
                 obj as TeamFoundationServerExt;
             if (tfse != null)
             {
                 tfse.ProjectContextChanged += VsTfsProjectContextChanged;
             }
             else
             {
                 SimpleLogger.Log(SimpleLogLevel.Error,
                                  "Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt is " +
                                  obj.GetType().Namespace + "." + obj.GetType().Name + " from " +
                                  obj.GetType().AssemblyQualifiedName);
                 try
                 {
                     tfse.ProjectContextChanged += VsTfsProjectContextChanged;
                 }
                 catch (Exception ex)
                 {
                     SimpleLogger.Log(ex, false, false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         SimpleLogger.Log(ex, true);
     }
 }
        public void DoConnect(TeamFoundationServerExt tfsEx)
        {
            try
            {
                m_tfsExt = tfsEx;

                if (null != m_tfsExt)
                {
                    m_tfsExt.ProjectContextChanged += new EventHandler(m_tfsExt_ProjectContextChanged);

                    if (null != m_tfsExt.ActiveProjectContext)
                    {
                        // Run the event handler without the event actually having fired, so we pick up the initial state.
                        m_tfsExt_ProjectContextChanged(null, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("***** MATTIAS **** " + ex.Message);
            }
        }
        public void DoConnect(TeamFoundationServerExt tfsEx)
        {
            try
            {
                m_tfsExt = tfsEx;

                if (null != m_tfsExt)
                {
                    m_tfsExt.ProjectContextChanged += TfsExt_ProjectContextChanged;

                    if (null != m_tfsExt.ActiveProjectContext)
                    {
                        // Run the event handler without the event actually having fired, so we pick up the initial state.
                        TfsExt_ProjectContextChanged(null, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("[TfsVisualHistory][DoConnect] " + ex.Message);
                ////MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 29
0
        private void btn1_Click(object sender, EventArgs e)
        {
            //check whether the value in tb1 is integer
            int  workitemID = 0;
            bool isInteger  = int.TryParse(tb1.Text, out workitemID);

            if (!isInteger || workitemID <= 0)
            {
                MessageBox.Show("Work Item ID must be an integer and lager than 0");
                return;
            }



            TeamFoundationServerExt tfsExt = this.GetTFSExt();

            //chech whether tfsExt exists
            if (tfsExt != null)
            {
                DocumentService witDocumentService = (DocumentService)DTE2.DTE.GetObject(
                    "Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService");
                //create a TFS instance with the url
                TeamFoundationServer activeTFS = new TeamFoundationServer(
                    tfsExt.ActiveProjectContext.DomainUri);
                IWorkItemDocument widoc = null;
                widoc = witDocumentService.GetWorkItem(activeTFS, workitemID, this);
                try
                {
                    //Open the work item in Visual Studio
                    witDocumentService.ShowWorkItem(widoc);
                }
                finally
                {
                    widoc.Release(this);
                }
            }
        }
Ejemplo n.º 30
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();
                    }
                }
            }
        }
 /// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary> 
 /// <param name='disconnectMode'>Describes how the Add-in is being unloaded.</param> 
 /// <param name='custom'>Array of parameters that are host application specific.</param> 
 /// <seealso class='IDTExtensibility2' /> 
 public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
 {
     // Unhook the ProjectContextChanged event handler.
     if (null != this.tfsExt)
     {
         this.tfsExt.ProjectContextChanged -= new EventHandler(this.TfsExt_ProjectContextChanged);
         this.tfsExt = null;
     }
 }
Ejemplo n.º 32
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="service"></param>
        /// <param name="workspace"></param>
        /// <param name="force">True when the user manually initiates a ShelveSet via the Team menu or mapped shortcut key.</param>
        private void CreateShelveset(VersionControlServer service, Workspace workspace, bool force)
        {
            // Build event args for notification create shelveset result
            var autoShelveEventArg = new ShelvesetCreatedEventArgs();

            autoShelveEventArg.ShelvesetChangeCount = 0; // Shouldn't be necessary, but forcing it to be safe.

            try
            {
                // If there are no pending changes that have changed since the last shelveset then there is nothing to do
                bool isDelta        = false;
                var  pendingChanges = workspace.GetPendingChanges();
                int  numPending     = pendingChanges.Count();

                if (numPending > 0)
                {
                    if (!force)
                    {
                        var lastShelveset = GetPastShelvesets(service, workspace).FirstOrDefault();
                        if (lastShelveset == null)
                        {
                            // If there are pending changes and no shelveset yet exists, then create shelveset.
                            isDelta = true;
                        }
                        else
                        {
                            // Compare numPending to shelvedChanges.Count();  Force shelveset if they differ
                            // Otherwise, resort to comparing file HashValues
                            var shelvedChanges = service.QueryShelvedChanges(lastShelveset).FirstOrDefault();
                            isDelta = (shelvedChanges == null || numPending != shelvedChanges.PendingChanges.Count()) || pendingChanges.DifferFrom(shelvedChanges.PendingChanges);
                        }
                    }
                    if (force || isDelta)
                    {
                        autoShelveEventArg.ShelvesetChangeCount = numPending;

                        // Build a new, valid shelve set name
                        var setname = string.Format(ShelvesetName, workspace.Name, workspace.OwnerName, DateTime.Now, workspace.OwnerName.GetDomain(), workspace.OwnerName.GetLogin());
                        setname = CleanShelvesetName(setname);

                        // Actually create a new Shelveset
                        var shelveset = new Shelveset(service, setname, workspace.OwnerName);
                        autoShelveEventArg.ShelvesetName = setname;
                        shelveset.Comment = string.Format("Shelved by {0}. {1} items", _extensionName, numPending);
                        workspace.Shelve(shelveset, pendingChanges, ShelvingOptions.Replace);

                        // Clean up past Shelvesets
                        if (MaximumShelvesets > 0)
                        {
                            foreach (var set in GetPastShelvesets(service, workspace).Skip(MaximumShelvesets))
                            {
                                service.DeleteShelveset(set);
                                autoShelveEventArg.ShelvesetsPurgeCount++;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _tfsExt = null; // Force re-init on next attempt
                autoShelveEventArg.ExecutionException = ex;
            }
            // Fire event for each VS instance to report results
            if (OnShelvesetCreated != null)
            {
                OnShelvesetCreated(this, autoShelveEventArg);
            }
        }
Ejemplo n.º 33
0
 public void InitializeExtension(TeamFoundationServerExt ext, IVsTeamFoundationBuild buildExt)
 {
     this.ctx = new VSExtensionContext(ext, buildExt);
     this.ctx.ProjectChanged += this.OnProjectChanged;
     this.ChangeConnection();
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TfsClient"/> class.
 /// </summary>
 /// <param name="tfsServer">The TFS server.</param>
 public TfsClient(TeamFoundationServerExt tfsServer)
 {
     this.TfsServer = tfsServer;
 }
 public void InitializeExtension(TeamFoundationServerExt ext, IVsTeamFoundationBuild buildExt)
 {
     this.ctx = new VSExtensionContext(ext, buildExt);
     this.ctx.ProjectChanged += this.OnProjectChanged;
     this.ChangeConnection();
 }
Ejemplo n.º 36
0
        /// <summary>
        /// Creates a <see cref="MarginCore"/> for a given <see cref="IWpfTextView"/>.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> to attach the margin to.</param>
        /// <param name="textDocumentFactoryService">Service that creates, loads, and disposes text documents.</param>
        /// <param name="vsServiceProvider">Visual Studio service provider.</param>
        /// <param name="formatMapService">Service that provides the <see cref="IEditorFormatMap"/>.</param>
        /// <param name="scrollMapFactoryService">Factory that creates or reuses an <see cref="IScrollMap"/> for an <see cref="ITextView"/>.</param>
        public MarginCore(IWpfTextView textView, ITextDocumentFactoryService textDocumentFactoryService, SVsServiceProvider vsServiceProvider, IEditorFormatMapService formatMapService, IScrollMapFactoryService scrollMapFactoryService)
        {
            Debug.WriteLine("Entering constructor.", Properties.Resources.ProductName);

            _textView = textView;
            if (!textDocumentFactoryService.TryGetTextDocument(_textView.TextBuffer, out _textDoc))
            {
                Debug.WriteLine("Can not retrieve TextDocument. Margin is disabled.", Properties.Resources.ProductName);
                _isEnabled = false;
                return;
            }

            _formatMap = formatMapService.GetEditorFormatMap(textView);
            _marginSettings = new MarginSettings(_formatMap);

            _scrollMap = scrollMapFactoryService.Create(textView);

            var dte = (DTE2)vsServiceProvider.GetService(typeof(DTE));
            _tfExt = dte.GetObject(typeof(TeamFoundationServerExt).FullName);
            Debug.Assert(_tfExt != null, "_tfExt is null.");
            _tfExt.ProjectContextChanged += OnTfExtProjectContextChanged;

            UpdateMargin();
        }
Ejemplo n.º 37
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="service"></param>
        /// <param name="workspace"></param>
        /// <param name="force">True when the user manually initiates a ShelveSet via the Team menu or mapped shortcut key.</param>
        private void CreateShelveset(VersionControlServer service, Workspace workspace, bool force)
        {
            // Build event args for notification create shelveset result
            var autoShelveEventArg = new ShelvesetCreatedEventArgs();

            try
            {
                // If there are no pending changes that have changed since the last shelveset then there is nothing to do
                bool isDelta = false;
                var pendingChanges = workspace.GetPendingChanges();
                int numPending = pendingChanges.Count();

                if (!force && numPending > 0)
                {
                    // Compare numPending to numItemsShelved;  Force shelveset if they differ
                    // Otherwise, resort to comparing file HashValues
                    var lastShelveset = GetPastShelvesets(service, workspace).FirstOrDefault();
                    var shelvedChanges = service.QueryShelvedChanges(lastShelveset)[0].PendingChanges;
                    int numItemsShelved = lastShelveset == null ? 0 : shelvedChanges.Count();
                    isDelta = (numPending != numItemsShelved) || pendingChanges.DifferFrom(shelvedChanges);
                }
                autoShelveEventArg.ShelvesetChangeCount = (force || isDelta) ? numPending : 0;
                if (force || isDelta)
                {
                    // Build a new, valid shelve set name
                    var setname = string.Format(ShelvesetName, workspace.Name, workspace.OwnerName, DateTime.Now, workspace.OwnerName.GetDomain(), workspace.OwnerName.GetLogin());
                    setname = CleanShelvesetName(setname);

                    // Actually create a new Shelveset 
                    var shelveset = new Shelveset(service, setname, workspace.OwnerName);
                    autoShelveEventArg.ShelvesetName = setname;
                    shelveset.Comment = string.Format("Shelved by {0}. {1} items", _extensionName, numPending);
                    workspace.Shelve(shelveset, pendingChanges, ShelvingOptions.Replace);

                    // Clean up past Shelvesets
                    if (MaximumShelvesets > 0)
                    {
                        foreach (var set in GetPastShelvesets(service, workspace).Skip(MaximumShelvesets))
                        {
                            service.DeleteShelveset(set);
                            autoShelveEventArg.ShelvesetsPurgeCount++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _tfsExt = null; // Force re-init on next attempt
                autoShelveEventArg.ExecutionException = ex;
            }
            // Fire event for each VS instance to report results
            if (OnShelvesetCreated != null)
            {
                OnShelvesetCreated(this, autoShelveEventArg);
            }
        }
        /// <summary>
        /// Called when [plan work item].
        /// </summary>
        /// <param name="workItemIds">The work item ids.</param>
        public void OnPlanWorkItem(int[] workItemIds, bool areWorkItemsSelected = true)
        {
            var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            if (dteService == null)
            {
                Debug.WriteLine("[PlanWorkItemController] DTE Service is null.");
                return;
            }

            var teamExplorer = (ITeamExplorer)(Package.GetGlobalService(typeof(ITeamExplorer)));

            teamFoundationServerExt = (dteService.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt);

            TfsClient tfsClient = new TfsClient(teamFoundationServerExt);

            teamExplorer.NavigateToPage(new Guid(PlanWorkItemPage.PageId), new PlanWorkItemPageModel()
            {
                WorkItemIds = workItemIds,
                UsersAvailableForAssign = tfsClient.GetUsers(),
                ConfigurationFilePath = TFSScrumExtensionsPackage.ConfigurationFilePath,
                AvailableWorkItemTypes = tfsClient.GetWorkItemsTypes(),
                AvailableWorkItemLinkTypes = tfsClient.GetWorkItemLinkTypes(),
                TfsClient = tfsClient,
                AreWorkItemsSelected = areWorkItemsSelected
            });
        }
Ejemplo n.º 39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TfsClient"/> class.
 /// </summary>
 /// <param name="tfsServer">The TFS server.</param>
 public TfsClient(TeamFoundationServerExt tfsServer)
 {
     this.TfsServer = tfsServer;
 }
 public TFSConnection(EnvDTE80.DTE2 _dte, ILogger _logger)
 {
     logger = _logger;
     teamFoundationServerExt = _dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;
 }
        public void DoConnect(TeamFoundationServerExt tfsEx)
        {
            try
            {
                this.tfsExt = tfsEx;

                if (null != this.tfsExt)
                {
                    this.tfsExt.ProjectContextChanged += new EventHandler(this.TfsExt_ProjectContextChanged);

                    if (null != this.tfsExt.ActiveProjectContext)
                    {
                        // Run the event handler without the event actually having fired, so we pick up the initial state.
                        this.TfsExt_ProjectContextChanged(null, EventArgs.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("***** MATTIAS **** " + ex.Message);
                ////MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 42
0
        public void CreateShelveset(bool force = false)
        {
            try
            {
                if (TfsExt == null) return;
                var domainUri = WebUtility.UrlDecode(_tfsExt.ActiveProjectContext.DomainUri);
                var teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(domainUri));
                teamProjectCollection.Credentials = CredentialCache.DefaultNetworkCredentials;
                teamProjectCollection.EnsureAuthenticated();

                var service = (VersionControlServer)teamProjectCollection.GetService(typeof(VersionControlServer));
                var allLocalWorkspaceInfo = Workstation.Current.GetAllLocalWorkspaceInfo();

                foreach (var workspaceInfo in allLocalWorkspaceInfo)
                {
                    // Replace(/,"") before comparing domainUri to prevent: "TFS Auto Shelve shelved 0 pending changes. Shelveset Name: "
                    if (workspaceInfo.MappedPaths.Length <= 0 ||
                        workspaceInfo.ServerUri.ToString().Replace("/", string.Empty) !=
                        domainUri.Replace("/", string.Empty)) continue;
                    var workspace = service.GetWorkspace(workspaceInfo);
                    CreateShelveset(service, workspace, force);
                }
            }
            catch (Exception ex)
            {
                _tfsExt = null; // Force re-init on next attempt
                if (OnShelvesetCreated != null)
                {
                    var autoShelveEventArg = new ShelvesetCreatedEventArgs { ExecutionException = ex };
                    OnShelvesetCreated(this, autoShelveEventArg);
                }
            }
        }