hi when i am trying to create connection using singleton class my methods showing error. XMPPClient_OnStateChanged,txtUserName,pw everything showeing error.i cant fix pleese help me what happend. pls find my attached .rar
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WP8Xmpp.Resources;
using System.Net.XMPP;
using System.Threading;
namespace WP8Xmpp
{
public partial class MainPage : PhoneApplicationPage
{
/// <summary>
/// Username of the client
/// </summary>
public String UserName { get; set; }
/// <summary>
/// Password
/// </summary>
public String PassWord { get; set; }
private Boolean IsXmppSuccess { get; set; }
private readonly String Server = "taurus";
private readonly String ServerIPAddress = "127.0.0.1:9090";//127.0.0.1:9090/
/// <summary>
/// Xmpp Client
/// </summary>
/// <summary>
/// XMPP Connection
/// </summary>
public XMPPConnection ObjXmppCon { get; set; }
// Constructor
public MainPage()
{
InitializeComponent();
}
private static XMPPClient ObjXmppClient ;
public class singleton
{
private static singleton instance;
private static XMPPConnection ObjXmppCon;
public String UserName { get; set; }
public String PassWord { get; set; }
private Boolean IsXmppSuccess { get; set; }
private readonly String Server = "taurus";
private readonly String ServerIPAddress = "127.0.0.1:9090";//127.0.0.1:9090/
private singleton()
{
}
public static singleton GetInstance()
{
if (instance== null)
{
instance = new singleton();
}
return instance;
}
public void IsXmppValid(string UserName,string PassWord )
{
ObjXmppClient = new XMPPClient();
ObjXmppClient.JID = UserName + "@" + Server;
ObjXmppClient.Password = PassWord;
ObjXmppClient.Server = ServerIPAddress; //user server for emulator and ip address for device.
ObjXmppClient.AutoReconnect = true;
ObjXmppClient.RetrieveRoster = true;
ObjXmppClient.PresenceStatus = new PresenceStatus() { PresenceType = PresenceType.available, IsOnline = true };
ObjXmppClient.AutoAcceptPresenceSubscribe = true;
ObjXmppClient.AttemptReconnectOnBadPing = true;
ObjXmppCon = new XMPPConnection(ObjXmppClient);
ObjXmppCon.Connect();
ObjXmppClient.Connect();
//initializing the xmpp connection
ObjXmppCon.OnAsyncConnectFinished += ObjXmppCon_OnAsyncConnectFinished;
ObjXmppClient.OnStateChanged += new EventHandler(XMPPClient_OnStateChanged);
Thread.Sleep(2000);
}
void ObjXmppCon_OnAsyncConnectFinished(xmedianet.socketserver.SocketClient client, bool bSuccess, string strErrors)
{
IsXmppSuccess = client.Connected;
}
public static void XMPPClient_OnStateChanged(object sender, EventArgs e)//error
{
switch (ObjXmppClient.XMPPState)
{
case XMPPState.Ready:
if (IsXmppSucces)
{
this.Dispatcher.BeginInvoke(() =>
{
//CloseOverLay();
//MessageBox.Show("Successfully logged in");
NavigationService.Navigate((new Uri("/Output.xaml?key=success", UriKind.Relative)));
//return;
});
}
else
{
this.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Check server name/IpAddress");
//NavigationService.Navigate((new Uri("/Output.xaml?key=failed", UriKind.Relative)));,knhjslkil
return;
});
}
break;
case XMPPState.AuthenticationFailed: this.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Enter valid username and password");
//NavigationService.Navigate((new Uri("/Output.xaml?key=wrong", UriKind.Relative)));
return;
}); break;
}
}
private void btnLogin_Click(object sender, RoutedEventArgs e)//error
{
if (txtUserName.Text.Trim() == string.Empty)
{
MessageBox.Show("Enter Username");
return;
}
if (txtPassword.Password.Trim() == string.Empty)
{
MessageBox.Show("Enter Password");
return;
}
UserName = txtUserName.Text.Trim();//error
PassWord = txtPassword.Password.Trim();
IsXmppValid();
}
}
}
}