================================================================================ PAGE 81 ================================================================================ someform,e.g.applyingthesamefiltersettosubsequent queries. Tosignalthedatabase enginethatyourqueriesareassociated, youpassauniquequeryhandlewiththem.The queryhandleistheresultyoureceivefromaCDBQCreateActionQuery orCDBQCrea - teAlarmQuery .Thereforethesequeriesarethefirstyousendwheninteracting withthedata- base. C++Example forgetting aquery handle: //CreateanewActionQuery CDataBaseQuery* geviquery =newCDBQCreateActionQuery (0); //SendtheActionQuerytotheserver CDataBaseAnswer* dbanswer =m_APIClient- >SendDatabaseQuery (geviquery, INFI- NITE); geviquery- >DeleteObject (); if(dbanswer- >m_AnswerCode ==dbac_QueryHandle) { //Extract thequeryhandlefromtheanswer CDBAQueryHandle* handle=reinterpret_ cast (dbanswer); } ================================================================================ PAGE 82 ================================================================================ Iterating overDatabase Records Youcansendagroupofassociated databasequeriesafterhavingobtainedthequeryhandle. PleasenotethattheGeViSoftarchitecture alwaysreturnsonesingleanswerforeveryquery. Asaconsequence, youmightneedtoissueseveraldatabasequeriesconsecutively toget yourdesiredpiecesofinformation. Thiscanbeillustrated byanexampledatabasequery.Imagineyouwanttoretrievethetwo latestactionsinsidethedatabase: Example:  Retrieving ofthetwolatest actions inside thedata- base Pseudo code 1.CreateanewCDBQCreateActionQuery 2.SendthequerytoGeViServer andretrievethehandlefromtheanswer 3.CreateanewCDBQGetLast querywiththehandleastheargument 4.Sendthequeryandfetchthelatestactionasananswer 5.Extractthelatestaction’sprimarykeyfromtheanswer 6.CreateanewCDBQGetPrev querywiththehandleandthelatestaction’sprimarykeyas anargument 7.Sendthequeryandfetchthesecondlatestactionasananswer C++: ================================================================================ PAGE 83 ================================================================================ //Declare aqueryhandle CDBAQueryHandle* handle; __int64primaryKey; //CreateanewActionQuery CDataBaseQuery* geviquery =newCDBQCreateActionQuery (0); //SendtheActionQuerytotheserver CDataBaseAnswer* dbanswer =m_APIClient- >SendDatabaseQuery (geviquery, INFI- NITE); geviquery- >DeleteObject (); if(dbanswer- >m_AnswerCode ==dbac_QueryHandle) { //Extract thequeryhandefromtheanswer handle=reinterpret_ cast (dbanswer); } //Createadatabase queryforthelatestactionentry CDataBaseQuery* getEntry =newCDBQGetLast (handle- >m_Handle); //SendthequerytotheGeViServer dbanswer =m_APIClient- >SendDatabaseQuery (getEntry, INFINITE); getEntry- >DeleteObject (); //Checkifanactionentryisinthedatabase if(dbanswer- >m_AnswerCode ==dbac_ActionEntry) {  //Dos.th.withtheanswerhere... //Gettheprimary keywhichisusedto //address therecords internally primaryKey =reinterpret_ cast (dbanswer) ->m_PK; }//TODO: Adderrorhandling ifnoactionisinthedatabase //Create adatabase querytogetthesecondlatestactionentry getEntry =newCDBQGetPrev (handle- >m_Handle, primaryKey); //SendthequerytotheGeViServer dbanswer =m_APIClient- >SendDatabaseQuery (getEntry, INFINITE); getEntry- >DeleteObject (); ================================================================================ PAGE 84 ================================================================================ //Checkifanactionentryisinthedatabase if(dbanswer- >m_AnswerCode ==dbac_ActionEntry) {  //Dos.th.withtheanswerhere... }//TODO: Adderrorhandling ifnoactionisinthedatabase dbanswer- >DeleteObject (); ================================================================================ PAGE 85 ================================================================================ Filtering Database Queries GeViSoftsupportsvariousfiltersallowingyoutospecifyyourqueriesinamorepreciseway. Forexample,youcannarrowdownyoursearchtocertainactiontypesorsenders.Allthe availablefiltersaredeclaredintheDatabaseQueries headerfile. TosetthefilteringontheGeViServer, youhavetosendadatabasequeryforeveryfilterele- mentafteryouhaveobtainedthequeryhandle.Youcanmonitortheprocessing ofthequeries insidetheGeViAPITestClient. Hereisascreenshot ofadatabasequerysequence whichsetsafilterfortheactiontype nameCrossSwitch .Themessagesettingthefilterishighlighted. Thefilterhasbeendefined intheDatabase FiltertaboftheGeViAPITestClient.Afterwards, thefetchoperationwas startedfromtheDatabase Viewertab. Composing Filtered Queries Inthisparagraph youwilllearnhowtocomposesimplefiltersfirstandfinallyextenttheexam- plefromabove(IteratingoverDatabase Records)withafilterthatwillonlyreturn ================================================================================ PAGE 86 ================================================================================ CustomAction messages withcertainprimarykeys. Prerequisite foratestonyoursystemisthatthereareCrossSwitch ,CustomAction ,andsev- eralotheractiontypeentriesstoredinsideyourdatabase. Topopulateyourdatabasewith these,youcansendthemwiththeGeViAPITestClient.DoingafetchintheDatabase Vie- wer’staballowsyoutoverifythattheyarestoredcorrectlyafterwards. Example Filters ExampleforafilterthatwillonlyreturnCustomActions : CDataBaseFilter* myActionNameFilter = newCDBFTypeName (handle- >m_Handle, "CustomAction", dbc_LIKE); Aftercreatingyourfilters,youcansendthemwithGeViAPIClients SendDatabaseQuery method. CDataBaseAnswer* dbanswer = m_APIClient- >SendDatabaseQuery (myActionNameFilter, INFINITE); Makesuretoverifythattheanswercodeisdbac_DBOkandtocalltheDeleteObject method foryourfilteraftersendingit. Composing complex filters: Youcancomposeacomplexfilterbysendingasequence ofmultiplesinglefilterstothedata- base.Thesefilterswillthenbetreatedasaconjunction (logicalAND)byGeViServer. Hereisanexampleforacomplexfilterthatonlyreturnsactionswithprimarykeysbetween 500and600.Thisfilterhastobecomposed bysendingtwosimplefilterssequentially: CDataBaseFilter* myMinFilter = newCDBFPK_GrtEqu(handle- >m_Handle, 500); ================================================================================ PAGE 87 ================================================================================ CDataBaseFilter* myMaxFilter = newCDBFPK_LowEqu(handle- >m_Handle, 600); Complete Example ofaFiltered Database Query TheexampleIteratingoverDatabase RecordswillbeextendedtofilterforCustomActions with aprimarykeybetween500and600inthisparagraph. Toachievethis,thefiltermessages havetobesentdirectlyafterretrievingthedatabasehandle.Thefiltersarecreatedina methodcalledsetActionFilter .Thismessageisthencalledafterobtainingthedatabase handle. Examplefilteringmethod: voidsetActionFilter (CDBAQueryHandle* handle) { //Createavectorwithyourfiltermessages std::vector filterList; filterList.push_ back( newCDBFPK_GrtEqu(handle- >m_Handle, 500)); filterList.push_ back( newCDBFPK_LowEqu(handle- >m_Handle, 600)); filterList.push_ back( newCDBFTypeName (handle- >m_Handle, "CustomAction", dbc_LIKE)); //Sendthefilters for(vector::iterator it= filterList.begin ();it!=filterList.end (); it++) { CDataBaseAnswer* dbanswer =m_APIClient- >SendDatabaseQuery (*it,INFI- NITE); if(dbanswer- >m_AnswerCode !=dbac_DBOk) { //Doerrorhandling here! (*it)->DeleteObject (); return; } ================================================================================ PAGE 88 ================================================================================ (*it)->DeleteObject (); } } Nowyoucancallthatmethodinyourexamplefromabove: /* ... */ CDataBaseAnswer* dbanswer =m_APIClient- >SendDatabaseQuery ( geviquery, INFINITE); geviquery- >DeleteObject (); if(dbanswer- >m_AnswerCode ==dbac_QueryHandle) { //Extract thequeryhandefromtheanswer handle=reinterpret_ cast (dbanswer); //SendFilterhere setActionFilter (handle); } /* ... */ Asaresult,youshouldseethetwolatestCustomAction recordswithaprimarykeybetween 500and600.Ifyoudonotgetanyresults,youneedtoadoptthefilteringcriteriatomatchrec- ordsinyourdatabase. Database queries andfiltering isimplemented intheSDK’sexample Delphi/CPP_ SimpleDatabaseClient. ================================================================================ PAGE 89 ================================================================================ C#and.Netspecifics ThischapterdealswiththeGeViSoftSDKs.Netcapabilities andspecifics. Itdescribes the architecture ofthewrappersandthespecificsoftheusage. Architecture TheGeViSoftSDKisdeliveredwitha.Net-Wrapper,allowingyoutodesignapplications in C#orother.Netlanguages. TheGeutebrueck.GeViSoftSDKNET.Wrapper.dll encapsulates allthenativeGeViProcAPI.dll calls.Additionally, theGscActionsNet.dll fromtheGeV- iScopeSDK isneededtoallowforGeViScope interoperability. Thiswrapperencapsulates the GscActions.dll whichitselfusestheGscDBI.dll. ================================================================================ PAGE 90 ================================================================================ Diagram oftheGeViSoft .Netwrappers Configuring yourIDEforGeViSoft .NetProjects VisualStudio2008,C# 1.)Addthe.Netwrapperstoyourproject’sreferences. (Youcandothisbyright-clickingonReferences inyourSolution Explorer.Afterpressing Add Reference browsetoyour%GEVISOFTSDKPATH% andaddGeViProcAPINET_ 2_0.dll.Ifyou plantouseGeViScope ActionsalsoaddGscActionsNET_ 2_0.dll.