using System; using System.Collections.Generic; using System.Text; using p4dn; using System.Diagnostics; namespace P4API { class P4Connection : IDisposable { private p4dn.ClientApi m_ClientApi; private bool _tagged = false; private p4dn.ClientApi _ClientAPI { get { if (!_Connected) throw new Exceptions.ServerNotConnected(); return _ClientAPI; } set { _ClientAPI = value; } } private bool _Connected; private string _CallingProgram; private string _CallingProgramVersion; public P4Connection() { this._Connected = false; this._CallingProgram = "P4.Net API"; this._CallingProgramVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); } public string Client { get { return _ClientAPI.Client; } set { _ClientAPI.SetClient(value); } } public string CWD { get { return _ClientAPI.Cwd; } set { _ClientAPI.SetCwd(value); } } public string Host { get { return _ClientAPI.Host; } set { _ClientAPI.SetHost(value); } } public string Port { get { return _ClientAPI.Port; } set { _ClientAPI.SetPort(value); } } public string User { get { return _ClientAPI.User; } set { _ClientAPI.SetUser(value); } } public string Charset { get { return _ClientAPI.Charset; } set { _ClientAPI.SetCharset(value); } } public string CallingProgram { get { return _CallingProgram; } set { _CallingProgram = value; // _ClientAPI.SetProgram = value; } } public string CallingVersion { get { return _CallingProgramVersion; } set { _CallingProgramVersion = value; // _ClientAPI.SetVersion = value; } } public string Password { set { _ClientAPI.SetPassword(value); } } public string TicketFile { set { // _ClientAPI.SetTicketFile(value); } } /// <summary> /// Connect to the Perforce server /// </summary> public void Connect() { throw new System.NotImplementedException(); } /// <summary> /// Disconnect from the Perforce Server /// </summary> public void Disconnect() { if (!_Connected) { } _Connected = false; } /// <summary> /// Login to the Perforce Server /// </summary> public void Login(string password) { throw new System.NotImplementedException(); } /// <summary> /// Fetch a form object from Perforce. /// </summary> /// <remarks> /// These are the things that pop-up in an editor, like: /// client /// branch /// label /// user /// group /// protect /// triggers /// branch /// </remarks> /// <returns>A Form object. The fields of the form can be read in, or updated. If you update a filed, you can save it with Save_Form.</returns> public P4Form Fetch_Form(string FormCommand) { throw new System.NotImplementedException(); } /// <summary> /// Saves the form to Perforce. /// </summary> /// <remarks>Executes the equivilent of p4 [form] -i</remarks> /// <returns>P4StringsResult. Output can be parsed to verify the form was processed correctly.</returns> public P4StringsResult Save_Form(P4Form Form) { throw new System.NotImplementedException(); } /// <summary> /// Executes the command in tagged mode. /// </summary> public P4TaggedResult Run_Tags(string Command, params string[] Args) { throw new System.NotImplementedException(); } /// <summary> /// Executes the command in non-tagged mode. /// </summary> public P4StringsResult Run_Strings(string Command, params string[] Args) { throw new System.NotImplementedException(); } #region Private Helper Methods private void EstablishConnection(bool tagged) { // If we're switching contexts from tagged to un-tagged, then we need to reset // the connection if ((_ClientAPI != null) && tagged != _tagged) { CloseConnection(); } if (_ClientAPI == null) { Error err = null; try { m_ClientApi = new ClientApi(); err = new Error(); if (tagged) m_ClientApi.SetProtocol("tag", ""); if (tagged) m_ClientApi.SetProtocol("specstring", ""); //if (m_P4Client != null) clientapi.SetClient(m_P4Client); //if (m_P4Port != null) clientapi.SetPort(m_P4Port); //if (m_P4User != null) clientapi.SetUser(m_P4User); m_ClientApi.Init(err); if (err.IsFatal()) { Trace.WriteLine(err.Fmt()); Trace.WriteLine("Unable to connect to Perforce!"); throw new Exception("Unable to connect to Perforce!"); } } catch (Exception e) { Trace.WriteLine(e.Message); } finally { m_ClientApi.Final(err); err.Dispose(); m_ClientApi.Dispose(); m_ClientApi = null; } } } private void CloseConnection() { // Need to reset the connection Error err = new Error(); m_ClientApi.Final(err); err.Dispose(); m_ClientApi.Dispose(); m_ClientApi = null; } private void RunIt(string command, string[] args, ClientUser cu, bool tagged) { RunIt(command, args, cu, tagged, false, false); } private void RunIt(string command, string[] args, ClientUser cu, bool tagged, bool ParseForms) { RunIt(command, args, cu, tagged, false, false); } private void RunIt(string command, string[] args, ClientUser cu, bool tagged, bool ParseForms, bool SaveForm) { m_ClientApi.SetArgv(args); if (SaveForm) { m_ClientApi.SaveForm(command, cu); } else { m_ClientApi.Run(command, cu); } } #endregion #region IDisposable Members public void Dispose() { this.Disconnect(); } #endregion } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#18 | 5830 | Shawn Hladky | P4.Net: reorg to support release branches | ||
#17 | 5812 | Shawn Hladky | P4.Net: More documentation. | ||
#16 | 5801 | Shawn Hladky |
P4.Net. More misc changes |
||
#15 | 5798 | Shawn Hladky |
P4.Net... still not ready for beta Added license to all files Added several doc files Misc bugs |
||
#14 | 5734 | Shawn Hladky | More unit tests, and bug fixes. | ||
#13 | 5678 | Shawn Hladky |
WIP... more tests. OnPrompt event to recieve input from prompts. |
||
#12 | 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 |
||
#11 | 5447 | Shawn Hladky | refactor, and added options class | ||
#10 | 5438 | Shawn Hladky | refactoring, and documentation code | ||
#9 | 5436 | Shawn Hladky | P4.Net -- Added some high-level functionality | ||
#8 | 5433 | Shawn Hladky | P4.Net More refactoring | ||
#7 | 5431 | Shawn Hladky |
Refactoring... step 1. |
||
#6 | 5427 | Shawn Hladky | P4.Net -- several fixes and added sample application | ||
#5 | 5411 | Shawn Hladky | WIP -- forms are working now. | ||
#4 | 5373 | Shawn Hladky | P4.Net: Still WIP, but some things starting to work | ||
#3 | 5362 | Shawn Hladky | Chipping away at the API changes | ||
#2 | 5350 | Shawn Hladky | WIP few more changes | ||
#1 | 5349 | Shawn Hladky |
Initial check-in for the new API interface. Nothing works yet, but it should compile at least. |