Hi all,
I have a below code using ucma sample , but its giving an exception "NullReference" on
_helper = new UCMASampleHelper();
_userendpoint = _helper.CreateEstablishedUserEndpoint("MyUCApp");
Plz suggest how can i make this code work.
the code is as below
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.Rtc;
using Microsoft.Rtc.Collaboration;
using System.Threading;
using Microsoft.Rtc.Signaling;
using LyncUCMA;
using System.Threading;
namespace LyncUCMA.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
#region Locals
private static String _conversationSubject;
private static String _conversationPriority = ConversationPriority.Urgent;
private static String _messageToSend;
private InstantMessagingCall _instantMessagingCall1;
private InstantMessagingCall _instantMessagingCall2;
private UserEndpoint _userendpoint;
private UCMASampleHelper _helper;
private AutoResetEvent _sampleCompletedEvent = new AutoResetEvent(false);
#endregion
#region method
protected void Page_Load(object sender, EventArgs e)
{
}
protected void bt_Trigger_Click(object sender, EventArgs e)
{
try
{
using (SPSite site = new SPSite(SPContext.Current.Web.Url.ToString()))
{
using (SPWeb objSPWeb = site.OpenWeb())
{
string question = l_title.Text;
_conversationSubject = question;
_messageToSend = txt_Text.Text;
VisualWebPart1UserControl ucmaSampleInstantMessagingCall = new VisualWebPart1UserControl();
ucmaSampleInstantMessagingCall.Run();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private void Run()
{
Exception ex = null;
try
{
_helper = new UCMASampleHelper();
_userendpoint = _helper.CreateEstablishedUserEndpoint("MyUCApp");
Console.Write("The User Endpoint owned by URI: ");
Console.Write(_userendpoint.OwnerUri);
Console.WriteLine(" is now established and registered.");
ConversationSettings convSettings = new ConversationSettings();
convSettings.Priority = _conversationPriority;
convSettings.Subject = _conversationSubject;
Conversation conversation1 = new Conversation(_userendpoint, convSettings);
_instantMessagingCall1 = new InstantMessagingCall(conversation1);
_instantMessagingCall1.StateChanged += this.InstantMessagingCall_StateChanged;
_instantMessagingCall1.BeginEstablish("sip:vineeth@sp.com",new ToastMessage(_messageToSend),null,CallEstablishCompleted,_instantMessagingCall1);
Conversation conversation2 = new Conversation(_userendpoint, convSettings);
_instantMessagingCall2 = new InstantMessagingCall(conversation2);
_instantMessagingCall2.StateChanged += this.InstantMessagingCall_StateChanged;
_instantMessagingCall2.BeginEstablish("sip:Sree@sp.com", new ToastMessage(_messageToSend), null,CallEstablishCompleted, _instantMessagingCall2);
} catch (InvalidOperationException iOpEx)
{
ex = iOpEx;
}
finally
{
if (ex != null)
{
Console.WriteLine(ex.ToString());
Console.WriteLine("Shutting down platform due to error");
_helper.ShutdownPlatform();
}
}
_sampleCompletedEvent.WaitOne();
}
void InstantMessagingCall_StateChanged(object sender, CallStateChangedEventArgs e)
{
Console.WriteLine("Call has changed state. The previous call state was: " + e.PreviousState +"and the current state is: " + e.State);
}
private void InstantMessagingFlow_StateChanged(object sender, MediaFlowStateChangedEventArgs e)
{
InstantMessagingFlow instantMessagingFlow = (InstantMessagingFlow)sender;
Console.WriteLine("Flow state changed from " + e.PreviousState + " to " + e.State);
if (e.State == MediaFlowState.Active)
{
instantMessagingFlow.BeginSendInstantMessage(_messageToSend, SendMessageCompleted,instantMessagingFlow);
}
}
private void InstantMessagingFlow_RemoteComposingStateChanged(object sender,ComposingStateChangedEventArgs e)
{
Console.WriteLine("Participant "+ e.Participant.Uri.ToString()+ " is "+ e.ComposingState.ToString());
}
private void InstantMessagingFlow_MessageReceived(object sender, InstantMessageReceivedEventArgs e)
{
InstantMessagingFlow instantMessagingFlow = (InstantMessagingFlow)sender;
Console.WriteLine(e.Sender.Uri + " said: " + e.TextBody);
if (e.TextBody.Equals("bye", StringComparison.OrdinalIgnoreCase))
{
instantMessagingFlow.BeginSendInstantMessage("Shutting Down...", SendMessageCompleted,instantMessagingFlow);
_helper.ShutdownPlatform();
_sampleCompletedEvent.Set();
}
else
{
instantMessagingFlow.LocalComposingState =
ComposingState.Composing;
Thread.Sleep(2000);
instantMessagingFlow.BeginSendInstantMessage("Echo: " + e.TextBody, SendMessageCompleted,instantMessagingFlow);
}
}
private void CallEstablishCompleted(IAsyncResult result)
{
InstantMessagingCall instantMessagingCall = result.AsyncState as InstantMessagingCall;
Exception ex = null;
try
{
instantMessagingCall.EndEstablish(result);
Console.WriteLine("The call is now in the established state.");
}
catch (OperationFailureException opFailEx)
{
ex = opFailEx;
}
catch (RealTimeException rte)
{
ex = rte;
}
finally
{
if (ex != null)
{
Console.WriteLine(ex.ToString());
Console.WriteLine("Shutting down platform due to error");
_helper.ShutdownPlatform();
}
}
}
private void SendMessageCompleted(IAsyncResult result)
{
InstantMessagingFlow instantMessagingFlow = result.AsyncState as InstantMessagingFlow;
Exception ex = null;
try
{
InstantMessagingFlow.EndSendInstantMessage(result);
Console.WriteLine("The message has been sent.");
}
catch (OperationTimeoutException opTimeEx)
{
ex = opTimeEx;
}
catch (RealTimeException rte)
{
ex = rte;
}
finally
{
instantMessagingFlow.LocalComposingState =
ComposingState.Idle;
if (ex != null)
{
Console.WriteLine(ex.ToString());
Console.WriteLine("Shutting down platform due to error");
_helper.ShutdownPlatform();
}
}
}
#endregion
}
}