using System; namespace P4API { /// /// A P4Callback class that populates a P4Recordset /// /// /// /// public class P4RecordsetCallback : P4Callback { private P4BaseRecordSet _P4Result; // instance variable for the super class when this is created externally private P4RecordSet _P4ResultRecordset; internal P4RecordsetCallback(P4BaseRecordSet p4Result) { _P4Result = p4Result; _P4ResultRecordset = null; } /// /// Initializes a new instance of the class. /// public P4RecordsetCallback() { _P4ResultRecordset = new P4RecordSet(); _P4Result = _P4ResultRecordset; } /// /// Gets the recordset. /// /// The recordset. public P4RecordSet Recordset { get { return _P4ResultRecordset; } } #region P4Callback Members /// /// Edits the specified f1. /// /// The f1. public override void Edit(System.IO.FileInfo f1) { throw new P4API.Exceptions.FormCommandException(); } /// /// Prompts the specified MSG. /// /// The MSG. /// The RSP. public override void Prompt(string msg, ref string rsp) { rsp = _P4Result.RaiseOnPromptEvent(msg); } /// /// Resolves the file. /// /// The merge data. /// public override MergeAction ResolveFile(MergeData mergeData) { // don't handle a merge action here throw new Exceptions.MergeNotImplemented(); } /// /// Finisheds this instance. /// public override void Finished() { _P4Result.SpecDef = base.SpecDef; _P4Result.Finished(); } /// /// Outputs the info. /// /// The data. public override void OutputInfo(string data) { _P4Result.AddInfo(data); } /// /// Cancels this instance. /// /// public override bool Cancel() { return false; } /// /// Outputs the content. /// /// The buffer. /// if set to true [is text]. public override void OutputContent(byte[] buffer, bool IsText) { if (IsText) { string data = base.ContentEncoding.GetString(buffer); _P4Result.AddInfo(data); } else { _P4Result.BinaryOutput = buffer; } } /// /// Inputs the data. /// /// The buffer. public override void InputData(System.Text.StringBuilder buffer) { buffer.Append(_P4Result.InputData); } /// /// Outputs the record. /// /// The record. public override void OutputRecord(P4Record record) { _P4Result.AddRecord(record); } /// /// Outputs the message. /// /// The message. public override void OutputMessage(P4Message message) { _P4Result.AddP4Message(message); //Console.WriteLine("{0}: {1}", (int)message.Severity, message.Identity); switch (message.Severity) { case P4MessageSeverity.Empty: // E_EMPTY (0) | no error _P4Result.AddString(message.Format()); break; case P4MessageSeverity.Info: // E_INFO (1) | information, not necessarily an error _P4Result.AddInfo(message.Format()); break; case P4MessageSeverity.Warning: // E_WARN (2) | a minor error occurred _P4Result.AddWarning(message.Format()); break; case P4MessageSeverity.Failed: // E_FAILED(3) | the command was used incorrectly _P4Result.AddError(message.Format()); break; case P4MessageSeverity.Fatal: // E_FATAL (4) | fatal error, the command can't be processed _P4Result.AddError(message.Format()); break; default: //TODO throw an error... unknown severity break; } } #endregion } }