Session Explorer Interface
The interface describes a hosted control that acts as a session explorer. The interface implements the methods of the previous IHostedApplication3 interface and consists of methods that interact directly with the Agent Desktop. The project Microsoft.Ccf.Samples.SessionExplorerControl illustrates a sample implementation of the ICcfSessionExplorer interface.
The following figure shows the public interface of the Session Explorer interface:
The following table describes the elements of the interface:
|
Element |
Description |
|---|---|
|
AddApplicationNode method |
The method is used to add an application node. In case the application is global, the node is added for all sessions else the node is added to the active session. |
|
AddSession method |
The method is used to add the session node to the tree control, in case it does not already exist. |
|
AddWorkflowApplicationNodes method |
The method is used to add application nodes back to session explorer. |
|
ControlRefresh method |
The method is used to refresh the hosted control. |
|
FocusOnApplication method |
The method is used to focused on a given application. |
|
RefreshView method |
The method is used to refresh the complete view. |
|
RemoveApplicationNode method |
The method is used to remove an application node. In case the application is global, the node is removed from all sessions else the node is removed from the active session. |
|
RemoveSession method |
The method is used to remove an existing session node from the tree control. |
|
RemoveWorkflowApplicationNodes method |
The method is used to remove application nodes from the session explorer. |
|
AppsUI property |
The property holds the application UI value. |
|
ControlHeight property |
The property holds the height of the hosted control. |
|
ControlParent property |
The property holds the parent container of the control. |
|
isControlValue property |
The property is a Boolean value indicating if the control is visible. |
|
SEHostedAppSelected event |
The event is raised when the hosted application is selected. |
|
SessionClose event |
The event is raised when the current session is closed. |
The following sections illustrate the use of each of the core methods used in the SessionExplorer interface.
The following code snippet lists the usage of the AddApplicationNode method. If the application is global, the application (app parameter) node is added for all the active sessions; else it is added only to the session passed as a parameter (session parameter).
public void AddApplicationNode(Session session, IHostedApplication app)
{
foreach (TreeNode sessionNode in sessionsTree.Nodes)
{
// If app is global then add for all sessions
if (session.AppHost.IsGlobalApplication(app))
{
// If this node is the current active session
if (session.Name == sessionNode.Text)
{
sessionNode.Nodes.Add(CreateApplicationNode(app, session));
}
else
{
sessionNode.Nodes.Add(CreateApplicationNode(app, null));
}
}
// Not global so only add for correct session
else if (session.Name == sessionNode.Text)
{
sessionNode.Nodes.Add(CreateApplicationNode(app, session));
return;
}
}
}
The following example illustrates the AddSession method, which adds a session to the tree control (if not already added).
public void AddSession(Session session, bool selected)
{
TreeNode parent, node;
// if there is no session name, then hide this session
if (session == null || session.Name == null)
{
return;
}
// see if active session is already in the session explorer
foreach (TreeNode sessionNode in sessionsTree.Nodes)
{
if (sessionNode.Tag == session)
{
sessionNode.Text = session.Name; // in case the name has changed
return;
}
}
parent = new TreeNode(session.Name);
parent.Tag = session;
// find where to insert this session node at based on the sort
bool sortByName = (SortBy.SelectedItem as string == Strings.SESSION_EXPLORER_STR_SORTBY_CUSTOMER_NAME);
int position = 0;
for (; position < sessionsTree.Nodes.Count; position++)
{
node = sessionsTree.Nodes[position];
if (sortByName && parent.Text.CompareTo(node.Text) < 0)
break;
if (!sortByName)
{
Session oldSession = node.Tag as Session;
if (oldSession!= null && session.StartTime < oldSession.StartTime)
break;
}
}
sessionsTree.Nodes.Insert(position, parent);
// if asked to select this node or if its the active session, then select it
if (selected || session == sessionManager.ActiveSession)
{
sessionsTree.SelectedNode = parent;
}
// Add the applications in this session to the session explorer view
foreach (IHostedApplication app in session)
{
IHostedApplication3 app3 = app as IHostedApplication3;
if (app3 != null && app3.IsListed)
{
// This prevents external apps that are not integrated
// into CCF from being shown in the session explorer.
if (app.TopLevelWindow != null)
{
// if workflow has not started, empty workflow means no workflow has started
if (session.Workflow == string.Empty)
{
// only add untagged applications
if (!session.AppHost.IsTaggedApplication(app))
{
node = CreateApplicationNode(app, session);
parent.Nodes.Add(node);
}
}
else //workflow has started so add all apps
{
node = CreateApplicationNode(app, session);
parent.Nodes.Add(node);
}
}
}
}
sessionsTree.ExpandAll();
updateFields(); // updates some fields to current state
}
The method is used to add application nodes back to session explorer. The following sample code snippet searches for the session passed and add all application nodes to the session tree.
public void AddWorkflowApplicationNodes(Session session, bool selected)
{
// find the session
foreach (TreeNode sessionNode in sessionsTree.Nodes)
{
if (session.Name == sessionNode.Text)
{
// add each tagged application node to the tree under that session
foreach (IHostedApplication app in session)
{
if (session.AppHost.IsTaggedApplication(app))
{
sessionNode.Nodes.Add(CreateApplicationNode(app, session));
}
}
return;
}
}
}
The following sample illustrates removing an application node (passed as the parameter app) from a session (passed as the parameter session). The sample also checks if the session is global; and removes it from all active sessions if true.
public void RemoveApplicationNode(Session session, IHostedApplication app)
{
if (app != null)
{
// If the application is global
if (session.AppHost.IsGlobalApplication(app))
{
foreach (TreeNode sessionNode in sessionsTree.Nodes)
{
// Remove of nodes for the all session
ArrayList al = new ArrayList();
foreach (TreeNode applicationNode in sessionNode.Nodes)
{
IHostedApplication adapter = applicationNode.Tag as IHostedApplication;
if (adapter != null && adapter.ApplicationName == app.ApplicationName)
{
al.Add(applicationNode);
}
}
foreach (object o in al)
{
TreeNode tn = (TreeNode)o;
sessionNode.Nodes.Remove(tn);
}
sessionsTree.ExpandAll();
}
}
// The application is non-global
else
{
foreach (TreeNode sessionNode in sessionsTree.Nodes)
{
// Remove of application nodes only for the correct session
if (session.Name == sessionNode.Text)
{
ArrayList al = new ArrayList();
foreach (TreeNode applicationNode in sessionNode.Nodes)
{
IHostedApplication adapter = applicationNode.Tag as IHostedApplication;
if (adapter != null && adapter.ApplicationName == app.ApplicationName)
{
al.Add(applicationNode);
}
}
foreach (object o in al)
{
TreeNode tn = (TreeNode)o;
sessionNode.Nodes.Remove(tn);
}
sessionsTree.ExpandAll();
}
}
}
}
}
The following snippet illustrates the RemoveSession method that removes the session (passed as an argument session) from the Sessions tree.
public void RemoveSession(Session session)
{
foreach (TreeNode node in sessionsTree.Nodes)
{
if (session == node.Tag)
{
sessionsTree.Nodes.Remove(node);
break;
}
}
updateFields(); // updates some fields to current state
}