0

I have created a basic Custom Module (KC.CM.Divalto) that aims to:

  • read data extracted from a batch
  • call a webservice
  • redirect to validation module or PDF generator depending on webservice response

enter image description here

I will output data into MessageBox for beginning.

At this stage, I read previous questions concerning Custom Modules and it helped me have a valid exe:

  • create setup form for custom module

  • create custom module for pdf manipulation

    internal class Program
    {
      static void Main(string[] args)
      {
          AppDomain.CurrentDomain.AssemblyResolve += (sender, eventArgs) => KcAssemblyResolver.Resolve(eventArgs);
          Run(args);
          return;
      }
    
      static void Run(string[] args)
      {
          var login = new Login();
          login.EnableSecurityBoost = true;
          login.Login();
          login.ApplicationName = "KC.CM.Divalto";
          login.Version = "1.0";
    
          login.ValidateUser("KC.CM.Divalto.exe", false, "", "");
    
          var session = login.RuntimeSession;
    
          var activeBatch = session.NextBatchGet(login.ProcessID);
    
          MessageBox.Show("activeBatch.Name: " + activeBatch.Name);
    
          activeBatch.BatchClose(
               KfxDbState.KfxDbBatchReady, KfxDbQueue.KfxDbQueueNext, 0, "");
    
          var url = "http://localhost/webservice.asmx";
    
          var data1 = "data1";
          var data2 = "data2";
          var data3 = "data3";
    
          Dictionary<string, string> data = new Dictionary<string, string>();
          data.Add("data1", data1);
          data.Add("data2", data2);
          data.Add("data3", data3);
    
    
          WsCaller wsCaller= new WsCaller();
          WsResponse returnValue =
              wsCaller.SoapApiCaller(url, data1, data2, data3);
    
          Console.WriteLine(returnValue);
          MessageBox.Show("returnValue" + returnValue);
    
          session.Dispose();
          login.Logout();
      }
    

    }

Here my test call is working and returns the webservice response. I need to get extracted fields values in order to pass them to the webservice.

My questions are the following:

  • how do i get the data from KTM Server (the values that are displayed in KTM Validation module)
  • how do i bypass the validation module depending on webservice response ? I should go to PDF Generator module if webservice response is positive
  • how do i pass values returned by my web service to validation module ? For example, I expect a status message with error message, or data from web service. I would like to set a property

Thanks

davidvera
  • 1,292
  • 2
  • 24
  • 55

1 Answers1

0

I solved the first part of my issue:

    static void Run(string[] args)
    {
      
        // MessageBox.Show("activeBatch.BatchFieldValue: " + activeBatch.BatchFieldValue);

        var url = "http://myurl/soap.asmx";
        try
        {
            var login = new Login();
            login.EnableSecurityBoost = true;
            login.Login();
            login.ApplicationName = "KC.CM.Divalto";
            login.Version = "1.0";

            login.ValidateUser("KC.CM.Divalto.exe", false, "", "");

            var session = login.RuntimeSession;
            // get the batch 
            var activeBatch = session.NextBatchGet(login.ProcessID);
            IACDataElement oRoot = activeBatch.ExtractRuntimeACDataElement(0);
            IACDataElement oBatch = oRoot.FindChildElementByName("Batch");
            // get the documents elt
            IACDataElement oDocument = oBatch.FindChildElementByName("Documents");
            IACDataElementCollection oDocColl = oDocument.FindChildElementsByName("Document");

           
            Dictionary<string, string> data = new Dictionary<string, string>();
            foreach (IACDataElement oDoc in oDocColl)
            {
                IACDataElement oIndex = oDoc.FindChildElementByName("IndexFields");
                IACDataElementCollection oIndexColl = oIndex.FindChildElementsByName("IndexField");
                sw.WriteLine("Document: {0}", oDoc["UniqueID"].ToString());
                foreach (IACDataElement oField in oIndexColl)
                {
                    data.Add(oField["Name"].ToString(), oField["Value"].ToString());
                    sw.WriteLine("Name: {0}, Value: {1}", oField["Name"].ToString(), oField["Value"].ToString());
                }
                sw.WriteLine("---------------------------------------");
                WsCaller wsCaller= new WsCaller();
  
  WsResponse returnValue =
      wsCaller.SoapApiCaller(url, data);
                var js = new JavaScriptSerializer();

                MessageBox.Show("data send" + js.Serialize(data));

                Console.WriteLine(returnValue);
                MessageBox.Show("returnValue" + returnValue);
            }
        }                    
        activeBatch.BatchClose(
             KfxDbState.KfxDbBatchReady, KfxDbQueue.KfxDbQueueNext, 0, "");
        session.Dispose();
        login.Logout();
    } catch(Exception ex)
    {
        throw new Exception(ex.Message);
    }
}

The data are stored in oIndexColl: with a foreach, i build my query... My dictionnary has a known size...

davidvera
  • 1,292
  • 2
  • 24
  • 55