using System; namespace P4API { /// <summary> /// A P4Callback class that populates a P4Recordset /// </summary> /// <remarks> /// /// </remarks> 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; } /// <summary> /// Initializes a new instance of the <see cref="P4RecordsetCallback"/> class. /// </summary> public P4RecordsetCallback() { _P4ResultRecordset = new P4RecordSet(); _P4Result = _P4ResultRecordset; } /// <summary> /// Gets the recordset. /// </summary> /// <value>The recordset.</value> public P4RecordSet Recordset { get { return _P4ResultRecordset; } } #region P4Callback Members /// <summary> /// Edits the specified f1. /// </summary> /// <param name="f1">The f1.</param> public override void Edit(System.IO.FileInfo f1) { throw new P4API.Exceptions.FormCommandException(); } /// <summary> /// Prompts the specified MSG. /// </summary> /// <param name="msg">The MSG.</param> /// <param name="rsp">The RSP.</param> public override void Prompt(string msg, ref string rsp) { rsp = _P4Result.RaiseOnPromptEvent(msg); } /// <summary> /// Resolves the file. /// </summary> /// <param name="mergeData">The merge data.</param> /// <returns></returns> public override MergeAction ResolveFile(MergeData mergeData) { // don't handle a merge action here throw new Exceptions.MergeNotImplemented(); } /// <summary> /// Finisheds this instance. /// </summary> public override void Finished() { _P4Result.SpecDef = base.SpecDef; _P4Result.Finished(); } /// <summary> /// Outputs the info. /// </summary> /// <param name="data">The data.</param> public override void OutputInfo(string data) { _P4Result.AddInfo(data); } /// <summary> /// Cancels this instance. /// </summary> /// <returns></returns> public override bool Cancel() { return false; } /// <summary> /// Outputs the content. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="IsText">if set to <c>true</c> [is text].</param> public override void OutputContent(byte[] buffer, bool IsText) { if (IsText) { string data = base.ContentEncoding.GetString(buffer); _P4Result.AddInfo(data); } else { _P4Result.BinaryOutput = buffer; } } /// <summary> /// Inputs the data. /// </summary> /// <param name="buffer">The buffer.</param> public override void InputData(System.Text.StringBuilder buffer) { buffer.Append(_P4Result.InputData); } /// <summary> /// Outputs the record. /// </summary> /// <param name="record">The record.</param> public override void OutputRecord(P4Record record) { _P4Result.AddRecord(record); } /// <summary> /// Outputs the message. /// </summary> /// <param name="message">The message.</param> 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 } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7291 | Andrew McDonald | initial submittal | ||
//guest/shawn_hladky/P4.Net/main/src/P4API/P4RecordsetCallback.cs | |||||
#2 | 7204 | Shawn Hladky | P4.Net: Added Map functionality | ||
#1 | 6505 | Shawn Hladky |
P4.Net: Multiple Changes 1. Update samples to VS2008 and new bin paths 2. Update MSBuild sync tasks to have IgnoredWarnings parameter 3. Added public class for P4RecordsetCallback. This allows consumers to easily migrate code that uses Recordsets to also take advantage of callback hooks. 4. Reworked method signiture of RunCallback. Removed tagged parameter and added RunCallbackUnparsed method. Made Callback parameter first so command and arguments are next to one-another. Note: this is a BREAKING CHANGE if you are using callbacks. 5. Reworked so switching between tagged and untagged runs will not disconnect/reconnect. 6. Add initial work for a file diffing object. |