Site Tools


guides:ws_payloads_lock_unlock_finalize

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
guides:ws_payloads_lock_unlock_finalize [2020/08/24 23:16] brett.zamoraguides:ws_payloads_lock_unlock_finalize [2020/08/24 23:30] (current) brett.zamora
Line 165: Line 165:
 Payloads that are 'Sent' (uploaded) are uploaded as .tmp files and the finalize web service is used to rename the .tmp extension to .xml. Payloads that are 'Sent' (uploaded) are uploaded as .tmp files and the finalize web service is used to rename the .tmp extension to .xml.
  
-Payloads that are 'Retrieved' must be locked before they can be retrieved. If the retrieval is successful and any validation requirements are satisfied, then the remote payload can be deleted with the payloads:delete_payload web service, otherwise the payload can be unlocked and the callers application will determine the next steps in their flow.+Payloads that are 'Retrieved' must be locked before they can be retrieved. If the retrieval is successful and any validation requirements are satisfied, then the remote payload can be deleted with the [[guides:ws_payloads_delete_payload|payloads:delete_payload]] web service, otherwise the payload can be unlocked and the callers application will determine the next steps in their flow.
  
-The sample code snippet that appears below shows the usage for all 3 web services. (Lock, Unlock, Finalize) +The sample code snippets that appear below show the usage for all 3 web services. (Lock, Unlock, Finalize)
- +
-These snippet of code was derived from the [[guides:web_service_toolbox_project|Web Service Toolbox]] that is available on the CeRTNA Wiki. The sample application is intended for easy to read demonstration purposes and not production quality code. The [[guides:web_service_toolbox_project|Web Service Toolbox]] application is documented, on the CeRTNA Wiki, to aid in understanding the code snippet shown below.+
  
 +These snippet of code was derived from the [[guides:web_service_toolbox_project|Web Service Toolbox]] that is available on the CeRTNA Wiki. The sample application is intended for easy to read demonstration purposes and not production quality code. The [[guides:web_service_toolbox_project|Web Service Toolbox]] application is documented, on the CeRTNA Wiki, to aid in understanding the code snippets shown below.
  
  
 +**Snippet 1: Lock/Unlock**
  
  
 <code C#> <code C#>
-private bool SendFile(string strRepositoryType, string strFileName)+private bool LockUnlockRemoteFile(string strRepositoryType, string strFileName, string strAction)
 { {
-    tbMessageLine.Text "";+    bool rc false //Default
  
-    bool rc false;+    if (strAction == "lock"
 +    { 
 +        tbMessageLine.Text = "Locking remote file " + strFileName; 
 +    } 
 +    else if (strAction == "unlock"
 +    { 
 +        tbMessageLine.Text = "Unlocking remote file " + strFileName; 
 +    } 
 +    else 
 +    { 
 +        tbMessageLine.Text = ""; 
 +    }
  
     RestClient client = null;     RestClient client = null;
Line 190: Line 201:
     // Password has to be hashed.     // Password has to be hashed.
     // New convention uses a Salt value from the user record     // New convention uses a Salt value from the user record
-    // See the Login documentation for more detail+    // See the Login web service for more detail.
  
     string strSalt = GetSalt(tbUserName.Text);     string strSalt = GetSalt(tbUserName.Text);
Line 214: Line 225:
     if (response.IsSuccessful)     if (response.IsSuccessful)
     {     {
-        tbMessageLine.Text = "Sending XML file "+strFileName; 
-                 
         var jsonResult1 = JsonConvert.DeserializeObject<dynamic>(response.Content);         var jsonResult1 = JsonConvert.DeserializeObject<dynamic>(response.Content);
         string token = jsonResult1.access_token;         string token = jsonResult1.access_token;
- 
-        FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read); 
- 
-        XmlDocument xmlDoc = new XmlDocument(); 
- 
-        xmlDoc.Load(fs); 
  
         strURL = null;         strURL = null;
Line 230: Line 233:
         response = null;         response = null;
  
-        strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/" + strRepositoryType;  +        strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/" + strRepositoryType + "/" + strFileName + "?operation=" + strAction;  
  
         client = new RestClient(strURL);         client = new RestClient(strURL);
-        request = new RestRequest(Method.POST);+        request = new RestRequest(Method.PATCH);
  
         request.AddHeader("Cache-Control", "no-cache");         request.AddHeader("Cache-Control", "no-cache");
         request.AddHeader("access_token", token);         request.AddHeader("access_token", token);
-        request.AddHeader("content-type", "text/plain"); 
-        request.AddParameter("undefined", xmlDoc.InnerXml, ParameterType.RequestBody); 
         response = client.Execute(request);         response = client.Execute(request);
  
         if (response.IsSuccessful)         if (response.IsSuccessful)
         {         {
-            var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content); +            if (strAction == "lock")
-            string strRemoteFileName = jsonResult2.result; +
- +
-            // You must finalize the remote file to change the extension from .tmp to .xml +
-             +
-            string strAction = "finalize"; +
- +
-            strURL = null; +
-            client = null; +
-            request = null; +
-            response = null; +
- +
-            strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/+ strRepositoryType + "/" + strRemoteFileName + "?operation=" + strAction;   +
- +
-            client = new RestClient(strURL); +
-            request = new RestRequest(Method.PATCH); +
- +
-            request.AddHeader("Cache-Control", "no-cache"); +
-            request.AddHeader("access_token", token); +
-            response = client.Execute(request); +
- +
-            if (response.IsSuccessful)+
             {             {
-                tbMessageLine.Text = "XML file " + strFileName+" successfully sent."; +                tbMessageLine.Text = "Remote file " + strFileName + " successfully locked."; 
-                rc true;+            } 
 +            else if (strAction == "unlock"
 +            { 
 +                tbMessageLine.Text "Remote file " + strFileName + " successfully unlocked.";
             }             }
             else             else
             {             {
-                var jsonResult3 = JsonConvert.DeserializeObject<dynamic>(response.Content); +                tbMessageLine.Text = "";
-                string strMessage = jsonResult3.Exception.Message; +
-                tbMessageLine.Text = strMessage;+
             }             }
 +            rc = true;
         }         }
         else         else
Line 280: Line 262:
             var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content);             var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content);
             string strMessage = jsonResult2.Exception.Message;             string strMessage = jsonResult2.Exception.Message;
 +            tbMessageLine.Clear();
             tbMessageLine.Text = strMessage;             tbMessageLine.Text = strMessage;
         }         }
Line 288: Line 271:
         tbMessageLine.Text = jsonResult2.ToString();         tbMessageLine.Text = jsonResult2.ToString();
     }     }
- 
     return (rc);     return (rc);
 } }
 </code> </code>
 +
 +
 +**Snippet 2: Finalize**
 +
 +The following is just a fragment of code that was copied over from the [[guides:ws_payloads_send_payload|payloads:send_payload]] documentation
 +
 +<code C#>
 +var jsonResult2 = JsonConvert.DeserializeObject<dynamic>(response.Content);
 +string strRemoteFileName = jsonResult2.result;
 +
 +// You must finalize the remote file to change the extension from .tmp to .xml
 +            
 +string strAction = "finalize";
 +
 +strURL = null;
 +client = null;
 +request = null;
 +response = null;
 +
 +strURL = "https://apex-prd.certna.org/APEX/Service/APEXPublicServer.svc/payloads/" + strRepositoryType + "/" + strRemoteFileName + "?operation=" + strAction;  
 +
 +client = new RestClient(strURL);
 +request = new RestRequest(Method.PATCH);
 +
 +request.AddHeader("Cache-Control", "no-cache");
 +request.AddHeader("access_token", token);
 +response = client.Execute(request);
 +
 +if (response.IsSuccessful)
 +{
 +    tbMessageLine.Text = "XML file " + strFileName+" successfully sent.";
 +    rc = true;
 +}
 +else
 +{
 +    var jsonResult3 = JsonConvert.DeserializeObject<dynamic>(response.Content);
 +    string strMessage = jsonResult3.Exception.Message;
 +    tbMessageLine.Text = strMessage;
 +}
 +</code>
 +
 +
  
  
guides/ws_payloads_lock_unlock_finalize.1598310973.txt.gz · Last modified: by brett.zamora