- /*
- * 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.Collections;
- using System.Collections.Specialized;
- using System.Collections.Generic;
- using System.Text;
- using System.Diagnostics;
- namespace P4API
- {
- /// <summary>
- /// Base functionality for P4Recordset and P4UnParsedRecordset.
- /// </summary>
- /// <remarks>This is a base class for internal use. Do not use directly.</remarks>
- /// <seealso cref="P4API.P4RecordSet"/>
- public abstract class P4BaseRecordSet
- {
- internal List<string> StringOutputs;
- internal List<string> InfoOutputs;
- internal List<string> ErrorOutputs;
- internal List<string> WarningOutputs;
- internal List<P4Record> TaggedOutputs;
- internal List<P4Message> Messages;
- private string _loginPassword;
- private string _inputData = String.Empty;
- internal string _SpecDef;
- internal byte[] BinaryOutput;
- virtual internal string SpecDef
- {
- get
- {
- return _SpecDef;
- }
- set
- {
- _SpecDef = value;
- }
- }
- internal delegate void OnPromptEventHandler(object sender, P4PromptEventArgs e);
- internal event OnPromptEventHandler OnPrompt;
- internal P4BaseRecordSet()
- {
- StringOutputs = new List<string>();
- InfoOutputs = new List<string>();
- ErrorOutputs = new List<string>();
- WarningOutputs = new List<string>();
- TaggedOutputs = new List<P4Record>();
- Messages = new List<P4Message>();
- }
- internal void AddP4Message(P4Message message)
- {
- Messages.Add(message);
- }
- internal void AddInfo(string S)
- {
- StringOutputs.Add(S);
- }
- internal void AddString(string S)
- {
- InfoOutputs.Add(S);
- }
- internal void AddError(string S)
- {
- ErrorOutputs.Add(S);
- }
- internal void AddWarning(string S)
- {
- WarningOutputs.Add(S);
- }
- virtual internal void AddRecord(P4Record r)
- {
- TaggedOutputs.Add(r);
- }
- virtual internal void Finished()
- {
- // do nothing by default
- }
- /// <summary>
- /// Checks the Recordset to determine if errors occured.
- /// </summary>
- /// <returns>True if the p4 command returned errors.</returns>
- /// <remarks>This is the same as testing <c>Errors.Count</c>.</remarks>
- public bool HasErrors()
- {
- return (!(ErrorOutputs.Count == 0));
- }
- /// <summary>
- /// Dumps recordset data to the Trace listner.
- /// </summary>
- /// <remarks>Only availble for debug libraries.</remarks>
- public void Dump()
- {
- foreach (P4Message msg in Messages)
- {
- msg.Dump();
- }
- foreach (P4Record r in TaggedOutputs)
- {
- foreach (string key in r.Fields.Keys)
- {
- Trace.WriteLine(string.Format("... ... {0}={1}", key, r[key]));
- }
- foreach (string key in r.ArrayFields.Keys)
- {
- for (int i = 0; i < r.ArrayFields[key].Length; i++ )
- {
- Trace.WriteLine(string.Format("... ... {0}{2}={1}", key, r.ArrayFields[key][i], i));
- }
- }
- }
- }
- /// <summary>
- /// Checks the Recordset to determine if warnings occured.
- /// </summary>
- /// <remarks>This is the same as testing <c>Warnings.Count</c>.</remarks>
- /// <returns>True if the p4 command returned warnings.</returns>
- public bool HasWarnings()
- {
- return (!(WarningOutputs.Count == 0));
- }
- /// <summary>
- /// Gets an array of error messages returned from the Perforce command.
- /// </summary>
- /// <remarks>These are the error messages that are returned from Perforce.</remarks>
- public string[] Errors
- {
- get
- {
- return ErrorOutputs.ToArray();
- }
- }
- /// <summary>
- /// Gets an array of P4Messages returned from the Perforce command.
- /// </summary>
- /// <remarks>These are the error messages that are returned from Perforce.</remarks>
- public IList<P4Message> P4Messages
- {
- get
- {
- return Messages;
- }
- }
- /// <summary>
- /// Gets an error messages returned from the Perforce command.
- /// </summary>
- /// <remarks>Errors are concatanated to one string, seperated by new lines.</remarks>
- public string ErrorMessage
- {
- get
- {
- string ret = "";
- foreach (string s in Errors)
- {
- ret += s + "\n";
- }
- return ret;
- }
- }
- /// <summary>
- /// Gets an array of warning messages returned from the Perforce command.
- /// </summary>
- /// <remarks>These are the warning messages that are returned from Perforce.</remarks>
- /// <note>Perforce is not always intuitive in how it defines warnings vs. messages.
- /// Always test various scenarios to determine whether the output is a warning or message.</note>
- /// <value>Array of warnings returned from Perforce.</value>
- public string[] Warnings
- {
- get
- {
- return WarningOutputs.ToArray();
- }
- }
- internal string InputData
- {
- get
- {
- return _inputData;
- }
- set
- {
- _inputData = value;
- }
- }
- internal string LoginPassword
- {
- get
- {
- return _loginPassword;
- }
- set
- {
- _loginPassword = value;
- }
- }
- internal string RaiseOnPromptEvent(string Message)
- {
- if (_loginPassword != null && Message == "Enter password: ")
- {
- //no need to raise an event...
- return _loginPassword;
- }
- // Make a temporary copy of the event to avoid possibility of
- // a race condition if the last subscriber unsubscribes
- // immediately after the null check and before the event is raised.
- OnPromptEventHandler handler = OnPrompt;
- // Event will be null if there are no subscribers
- if (handler != null)
- {
- P4PromptEventArgs e = new P4PromptEventArgs(Message);
- // Use the () operator to raise the event.
- handler(this, e);
- return e.Response;
- }
- else
- {
- return string.Empty;
- }
- }
- }
- }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7889 | Johan Nilsson | Branch from Shawn Hladky's original P4.Net (main branch). Changed file type for StandardT...est.cs and UnicodeTest.cs in order to be able to check them in. « |
14 years ago | |
//guest/shawn_hladky/P4.Net/main/src/P4API/P4BaseRecordSet.cs | |||||
#9 | 7709 | Shawn Hladky | P4.Net: Cleanup, documentation, and a a start for implementing an object-based outpu...t for filelog. « | 15 years ago | |
#8 | 6505 | Shawn Hladky | P4.Net: Multiple Changes 1. Update samples to VS2008 and new bin paths 2.&nb...sp; 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. « |
16 years ago | |
#7 | 6457 | Shawn Hladky | P4.Net: Added form_save overload to allow arbitrary arguments (primarily for -u flag on su...bmitted changelists) Added unit tests for Resolve workflow. Still need work on this and test partially fails. Updated some internal data structures to use generics Added documentation comments « |
17 years ago | |
#6 | 6353 | Shawn Hladky | P4.Net: Implemented diff functionality Implemented Merge functionality Converted p...rint commands to the callback interface « |
17 years ago | |
#5 | 6238 | Shawn Hladky | P4.Net: More work on callback interface. Run and RunUnparsed now use the callback... interface under the covers. « |
17 years ago | |
#4 | 6102 | Shawn Hladky | P4.Net: Documentation. Fixed SetTicketFile bug. Added form processing with Sp...ecDef. Stubbed-out code for launching external merge tool, but is disabled since it's too difficult to use. « |
17 years ago | |
#3 | 6052 | Shawn Hladky |
P4.Net: allow build against 2007.2 Code documentation |
18 years ago | |
#2 | 5878 | Shawn Hladky | P4.Net: 1.0, support for raw spec processing. Update copyright. Fix bu...ild script. Bugs found along the way. « |
18 years ago | |
#1 | 5830 | Shawn Hladky | P4.Net: reorg to support release branches | 18 years ago | |
//guest/shawn_hladky/P4.Net/src/P4API/P4BaseRecordSet.cs | |||||
#7 | 5812 | Shawn Hladky | P4.Net: More documentation. | 18 years ago | |
#6 | 5798 | Shawn Hladky | P4.Net... still not ready for beta Added license to all files Added several doc fi...les Misc bugs « |
18 years ago | |
#5 | 5734 | Shawn Hladky | More unit tests, and bug fixes. | 18 years ago | |
#4 | 5678 | Shawn Hladky |
WIP... more tests. OnPrompt event to recieve input from prompts. |
19 years ago | |
#3 | 5636 | Shawn Hladky | 1. Added test harness framework, and some initial tests 2. Fixed many bugs (...oddly enough identified by the unit tests) 3. Fixes so will build 1.1 Framework (and build batch files actually work) 4. Pathetic attempt at documentation « |
19 years ago | |
#2 | 5433 | Shawn Hladky | P4.Net More refactoring | 19 years ago | |
#1 | 5432 | Shawn Hladky | Refactoring step 2 -- rename source files | 19 years ago | |
//guest/shawn_hladky/P4.Net/src/P4API/P4Result.cs | |||||
#5 | 5431 | Shawn Hladky |
Refactoring... step 1. |
19 years ago | |
#4 | 5427 | Shawn Hladky | P4.Net -- several fixes and added sample application | 19 years ago | |
#3 | 5411 | Shawn Hladky | WIP -- forms are working now. | 19 years ago | |
#2 | 5373 | Shawn Hladky | P4.Net: Still WIP, but some things starting to work | 19 years ago | |
#1 | 5349 | Shawn Hladky | Initial check-in for the new API interface. Nothing works yet, but it should compi...le at least. « |
19 years ago |