Sign in to follow this  
Stefano Pranzo

read the status of the user

Recommended Posts

Good evening.
I'm using SDK Ver. 9
Dev = + C # WPF
How can I read the status of the user?
OnLine, Forwarding, Forwarding, Forwarding: Voicemail, etc ...
example:
user Stefano
OnLine = off
Forwarding = true
ForwardingTowards = 104

thank you.

Share this post


Link to post
Share on other sites

Hi Stefano,

 

try following C# code.. possible there are better ways to receive the status, not sure.

public class UserInfo
{
	public string name { get; set; }
	public int id { get; set; }
	public short statusInt { get; set; }
	public string status { get; set; }
	public bool bForwardDefault { get; set; }
	public string forwardDefaultNum { get; set; }
	public bool bForwardOnbusy { get; set; }
	public string forwardOnbusyNum { get; set; }
	public bool bForwardOnnoanswer { get; set; }
	public string forwardOnnoanswerNum { get; set; }
	public int forwardOnnoanswerTime { get; set; }
}

public JsonResult JsonUserinfo(string username)
{
	// UserInfo Model
	var mUserInfo = new UserInfo();
	mUserInfo.name = username;

	// Get LibManager
	var libManagerIntern = new SWConfigDataClientLib.LibManager()
	{
		BaseProtocol = SWConfigDataClientLib.SProxyObject.BaseProtocol.TCP,
		WSBaseUrl = "localhost",
		AuthenticationMode = SWConfigDataClientLib.SProxyObject.AuthenticationMode.Trusted // Trusted User needs to be Swyx-Sysadmin
	};

	// Get UserId
	var userEnum = libManagerIntern.GetUserEnum();
	userEnum.ExecuteNameFilter(mUserInfo.name, new SWConfigDataClientLib.Data.OrderByList());
	var userResult = userEnum.PrimaryCollection.CreateSortableFilterCollection().FirstOrDefault();
	mUserInfo.id = userResult.UserID;

	// Get UserStatus i.e. by Phonebook
	var pbEnum = libManagerIntern.GetUserPhoneBookEnum();
	var pbEx = pbEnum.GetPBXPhoneBookEx(mUserInfo.name, true, false, true, true).CreateSortableFilterCollection().FirstOrDefault();
	mUserInfo.statusInt = pbEx.UserStatus;
	// 0 = loggedoff
	// 1 = available
	// 2 = busy
	// 4 = away
	// 5 = dnd
	switch (mUserInfo.statusInt)
	{
		case 0:
				mUserInfo.status = "loggedoff";
				break;
		case 1:
				mUserInfo.status = "available";
				break;
		case 2:
				mUserInfo.status = "busy";
				break;
		case 4:
				mUserInfo.status = "away";
				break;
		case 5:
				mUserInfo.status = "dnd";
				break;
		default:
				mUserInfo.status = "unknown";
				break;
	}

	// Get Forwarding Info
	mUserInfo.bForwardDefault = false;
	if (userResult.DefaultFwd == 1)
	{
		mUserInfo.bForwardDefault = true;
	}
	mUserInfo.forwardDefaultNum = userResult.DefaultFwdNum;

	mUserInfo.bForwardOnbusy = false;
	if (userResult.FwdOnBusy == 1)
	{
		mUserInfo.bForwardOnbusy = true;
	}
	mUserInfo.forwardOnbusyNum = userResult.FwdOnBusyNumber;

	mUserInfo.bForwardOnnoanswer = false;
	if (userResult.FwdOnNoAnswer == 1)
	{
		mUserInfo.bForwardOnnoanswer = true;
	}
	mUserInfo.forwardOnnoanswerNum = userResult.FwdOnNoAnswerNumber;
	mUserInfo.forwardOnnoanswerTime = userResult.FwdOnNoAnswerTimeout;

	// Freeing
	userEnum.FreeForReuse();
	pbEnum.FreeForReuse();

	// Return
	return Json(mUserInfo, JsonRequestBehavior.AllowGet);
}

Good luck!

Share this post


Link to post
Share on other sites
On 4.11.2016 at 10:26 AM, ogoettlich said:

Hi Stefano,

 

try following C# code.. possible there are better ways to receive the status, not sure.


public class UserInfo
{
	public string name { get; set; }
	public int id { get; set; }
	public short statusInt { get; set; }
	public string status { get; set; }
	public bool bForwardDefault { get; set; }
	public string forwardDefaultNum { get; set; }
	public bool bForwardOnbusy { get; set; }
	public string forwardOnbusyNum { get; set; }
	public bool bForwardOnnoanswer { get; set; }
	public string forwardOnnoanswerNum { get; set; }
	public int forwardOnnoanswerTime { get; set; }
}

public JsonResult JsonUserinfo(string username)
{
	// UserInfo Model
	var mUserInfo = new UserInfo();
	mUserInfo.name = username;

	// Get LibManager
	var libManagerIntern = new SWConfigDataClientLib.LibManager()
	{
		BaseProtocol = SWConfigDataClientLib.SProxyObject.BaseProtocol.TCP,
		WSBaseUrl = "localhost",
		AuthenticationMode = SWConfigDataClientLib.SProxyObject.AuthenticationMode.Trusted // Trusted User needs to be Swyx-Sysadmin
	};

	// Get UserId
	var userEnum = libManagerIntern.GetUserEnum();
	userEnum.ExecuteNameFilter(mUserInfo.name, new SWConfigDataClientLib.Data.OrderByList());
	var userResult = userEnum.PrimaryCollection.CreateSortableFilterCollection().FirstOrDefault();
	mUserInfo.id = userResult.UserID;

	// Get UserStatus i.e. by Phonebook
	var pbEnum = libManagerIntern.GetUserPhoneBookEnum();
	var pbEx = pbEnum.GetPBXPhoneBookEx(mUserInfo.name, true, false, true, true).CreateSortableFilterCollection().FirstOrDefault();
	mUserInfo.statusInt = pbEx.UserStatus;
	// 0 = loggedoff
	// 1 = available
	// 2 = busy
	// 4 = away
	// 5 = dnd
	switch (mUserInfo.statusInt)
	{
		case 0:
				mUserInfo.status = "loggedoff";
				break;
		case 1:
				mUserInfo.status = "available";
				break;
		case 2:
				mUserInfo.status = "busy";
				break;
		case 4:
				mUserInfo.status = "away";
				break;
		case 5:
				mUserInfo.status = "dnd";
				break;
		default:
				mUserInfo.status = "unknown";
				break;
	}

	// Get Forwarding Info
	mUserInfo.bForwardDefault = false;
	if (userResult.DefaultFwd == 1)
	{
		mUserInfo.bForwardDefault = true;
	}
	mUserInfo.forwardDefaultNum = userResult.DefaultFwdNum;

	mUserInfo.bForwardOnbusy = false;
	if (userResult.FwdOnBusy == 1)
	{
		mUserInfo.bForwardOnbusy = true;
	}
	mUserInfo.forwardOnbusyNum = userResult.FwdOnBusyNumber;

	mUserInfo.bForwardOnnoanswer = false;
	if (userResult.FwdOnNoAnswer == 1)
	{
		mUserInfo.bForwardOnnoanswer = true;
	}
	mUserInfo.forwardOnnoanswerNum = userResult.FwdOnNoAnswerNumber;
	mUserInfo.forwardOnnoanswerTime = userResult.FwdOnNoAnswerTimeout;

	// Freeing
	userEnum.FreeForReuse();
	pbEnum.FreeForReuse();

	// Return
	return Json(mUserInfo, JsonRequestBehavior.AllowGet);
}

Good luck!

Where can i find SWConfigDataClientLib?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this