{"id":1066,"date":"2018-07-19T10:31:55","date_gmt":"2018-07-19T08:31:55","guid":{"rendered":"https:\/\/www.tests-performance.fr\/?p=1066"},"modified":"2018-07-25T13:49:36","modified_gmt":"2018-07-25T11:49:36","slug":"scripting-vugen-exemple-de-traitement-de-variable-c-et-de-parametres-vugen","status":"publish","type":"post","link":"https:\/\/www.tests-performance.fr\/?p=1066","title":{"rendered":"Scripting Vugen \u2013 Exemple de traitement de variables C et de param\u00e8tres VUGEN"},"content":{"rendered":"<p>Je vous pr\u00e9sente, ci-dessous, un exemple de code VUGEN dans lequel plusieurs points sont abord\u00e9s :<\/p>\n<ul>\n<li>D\u00e9claration de variables C<\/li>\n<li>Sauvegarde d&#8217;un retour HTTP dans un param\u00e8tre VUGEN<\/li>\n<li>Instanciation d&#8217;une variable C avec la taille exacte du param\u00e8tre VUGEN (malloc)<\/li>\n<li>Traitement de la variable C pour enlever les espaces<\/li>\n<li>Sauvegarde d&#8217;une variable C dans un param\u00e8tre VUGEN<\/li>\n<li>Traitement du Param\u00e8tre VUGEN avec une expression r\u00e9guli\u00e8re<\/li>\n<li>Boucle sur la liste d&#8217;un param\u00e8tre VUGEN<\/li>\n<li>Et autre&#8230;<\/li>\n<\/ul>\n<pre>\/\/ D\u00e9claration de la m\u00e9thode Strip\r\nvoid strip(char *s);\r\n\t\r\n\/\/ D\u00e9claration des variables C\r\nint arrSize;\r\nint iBureauxcount;\r\nint x;\r\nchar arrayParamName[512]; \r\nchar *sStr = NULL;\r\nchar sVar[8192];\r\n\t\r\nAction()\r\n{\r\n\t\r\n\/\/ Recup\u00e9ration d'une partie du BODY\r\nweb_reg_save_param_ex(\r\n\t\"ParamName=ALL_BUREAUX\",\r\n\t\"LB\/IC=Example\",\r\n\t\"RB\/IC=Example\",\r\n\t\"Ordinal=1\",\r\n\t\"SEARCH_FILTERS,\r\n\t\"Scope=body\",\r\n\t\"IgnoreRedirections=No\",\r\n\t\"RequestUrl=*\/example.do\",\r\n\tLAST);\r\n\t\t\r\n\/\/ Appel m\u00e9tier\r\nweb_custom_request(\"calculAlertesAction.do_7\", \r\n\t\"URL=https:\/\/example.do\", \r\n\t\"Method=POST\", \r\n\t\"Resource=0\", \r\n\t\"RecContentType=application\/json\", \r\n\t\"Referer=https:\/\/example.do\", \r\n\t\"Snapshot=t373.inf\", \r\n\t\"Mode=HTTP\", \r\n\t\"EncType=application\/json; charset=UTF-8\", \r\n\t\"Body=BODY REQUEST\", \r\n\tLAST);\r\n\r\n\/\/ Cr\u00e9ation d'une variable C de type integer contenant la valeur de la taille du param\u00e8tre {ALL_BUREAUX}\r\narrSize = strlen(lr_eval_string(\"{ALL_BUREAUX}\"));\r\n\t\t\r\n\/\/ Cr\u00e9ation d'une variable C de type char, de la taille exacte du param\u00e8tre VUGEN {ALL_BUREAUX}\r\nsStr = (char *)malloc((arrSize + 1) * sizeof(char));\r\n\t\t\r\n\/\/ Copy du param\u00e8tre VUGEN {ALL_BUREAUX} dans la variable C sStr\r\nstrcpy(sStr, lr_eval_string(\"{ALL_BUREAUX}\") );\r\n\t\t\r\n\/\/ Suppression des espaces dans la variable C sStr\r\nstrip(sStr);\r\n\t\t\r\n\/\/ Sauvegarde de la variable C sStr dans un nouveau param\u00e8tre VUGEN {ALL_BUREAUX_CLEAN}\r\nlr_save_string(sStr, \"ALL_BUREAUX_CLEAN\");\r\n\t\t\r\n\/\/ Suppression de la variable C sStr\r\nfree(sStr);\r\n\t\t\r\n\/\/ Traitement du nouveau param\u00e8tre VUGEN {ALL_BUREAUX_CLEAN} avec une expression r\u00e9guli\u00e8re\r\nlr_save_param_regexp (\r\n\tlr_eval_string(\"{ALL_BUREAUX_CLEAN}\"),\r\n\tstrlen(lr_eval_string(\"{ALL_BUREAUX_CLEAN}\")),\r\n\t\"RegExp\/IC=(option value=\\\\\\\".*?\\\\\\\"&gt;.*?\\\\\\\/option)\",\r\n\t\"Ordinal=All\",\r\n\t\"ResultParam=BUREAU_CLEAN\",\r\n\tLAST );\r\n\t\t\r\n\/\/ Cr\u00e9ation d'une variable C de type integer contenant le nombre d'enregistrements trouv\u00e9s\r\niBureauxcount = atoi(lr_eval_string(\"{BUREAU_CLEAN_count}\"));\r\n\r\n\/\/ Affiche du nombre d'enregistrement trouv\u00e9s\r\nlr_output_message(\"Number of items found = %d\", iBureauxcount);\r\n\r\n\/\/ Boucle tant qu'il y a des enregistrements\r\nfor (x=1; x&lt;=iBureauxcount; x++) \r\n{ \r\n\r\n        \/\/ Incrementation du param\u00e8tre VUGEN avec la valeur de la variable C x \r\n        sprintf(arrayParamName, \"{BUREAU_CLEAN_%d}\", x); \r\n\r\n        \/\/ Test si la valeur est trouv\u00e9e \r\n        if (((char *)strstr(lr_eval_string(arrayParamName), lr_eval_string(\"{Terrain_Param}\")) != 0)) { \r\n\r\n               \/\/ Affichage de la chaine recherch\u00e9e \r\n               \/\/lr_output_message (\"%s: %s\", arrayParamName, lr_eval_string(arrayParamName)); \r\n\r\n               \/\/ La valeur est trouv\u00e9e, traitement du param\u00e8tre arrayParamName avec une expression r\u00e9guli\u00e8re \r\n               \/\/ et sauvegarde d'un nouveau param\u00e8tre VUGEN {BUREAU_VALIDE} \r\n\r\n               lr_save_param_regexp ( lr_eval_string(arrayParamName), \r\n                     strlen(lr_eval_string(arrayParamName)), \r\n                     \"RegExp\/IC=option value=\\\\\\\"(.*?)\\\\\\\"&gt;.*?\\\\\\\/option\",\r\n                     \"Ordinal=1\",\r\n\t             \"ResultParam=BUREAU_VALIDE\",\r\n\t             LAST );\r\n\t\t\t\t\r\n                lr_output_message (\"%s: %s\", arrayParamName, lr_eval_string(arrayParamName)); \t\t\t\r\n         }\r\n         else\r\n         {\r\n                lr_output_message (\"NON\"); \r\n         }\t\r\n                \/\/lr_output_message (\"%s: %s\", arrayParamName, lr_eval_string(arrayParamName)); \r\n         }\r\n\t\t\r\n\/\/ Cr\u00e9ation d'une variable C de type integer contenant le nombre d'enregistrements trouv\u00e9s\r\niBureauxcount = atoi(lr_eval_string(\"{LISTE_BUREAU_count}\"));\r\n\r\n\/\/strcpy(sVar, \"idDossierSelectionne=&amp;\");\r\n\/\/strcat(sVar, \"Name=idObjetDetail&amp;\");\r\n\r\n\/\/ Boucle tant qu'il y a des enregistrements\r\nfor (x=1; x&lt;=iBureauxcount; x++) { \r\n\r\n        \/\/ Incrementation du param\u00e8tre VUGEN avec la valeur de la variable C x \r\n        sprintf(arrayParamName, \"{LISTE_BUREAU_%d}\", x); \r\n\r\n        lr_output_message (\"%s: %s\", arrayParamName, lr_eval_string(arrayParamName)); \r\n\r\n        if(x == 1 &amp;&amp; x == iBureauxcount ) \r\n        { \r\n                strcpy(sVar, lr_eval_string(arrayParamName)); \r\n        } \r\n        else if (x == 1 &amp;&amp; x != iBureauxcount) \r\n        { \r\n                strcpy(sVar, lr_eval_string(arrayParamName)); \r\n                strcat(sVar, \"%2C\"); \r\n        } \r\n        else if (x &gt; 1 &amp;&amp; x &lt; iBureauxcount) \r\n        { \r\n                strcat(sVar, lr_eval_string(arrayParamName)); strcat(sVar, \"%2C\"); \r\n        } \r\n        else if (x &gt; 1 &amp;&amp; x == iBureauxcount)\r\n        {\r\n                strcat(sVar, lr_eval_string(arrayParamName));\r\n        }\r\n\t\t\t\t\t\r\n}\r\n\t\t\t\r\n\/\/ Sauvegarde de la variable C sVar dans le param\u00e8tre VUGEN {LISTE_BUREAU_CLEAN}\r\nlr_save_string(sVar, \"LISTE_BUREAU_CLEAN\");\r\n\t\r\n\t\r\nreturn 0;\r\n}\r\n\r\n\/\/ M\u00e9thode pour supprimer les espaces vide d'une variable C\r\nvoid strip(char *s) \r\n{\r\n\tchar *p2 = s;\r\n\twhile(*s != '\\0') \r\n\t{\r\n\t        if(*s != '\\t' &amp;&amp; *s != '\\n') \r\n\t        {\r\n\t               *p2++ = *s++;\r\n\t        } \r\n                else \r\n\t        {\r\n\t                ++s;\r\n\t        }\r\n\t}\r\n\t*p2 = '\\0';\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Je vous pr\u00e9sente, ci-dessous, un exemple de code VUGEN dans lequel plusieurs points sont abord\u00e9s : D\u00e9claration de variables C Sauvegarde d&#8217;un retour HTTP dans un param\u00e8tre VUGEN Instanciation d&#8217;une variable C avec la taille exacte du param\u00e8tre VUGEN (malloc) Traitement de la variable C pour enlever les espaces Sauvegarde d&#8217;une variable C dans un [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[21],"tags":[27],"class_list":["post-1066","post","type-post","status-publish","format-standard","hentry","category-vugen","tag-tests-de-performance"],"acf":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=\/wp\/v2\/posts\/1066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1066"}],"version-history":[{"count":33,"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=\/wp\/v2\/posts\/1066\/revisions"}],"predecessor-version":[{"id":1172,"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=\/wp\/v2\/posts\/1066\/revisions\/1172"}],"wp:attachment":[{"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tests-performance.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}