You are on page 1of 30

IST Amigo Project

Amigo Training Document:


UMPS
Version 1.0

IST-2004-004182
Public
June 2007 Confidential

Project Number : IST-004182


Project Title : Amigo
Deliverable Type : Tutorial

Deliverable Number :
Title of Deliverable : UMPS
Nature of Deliverable : Public
Internal Document Number :
Contractual Delivery Date :
Actual Delivery Date :
Contributing WPs :
Version : 1.0
Author(s) : Otilia Kocsis, Elena Vidjiounaite, Maja Stikic, Todor Dimitrov,
Edwin Naroska, Ron Mevissen, Stephan Tobies, Rich
Hanbidge

Abstract
This tutorial teaches how to use the User modeling and profiling service (UMPS). UMPS provides the
methodology to enhance the effectiveness and usability of services and interfaces in order to (a) tailor
information presentation to user and context, (b) reason about user’s future behavior, (c) help the user
to find relevant information, (d) adapt interface features to the user and the context in which it is used,
(e) indicate interface features and information presentation features for their adaptation to a multi-user
environment.

Keyword list
UMPS, user profiling, user preferences, user modeling, stereotypes

Amigo IST-2004-004182 1/29


June 2007 Confidential

Table of Contents
Table of Contents................................................................................................... 2

1 Introduction ..................................................................................................... 3
1.1 Prerequisites..............................................................................................................................3
1.2 How to use this document ........................................................................................................3

2 System and software requirements ............................................................... 4

3 UMPS................................................................................................................ 5
3.1 UMPS architecture...................................................................................................................6
3.2 Deployment ...............................................................................................................................6

4 Using the UMPS tools ..................................................................................... 7


4.1 Managing Stereotypes..............................................................................................................7
4.1.1 Creating Stereotypes...........................................................................................................8
4.1.2 Creating a new user profile...............................................................................................10
4.1.3 Retrieving user profile properties.....................................................................................15
4.1.4 Setting user profile properties ..........................................................................................15
4.2 Using the GUI to manipulate user preferences....................................................................16
4.2.1 Using the GUI ..................................................................................................................17

5 Using the UMPS API .................................................................................... 21


5.1 UMPS client in .NET..............................................................................................................21
5.1.1 Complete client code ........................................................................................................24
5.1.2 Executing the client ..........................................................................................................26

6 Recommended next steps.............................................................................. 29

Amigo IST-2004-004182 2/29


June 2007 Confidential

1 Introduction
This document is a tutorial about how to use the User modeling and profiling service (UMPS).
UMPS provides the methodology to enhance the effectiveness and usability of services and
interfaces in order to (a) tailor information presentation to user and context, (b) reason about
user’s future behavior, (c) help the user to find relevant information, (d) adapt interface
features to the user and the context in which it is used, (e) indicate interface features and
information presentation features for their adaptation to a multi-user environment.
The tutorial will teach how to use the tools that come along with UMPS and how to access
user information via the UMPS API.

1.1 Prerequisites
Amigo training blocks typically requires some Amigo related as well as non Amigo related
skills or knowledge. These are given in the following:
 Non Amigo related prerequisites:
o The reader should be familiar with either Java or C# to easily follow the
explanations.
o The reader should be familiar with an integrated development environment
(IDE) for the programming language that shall be used. It is suggested to use
either Eclipse 3.2 (or higher) for Java or Visual Studio 2005 for C#.
 Amigo related prerequisites: The user should be familiar with the deployment
frameworks. To this end, the Web Services tutorial may be used (see
https://gforge.inria.fr/frs/?group_id=160).
For some general information on the Amigo project please refer to the Amigo project web site
at http://www.hitech-projects.com/euprojects/amigo/index.htm.

1.2 How to use this document


This document aims at providing the reader with valuable information about how to use the
Amigo middleware. To this end it gives a step by step introduction where explanations are
accompanied with short programming assignments. Please proceed to the document section
by section and step by step and try to do the assignments. In order to save some typing, an
appropriate set of template files is given. These template files already include a programming
frame that must be extend by you in order to complete the assignment. For information on how
where to obtain these template files please refer to Chapter 2.
If code is printed in normal text, it is shown in italic. This example shows how the method
name unsubscribe() is printed. Entire code blocks are embedded in a box as shown below:
using (Service service = new AddService(securedService)) {
WebServer.AddWebService(serviceLocation, service);
Console.WriteLine("Sample service 2 running." +
Environment.NewLine +
"Press <return> to quit");
Console.ReadLine();
}

Amigo IST-2004-004182 3/29


June 2007 Confidential

2 System and software requirements


For the tutorial you need a PC compatible system with the following properties:
 PC running Windows XP, Vista or Windows Server 2003.
 A working network connection if server and client applications shall be executed on
different machines.
If your are using Java, then the following software is needed:
 Java Software Development Kit. This is a general package needed for Java software
development. The package is available from http://java.sun.com.
 Oscar. Oscar is a open source OSGi framework. This software is available from
http://amigo.gforge.inria.fr/obr/tools/.
For the .Net following software components must be installed:
 Microsoft .Net Framework 2.0 or higher
 Amigo .NET deployment framework
 UMPS installation. The msi installation file can be downloaded from
https://gforge.inria.fr/frs/?group_id=160. Please download and install the package.
Note that the UMPS service is only available as .NET version. However, Java
applications may also use UMPS via the Web Services interface.
A set of template files have been prepared in order to help you running the practical parts of
this tutorial. These files can be found in branch labeld “UMPS\Code”. It is recommended that
you use these templates in order to save some typing. The entire package including these
templates along with some other files can be downloaded from
https://gforge.inria.fr/frs/?group_id=160. Note that all path names that are referred to in this
document are relative to the folder the package will be extracted to. Note further, that there is
a separate directory names “UMPS\Code_Solution” in the package. This directory contains the
complete solutions. You may use them as a reference.

Amigo IST-2004-004182 4/29


June 2007 Confidential

3 UMPS
User modeling and profiling service (UMPS) provides the methodology to enhance the
effectiveness and usability of services and interfaces in order to (a) tailor information
presentation to user and context, (b) reason about user’s future behavior, (c) help the user to
find relevant information, (d) adapt interface features to the user and the context in which it is
used, (e) indicate interface features and information presentation features for their adaptation
to a multi-user environment. These goals are achieved by constructing, maintaining and
exploiting user models and profiles, which are explicit representations of individual user’s
preferences. User profile updates will be performed using static and dynamic modeling
methodologies.
The User Modeling and Profiling Service (UMPS) models and maintains user profiles by
means of personalization of content and user interfaces, by combining this information in user
profiles and by keeping histories. It handles multiple user profiles and more complex or
aggregated information and publishes new information. This service enables the applications
to become personalized.
The current trend in user modeling and profiling research has evolved from representation of
groups of users using a certain system in certain conditions, to personalization of these
systems towards individual users preferences and requirements. Personalization applies to
different system components and application domains, but in particular to user interfaces (e.g.,
graphical, gesture, voice-based) and content (e.g., multimedia). Personalization depends on
the initial knowledge of the system about its potential users and the mechanism used to learn
user’s behavior and preferences. But, it also depends heavily on the context in which the
system is used. Therefore the system should be adaptable to the context. In addition, system
behavior and adaptation to multi-user environments must be considered.
Personalization of user interfaces comprises several advantages. It can be used to adapt the
appearance and structure to the user and the user’s way of behaving to provide interfaces that
are more effective and acceptable for all users. Today, adaptation of the appearance is
commonly used in all kinds of graphical user interfaces. The user can choose, for example,
background images, color of menu bars and dialog windows, and sort menu entries into
customized submenus. Normally, this sorting has to be done by the user. But it is also
imaginable that this sorting is done automatically and the user has just to describe the idea of
different submenus (e.g. into this submenu put every multimedia device). This approach would
support flexible systems with dynamical services like the Amigo system. Such flexibility in the
user interface could also allow adaptation of the input recognition part of user-system
interaction acts to help to prevent misinterpretations. For example, a speech interface could be
adapted to the user’s voice and expressions to reduce the error ratio of the subsystems.
Furthermore the information about user behavior can be used to predict future inputs and offer
shortcuts to reach the interaction goal in a more effective way (e.g. less interaction steps).
Personalization of multimedia content implies presentation of different multimedia items (e.g.,
videos, music or news) to different users based on their preferences. For example, one person
likes action movies, and another person does not like violence scenes at all; one person is
interested in news about politics, and another one about football, and so on. However, these
personal preferences depend also on the current situation (context) of the person. There could
be multimedia content which parents do not want to watch in the presence of their children, but
which they would prefer when they are alone; even the person who almost never watches
news about political events most probably will want to see the news about such important
events as the result of a presidential election or a major terrorist attack; generally, the
presentation of the news should be perhaps very short in the morning of a work day and be
more detailed later in the evening, while on weekends the news can already be presented in
more details in the morning. Thus, user models for personalization of multimedia content

Amigo IST-2004-004182 5/29


June 2007 Confidential

should be context-dependent and should be able to learn from user-system interaction in


different contexts over time.

3.1 UMPS architecture


The User Modeling and Profiling Service consists of the following main components, some
representing services by themselves:
Reasoning Module. This service is responsible for exploring the user profile and responding
to other service requests either for parts of the user profile (collection of user preferences for a
particular situation) or discrete preferences. Services and applications can use the
IUserProfileQuerying interface to explore the profiles.
Static Modeler. This service is responsible for the creation, removal and modification of user
profiles at user’s or application’s request. For the user, a GUI will be provided, allowing him to
modify preference values, or to enable or disable the modeling of a series of preferences
corresponding to a branch in the user profile. For services and applications the
IUserProfileManagement interface is provided.
Feedback Analyzer. This service will enable the update of the profile at system’s initiative,
based on explicit or implicit user feedback. The interface provided to log user feedback is the
IUserFeedbackLogging interface.
Context Module. This service provides access to the context history data gathered by the
Context Management Service (CMS) based on synchronous queries and asynchronous event-
based subscriptions. In order to receive the «context changed» events, the IEventMonitor
interface is provided.
Dynamic Modeler. This component is responsible for the modification (update) of the user
profile at runtime, using the logged user feedback and context history data. It is composed by
4 subcomponents: (1) Stereotype Activator, (2) Multimedia Dynamic Modeler, (3) Speech
Dynamic Modeler and (4) Automatic Updater. Each of these subcomponents represents
services that will be used by the other components of UMPS, and provide the corresponding
interfaces, ITrigger, IModelMultimed, IModelSpeech and IUpdate.
Multi-Profile Aggregator. This component provides an aggregated profile in case of multiple
users found in the same context (i.e. the same room).

3.2 Deployment
An operational user modeling and profiling service should have installed at least the
Reasoning Module and the Static Modeler, the basic components for management and
querying of user profiles. User profiles and the library of stereotypes are stored in an Access
database for the first software version. Reasoning Module and Static Modeler are accessing
the database through a common .NET module (DBInterface). This minimum installation
enables only direct manipulation of user profiles. In order to take advantage of enhanced user
modeling and profiling methodology, the rest of the components should also be installed. In
addition, application and service providers are provided with a Stereotypes Manager module in
order to modify the library of stereotypes.

Amigo IST-2004-004182 6/29


June 2007 Confidential

4 Using the UMPS tools


4.1 Managing Stereotypes
User profile initialization is based on a stereotypes library to overcome cost and time expenses
of profiles initialization through the system. Note that the stereotypes library is typically
configured and updated by system and application providers but not by end users.
Stereotypes can be visualized using a tree like structure where the root is the “ANY_PERSON”
stereotype.
The picture below shows a partial view on the stereotype library as it is displayed by the
StereoTypes Manager.

Stereotypes are organized as follows:


 The actual stereotypes consists of a declarative name. In the stereotype tree they are
marked with a capital “S”. Each stereotype is associated with a set of “keys” where

Amigo IST-2004-004182 7/29


June 2007 Confidential

each key describes an aspect that is related to the stereotype. Further, a “trigger”
defines a term that controls the affiliation of specific individual to a stereotype. Note
that a stereotype may consist or include other stereotypes.
 Keys describe a specific aspect of an individual. Keys are associated with a value and
a rating, where the value is an integer between -5 and 5 describing the strength and
direction of the connection between the aspect and the corresponding stereotype.
Here, -5 denotes the strongest negative connection, while +5 denotes the strongest
positive connection. Further, the rating value denotes the confidence with respect to
the value. The rating is between 0 (least confidence) and 1000 (max confidence). In
the manager, keys are displayed with a capital “K”. For example, a vegetarian person
does not eat beef. Hence, the value for beaf would be -5 with confidence (rating) 1000.
 “Classes” can be used logically group a set of keys or a set of included classes. As a
result, a class may contain other classes or keys. For example, the class “Preferences”
groups together various kinds of preferences (FoodPreferences,
MultimediaPreferences, etc.).
 “Triggers” associate a specific term with a stereotype. For example, the term
“Adult_Person” is associated with the stereotype “Adult”.

4.1.1 Creating Stereotypes


In the following it is shown how a stereotype is created using the StereType Manager tool. In
detail we will add the stereotype “GAMER” to the root “ANY_PERSON”. To this end perform
the following steps:
1. Start “C:\UMPS\Software\Manager.exe” application, and the interface that allow you to
edit the stereotypes database will be shown.
2. Browse Stereotypes library tree on the left to show different types of stereotypes.
3. Go to “ANY_PERSON” stereotype. Right click with the mouse and choose “Add -
>Stereotype”. In the right side of the GUI, in the “Name” text box enter “GAMER”.
Press the “Apply” button on the bottom-right side of the GUI.

4. Right-click the “GAMER” stereotype and choose “Add -> Trigger”. Enter trigger name
“Gamer” and press “Apply”.
5. Right-click the “GAMER” stereotype and choose “Add -> Class”. In the right “Name”
combo box choose “Preferences” and press “Apply”.
6. Right-click the “Preferences” class under the “GAMER” stereotype and choose “Add ->
Class”. Choose the “MultiMediaPrefs” name and press “Apply”.
7. Right-click the “MultiMediaPrefs” class under the “GAMER/Preferences” class and
choose “Add-> Class”. Choose the “GamesPrefs” name and press “Apply”.

Amigo IST-2004-004182 8/29


June 2007 Confidential

8. Right-click the “GamesPrefs” class under the “GAMER/Preferences/MultiMediaPrefs”


class and choose “Add-> Class”. Choose the “GamesGenrePrefs” name and press
“Apply”.
9. Right-click the “GamesGenrePrefs” class and choose “Add -> Key”. Choose the
“fighting” name, enter Value “2”, enter Rating “800” and press “Apply”. Repeat this for
keys “card”, “strategy”, and “combat”.
As a result, the stereotype tree will look like shown below. The meaning is that a gamer
has s specific set of preferences for games. Note that this list is not intended to be
complete.

As a next step we are going to add a specific variation of a gamer, the “on-line gamer”. To
this end proceed with the following steps:
10. Go to “GAMER” stereotype. Right click with the mouse and choose “Add -
>Stereotype”. In the right side of the GUI, in the “Name” text box enter
“ONLINE_GAMER”. Press the “Apply” button on the bottom-right side of the GUI.
11. Right-click the “ONLINE_GAMER” stereotype and choose “Add -> Trigger”. Enter
trigger name “Online_Gamer” and press “Apply”.
12. Right-click the “ONLINE_GAMER” stereotype and choose “Add -> Class”. In the right
“Name” combo box choose “Preferences” and press “Apply”.
13. Right-click the “Preferences” class under the “ONLINE_GAMER” stereotype and
choose “Add -> Class”. Choose the “MultiMediaPrefs” name and press “Apply”.
14. Right-click the “MultiMediaPrefs” class under the “ONLINE_GAMER/Preferences” class
and choose “Add-> Class”. Choose the “GamesPrefs” name and press “Apply”.

Amigo IST-2004-004182 9/29


June 2007 Confidential

15. Right-click the “GamesPrefs” class under the


“ONLINE_GAMER/Preferences/MultiMediaPrefs” class and choose “Add-> Class”.
Choose the “GamesGenrePrefs” name and press “Apply”.
16. Right-click the “GamesGenrePrefs” class and choose “Add -> Key”. Choose the
“combat” name, enter Value “2”, enter Rating “800” and press “Apply”. Repeat this for
key “strategy”.

The new tree should look like this:

4.1.2 Creating a new user profile


Personal details must be directly acquired from the user and added to the profile. These data
are also analyzed to extract triggers and activate stereotypes (i.e. if age <18 trigger=”Child”,
else trigger=”Adult”, etc.). The following instructions show how to add a new user profile, for a
guest named Andrew:
1. Start “C:\UMPS\Software\StaticModeler.exe” service.

Amigo IST-2004-004182 10/29


June 2007 Confidential

2. Start “C:\UMPS\Software\ReasoningModule.exe” service.


3. Start “C:\UMPS\Software\Client.exe” application.
4. Choose option “1” and press “Enter”. The system will ask for the user’s ID:

5. Enter to the Client console the userID for the new user profile (here: “Andrew@home”)
and press “Enter”

Amigo IST-2004-004182 11/29


June 2007 Confidential

6. The GUI for specification of personal details will appear.


7. Set all the compulsory fields in the “Personal Details” tab, and don’t forget to set an
“adult” date of birth – else Andrew will be considered a child.
8. Go to the “Additional Personal Details” tab, enable the Religion and choose “Muslim”.

Amigo IST-2004-004182 12/29


June 2007 Confidential

9. Go to “Security & Privacy” and choose for User Type “Guest”.


10. Press the “Add” button at the bottom of the form.
11. You will be asked if you want to edit also context-dependent settings. Select “Yes”. A
new GUI will be displayed, initialized with the profile data of “Andrew@home”.
12. Browse the profile tree and go to “Preferences/ProductsPrefs/FoodPrefs” to see the “-
5” value for “pork” coming from the “MUSLIM” stereotype…

Amigo IST-2004-004182 13/29


June 2007 Confidential

Figure 4.8. Use of the UMPS test Client to verify the addition of a new profile by selecting “8”.
This will plot a list of existing profiles on the screen:

Amigo IST-2004-004182 14/29


June 2007 Confidential

4.1.3 Retrieving user profile properties


From the UMPS Client we now add and query special properties. To this end, a set of
functions are provided. First, we query PersonalDetails -> Address:
1. Start the UMPS Client software (“C:\UMPS\Software\Manager.exe”) and enter 4.
2. The system will ask for the user’s ID and the property that is going to be retrieved.
Type in “Andrew@home” for the user ID and “PersonalDetails:Address” for the setting
ID. Note that the property name is build like a path name with “:” as separator:

The system will respond with “<key id="Address"><valueset><value type="string">Finkenstr.


61</value><rating>1000</rating><justification>Explicit</justification></valueset></key>” or
which ever address has been set.

4.1.4 Setting user profile properties


Similar, a property can be set. To this end, use the Client tool again:
1. Start the UMPS Client software (“C:\UMPS\Software\Manager.exe”) and enter 3.
2. The system will ask for the user’s ID, the property name, the property type and the
actual value that is going to be set. Type in “Andrew@home” for the user ID and
“PersonalDetails:Address” for the setting ID. Further, use “string” as value type and use
an arbitrary new address text:

Amigo IST-2004-004182 15/29


June 2007 Confidential

3. Finally, check whether the value has been saved by retrieving the property as
described in the previous section. This should give the following output:

4.2 Using the GUI to manipulate user preferences


The GUI interface provides a convenient the way for users to view and to manually set/
change their preference values that are already stored in the profile. The GUI also provides to
application developers a comfortable way to simulate user profiles.
The GUI works in a following way: the tree of user preferences is read from the User Modeling
Ontology file and presented via a GUI with the default preference values set to the lowest limit
of user preference (which indicates that the user has no interest in this topic). Via the GUI one
can now change any preference value. Further, a preference value can be attached to any
context from the Context Ontology. This is an interesting option to make user preferences
context dependent. For example, the movie preferences of an adult person may vary
depending on whether a child is present or not. By attaching preference values with context
information these kind of effects can be modeled.
Amigo IST-2004-004182 16/29
June 2007 Confidential

4.2.1 Using the GUI


Before editing user a profile, the ID of the appropriate user is required. In the figure below the
start page of the UMPS User Interface is shown. At the bottom of the window the user’s ID can
be typed into the field below label “User ID”. Next to this filed a list of already existing IDs is
presented. To add a new user profile, just enter a new number or string.

After the user entered the appropriate ID, his preferences are loaded, and the application
switches to the next page (see below). The leftmost box shows user profile tree, the rightmost
box shows the tree of contexts which the system is able to recognize.
One can click on a “+” sign in order to expand the corresponding part of the tree. The user
preference values are attached only to the leaf nodes of the tree (“leaf node” means a node
which can not be expanded anymore). The default value for user preferences is 0. If the user
preference is unknown, it’s value is shown as 0. For personal details the default value is an
empty string.

Amigo IST-2004-004182 17/29


June 2007 Confidential

The user can change a value of any leaf node. To this end, one selects a node and double-
click it with the mouse. As a result, a box with the prompt “Enter value here” appears and
shows the current preference value. For numeric preferences values the application will also
show upper and lower limits of the preference value.
After a new value has been entered the change must be confirmed by pressing the “Accept
Change” button. As a result, the new value is written to the user profile, and will of course also
appear in the preference tree. However, if the entered numeric value is above the upper or
below the lower limit, the change is not accepted. Note that after the change of the preference
value ha been confirmed, the text box “enter new value” and the button “Accept Change”
disappear, so if the user wants to change another value, he needs to double click on it again.
The user can attach contexts to the value by selecting a leaf node in a context tree and
pressing the “Attach Selected Context” button. The contexts attached are shown in the profile
tree and in the window under the caption “Your preference value is valid in context(s):”(see
Figure 4.12). If there is no context attached, the value is assumed to be always valid (which is
also the default configuration).

Amigo IST-2004-004182 18/29


June 2007 Confidential

The buttons “Delete Setting” and “Add Setting with the same key” allow the user to delete any
leaf node in the user profile tree, or duplicate any leaf node.
When the user presses “Add Setting with the same key” button, the leaf node with the same
key and with the default value is added to the tree. This is useful if different preference values
are needed for different contexts (see below).
The button “Add Setting with the same key” is needed also for entering personal details, e.g.,
the user can enter as many nicknames, names of children or friends as required.
When the user presses “Delete Setting” button, the selected leaf node is removed from the
tree.

Amigo IST-2004-004182 19/29


June 2007 Confidential

Removing some contexts attached to a preference value can be done by selecting the context
in the box labeled “Your preference value is valid in contexts” and by pressing “Remove
Context” button as shown below:

Amigo IST-2004-004182 20/29


June 2007 Confidential

5 Using the UMPS API


In the following chapter a simple example for using the UMPS programming API in order to
read and write user preferences is given. To this end, a program to read out and set the
address field of the user preference database is developed.
As Amigo is based on Web Services, using UMPS basically boils down to using appropriate
Web Services. To this end, the corresponding development frameworks for Java or .Net can
be exploited. In the following the code to access the database from .NET code is explained.
The template files that shall be used with this tutorial can be found in directory “UMPS\Code”
and subfolders.

5.1 UMPS client in .NET


The C# code for the UMPS client shall go into a file named
“UMPS\Code\UMPS_Example\UMPS_Example\Program.cs”.
In order to use the Amigo Web Services the appropriate packages must be included.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.IO;

using System.Runtime.InteropServices;

using EMIC.WebServer;
using EMIC.WSDiscovery.Server;
using EMIC.WSDiscovery.Client;
using EMIC.WSAddressing;

using System.Xml;
...

Then, a new namespace is defined that is going to hold our new sample application. Here, the
namespace is named UMPS_Example. Within the new namespace, a class Program is
defined. The class contains three main methods:
 A method called findServices which is called in order to find and binde all services that
are needed to access the UMPS database. In detail two services are needed, the user
profile management services and the user profile querying service.
 A method getXmlElement which is used to parse the results that are obtained form
querying the preferences database. Note the UMPS services will return an XML
formatted string that must be further analyzed in order to extract all interesting
information from it. Here, we are just interested in extracting the values that are
associated with a specific tag.
 The actual main routine which calls findServices and generates some in/output and
initiates the operations with the preferences database.
namespace UMPS_Example
{
public static UMPS_Example.IUserProfileManagement.Service
proxyStaticMod;

Amigo IST-2004-004182 21/29


June 2007 Confidential

public static UMPS_Example.IUserProfileQuerrying.Service


proxyResMod;

//static class Program


class Program
{
public bool findServices()
{
...
}

public static string getXmlElement(string xmlString, string tag)


{
XmlTextReader reader =
new XmlTextReader(new StringReader(xmlString));
while (reader.Read())
{
if (reader.Name == tag)
{
reader.Read();
string str = reader.ReadContentAsString();
return str;
}
}
return "???";
}

static void Main()


{
...
}
}
}

In order to look for the two needed services, appropriate probe clients are created and the
corresponding service scopes and services types are defined. Note that scope and type
names are case sensitive.
public bool findServices()
{
ProbeClient pc1 = new ProbeClient();
ProbeClient pc2 = new ProbeClient();

pc1.AddServiceScope(
new EMIC.WSDiscovery.ServiceScope("urn:Amigo"));
pc1.AddServiceType(
new EMIC.WSDiscovery.ServiceType("IUserProfileManagement"));

pc2.AddServiceScope(
new EMIC.WSDiscovery.ServiceScope("urn:Amigo"));
pc2.AddServiceType(
new EMIC.WSDiscovery.ServiceType("IUserProfileQuerrying"));

Thereafter, the lookup process is started. As both services are needed, we loop until both
have been found. Note that each loop iteration will last for 5 seconds. Hence, expect some
delay during program startup.
while (true)
Amigo IST-2004-004182 22/29
June 2007 Confidential

{
Console.WriteLine("Discovering services...");
if (pc1.ProbeMatches.Count == 0) pc1.SendProbe();
if (pc2.ProbeMatches.Count == 0) pc2.SendProbe();
System.Threading.Thread.Sleep(5000);

if (pc1.ProbeMatches.Count > 0 &&


pc2.ProbeMatches.Count > 0)
{
proxyStaticMod =
new UMPS_Example.IUserProfileManagement.Service();
proxyStaticMod.Url =
pc1.ProbeMatches[0].FirstXaddr.ToString();

proxyResMod =
new UMPS_Example.IUserProfileQuerrying.Service();
proxyResMod.Url =
pc2.ProbeMatches[0].FirstXaddr.ToString();
break;
}
}
Console.WriteLine("All required services found!");
return true;
}
If an appropriate set of services have been found, then the corresponding proxies are stored to
the appropriate member variables.
Within the main routine we first call findServices:
static void Main()
{
Program pr = new Program();
if (!pr.findServices())
{
Console.WriteLine("Press <Return> to exit...");
Console.ReadLine();
return;
}
...

Then, the program shall ask for the ID of the user that is going to be processed:
Console.Write("User ID=");
string userID = Console.ReadLine();

Next, we query the current address of the user from the preferences database calling the
getSetting method on the querying service. The method takes two arguments:
 The ID of the user that is going to be queried.
 A string defining the value to be retrieved. Note that this name is defined like a
directory path name with delimiters “:”. The path name starts with the root node
“PersonalDetails” and a corresponding string is added for each element which is hit
while walking the tree from root the intended leaf node.
Note that the result from getSetting is an XML formatted string that must be further analyzed.
To this end, we use the getXmlElement described above.
Console.WriteLine("Getting address for user " + userID + "...");
string address =

Amigo IST-2004-004182 23/29


June 2007 Confidential

getXmlElement(Program.proxyResMod.getSetting(
userID,"PersonalDetails:Address"),"value");
Console.WriteLine("Address is '" + address + "'!");
Console.WriteLine();
...

To test writing to the database, a new address string is read from the console and stored to
the database. To this end, method setSetting is called on the profile management proxy. Note
that this is a different proxy compared to the one used for the address retrieval operation
above. The call to setSetting takes four arguments:
 The ID of the user that is going to be addressed.
 A string defining the value to be written. Note that this name is defined like a directory
path name with delimiters “:”. The path name starts with the root node
“PersonalDetails” and a corresponding string is added for each element which is hit
while walking the tree from root the intended leaf node.
 The type of the value that is to be set. Here, the type is string.
 Finally, the new value that shall be stored to the preferences database.
Console.Write("Enter a new address: ");
string newAddress = Console.ReadLine();
Console.WriteLine("Setting address for user " + userID +
" to '" + newAddress + "'!");
Program.proxyStaticMod.setSetting(userID,
"PersonalDetails:Address", "string", newAddress);
...

Finally, we read back the address field from the database in order to check out whether the
operations was successful:
Console.WriteLine("Reading back address for user " + userID +
"...");
address = getXmlElement(Program.proxyResMod.getSetting(
userID, "PersonalDetails:Address"),"value");
Console.WriteLine("Address is '" + address + "'!");
Console.WriteLine();
...

As a last step, we wait for the user to press “return” in order to exit the program.

Console.WriteLine("Press <Return> to exit...");


Console.ReadLine();
}

5.1.1 Complete client code


For your convenience, the complete client code is printed below.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

using EMIC.WebServer;
Amigo IST-2004-004182 24/29
June 2007 Confidential

using EMIC.WSDiscovery.Server;
using EMIC.WSDiscovery.Client;
using EMIC.WSAddressing;

using System.Xml;

namespace UMPS_Example
{
//static class Program
class Program
{
public static UMPS_Example.IUserProfileManagement.Service
proxyStaticMod;
public static UMPS_Example.IUserProfileQuerrying.Service
proxyResMod;

public bool findServices()


{
ProbeClient pc1 = new ProbeClient();
ProbeClient pc2 = new ProbeClient();

pc1.AddServiceScope(
new EMIC.WSDiscovery.ServiceScope("urn:Amigo"));
pc1.AddServiceType(
new EMIC.WSDiscovery.ServiceType("IUserProfileManagement"));

pc2.AddServiceScope(
new EMIC.WSDiscovery.ServiceScope("urn:Amigo"));
pc2.AddServiceType(
new EMIC.WSDiscovery.ServiceType("IUserProfileQuerrying"));

while (true)
{
Console.WriteLine("Discovering services...");
if (pc1.ProbeMatches.Count == 0) pc1.SendProbe();
if (pc2.ProbeMatches.Count == 0) pc2.SendProbe();
System.Threading.Thread.Sleep(5000);

if (pc1.ProbeMatches.Count > 0 &&


pc2.ProbeMatches.Count > 0)
{
proxyStaticMod =
new UMPS_Example.IUserProfileManagement.Service();
proxyStaticMod.Url =
pc1.ProbeMatches[0].FirstXaddr.ToString();

proxyResMod =
new UMPS_Example.IUserProfileQuerrying.Service();
proxyResMod.Url =
pc2.ProbeMatches[0].FirstXaddr.ToString();
break;
}
}
Console.WriteLine("All required services found!");
return true;
}

public static string getXmlElement(string xmlString, string tag)


{
XmlTextReader reader =
new XmlTextReader(new StringReader(xmlString));
Amigo IST-2004-004182 25/29
June 2007 Confidential

while (reader.Read())
{
if (reader.Name == tag)
{
reader.Read();
string str = reader.ReadContentAsString();
return str;
}
}
return "???";
}

static void Main()


{
Program pr = new Program();
if (!pr.findServices())
{
Console.WriteLine("Press <Return> to exit...");
Console.ReadLine();
return;
}

Console.Write("User ID=");
string userID = Console.ReadLine();

Console.WriteLine("Getting address for user " + userID + "...");


string address = getXmlElement(Program.proxyResMod.getSetting(
userID,"PersonalDetails:Address"),"value");
Console.WriteLine("Address is '" + address + "'!");
Console.WriteLine();

Console.Write("Enter a new address: ");


string newAddress = Console.ReadLine();
Console.WriteLine("Setting address for user " + userID + " to '"
+ newAddress + "'!");
Program.proxyStaticMod.setSetting(
userID, "PersonalDetails:Address", "string", newAddress);
Console.WriteLine("Reading back address for user " + userID +
"...");
address = getXmlElement(Program.proxyResMod.getSetting(
userID, "PersonalDetails:Address"),"value");
Console.WriteLine("Address is '" + address + "'!");
Console.WriteLine();

Console.WriteLine("Press <Return> to exit...");


Console.ReadLine();
}
}
}

5.1.2 Executing the client


In order to execute the UMPS client the required services must be up and running. To this
end, go to the installation directory of UMPS (typically C:\UMPS\), Form sub directory
C:\UMPS\ Software start the modules ReasoningModule.exe and StaticModeler.exe.
Then, execute the UMPS client. After a few seconds, the following message should be printed
in the console: The system asks for an existing user ID. You may provide one of the user ID’s
that were used in the previous sections.

Amigo IST-2004-004182 26/29


June 2007 Confidential

After typing in an user ID, the system will query the current address field form the database
and print it to the screen. Enter a new address and press “return”.

Thereafter, the client will set the address in the database, re-read it and print the result to the
screen again.

Amigo IST-2004-004182 27/29


June 2007 Confidential

Amigo IST-2004-004182 28/29


June 2007 Confidential

6 Recommended next steps


Now that you have learned about using UMPS you may be interested in how to continue in the
most efficient way in order to become more familiar with the Amigo middleware. You may
proceed as follows:
 ANS Tutorial: ANS is part of the intelligent user services and provides an easy way to
get access to changes in the context of the home environment. ANS provides
functionality to allow people/applications to stay aware of context changes. The ANS
tutorial briefly introduces how to use ANS, i.e. how to write and ANS client. It can be
downloaded from https://gforge.inria.fr/frs/?group_id=160.
 In fact, when you followed the sequence of recommended tutorials you should now
have sufficient knowledge to develop your own simple services and applications.
Depending on your specific needs you may also browse the Amigo repository
(https://gforge.inria.fr/frs/?group_id=160) to check out further packages, tools and
documentation.

Amigo IST-2004-004182 29/29

You might also like