TFS Client Side Key

We use TFS as version control. Currently, project management is carried out through the local PMS application. We have a requirement, for example, when a team member checks the project, shows a user dialog for entering task information and updating our local pms database. I want to show a custom dialog that and / or after calling the check-in command. Also make sure that only successful submission of task information through these customizable dialog boxes, we can check projects.

+4
source share
2 answers

Create your own validation policy

. . , , , , Windows Forms .

fooobar.com/questions/1556178/....

, , .


Team Visual Studio , ​​ . , TFS.

URI IPolicyDefinition.InstallationInstructions. .msi, a .vsix zip script, . Visual Studio . Visual Studio, .

.msi, , .

, , , , " ". , .

, Visual Studio Power. Source Control Power Tools ( ), . , , , .

+9
 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.TeamFoundation.VersionControl.Client;
    namespace TFSPMSIntegration
    {
        [Serializable]
        public class CheckForPMSDetails : PolicyBase
        {
            public bool pmsDetailsConfirmed=false;
            private static frmPmsDetails _frm = null;
            public override string Description
            {
                get { return "Remind users to add PMS details to their checkins"; }
            }

            // This is a string that is stored with the policy definition on the source
            // control server.  If a user does not have our policy plugin installed, this string
            // will be displayed.  We can use this as an opportunity to explain to the user
            // how they might go about installing our policy plugin.
            public override string InstallationInstructions
            {
                get { return "To install this policy, follow the instructions in CheckForPMSDetails.cs."; }
            }

            // This string is the type of our policy.  It will be displayed to the user in a list
            // of all installed policy types when they are creating a new policy.
            public override string Type
            {
                get { return "Check for PMS Details"; }
            }

            // This string is a description of the type of our policy.  It will be displayed to the
            // user when they select our policy type in the list of policies installed on the system
            // as mentioned above.
            public override string TypeDescription
            {
                get { return "This policy will prompt the user to decide whether or not they should be allowed to check in."; }
            }

            // This method is invoked by the policy framework when the user creates a new checkin
            // policy or edits an existing checkin policy.  We can use this as an opportunity to
            // display UI specific to this policy type allowing the user to change the parameters
            // of the policy.
            public override bool Edit(IPolicyEditArgs args)
            {
                // no configuration to save
                return true;
            }

            // This method performs the actual evaluation.  It is called by the policy framework at various points in time
            // when policy should be evaluated.  In this example, we invoke this method ourselves when various asyc
            // events occur that may have invalidated the current list of failures.
            public override PolicyFailure[] Evaluate()
            {


                if (!pmsDetailsConfirmed)
                {
                    return new PolicyFailure[] {
                        new PolicyFailure("Please provide PMS Details about your checkin", this),
                    };
                }
                else
                {
                   //frmPmsDetails frm = Application.OpenForms["frmPmsDetails"] as frmPmsDetails;
                    if(_frm!=null)
                    PendingCheckin.PendingChanges.Comment = _frm.txtDescription.Text;
                    return new PolicyFailure[0];
                }
            }

            // This method is called if the user double-clicks on a policy failure in the UI.
            // We can handle this as we please, potentially prompting the user to perform
            // some activity that would eliminate the policy failure.
            public override void Activate(PolicyFailure failure)
            {
                //The Singleton design pattern is used for maitntain only one instance of Form class(UI).But everytime we have passing new value to the custom policy class.
                //Singleton approach needed , otherwise each time we click on policy message error, it will open multiple forms(UI)
                if (_frm == null)
                    _frm = new frmPmsDetails(this);
                else
                    _frm.CheckForPMSDetails = this;

                _frm.WindowState = FormWindowState.Minimized;
                _frm.TopMost = true;
                _frm.Show();
               _frm.ClearAll();
                _frm.WindowState = FormWindowState.Normal;
                _frm.BringToFront();

            }
            public void fn_Evaluate()
            {

                pmsDetailsConfirmed = true;
                base.OnPolicyStateChanged(Evaluate());


            }

            // This method is called if the user presses F1 when a policy failure is active in the UI.
            // We can handle this as we please, displaying help in whatever format is appropriate.
            // For this example, we'll just pop up a dialog.
            public override void DisplayHelp(PolicyFailure failure)
            {
                MessageBox.Show("This policy helps you to remember to add PMS details to your checkins.", "Prompt Policy Help");
            }

        }
    }

  • -

  • , VSIX, .

  • VS 2010, VS 2012, VS 2013, Visual Studio , Visual Studio SDK . VSIX Visual Studio SDK.

VSIX Visual Studio 2012

1. visual studio 2012.

2. Extensibility VSIX. enter image description here

  1. VSIX enter image description here
  2. , License.txt, : "policy.pkgdef" enter image description here

    1. policy.pkgdef. , "pkgdef".
  3. policy.pkgdef :

[$ RootKey $\ TeamFoundation\SourceControl\Checkin Policies] "TFSPMSIntegration" = "$ PackageFolder $\ TFSPMSIntegration.dll" enter image description here

1: , , , 2: , , " /".

  1. , vsixmanifest, source.extension.vsixmanifest.
  2. "" "policy.pkgdef", " " enter image description here

  3. VSIX, . , Visual Studio.

* , " ", enter image description here

enter image description here

+4

All Articles