1: using System;
2: using System.Collections;
3: using System.Collections.Specialized;
4: using System.Management.Automation;
5: using Com.FastSearch.Esp.Content;
6: using Com.FastSearch.Esp.Content.Config;
7: using Com.FastSearch.Esp.Content.Errors;
8: using Com.FastSearch.Esp.Content.Util;
9:
10: namespace PointBridge.FAST.Cmdlets.Content
11: {
12: [Cmdlet("Remove", "ContentItem")]
13: public class RemoveContentItem : Cmdlet
14: {
15: [Parameter(Mandatory=true, ValueFromPipeline=true, Position=0)]
16: public string ContentID { get; set; }
17:
18: [Parameter(Mandatory=true, Position=1)]
19: public string Collection { get; set; }
20:
21: [Parameter(Mandatory=true, Position=2)]
22: public string ContentDistributor { get; set; }
23:
24: private IDocumentFeeder _feeder = null;
25:
26: protected override void BeginProcessing()
27: {
28: base.BeginProcessing();
29: try
30: {
31: _feeder = Factory.CreateDocumentFeeder(ContentDistributor, Collection);
32: }
33: catch (Exception ex)
34: {
35: WriteError(new ErrorRecord(ex, "ContentFactoryOperationError", ErrorCategory.InvalidOperation, _feeder));
36: }
37:
38: }
39:
40: protected override void ProcessRecord()
41: {
42: base.ProcessRecord();
43:
44: if (_feeder == null) return;
45:
46: long opID = _feeder.RemoveDocument(ContentID);
47: WriteObject(string.Format("Removing item '{0}'. Operation ID: {1}", ContentID, opID));
48:
49: }
50:
51: protected override void EndProcessing()
52: {
53: base.EndProcessing();
54:
55: if (_feeder == null) return;
56:
57: _feeder.WaitForCompletion();
58: BuildStatusReport(_feeder.GetStatusReport());
59: _feeder.Dispose();
60: }
61:
62: private void BuildStatusReport(IDocumentFeederStatus status)
63: {
64: if (status.HasDocumentErrors())
65: {
66: WriteObject(string.Format("Total Errors: {0}", status.NumDocumentErrors));
67:
68: foreach (Pair p in status.AllDocumentErrors)
69: {
70: DocumentError error = (DocumentError)p.Second;
71:
72: WriteObject(string.Format("Operation ID: {0} Document ID: {1} Error Code: {2} Description: {3}",
73: (long)p.First, error.DocumentId, error.ErrorCode, error.Description));
74:
75: }
76: }
77:
78: if (status.HasDocumentWarnings())
79: {
80: WriteObject(string.Format("Total Warnings: {0}", status.NumDocumentWarnings));
81:
82: foreach (Pair p in status.DocumentWarnings)
83: {
84: DocumentWarning warning = (DocumentWarning)p.Second;
85:
86: WriteObject(string.Format("Operation ID: {0} Document ID: {1} Warning Code: {2} Description: {3}",
87: (long)p.First, warning.DocumentId, warning.WarningCode, warning.Description));
88:
89: }
90:
91: }
92: }
93: }
94: }