Implementing a Context Session
-
Adding Context Participant Control to an Application
To enable an application to become a context participant create a class that implements the IContextParticipant interface. The class implementation is required to be a COM object. As a result the ComVisibleAttribute is required when decalring the class.
C#
[ComVisible(true)]T public class ContextParticipant:IContextParticipant
{
}
<ComVisible(True)>_ Public Class ContextParticipant Implements IContextParticipant End Class -
Joining a Context Session
To become a participant in a context session:- First create a Context Manager. The LEADTOOLS CCOW SDK provides a convenient method that allows you easily create a Context Manager. To create the Context Manager do the following:
IContextManager ContextManager = Utils.COMCreateObject<IContextManager>("CCOW.ContextManager");
- Once a context manager has been created, call the IContextManager.JoinCommonContext method to become a participant.
- First create a Context Manager. The LEADTOOLS CCOW SDK provides a convenient method that allows you easily create a Context Manager. To create the Context Manager do the following:
-
Current Context Participant State
After an application has joined a context session, call the IContextData.GetItemNames method and the IContextData.GetItemValues method to get the current context session state.
-
Leave or Suspend a Link to a Context Session
- Call the IContextManager.LeaveCommonContext method to disconnect an application from a context session.
- Call the IContextManager.SuspendParticipation method to disable survey requests to an application without disconnecting it from the context session.
-
Rejoining a Context Session
If an application has suspended its participation in a context session by calling the IContextManager.SuspendParticipation method it can rejoin the session by calling the IContextManager.ResumeParticipation method. If the application has disconnected from the context session by calling the IContextManager.LeaveCommonContext method it will need to call the IContextManager.JoinCommonContext method to rejoin the context session.
Implementing Context Transactions
-
Initiating a Context Change
When initiating a context change, an application needs to perform the following steps:
- Create a Subject item passing the name of the item as a string to the constructor.
- Set name/value pairs by calling the IContextData.SetItemValues method of the Subject class.
- Create arrays needed to for the IContextManager.StartContextChanges by calling ToItemNameArray and ToItemValuesArray methods.
- Initiate the context change by calling the IContextManager.StartContextChanges method.
- Set the subject values by calling Leadtools.Ccow.IContextData.SetItemValues(System.Int32,System.Object,System.Object,System.Int32) method.
- Call the IContextManager.EndContextChanges after making all of the required changes.
- Check the return values of the IContextManager.EndContextChanges.
- Call the IContextManager.PublishChangesDescision if all applications returned decision is “accept”.
- Present the user with a dialog of choices if all applications do not return an “accept” decision.
-
Handling a Survey
To handle a survey request an application needs to respond to the IContextParticipant.ContextChangesPending method. It should return the appropriate response string (accept, conditionally _accept) based on the current application state. -
Handling Survey Failure
During a context change transaction, the application that instigated the context transaction informs participants that it has completed the context change by calling the ContextManager.EndContextChanges. If any participant applications are unable to make the change, the user will be informed that there is a problem. To complete the changes the instigating application will need to call IContextManger.LeaveCommonContext. This disconnects the instigating application from the context session and prevents spreading the changes to the other session participants.
Implementing a Secure Context System
-
Participating in a Secure Context System
In order to participate in a context system and securely bind to the ContextManager, an application needs to perform the following steps:- Get the ISecureBinding interface of the ContextManager.
- Call the ISecureBinding.InitializeBinding method to begin the secure binding process.
- Call the ISecureBinding.FinalizeBinding method to complete the secure binding process.
- Call the ISecureContextData.SetItemValues method to set secure context items.
-
Authentication Repository
The LEADTOOLS CCOW SDK implements the interface IAuthenticationRepository. Users wishing to implement an Authentication Repository need to derive a class from the IAuthenticationRepository interface.
public class AuthenticationRepository:IAuthenticationRepository
{
}
Implementing Context Action Agents
All context agents (mapping, annotation and action) implement the Leadtools.Ccow.IContextAgent interface. The difference between the context agents is in the implementation of the agent's Leadtools.Ccow.IContextParticipant.ContextChangesPending(System.Int32,System.String@) method.