Wiki

« Back to PresenceMonitor

PresenceMonitor-Designer

Designer implementation of PresenceMonitor

Create the project#

Create a new project#

1. Launch the CUAE-developer tool.

2. Select the File -> New Project option and enter the Project Name and Location in the "New Application Deisnger Project" form.

Define a new application script and the triggering event#

While creating a new application, the CUAE developer tool will prompt you to name the first script of the application and a triggering event for that script. For PresenceMonitor application we'll name the first script as "script1" and we'll select the triggering event named "Metreos.Providers.Http.GotRequest"

Adding Installer#

In this application we need to use an installer. To add an installer to the project we need to R-click on the root project directory. Then select Add Installer->New Installer.

  • This installer can be used to configure the application through the application server web-console.

Configuring the Installer#

The Installer added in the previous step needs to be configured. Configuring an installer means adding values to the installer. For this application, it is shown in the figure below.

  • For this application, we need to add four configuration items namely Subscriber, Password, RequestURI and Action.These configuration items are given default values.These values can be reconfigured from the Application Server Console when this application is uploaded to the Application Server.
  • Once you are done with adding the configuration items to the installer, double click on the Script1 under the root project directory. It will ask you whether do you want to save the changes made in the installer file. Click on "Yes".

Adding Global(Or Script) Variables#

Now we need to add some global/script variables which can be used throughout one script. Only global variables are capable of collecting the configuration item values which are set in the installer.

-> Initialize g_Subscriber with Config.Subscriber, g_Password with Config.Password, g_requestURI with Config.requestURI and g_action with Config.Action.

Handling the incoming Http request#

While creating applications on CUAE developer tool, we try to handle the triggering events for the applications. The events which trigger the application script are displayed as tabs on the top of the designer canvas. To handle a particular event you need to add some actions, which will be executed on the occurrence of that event.

The actions are listed in the Toolbox under different tabs.

For this application, the triggering event is "Metreos.Providers.Http.GotRequest" and for this event there is only one event handler named "OnGotRequest". Using this event handler we'll start creating our application.

The steps to create the complete application are listed below:#

1. The application is triggered by an incoming HTTP request.A switch is inserted which is enlisted under the "Application components" tab in the ToolBox. Click and hold on this action and drag-drop this action onto the designer canvas. Since it is the first action, it will be automatically connected to the Start point.

  • This Switch will switch on the configurable global variable g_action.

2. In this application, we need to use some actions and event handlers of Presence. These actions are not in the Toolbox. We need to add it manually. To do this, R-click on Toolbox->Application Components tab and select Add Tab. This is shown in the figure below.

  • This will add a new tab to the Toolbox. Rename this new tab to Presence and press Enter. Now R-click on this new tab and select Add/Remove Items. We are doing this to add Presence tools to the Toolbox. It will open a new window named Customize Toolbox. Select the Presence tools, the ones for which Package name is Metreos.Providers.Presence, from the list and click on Ok. It will add the Presence tools to the Toolbox

  • Now drag and drop the NonTriggeringSubscribe and Unsubscribe actions from the Presence tab to the canvas and connect them with the Switch action with directed lines.

  • To connect the Switch action to these two actions, move your cursor to the Switch icon. When your cursor approaches the center of the icon a 'dot' will appear in the center of the icon and your cursor will turn into a 'hand'. Once your cursor has become a 'hand', click and drag the cursor from the Switch action to these two actions respectively.

4. The Switch will determine the program flow of the application. If the application is configured with action NTS then it will go to NonTriggeringSubscribe or if it is configured with U it will go to Unsubscribe action. To do this we need to rename the directed lines emanating from Switch. To do this click on the directed line's name and type NTS.

  • Rename the line to Unsubscribe action similarly.

5. Drag and drop the action Write from the tab Application Components under the Toolbox. We are doing this to handle a case when the Action field in the application is configured with any other value than NTS or U.

6. Now we will provide the action parameters for these three action items. We'll start with NonTriggeringSubscribe. To execute this action it needs to be provided three values namely Password, Request URI and Subscriber. We have these values collected in the three global variables namely g_Password, g_RequestUri and g_Subscriber. Now we'll populate the action parameters for NonTriggeringSubscribe with these variables.

  • We need to collect the result data which will tell us that whether the NonTriggeringSubscribe or Unsubscribe action was executed successfully or not. For this we'll create a local variable named actionStatus. A local variable can be added to the Variables Tray. To view the Variables Tray go to View->Variables Tray. To add a new variable to the tray, R-click on the tray and select Add New Item, rename it to actionStatus and provide it a default value of -1. If the NonTriggeringSubscribe/Unsubscribe action is executed then this value will change.

  • Click on the action NonTriggeringSubscribe. This will display the properties window of this action. R-click on the box on right hand side of the action parameter Password and select variable

  • Now select g_Password from the drop down list, which is populated with all the available variables.

  • Similarly set the RequestUri and Subscriber fields to g_RequestUri and g_Subscriber respectively.
  • Once this is done, set the ResultData parameter ResultCode as local variable actionStatus. The result code for the execution of NonTriggeringSubscribe will be the new value for actionStatus.
  • After all the parameters are set, the properties window for NonTriggeringSubscribe action will look like as shown below.

7. In a similar manner provide the action parameters for the action Unsubscribe and set the ResultData parameter ResultCode as local variable actionStatus. One more action parameter named Triggering needs to be set to false. To do this you need to write false in the text box for Triggering. This indicates if the subscription you are terminating is a triggering one or a non-triggering one. Since we have used NonTriggeringSubscribe hence we need to make it false.

  • After setting all the parameters, the properties window for the Unsubscribe will look like as shown below.

8. Now we will add another action in case the application is configured with an action name other than NTS or U. This will write a message into the app-server logs that an invalid action type is provided. To do this we will use an action named Write. It is available under the Application Components tab in the Toolbox. Drag and drop it and fill in the action parameters as shown below.

9. Now we need to send a response back to the device which initiated the HTTP request. The application treats this device as Remote Host. The IP address of this remote host needs to be saved in a local variable named remoteHost. Create a local variable, rename it to remoteHost and initialize it with the event parameter RemoteHost.

  • NOTE:- Event parameters are the parameters which will be populated when the event is triggered.

  • Drag and drop the action SendResponse which is under the HTTP tab and provide the values shown in the figure below.

10. Drag and drop another Write action and provide the values as given in the figure below.

11. Drag and drop another action EndFunction from the Application Components and connect it with the SendResponse action with a directed line.

12. Now we'll add some event handlers to the main script. To add an event handler we need to drag and drop it onto the script as shown in the figure below. The three event handlers to be added are OnNotify, OnSubscriptionTerminated and OnSessionExpired. The first two event handlers are under the Presence tab and the third one is under the HTTP tab of the Toolbox. This is shown in the figure below.

  • Similarly drag and drop the OnSessionExpired event handler from the HTTP tab.
  • This will add new pages under the script. We need to write the handlers for these events.

12. Click on the tab named OnSubscriptionTerminated. This will open a fresh page with a Start point. Drag and drop the action Write from the Application Components tab of Toolbox and provide the parameters as shown below.

  • This event handler will start executing the moment any subscription is terminated.

  • Drag and drop the action EndFunction from the Application Components tab of Toolbox and connect it with the above mentioned Write action.

13. Click on the tab named OnNotify. This will open a fresh page with a start point. Drag and drop the action CustomCode from the Application Components tab of Toolbox and connect it with the Start point using a directed line. Using this custom code action we will execute a C-Sharp code snippet which will make some log entries to the app server if the status of any presentity changes.

  • First create a local variable status and change its type to Metreos.Types.Presence.PresenceNotification using the drop down list. This is shown below.

  • Now initialize this local variable status with the event parameter Status as shown below.

  • Now select the CustomCode action by clicking on it and go to its Properties window. Click the action parameter named Code and the click on the button at the rightmost side of the text box.

  • This will open a new window with a default code block. Copy the below given code and paste it to the new window overwriting the default code block
public static string Execute(Metreos.Types.Presence.PresenceNotification status, LogWriter log)
{
  if(status == null)
  {
      log.Write(TraceLevel.Warning, "Status is null");
      return IApp.VALUE_FAILURE;
  }

  if(status.ResourceList != null)
  {
    foreach(Resource r in status.ResourceList.Resources.Values)
    {
      if(r.Presence != null && r.Presence.tuple != null && r.Presence.tuple.Length > 0 &&
         r.Presence.tuple[0] != null && r.Presence.tuple[0].status != null)
      {
        log.Write(TraceLevel.Info, "Resource: {0} Status: {1}", r.Uri,
          r.Presence.tuple[0].status.basic);
      }
      else if(r.Uri != null)
      {
        log.Write(TraceLevel.Warning, "Received Notify for {0} with no resource information", r.Uri);
      }
    }
  }
  else
  {
    log.Write(TraceLevel.Warning, "No presence information present in Notify message");
    return IApp.VALUE_FAILURE;
  }
  return IApp.VALUE_SUCCESS;
}
  • Now in the text box named Using on the left side top of this window write Metreos.Types.Presence and press Enter. This will add the namespace Metreos.Types.Presence to the custom code.

  • Drag and drop EndFunction from the ApplicationComponents tab of the Toolbox.

14. Now click on the tab named OnSessionExpired. This will open a fresh page with a start point. Drag and drop the action Write from the Application Components and set the parameters as shown below.

  • Drag and drop EndScript from the Application Components tab under Toolbox and connect it with the Write action using a directed line.

  • This application is complete now.

Building The Application#

  • Build the created application using the "Build Project" option under the "Build" tab of the designer.
  • Once the application is built, it will create a file named PresenceMonitor.mca at C:\Wxp\PresenceMonitor\bin. This file needs to be loaded to the App server for execution. For loading this file open the Cuaeadmin page and go to Applications->List Applications and browse to the directory C:\Wxp\PresenceMonitor\bin and upload the .mca file to the app-server.

Running the application#

  • Before running the application, set up a CUPS server and client to communicate with the Cisco Unified Application Environment as described in Presence Configuration for Examples
  • Login to the CUPC installed on the client machine as the user who is on the contact list of the username provided as a runtime parameter for the PresenceMonitor application. e.g. if User1 is provided as a runtime parameter in the below given step and User2 is on his contact list, then login to the CUPC as User2.
  • Now set the following runtime parameters for the PresenceMonitor application
    • Subscriber: <user associated with CUPS>@cisco.com
    • Password: password of the user
    • RequestUri: <user associated with CUPS>-contacts@cisco.com
    • Action: NTS/U
    • Apply the change

Where:

NTS = Non triggering subscribe

U = Unsubscribe

  • Set a trigger parameter for the application at Applications->Triggers. Since this application is designed to be triggered by an incoming HTTP request, so you need to add a parameter named url with a value /PresenceMonitor.
  • Now open a web-page and in the address bar type the following URL
    http://<App-server_IP_address>:8000/PresenceMonitor
  • This will trigger the application and it will start executing and the status of User2 will be printed on the console window.
  • If the status of the User2 is changed from Available to Busy then it will be displayed on the console window
0 Attachments
1254 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
No comments yet. Be the first.