Leadtools.Ccow Namespace > IContextManager Interface : JoinCommonContext Method |
true
participate in context change surveys. If false
the application will only be informed when a context change has been accepted.
true
wait for the current context change transaction to complete.
int JoinCommonContext( IContextParticipant contextParticipant, string applicationName, bool survey, bool wait )
'Declaration Function JoinCommonContext( _ ByVal contextParticipant As IContextParticipant, _ ByVal applicationName As String, _ ByVal survey As Boolean, _ ByVal wait As Boolean _ ) As Integer
'Usage Dim instance As IContextManager Dim contextParticipant As IContextParticipant Dim applicationName As String Dim survey As Boolean Dim wait As Boolean Dim value As Integer value = instance.JoinCommonContext(contextParticipant, applicationName, survey, wait)
int JoinCommonContext( IContextParticipant contextParticipant, string applicationName, bool survey, bool wait )
function Leadtools.Ccow.IContextManager.JoinCommonContext( contextParticipant , applicationName , survey , wait )
int JoinCommonContext( IContextParticipant^ contextParticipant, String^ applicationName, bool survey, bool wait )
true
participate in context change surveys. If false
the application will only be informed when a context change has been accepted.true
wait for the current context change transaction to complete.Private ApplicationName As String = "LEADTOOLS CCOW App" <Test> _ Public Sub JoinCommonContext() Dim contextManager As IContextManager = Utils.COMCreateObject(Of IContextManager)(CcowProgId) Dim participant As ContextParticipant = New ContextParticipant() Dim coupon As Integer = 0 Try coupon = contextManager.JoinCommonContext(participant, ApplicationName, True, False) ' ' Set Patient Context ' SetPatientContext(contextManager, coupon) ' ' Get Patient Context ' GetPatientContext(contextManager, coupon) contextManager.LeaveCommonContext(coupon) Catch e As Exception Debug.WriteLine(e.Message) End Try End Sub Public Sub SetPatientContext(ByVal contextManager As IContextManager, ByVal coupon As Integer) Dim patientSubject As Subject = New Subject("Patient") Dim contextData As IContextData = TryCast(contextManager, IContextData) Dim transactionCoupon As Integer = 0 Dim noContinue As Boolean = True, disconnect As Boolean = False Dim reasons As Object Dim decision As String = "accept" patientSubject.Items.Add(New ContextItem("Patient.id.mrn", "123456789")) patientSubject.Items.Add(New ContextItem("Patient.co.Patientname", "Doe^John^^^")) Try transactionCoupon = contextManager.StartContextChanges(coupon) contextData.SetItemValues(coupon, patientSubject.ToItemNameArray(), patientSubject.ToItemValueArray(), transactionCoupon) reasons = contextManager.EndContextChanges(transactionCoupon, noContinue) ' ' If any application responded that they cannot apply the change we need to display ' a dialog that displays the reasons for the problems. ' If (Not reasons Is Nothing AndAlso (CType(reasons, String())).Length > 0) OrElse noContinue Then Dim pd As ProblemDialog = New ProblemDialog(CType(reasons, String()), noContinue) Dim result As DialogResult result = pd.ShowDialog() If noContinue Then decision = "cancel" End If If result = System.Windows.Forms.DialogResult.OK Then decision = "accept" ElseIf result = DialogResult.Cancel Then decision = "cancel" Else decision = "cancel" disconnect = True End If End If contextManager.PublishChangesDecision(transactionCoupon, decision) ' ' If user decided to break context we must leave ' If disconnect Then contextManager.LeaveCommonContext(coupon) End If Catch e As Exception Debug.WriteLine(e.Message) End Try End Sub Public Sub GetPatientContext(ByVal contextManager As IContextManager, ByVal coupon As Integer) Dim contextData As IContextData = TryCast(contextManager, IContextData) Dim data As Object = Nothing Try data = contextData.GetItemNames(contextManager.MostRecentContextCoupon) If data.GetType() Is GetType(String() ) AndAlso (CType(data, String())).Length > 0 Then Dim names As String() = CType(data, String()) For Each name As String In names Debug.WriteLine(name) Next name data = contextData.GetItemValues(data, False, contextManager.MostRecentContextCoupon) If data.GetType() Is GetType(Object() ) Then Dim values As Object() = CType(data, Object()) Dim i As Integer = 0 Do While i < values.Length Debug.Write(values(i).ToString()) Debug.Write(" ") Debug.WriteLine(values(i + 1).ToString()) i += 2 Loop End If End If Catch e As Exception Debug.WriteLine(e.Message) End Try End Sub <ComVisible(True)> _ Public Class ContextParticipant Implements IContextParticipant #Region "IContextParticipant Members" Public Sub CommonContextTerminated() Implements IContextParticipant.CommonContextTerminated Console.WriteLine("CommonContextTerminated") End Sub Public Sub ContextChangesAccepted(ByVal contextCoupon As Integer) Implements IContextParticipant.ContextChangesAccepted Console.WriteLine("ContextChangesAccepted") End Sub Public Sub ContextChangesCanceled(ByVal contextCoupon As Integer) Implements IContextParticipant.ContextChangesCanceled Console.WriteLine("ContextChangesCanceled") End Sub Public Function ContextChangesPending(ByVal contextCoupon As Integer, ByRef reason As String) As String Implements IContextParticipant.ContextChangesPending reason = String.Empty Console.WriteLine("ContextChangesPending") Return "accept" End Function Public Sub Ping() Implements IContextParticipant.Ping End Sub #End Region End Class
private string ApplicationName = "LEADTOOLS CCOW App"; public void JoinCommonContext() { IContextManager contextManager = Utils.COMCreateObject<IContextManager>(CcowProgId); ContextParticipant participant = new ContextParticipant(); int coupon = 0; try { coupon = contextManager.JoinCommonContext(participant, ApplicationName, true, false); // // Set Patient Context // SetPatientContext(contextManager, coupon); // // Get Patient Context // GetPatientContext(contextManager, coupon); contextManager.LeaveCommonContext(coupon); } catch (Exception e) { Debug.WriteLine(e.Message); } } public void SetPatientContext(IContextManager contextManager, int coupon) { Subject patientSubject = new Subject("Patient"); IContextData contextData = contextManager as IContextData; int transactionCoupon = 0; bool noContinue = true, disconnect = false; object reasons; string decision = "accept"; patientSubject.Items.Add(new ContextItem("Patient.id.mrn", "123456789")); patientSubject.Items.Add(new ContextItem("Patient.co.Patientname", "Doe^John^^^")); try { transactionCoupon = contextManager.StartContextChanges(coupon); contextData.SetItemValues(coupon, patientSubject.ToItemNameArray(), patientSubject.ToItemValueArray(), transactionCoupon); reasons = contextManager.EndContextChanges(transactionCoupon, ref noContinue); // // If any application responded that they cannot apply the change we need to display // a dialog that displays the reasons for the problems. // if ((reasons != null && ((string[])reasons).Length > 0) || noContinue) { ProblemDialog pd = new ProblemDialog((string[])reasons, noContinue); DialogResult result; result = pd.ShowDialog(); if (noContinue) decision = "cancel"; if (result == DialogResult.OK) decision = "accept"; else if (result == DialogResult.Cancel) decision = "cancel"; else { decision = "cancel"; disconnect = true; } } contextManager.PublishChangesDecision(transactionCoupon, decision); // // If user decided to break context we must leave // if (disconnect) { contextManager.LeaveCommonContext(coupon); } } catch (Exception e) { Debug.WriteLine(e.Message); } } public void GetPatientContext(IContextManager contextManager, int coupon) { IContextData contextData = contextManager as IContextData; object data = null; try { data = contextData.GetItemNames(contextManager.MostRecentContextCoupon); if (data.GetType() == typeof(string[]) && ((string[])data).Length > 0) { string[] names = (string[])data; foreach (string name in names) { Debug.WriteLine(name); } data = contextData.GetItemValues(data, false, contextManager.MostRecentContextCoupon); if (data.GetType() == typeof(object[])) { object[] values = (object[])data; for (int i = 0; i < values.Length; i += 2) { Debug.Write(values[i].ToString()); Debug.Write(" "); Debug.WriteLine(values[i + 1].ToString()); } } } } catch (Exception e) { Debug.WriteLine(e.Message); } } [ComVisible(true)] public class ContextParticipant : IContextParticipant { #region IContextParticipant Members public void CommonContextTerminated() { Console.WriteLine("CommonContextTerminated"); } public void ContextChangesAccepted(int contextCoupon) { Console.WriteLine("ContextChangesAccepted"); } public void ContextChangesCanceled(int contextCoupon) { Console.WriteLine("ContextChangesCanceled"); } public string ContextChangesPending(int contextCoupon, ref string reason) { reason = string.Empty; Console.WriteLine("ContextChangesPending"); return "accept"; } public void Ping() { } #endregion }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2