/* * P4.Net * Copyright (c) 2007-2010 Shawn Hladky Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using System; using System.Text; using System.IO; namespace P4API { /// /// /// public abstract class P4Callback { private Encoding _encoding = null; internal void SetEncoding(Encoding encoding) { _encoding = (Encoding)encoding.Clone(); } private string _specDef = null; internal void SetSpecDef(string specDef) { _specDef = specDef; } /// /// Gets the specdef for a form if it exists. /// /// /// A specdef is a specially coded character string that Perforce uses internally to define the /// structure of fields in a form. /// protected string SpecDef { get { return _specDef; } } /// /// Gets the content encoding. /// /// The content encoding is either UTF-8 for Unicode-enabled servers or ASCII otherwise. protected Encoding ContentEncoding { get { return _encoding; } } /// /// Executed when a command requests an editor to launch. /// /// The file on the local system to launch in the editor. public virtual void Edit(FileInfo f1) { } /// /// Executed when the Perforce command needs to "prompt" the user for a response. /// /// The message output from the Perforce command. /// The response sent back to Perforce. public virtual void Prompt(string message, ref string response) { } /// /// Executes when the command is finished. /// public virtual void Finished() { // do nothing } /// /// Allows consumers to cancel the current command. /// /// Return true to kill the current command. /// /// The cancel method is called periodically during long-running commands. /// You can't always guarantee when it will be called, or how quickly it will cancel the command. /// public virtual bool Cancel() { return false; } /// /// Executed when a command outputs file content. /// /// A buffer containing a chunk of data. /// If set to true [is text]. /// /// OutputContent is typically called from the 'print' command, but can also be called from 'describe', /// 'diff', or 'diff2'. /// Output content may be called several times for a single file if it is large. You must orchestrate /// between calls to OutputMessage and OutputContent to know which file you are working with. /// If the content is textual, you can use the ContentEncoding property to convert to text. /// public virtual void OutputContent(byte[] buffer, bool IsText) { } /// /// Executed when a command expects a file buffer input. /// /// A reference to a buffer. Append strings to the buffer to send file content to the server. /// /// InputData is called from form input commands. In general it's easier to use the P4Form class to manipulate forms than /// handling through the P4Callback interface. /// public virtual void InputData(StringBuilder buffer) { } /// /// Executed when tagged output is streamed from the server. /// /// The tagged output in the form of a P4Record. public virtual void OutputRecord(P4Record record) { } /// /// Executed when a textual message is streamed from the server. /// /// The message. public abstract void OutputMessage(P4Message message); /// /// Executed when a textual message is output from the underlying API. /// /// The textual message. /// /// The majority of commands output messages from OutputMessage, but there are some commands that ocasionally /// call OutputInfo without the full data of the message string. /// public virtual void OutputInfo(string data) { } /// /// Executed when a 'resolve' command seeks input on how to resolve a file. /// /// The merge data containing information on the files to resolve. /// Merge action for the file. /// /// mergeData is disposed after ResolveFile completes. Do not persist a reference to the mergeData object. /// public virtual MergeAction ResolveFile(MergeData mergeData) { return MergeAction.Quit; } } }