/Source/Trunk/PSStudio/AspenManagementCmdlets/AspenManagementCmdlets/SetCmdletCommand.cs

# · C# · 511 lines · 465 code · 44 blank · 2 comment · 34 complexity · d462edddbd26cd62e048c47d121490d0 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Management.Automation;
  5. namespace Microsoft.PowerShell.CmdletManagement
  6. {
  7. [Cmdlet(VerbsCommon.Set, "PsSpecCmdlet", SupportsShouldProcess = true)]
  8. public class SetPsSpecCmdletCommand : PsSpecCommandBase
  9. {
  10. [Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true)]
  11. public int Id
  12. {
  13. get
  14. {
  15. return _id;
  16. }
  17. set
  18. {
  19. _id = value;
  20. }
  21. }
  22. private int _id = -1;
  23. [Parameter(ValueFromPipelineByPropertyName = true)]
  24. public String Snapin
  25. {
  26. get
  27. {
  28. return _snapin;
  29. }
  30. set
  31. {
  32. if ((value != null) && (value.Length > 200))
  33. throw new ArgumentOutOfRangeException("Snapin");
  34. _snapin = value;
  35. }
  36. }
  37. private string _snapin;
  38. [Parameter(ValueFromPipelineByPropertyName = true)]
  39. [ValidateLength(1, 50)]
  40. public String Verb
  41. {
  42. get
  43. {
  44. return _verb;
  45. }
  46. set
  47. {
  48. _verb = value;
  49. }
  50. }
  51. private string _verb;
  52. [Parameter(ValueFromPipelineByPropertyName = true)]
  53. [ValidateLength(1, 50)]
  54. public String Noun
  55. {
  56. get
  57. {
  58. return _noun;
  59. }
  60. set
  61. {
  62. _noun = value;
  63. }
  64. }
  65. private string _noun;
  66. [Parameter(ValueFromPipelineByPropertyName = true)]
  67. [AllowNull]
  68. [AllowEmptyString]
  69. public String TeamMembers
  70. {
  71. get
  72. {
  73. return _teamMembers;
  74. }
  75. set
  76. {
  77. if ((value != null) && (value.Length > 500))
  78. throw new ArgumentOutOfRangeException("TeamMembers");
  79. _teamMembers = value;
  80. }
  81. }
  82. private string _teamMembers;
  83. [Parameter(ValueFromPipelineByPropertyName = true)]
  84. [AllowNull]
  85. [AllowEmptyString]
  86. public String ShortDescription
  87. {
  88. get
  89. {
  90. return _shortDescription;
  91. }
  92. set
  93. {
  94. if ((value != null) && (value.Length > 2000))
  95. throw new ArgumentOutOfRangeException("ShortDescription");
  96. _shortDescription = value;
  97. }
  98. }
  99. private string _shortDescription;
  100. [Parameter(ValueFromPipelineByPropertyName = true)]
  101. [AllowNull]
  102. [AllowEmptyString]
  103. public String LongDescription
  104. {
  105. get
  106. {
  107. return _longDescription;
  108. }
  109. set
  110. {
  111. _longDescription = value;
  112. }
  113. }
  114. private string _longDescription;
  115. [Parameter(ValueFromPipelineByPropertyName = true)]
  116. public bool? SupportsShouldProcess
  117. {
  118. get
  119. {
  120. return _supportsShouldProcess;
  121. }
  122. set
  123. {
  124. _supportsShouldProcess = value;
  125. }
  126. }
  127. private bool? _supportsShouldProcess;
  128. [AllowNull]
  129. [AllowEmptyString]
  130. [Parameter(ValueFromPipelineByPropertyName = true)]
  131. public String Notes
  132. {
  133. get
  134. {
  135. return _notes;
  136. }
  137. set
  138. {
  139. _notes = value;
  140. }
  141. }
  142. private string _notes;
  143. [Parameter(ValueFromPipelineByPropertyName = true)]
  144. [AllowNull]
  145. [AllowEmptyString]
  146. public String SpecExamples
  147. {
  148. get
  149. {
  150. return _specExamples;
  151. }
  152. set
  153. {
  154. _specExamples = value;
  155. }
  156. }
  157. private string _specExamples;
  158. [Parameter(ValueFromPipelineByPropertyName = true)]
  159. public PsSpecHelpExample[] HelpExamples
  160. {
  161. get
  162. {
  163. return _helpExamples;
  164. }
  165. set
  166. {
  167. _helpExamples = value;
  168. }
  169. }
  170. private PsSpecHelpExample[] _helpExamples;
  171. [Parameter(ValueFromPipelineByPropertyName = true)]
  172. [AllowNull]
  173. [AllowEmptyString]
  174. public String OutputObject
  175. {
  176. get
  177. {
  178. return _outputObject;
  179. }
  180. set
  181. {
  182. if ((value != null) && (value.Length > 500))
  183. throw new ArgumentOutOfRangeException("OutputObject");
  184. _outputObject = value;
  185. }
  186. }
  187. private string _outputObject;
  188. [Parameter(ValueFromPipelineByPropertyName = true)]
  189. [AllowNull]
  190. [AllowEmptyString]
  191. public String OutputObjectDescription
  192. {
  193. get
  194. {
  195. return _outputObjectDescription;
  196. }
  197. set
  198. {
  199. _outputObjectDescription = value;
  200. }
  201. }
  202. private string _outputObjectDescription;
  203. [Parameter(ValueFromPipelineByPropertyName = true)]
  204. [AllowNull]
  205. [AllowEmptyString]
  206. public String RelatedTo
  207. {
  208. get
  209. {
  210. return _relatedTo;
  211. }
  212. set
  213. {
  214. if ((value != null) && (value.Length > 1000))
  215. throw new ArgumentOutOfRangeException("RelatedTo");
  216. _relatedTo = value;
  217. }
  218. }
  219. private string _relatedTo;
  220. [Parameter(ValueFromPipelineByPropertyName = true)]
  221. [AllowNull]
  222. [AllowEmptyString]
  223. public String DefaultParameterSetName
  224. {
  225. get
  226. {
  227. return _defaultParameterSetName;
  228. }
  229. set
  230. {
  231. if ((value != null) && (value.Length > 50))
  232. throw new ArgumentOutOfRangeException("DefaultParameterSetName");
  233. _defaultParameterSetName = value;
  234. }
  235. }
  236. private string _defaultParameterSetName;
  237. [Parameter(ValueFromPipelineByPropertyName = true)]
  238. [AllowNull]
  239. [AllowEmptyString]
  240. public String Custom1
  241. {
  242. get
  243. {
  244. return _custom1;
  245. }
  246. set
  247. {
  248. _custom1 = value;
  249. }
  250. }
  251. private string _custom1;
  252. [Parameter(ValueFromPipelineByPropertyName = true)]
  253. [AllowNull]
  254. [AllowEmptyString]
  255. public String Custom2
  256. {
  257. get
  258. {
  259. return _custom2;
  260. }
  261. set
  262. {
  263. _custom2 = value;
  264. }
  265. }
  266. private string _custom2;
  267. [Parameter(ValueFromPipelineByPropertyName = true)]
  268. [AllowNull]
  269. [AllowEmptyString]
  270. public String Custom3
  271. {
  272. get
  273. {
  274. return _custom3;
  275. }
  276. set
  277. {
  278. _custom3 = value;
  279. }
  280. }
  281. private string _custom3;
  282. [Parameter(ValueFromPipelineByPropertyName = true)]
  283. [AllowNull]
  284. [AllowEmptyString]
  285. public String Custom4
  286. {
  287. get
  288. {
  289. return _custom4;
  290. }
  291. set
  292. {
  293. _custom4 = value;
  294. }
  295. }
  296. private string _custom4;
  297. [Parameter(ValueFromPipelineByPropertyName = true)]
  298. [AllowNull]
  299. [AllowEmptyString]
  300. public String Status
  301. {
  302. get
  303. {
  304. return _status;
  305. }
  306. set
  307. {
  308. if ((value != null) && (value.Length > 100))
  309. throw new ArgumentOutOfRangeException("Status");
  310. _status = value;
  311. }
  312. }
  313. private string _status;
  314. [Parameter(ValueFromPipelineByPropertyName = true)]
  315. [AllowNull]
  316. [AllowEmptyString]
  317. public String HelpStatus
  318. {
  319. get
  320. {
  321. return _helpStatus;
  322. }
  323. set
  324. {
  325. if ((value != null) && (value.Length > 100))
  326. throw new ArgumentOutOfRangeException("HelpStatus");
  327. _helpStatus = value;
  328. }
  329. }
  330. private string _helpStatus;
  331. [Parameter(ValueFromPipelineByPropertyName = true)]
  332. [AllowNull]
  333. [AllowEmptyString]
  334. public String HelpShortDescription
  335. {
  336. get
  337. {
  338. return _helpShortDescription;
  339. }
  340. set
  341. {
  342. if ((value != null) && (value.Length > 2000))
  343. throw new ArgumentOutOfRangeException("HelpShortDescription");
  344. _helpShortDescription = value;
  345. }
  346. }
  347. private string _helpShortDescription;
  348. [Parameter(ValueFromPipelineByPropertyName = true)]
  349. [AllowNull]
  350. [AllowEmptyString]
  351. public String HelpLongDescription
  352. {
  353. get
  354. {
  355. return _helpLongDescription;
  356. }
  357. set
  358. {
  359. _helpLongDescription = value;
  360. }
  361. }
  362. private string _helpLongDescription;
  363. [Parameter(ValueFromPipelineByPropertyName = true)]
  364. [AllowNull]
  365. [AllowEmptyString]
  366. public String InputObject
  367. {
  368. get
  369. {
  370. return _helpInputObject;
  371. }
  372. set
  373. {
  374. if ((value != null) && (value.Length > 500))
  375. throw new ArgumentOutOfRangeException("InputObject");
  376. _helpInputObject = value;
  377. }
  378. }
  379. private string _helpInputObject;
  380. [Parameter(ValueFromPipelineByPropertyName = true)]
  381. [AllowNull]
  382. [AllowEmptyString]
  383. public String HelpInputObjectDescription
  384. {
  385. get
  386. {
  387. return _helpInputObjectDescription;
  388. }
  389. set
  390. {
  391. _helpInputObjectDescription = value;
  392. }
  393. }
  394. private string _helpInputObjectDescription;
  395. [Parameter(ValueFromPipelineByPropertyName = true)]
  396. [AllowNull]
  397. [AllowEmptyString]
  398. public String HelpOutputObjectDescription
  399. {
  400. get
  401. {
  402. return _helpOutputObjectDescription;
  403. }
  404. set
  405. {
  406. _helpOutputObjectDescription = value;
  407. }
  408. }
  409. private string _helpOutputObjectDescription;
  410. [Parameter(ValueFromPipelineByPropertyName = true)]
  411. [AllowNull]
  412. [AllowEmptyString]
  413. public String HelpAdditionalNotes
  414. {
  415. get
  416. {
  417. return _helpAdditionalNotes;
  418. }
  419. set
  420. {
  421. _helpAdditionalNotes = value;
  422. }
  423. }
  424. private string _helpAdditionalNotes;
  425. protected override void ProcessRecord()
  426. {
  427. if (ShouldProcess(
  428. String.Format("{0}", ServiceUri),
  429. String.Format(resources.UpdateCmdletShouldProcess, Id)))
  430. {
  431. // Update the cmdlet
  432. try
  433. {
  434. PsSpecCmdletService.PsSpecHelpExample[] outgoingHelpExamples =
  435. new PsSpecCmdletService.PsSpecHelpExample[0];
  436. // Populate the help examples
  437. if (HelpExamples != null)
  438. {
  439. outgoingHelpExamples =
  440. new PsSpecCmdletService.PsSpecHelpExample[HelpExamples.Length];
  441. for (int counter = 0; counter < HelpExamples.Length; counter++)
  442. {
  443. PsSpecCmdletService.PsSpecHelpExample newExample =
  444. new PsSpecCmdletService.PsSpecHelpExample();
  445. PsSpecHelpExample incomingExample = HelpExamples[counter];
  446. newExample.Id = incomingExample.Id;
  447. newExample.Command = incomingExample.Command;
  448. newExample.Output = incomingExample.Output;
  449. newExample.Description = incomingExample.Description;
  450. outgoingHelpExamples[counter] = newExample;
  451. }
  452. }
  453. Service.UpdateCmdlet(Id, Snapin, Verb, Noun, TeamMembers, ShortDescription,
  454. HelpShortDescription, LongDescription, HelpLongDescription,
  455. Status, HelpStatus, SupportsShouldProcess, Notes, SpecExamples, outgoingHelpExamples,
  456. InputObject, HelpInputObjectDescription, OutputObject, OutputObjectDescription,
  457. HelpOutputObjectDescription, DefaultParameterSetName,
  458. RelatedTo, Custom1, Custom2, Custom3, Custom4, HelpAdditionalNotes, "%");
  459. }
  460. catch (System.Web.Services.Protocols.SoapException e)
  461. {
  462. WriteError(new ErrorRecord(e, "PROJECT_SERVICE_ERROR", ErrorCategory.InvalidOperation, Id));
  463. }
  464. }
  465. }
  466. }
  467. }