#using <mscorlib.dll> #include "StdAfx.h" #include "ClientUserDelegate.h" using namespace System::Runtime::InteropServices; 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) { StringDictionary* sd; mcu->InputForm(&sd, e); // Convert the StringDictionary to a StrDict, build a spec // and save if (!sd->ContainsKey("parseforms-specdef")) { //Throw an error... invalid form } if (!sd->ContainsKey("parseforms-specdata")) { //Throw an error... invalid form } //Fetch the specdata and specdef fields and convert to c-strings System::String* mSpecDef = sd->get_Item("parseforms-specdef"); sd->Remove("parseforms-specdef"); System::IntPtr pSpecDef; const char* sSpecDef; pSpecDef = Marshal::StringToHGlobalAnsi(mSpecDef); sSpecDef = static_cast< const char * >( pSpecDef.ToPointer() ); System::String* mSpecData = sd->get_Item("parseforms-specdata"); sd->Remove("parseforms-specdata"); System::IntPtr pSpecData; const char* sSpecData; pSpecData = Marshal::StringToHGlobalAnsi(mSpecData); sSpecData = static_cast< const char * >( pSpecData.ToPointer() ); //Now, build the spec object and get the dictionary System::IntPtr pKey; const char* sKey; System::IntPtr pVal; const char* sVal; ::Spec* cspec; ::SpecDataTable* specData; cspec = new Spec(sSpecDef, ""); specData = new SpecDataTable(); ::Error parseErr; cspec->Parse(sSpecData, specData, &parseErr); StrDict* varList = specData->Dict(); int i = 0; ::StrRef var, val; while (varList->GetVar(i,var,val) != -0) { pVal = Marshal::StringToHGlobalAnsi( sd->get_Item(var.Text())); sVal = static_cast< const char * >( pVal.ToPointer() ); if(sd->ContainsKey(var.Text())) { varList->ReplaceVar(var.Text(), sVal); } Marshal::FreeHGlobal(pVal); i++; } StrBuf specText; cspec->Format(specData, &specText); strbuf->Set(specText.Text()); delete cspec; delete specData; } 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::Specialized::StringDictionary* dict; System::String* key; System::String* value; ::Spec* cspec; ::SpecDataTable* specData; StrPtr* data = varList->GetVar("data"); StrPtr* specdef = varList->GetVar("specdef"); StrDict* Dict; int i = 0; ::StrRef var, val; dict = new System::Collections::Specialized::StringDictionary(); if (specdef && data) { // We have a form, parse it out ::Error e; cspec = new Spec(specdef->Text(), ""); specData = new SpecDataTable(); cspec->Parse(data->Text(), specData, &e); Dict = specData->Dict(); //since this is a spec, we will append the specdef string //This will be needed when the dictionary is passed back to save the form dict->Add( "parseforms-specdef", specdef->Text()); dict->Add( "parseforms-specdata", data->Text()); } else { // No form, just use the raw dictionary Dict = varList; } while (Dict->GetVar(i,var,val) != -0) { System::String* key = var.Text(); System::String* value = val.Text(); if (!dict->ContainsKey(key)) { dict->Add( key, value ); } i++; } delete cspec; delete specData; 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 | |
---|---|---|---|---|---|
#7 | 5830 | Shawn Hladky | P4.Net: reorg to support release branches | ||
#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 |