Agusto Xaverius P Sipahutar

Job:Making some bugs and patch
Moss/Wss,C#,Sql Server,WWF,K2.BlackPearl
Motto : Keep Study and study
See also: Other Geeks@INDC

News




MCP Logo
MCTS Logo

MCP ID# 3542391

My Curiculum Vitae


Agusto Xaverius P S's Facebook profile

Other Article

My Community

My Article/Share Knowledge

Others Moss/Wss Site

My Other Website/Blogs

My Share (Ebook,etc)

Programming OCS R2 : Getting Presence Status

Ini adalah source code untuk mendapatkan Presence Status di Microsoft OCS R2

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Linq;
   4: using System.Web;
   5: using System.Web.UI;
   6: using System.Web.UI.WebControls;
   7: using Microsoft.Rtc.Collaboration;
   8: using Microsoft.Rtc.Collaboration.Presence;
   9: using Microsoft.Rtc.Signaling;
  10: using System.IO;
  11: using System.Xml;
  12: using Microsoft.Rtc.Collaboration.ContactsGroups;
  13: using System.Text;
  14:  
  15: namespace OCSWeb
  16: {
  17:     public class GetPresenceUser
  18:     {
  19:         #region private members
  20:  
  21:         // These numbers and xml constructs are explained in the UCMA .chm, and the OCS Redline documentation. it is beyond the scope of this sample to reexplain this here.
  22:         private static String _userStateXml = "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" manual=\"true\" xsi:type=\"userState\"><availability>{0}</availability></state>";
  23:         private static String _machineStateXml = "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" manual=\"false\" xsi:type=\"machineState\"><availability>{0}</availability></state>";
  24:  
  25:         //Construct the network credential that the UserEndpoint will use to authenticate to the Office Communications Server instance.
  26:         // User name and password pair of a user enabled for Office Communications Server. 
  27:         private static String _userName = "agusto.xaverius";     // User name and password pair of a user enabled for Office Communications Server. 
  28:         private static String _userPassword = "1234567";
  29:  
  30:         private static String _userDomain = "constoso";    // Domain that this user is logging into. Note: This is the AD domain, not the portion of the SIP URI following the at sign.
  31:         private static System.Net.NetworkCredential _credential = new System.Net.NetworkCredential(_userName, _userPassword, _userDomain);
  32:  
  33:         //The URI and connection server of the user used.
  34:         private static String _userURI = "sip:agusto.xaverius@contoso.com";  // This should be the URI of the user given above.
  35:         private static String _userServer = "ocs.contoso.com";  // The Office Communications Server that the user listed will log in to..
  36:  
  37:         // Transport type used to communicate with your OCS (Office Communications Server) instance.
  38:         private static SipTransportType _transportType = SipTransportType.Tcp;
  39:  
  40:  
  41:         // Other UCMA objects, for global placeholding.
  42:         CollaborationPlatform _collabPlatform;
  43:         UserEndpoint _userEndpoint;
  44:         ContactGroupServices _cgServices;
  45:         LocalOwnerPresence _localOwnerPresence;
  46:         CustomPresenceCategory _userState;
  47:         CustomPresenceCategory _machineState;
  48:         RemotePresence _remotePresence;
  49:         #endregion
  50:  
  51:         private string _ErrorMesaage;
  52:         public string ErrorMesaage
  53:         {
  54:             get { return _ErrorMesaage; }
  55:             set { _ErrorMesaage = value; }
  56:         }
  57:  
  58:         public GetPresenceUser()
  59:         {
  60:             
  61:         }
  62:  
  63:         public void GetPresence(string sip)
  64:         {
  65:             ClientPlatformSettings clientPlatformSettings = new ClientPlatformSettings("GetPresence", _transportType);
  66:             clientPlatformSettings.DefaultAudioVideoProviderEnabled = false;
  67:             _collabPlatform = new CollaborationPlatform(clientPlatformSettings);
  68:             _collabPlatform.BeginStartup(PlatformStartupCompleted, null);
  69:  
  70:         }
  71:  
  72:         private void PlatformStartupCompleted(IAsyncResult result)
  73:         {
  74:             try
  75:             {
  76:                 _collabPlatform.EndStartup(result);
  77:                 InitalizeRegisteredUserEndpoint(_userURI, _userServer, _credential);
  78:             }
  79:             catch (ConnectionFailureException connFailEx)
  80:             {
  81:                 ErrorMesaage = connFailEx.Message + "," + connFailEx.StackTrace;
  82:             }
  83:             catch (InvalidOperationException ioe)
  84:             {
  85:                 ErrorMesaage = ioe.Message + "," + ioe.StackTrace;
  86:             }
  87:         }
  88:  
  89:         private void InitalizeRegisteredUserEndpoint(String userURI, String userServer, System.Net.NetworkCredential credential)
  90:         {
  91:             UserEndpointSettings userEndpointSettings = new UserEndpointSettings(userURI, userServer, 6060);
  92:             userEndpointSettings.Credential = credential;
  93:             _userEndpoint = new UserEndpoint(_collabPlatform, userEndpointSettings);
  94:             _userEndpoint.BeginEstablish(EndpointEstablishCompleted, null);
  95:         }
  96:  
  97:         private void EndpointEstablishCompleted(IAsyncResult result)
  98:         {
  99:             try
 100:             {
 101:                 _userEndpoint.EndEstablish(result);
 102:                 
 103:                 RemotePresence _remotePresence = _userEndpoint.RemotePresence;
 104:                 _remotePresence.PresenceNotificationReceived += new EventHandler<RemotePresenceNotificationEventArgs>(remotePresence_PresenceNotificationReceived);
 105:  
 106:                 RemotePresentitySubscriptionTarget _target1 = new RemotePresentitySubscriptionTarget(_userURI, String.Empty);
 107:                 List<string> _targetList = new List<string>();
 108:                 _targetList.Add(_userURI);
 109:                 
 110:                 string[] _cats = { "state", "contactCard" };
 111:                 _remotePresence.EndPresenceQuery(_remotePresence.BeginPresenceQuery(_targetList, _cats, remotePresence_PresenceNotificationReceived, null, null));
 112:                 
 113:             }
 114:             catch (ConnectionFailureException connFailEx)
 115:             {
 116:                 ErrorMesaage = connFailEx.Message + "," + connFailEx.StackTrace;
 117:             }
 118:             catch (InvalidOperationException iOpEx)
 119:             {
 120:                 ErrorMesaage = iOpEx.Message + "," + iOpEx.StackTrace;
 121:             }
 122:             catch (RegisterException regEx)
 123:             {
 124:                 ErrorMesaage = regEx.Message + "," + regEx.StackTrace;
 125:             }
 126:             catch (AuthenticationException ae)
 127:             {
 128:                 ErrorMesaage = ae.Message + "," + ae.StackTrace;
 129:             }
 130:             catch (OperationTimeoutException ate)
 131:             {
 132:                 ErrorMesaage = ate.Message + "," + ate.StackTrace;
 133:             }
 134:         }
 135:  
 136:         void remotePresence_PresenceNotificationReceived(object sender, RemotePresenceNotificationEventArgs e)
 137:         {
 138:             foreach (RemotePresentityNotificationData notification in e.Notifications)
 139:             {
 140:                 string targetUri = notification.Uri; 
 141:                 foreach (PresenceCategoryWithMetaData category in notification.Categories)
 142:                 {
 143:                     switch (category.Category.CategoryName)
 144:                     {
 145:                         case "state":
 146:                             ErrorMesaage = category.Category.GetCategoryDataXml(); //-> validasi xml ini dan dapatkan data visiblity
 147:                             break;
 148:                         default:
 149:                             break;
 150:                     }
 151:                 }
 152:             }
 153:         }
 154:     }
 155: }
Share this post: | | | |
Posted: Jan 26 2010, 02:20 PM by agusto | with 1 comment(s)
Filed under:

Comments

RossLloyd said:

Hi Agusto

I've been battling a while now trying to show OCS Presence in a webpage. I've had a look at your code above, is there anyway you could perhaps send me a basic solution implementing this class, so I can have a better understanding.

It will be greatly appreciated if you can help me.

Regards

Ross Lloyd

email is RSL@Frameworkone.co.za

# March 1, 2010 5:42 PM