<?xml version="1.0" encoding="UTF-8"?>
<process xmlns:blue="http://www.e-marson.com/bluelemon">

  <descriptor>
    <name>com/emarson/lemonade/examples/mobank/moaccount/_deployment/DownloadingScreen</name>
    <version>1.0</version>
    <description>
      Networking operations usually take time. It is good to show an
      interactive element to the user, like a moving gauge indicating
      the progress.
      
      This process generates a Bluelemon code which:
       - shows a moving gauge to the user; this gauge progresses
         slowly and waits for the actual network connection to be 
         initiated; when the connection is initiated, gauge is 
         showing the actual progress of downloading the 
         Bluelemon instruction.
       - calls a node in the network location, specifying two
         parameters: ammountOfMoney and targetAccountNumber.
       
       It is possible to use a template solution for most of that.
       We just need to focus on the actual networking action.
    </description>
    <vendor>E-MARSON</vendor>
  </descriptor>

  <path>

    <!-- ASSOCIATIONS --->

    <!-- association to MainScreen --->
    <action name="on 'Cancel'">
      <type>general/bluelemon/code</type>
      <definition resultTo="goToMainScreen">
        <blue:call node="com/emarson/lemonade/examples/mobank/moaccount/MainScreen"
                         location="@com/emarson/lemonade/examples/mobank/moaccount"/>

      </definition>
    </action>
    
    <!-- INSTRUCTION --->
    
    <!-- 
      this is the networking action, which will be part of the complete
      Bluelemon code doing what we need
     --->

    <action name="the networking action">
      <type>general/bluelemon/code</type>
      <description>
        This is the procedure which takes two parameters:
         - ammount of money being transferred : int
         - target account number : String
      </description>
      <definition resultTo="networkingAction">

        <blue:try>

          <!-- invoke the network process --->
          <blue:call node="com/emarson/lemonade/examples/mobank/moaccount/Transfer"
                     location="network">

            <blue:argument type="variable" name="arg_1"/>
            <blue:argument type="variable" name="arg_2"/>
          </blue:call>
          
        </blue:try>

        <!-- catch the IOException --->
        <blue:catch exception="com/emarson/midp/IOException">

          <!-- create the form and inform the user operation failed --->
          <blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/Form"
                            toVariable="form"/>

                            
          <blue:call object="form" method="initialize">
            <blue:argument type="String" value="Operation failed"/>
          </blue:call>

          <blue:call object="form" method="appendString">
            <blue:argument type="String" value="Due to networking problems we couldn't proceed. Try again later."/>
          </blue:call>

          <blue:call manager="UtilsManager" method="getActionCommand"
                     toVariable="command">

            <blue:argument type="String" value="Back"/>
            <blue:argument type="byte" value="ActionCommand.BACK"/>
            <blue:argument type="byte" value="0"/>
            <blue:argument type="byteArr" contextKey="goToMainScreen"/>
          </blue:call>

          <blue:call object="form" method="addCommand">
            <blue:argument type="variable" name="command"/>
          </blue:call>

          <blue:call manager="GeneralManager" method="setCurrent">
            <blue:argument type="variable" name="form"/>
          </blue:call>

        </blue:catch>

      </definition>
    </action>
    
    <!-- this subprocess will generate the code for us --->
    <subprocess name="akcja anulowania przetwarzania">
      <source>com/emarson/lemonade/templates/downloading/Screen</source>
      <arguments>
        <argument key="title">"Transfer..."</argument>
        <argument key="textUnderGauge">"Waiting for the response..."</argument>
        <argument key="cancelText">"Cancel"</argument>
        <argument key="cancelAction">goToMainScreen</argument>
        <argument key="networkingAction">networkingAction</argument>
      </arguments>
      <resultTo>actionCancelDownloading</resultTo>
    </subprocess>

    <finish name="done">
      <return>actionCancelDownloading</return>
    </finish>

  </path>

</process>