PageRenderTime 5031ms CodeModel.GetById 20ms RepoModel.GetById 4ms app.codeStats 0ms

/PsTFS.CmdLet/Commandes/Add/Add-Label.cs

#
C# | 143 lines | 82 code | 16 blank | 45 comment | 2 complexity | b3fecbd7c4c26020a49c9c2d41523d76 MD5 | raw file
  1. /*
  2. * PsTFS is a set of PowerShell commands to manage and use Team Foundation Server. PowerShell
  3. * effectiveness is combined with the power of TFS API to maximizes TFS capabilities.
  4. *
  5. * Creator : Choulant Noham
  6. * Mail : choulant@gmail.com
  7. * Blog : http://choulant.blogspot.com
  8. *
  9. */
  10. using System;
  11. using System.Management.Automation;
  12. using Microsoft.TeamFoundation.Client;
  13. using Microsoft.TeamFoundation.VersionControl.Client;
  14. using PsTFS.Objects;
  15. using PsTFS.Objects.Methodes;
  16. namespace PsTFS.Commandes.Add
  17. {
  18. /// <summary>
  19. /// Ajout d'un label
  20. /// </summary>
  21. [Cmdlet(VerbsCommon.Add, "Label")]
  22. public class Add_Label : PsCmdlet
  23. {
  24. /// <summary>
  25. /// Constructeur
  26. /// </summary>
  27. public Add_Label()
  28. {
  29. this.RecursionType = RecursionType.Full;
  30. this.Description = string.Empty;
  31. this.LabelName = string.Empty;
  32. this.Item = null;
  33. }
  34. /// <summary>
  35. /// Processus de création de label
  36. /// </summary>
  37. protected override void ProcessRecord()
  38. {
  39. try
  40. {
  41. if (this.Scope.IndexOf('$') < 0)
  42. {
  43. this.Scope = "$/" + this.Scope;
  44. }
  45. //Récupération du version control de tfs
  46. VersionControlServer versionControl = Methode_Service.VCS();
  47. //Récupération du version control pour le label
  48. VersionControlLabel vcl = new VersionControlLabel(versionControl
  49. , this.LabelName
  50. , versionControl.AuthenticatedUser
  51. , this.Scope
  52. , this.Description);
  53. //Création du tableau des item sur les quel mettre un label
  54. LabelItemSpec[] labelItemSpecs = new LabelItemSpec[this.Item.Length];
  55. for (int i = 0; i < this.Item.Length; i++)
  56. {
  57. ItemSpec itemSpec = new ItemSpec(this.Item[i], this.RecursionType);
  58. labelItemSpecs[i] = new LabelItemSpec(itemSpec, VersionSpec.Latest, false);
  59. }
  60. //Construction du label
  61. LabelResult[] result = versionControl.CreateLabel(vcl, labelItemSpecs, LabelChildOption.Replace);
  62. //Information
  63. Console.WriteLine("Successfully created label " + vcl.Name);
  64. //Renvois les informations
  65. WriteObject(result);
  66. }
  67. catch(Exception ex)
  68. {
  69. ErrorRecord err = new ErrorRecord(ex, Error.GetInstance().GetError(this), ErrorCategory.WriteError, null);
  70. WriteError(err);
  71. Log.AddLog(ex.StackTrace);
  72. }
  73. finally
  74. {
  75. base.ProcessRecord();
  76. }
  77. }
  78. /// <summary>
  79. /// Permet d'informer la fin de la commande
  80. /// </summary>
  81. protected override void EndProcessing()
  82. {
  83. Log.AddLog(null, "Add-Label is end");
  84. base.EndProcessing();
  85. }
  86. /// <summary>
  87. /// Object contenant Team Foundation Server
  88. /// </summary>
  89. [Parameter(Position = 0)]
  90. public TeamFoundationServer TFS
  91. {
  92. set
  93. {
  94. Context.GetContext().Tfs = value;
  95. }
  96. }
  97. /// <summary>
  98. /// Nom du label
  99. /// </summary>
  100. [Parameter(Position = 1, Mandatory = true)]
  101. [ValidateNotNullOrEmpty]
  102. public string LabelName { get; set; }
  103. /// <summary>
  104. /// Projet sur le quel mettre le label
  105. /// </summary>
  106. [Parameter(Position = 2)]
  107. public string Scope { get; set; }
  108. /// <summary>
  109. /// Description du label
  110. /// </summary>
  111. [Parameter(Position = 3, Mandatory = true)]
  112. [ValidateNotNullOrEmpty]
  113. public string Description { get; set; }
  114. /// <summary>
  115. /// Possibilité full, OneLenvel, none
  116. /// </summary>
  117. [Parameter(Position = 4, Mandatory = true)]
  118. [ValidateNotNullOrEmpty]
  119. public RecursionType RecursionType { get; set; }
  120. /// <summary>
  121. /// Elements ŕ labeliser
  122. /// </summary>
  123. [Parameter(Position = 5, Mandatory = true)]
  124. [ValidateNotNullOrEmpty]
  125. public string[] Item { get; set; }
  126. }
  127. }