/* * P4.Net * Copyright (c) 2006 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 <mscorlib.dll> #include "StdAfx.h" #include "ClientUserDelegate.h" using namespace System::Runtime::InteropServices; using namespace System::Collections; using namespace System::Collections::Specialized; ClientUserDelegate::ClientUserDelegate( gcroot<p4dn::ClientUser*> ManagedClientUser ) { mcu = ManagedClientUser; m_SaveForm = false; } ClientUserDelegate::~ClientUserDelegate() { delete mcu; } void ClientUserDelegate::SaveForm() { m_SaveForm = true; } void ClientUserDelegate::InputData( StrBuf *strbuf, ::Error* err ) { //Build a System::String to pass to DotNet System::String* s = strbuf->Text(); p4dn::Error* e = new p4dn::Error( err ); if (m_SaveForm) { Hashtable* sd; System::String* mSpecDef; mcu->InputForm(&sd, &mSpecDef, e); //convert to c-strings System::IntPtr pSpecDef; const char* sSpecDef; pSpecDef = Marshal::StringToHGlobalAnsi(mSpecDef); sSpecDef = static_cast< const char * >( pSpecDef.ToPointer() ); //Build our Spec objects ::SpecDataTable specData; ::Spec spec(sSpecDef, "" ); //Spin the managed dictionary IEnumerator* myEnum = sd->Keys->GetEnumerator(); while (myEnum->MoveNext()) { // Convert the key and values System::String* key = static_cast<System::String*>(myEnum->Current); System::IntPtr pKey = Marshal::StringToHGlobalAnsi(key); const char* sKey = static_cast< const char * >( pKey.ToPointer() ); System::IntPtr pVal = Marshal::StringToHGlobalAnsi(static_cast<System::String*>(sd->get_Item(key))); const char* sVal = static_cast< const char * >( pVal.ToPointer() ); // Create the unmanaged Dict entry specData.Dict()->SetVar(sKey, sVal); // Free our string pointers Marshal::FreeHGlobal( pKey ); Marshal::FreeHGlobal( pVal ); } //Format the Spec and pass it to the strbuf StrBuf s; spec.Format(&specData, &s); Marshal::FreeHGlobal(pSpecDef); strbuf->Set(s.Text()); //Console::WriteLine(s.Text()); } else { mcu->InputData(&s, e ); //Convert System::String back to a StrBuf System::IntPtr ptr = Marshal::StringToHGlobalAnsi( s ); const char* str = static_cast< const char * >( ptr.ToPointer() ); strbuf->Set( str ); Marshal::FreeHGlobal( ptr ); } e->Dispose(); } void ClientUserDelegate::HandleError( ::Error *err ) { p4dn::Error* e = new p4dn::Error( err); mcu->HandleError( e ); e->Dispose(); } void ClientUserDelegate::Message( ::Error *err ) { p4dn::Error* e = new p4dn::Error( err ); mcu->Message( e ); e->Dispose(); } void ClientUserDelegate::OutputError( const_char *errBuf ) { System::String* s = errBuf; mcu->OutputError( s ); } void ClientUserDelegate::OutputInfo( char level, const_char *data ) { System::String* s = data; mcu->OutputInfo( level, s ); } void ClientUserDelegate::OutputBinary( const_char *data, int length ) { System::Byte b[] = new System::Byte[length]; Marshal::Copy(IntPtr(data), b, 0, length); mcu->OutputBinary( b ); } void ClientUserDelegate::OutputText( const_char *data, int length ) { System::String *s = new System::String(data); mcu->OutputText( s ); } /* In this method, I deviate from the C++ api in form. If this is a form, I call OutputForm, otherwise OutputStat. This should be a lot easier in handling the Spec classes in managed code and still provide full functionality. */ void ClientUserDelegate::OutputStat( StrDict *varList ) { System::Collections::Hashtable* dict; ::SpecDataTable specData; // System::String* key; // System::String* value; StrPtr* data = varList->GetVar("data"); StrPtr* specdef = varList->GetVar("specdef"); // I'm not sure what the intention of the specFormatted field is // can't we just look for the "data" field? // StrPtr* specformatted = varList->GetVar("specFormatted"); StrDict* Dict; int i = 0; ::StrRef var, val; dict = new System::Collections::Hashtable(); if (specdef) { // Send the SpecDef to the ClientUser so it can save it if it wants System::String* ManagedSpecDef = specdef->Text(); mcu->SetSpecDef(ManagedSpecDef); } if (data) { // We have a form, not pre-parsed (i.e. pre-2005.2 server version) ::Error e; ::Spec s(specdef->Text(), ""); s.ParseNoValid(data->Text(), &specData, &e); Dict = specData.Dict(); } else { // No form, just use the raw dictionary Dict = varList; } while (Dict->GetVar(i,var,val) != -0) { if (!( var == "specdef" || var == "func" || var == "specFormatted" )) { System::String* key = var.Text(); System::String* value = val.Text(); //if (!dict->ContainsKey(key)) //{ dict->Add( key, value ); //} } i++; } mcu->OutputStat( dict ); } void ClientUserDelegate::Prompt( const StrPtr& msg, StrBuf& rsp, int noEcho, ::Error *err ) { String* response; String* message = msg.Text(); bool bEcho = ( noEcho != 0 ); p4dn::Error* e = new p4dn::Error( err ); mcu->Prompt( message, &response, bEcho, e ); char* str = (char *)(void *) Marshal::StringToHGlobalAnsi( response ); rsp.Set( str ); e->Dispose(); Marshal::FreeHGlobal( str ); } void ClientUserDelegate::ErrorPause( char *errBuf, ::Error *err ) { System::String* s = errBuf; p4dn::Error* e = new p4dn::Error( err ); mcu->ErrorPause( s, e ); e->Dispose(); } void ClientUserDelegate::Edit( FileSys *f1, ::Error *err ) { p4dn::Error* e = new p4dn::Error( err ); System::String* name = f1->Name(); System::IO::FileInfo* info = new System::IO::FileInfo( name ); mcu->Edit( info, e ); e->Dispose(); } void ClientUserDelegate::Diff( FileSys *f1, FileSys *f2, int doPage, char *diffFlags, ::Error *e ) { // TODO: System::Console::WriteLine( "10" ); } void ClientUserDelegate::Merge( FileSys *base, FileSys *leg1, FileSys *leg2, FileSys *result, ::Error *e ) { // TODO: } void ClientUserDelegate::Help( const_char *const *help ) { System::String* s = *help; mcu->Help( s ); } FileSys* ClientUserDelegate::File( FileSysType type ) { return FileSys::Create( type ); } void ClientUserDelegate::Finished() { mcu->Finished(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5831 | Shawn Hladky | P4.Net: Branch release 0.9 and delete a few files missed last time | ||
//guest/shawn_hladky/P4.Net/main/src/p4dn/ClientUserDelegate.cpp | |||||
#1 | 5830 | Shawn Hladky | P4.Net: reorg to support release branches | ||
//guest/shawn_hladky/P4.Net/src/p4dn/ClientUserDelegate.cpp | |||||
#6 | 5798 | Shawn Hladky |
P4.Net... still not ready for beta Added license to all files Added several doc files Misc bugs |
||
#5 | 5427 | Shawn Hladky | P4.Net -- several fixes and added sample application | ||
#4 | 5411 | Shawn Hladky | WIP -- forms are working now. | ||
#3 | 5373 | Shawn Hladky | P4.Net: Still WIP, but some things starting to work | ||
#2 | 5349 | Shawn Hladky |
Initial check-in for the new API interface. Nothing works yet, but it should compile at least. |
||
#1 | 5348 | Shawn Hladky | Re-organizing, for the improved API | ||
//guest/shawn_hladky/PerforceDotNet/p4dn/ClientUserDelegate.cpp | |||||
#3 | 5064 | Shawn Hladky |
WIP -- Added ability to parse forms. Added new tester application. ** not ready for human consumption, needs more review and testing. |
||
#2 | 4643 | Shawn Hladky | Clean-up some more memory issues | ||
#1 | 4545 | Shawn Hladky |
Several Fixes: Updated solution to Visual Studio 2003 Implemented InputData Implemented OutPutBinary Changed ClientAPI and Error objects to implement the IDisposable interface to improve Garbage Collection Changed header files so you don't need to add #pragma once to the p4 api headers. Refactored the ClientUserDelagate class Fixed a few minor memory leaks |