![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Invalidating Dependent Variables When Inputs ChangeSee more CURL ExamplesThis example demonstrates how After a multi-step execution plan runs successfully, variables such as However, if an input variable is cleared using For example, if Note: This example requires Chilkat v11.5.0 or greater. For more information, see https://www.chilkatsoft.com/curl_dependency_engine.asp
IncludeFile "CkHttpCurl.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() success.i = 0 httpCurl.i = CkHttpCurl::ckCreate() If httpCurl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; The target curl command we ultimately want to execute. ; It requires drive_id. targetCurl.s = "curl -X GET https://graph.microsoft.com/v1.0/drives/{{drive_id}}/root/children" ; Define a helper function that produces drive_id. ; This requires site_id. fnName.s = "getDrives" CkHttpCurl::ckAddFunction(httpCurl,fnName,"curl -X GET https://graph.microsoft.com/v1.0/sites/{{site_id}}/drives") CkHttpCurl::ckAddOutput(httpCurl,fnName,"value[0].id","drive_id") ; Define another helper function that produces site_id. ; This requires site_name. fnName = "getSite" CkHttpCurl::ckAddFunction(httpCurl,fnName,"curl -X GET https://graph.microsoft.com/v1.0/sites/root:/sites/{{site_name}}") CkHttpCurl::ckAddOutput(httpCurl,fnName,"id","site_id") ; site_name is the starting known value. CkHttpCurl::ckSetVar(httpCurl,"site_name","test") ; Configure OAuth2 authentication. jsonOAuth2.i = CkJsonObject::ckCreate() If jsonOAuth2.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::setCkEnableSecrets(jsonOAuth2, 1) CkJsonObject::ckUpdateString(jsonOAuth2,"oauth2.client_id","!!sharepoint|oauth2|client_id") CkJsonObject::ckUpdateString(jsonOAuth2,"oauth2.client_secret","!!sharepoint|oauth2|client_secret") CkJsonObject::ckUpdateString(jsonOAuth2,"oauth2.scope","https://graph.microsoft.com/.default") CkJsonObject::ckUpdateString(jsonOAuth2,"oauth2.token_endpoint","!!sharepoint|oauth2|token_endpoint") CkHttpCurl::ckSetAuth(httpCurl,jsonOAuth2) ; ----------------------------------------------------------------------------- ; First execution plan: ; site_id and drive_id are not known yet, so the full dependency chain is needed. ; ----------------------------------------------------------------------------- planJson.i = CkJsonObject::ckCreate() If planJson.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::setCkEmitCompact(planJson, 0) Debug "Execution plan before first call:" success = CkHttpCurl::ckExaminePlan(httpCurl,targetCurl,planJson) Debug CkJsonObject::ckEmit(planJson) ; Expected: ; ; { ; "plan": [{ ; "function": "getSite", ; "inputs": ["site_name"], ; "outputs": ["site_id"] ; },{ ; "function": "getDrives", ; "inputs": ["site_id"], ; "outputs": ["drive_id"] ; },{ ; "function": "targetCurl", ; "inputs": ["drive_id"], ; "outputs": [] ; }] ; } success = CkHttpCurl::ckDoYourThing(httpCurl,targetCurl) If success = 0 Debug CkHttpCurl::ckLastErrorText(httpCurl) CkHttpCurl::ckDispose(httpCurl) CkJsonObject::ckDispose(jsonOAuth2) CkJsonObject::ckDispose(planJson) ProcedureReturn EndIf Debug "After first call:" Debug "site_id = " + CkHttpCurl::ckGetVar(httpCurl,"site_id") Debug "drive_id = " + CkHttpCurl::ckGetVar(httpCurl,"drive_id") ; ----------------------------------------------------------------------------- ; Second execution plan: ; site_id and drive_id are now known, so only the target curl command is needed. ; ----------------------------------------------------------------------------- Debug "Execution plan after first call:" success = CkHttpCurl::ckExaminePlan(httpCurl,targetCurl,planJson) Debug CkJsonObject::ckEmit(planJson) ; Expected: ; ; { ; "plan": [{ ; "function": "targetCurl", ; "inputs": ["drive_id"], ; "outputs": [] ; }] ; } ; ----------------------------------------------------------------------------- ; Change the original input. ; Because site_id was produced from site_name, changing site_name invalidates site_id. ; Because drive_id depends on site_id, drive_id is also invalidated. ; ----------------------------------------------------------------------------- ; Note: Make sure this site exists on in your SharePoint... CkHttpCurl::ckSetVar(httpCurl,"site_name","anotherSite") Debug "After changing site_name:" Debug "site_id defined? " + Str(CkHttpCurl::ckVarDefined(httpCurl,"site_id")) Debug "drive_id defined? " + Str(CkHttpCurl::ckVarDefined(httpCurl,"drive_id")) ; ----------------------------------------------------------------------------- ; The execution plan is automatically rebuilt. ; Since site_id and drive_id were invalidated, the full dependency chain is needed again. ; ----------------------------------------------------------------------------- Debug "Execution plan after changing site_name:" success = CkHttpCurl::ckExaminePlan(httpCurl,targetCurl,planJson) Debug CkJsonObject::ckEmit(planJson) ; Expected: ; ; { ; "plan": [{ ; "function": "getSite", ; "inputs": ["site_name"], ; "outputs": ["site_id"] ; },{ ; "function": "getDrives", ; "inputs": ["site_id"], ; "outputs": ["drive_id"] ; },{ ; "function": "targetCurl", ; "inputs": ["drive_id"], ; "outputs": [] ; }] ; } success = CkHttpCurl::ckDoYourThing(httpCurl,targetCurl) If success = 0 Debug CkHttpCurl::ckLastErrorText(httpCurl) CkHttpCurl::ckDispose(httpCurl) CkJsonObject::ckDispose(jsonOAuth2) CkJsonObject::ckDispose(planJson) ProcedureReturn EndIf Debug "After running again with the new site_name:" Debug "site_id = " + CkHttpCurl::ckGetVar(httpCurl,"site_id") Debug "drive_id = " + CkHttpCurl::ckGetVar(httpCurl,"drive_id") ; ----------------------------------------------------------------------------- ; Clearing a variable also invalidates values that depend on it. ; Here, clearing site_id also invalidates drive_id. ; ----------------------------------------------------------------------------- CkHttpCurl::ckClearVar(httpCurl,"site_id") Debug "After clearing site_id:" Debug "site_id defined? " + Str(CkHttpCurl::ckVarDefined(httpCurl,"site_id")) Debug "drive_id defined? " + Str(CkHttpCurl::ckVarDefined(httpCurl,"drive_id")) Debug "Execution plan after clearing site_id:" success = CkHttpCurl::ckExaminePlan(httpCurl,targetCurl,planJson) Debug CkJsonObject::ckEmit(planJson) ; Expected: ; ; { ; "plan": [{ ; "function": "getSite", ; "inputs": ["site_name"], ; "outputs": ["site_id"] ; },{ ; "function": "getDrives", ; "inputs": ["site_id"], ; "outputs": ["drive_id"] ; },{ ; "function": "targetCurl", ; "inputs": ["drive_id"], ; "outputs": [] ; }] ; } CkHttpCurl::ckDispose(httpCurl) CkJsonObject::ckDispose(jsonOAuth2) CkJsonObject::ckDispose(planJson) ProcedureReturn EndProcedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.