如何让所有用户从Office Communicator到asp.net网页?

时间:2013-12-24 03:26:57

标签: c# javascript jquery asp.net office-communicator

我正面临一个严重的问题。我想在HTML表中显示所有用户及其状态。是否可以使用javascript?

我已经浏览了下面的链接,它只显示一个用户,并且它的状态和用户邮件ID是硬编码的。

Integrate Microsoft Office Communicator 2007 in ASP.NET Page

的Javascript

<script type="Javascript">

     var sipUri = "your.contact@your.domain.com";

     var nameCtrl = new ActiveXObject('Name.NameCtrl.1');
     if (nameCtrl.PresenceEnabled)
     {
        nameCtrl.OnStatusChange = onStatusChange;
        nameCtrl.GetStatus(sipUri, "1");
     }


     function onStatusChange(name, status, id)
     {
        // This function is fired when the contacts presence status changes.
        // In a real world solution, you would want to update an image to reflect the users presence
           alert(name + ", " + status + ", " + id);
     }

     function ShowOOUI()
     {
           nameCtrl.ShowOOUI(sipUri, 0, 15, 15);
     }

     function HideOOUI()
     {
           nameCtrl.HideOOUI();
     }

 </script>

HTML

 <span onmouseover="ShowOOUI()" onmouseout="HideOOUI()" style="border-style:solid">Your Contact</span>
 <table id="tblContacts" runat="server">
    <tr>
       <td> email id </td>
       <td> status </td>
    </tr>
    <tr>
       <td> --- </td>
       <td> --- </td>
    </tr>
    <tr>
       <td> --- </td>
       <td> --- </td>
    </tr>
    <tr>
       <td> --- </td>
       <td> --- </td>
    </tr>
 </table>

此示例中显示的是单个用户,用户邮件ID定义为字符串(硬编码)。我想向所有用户展示。可以通过javascript吗?

任何解决方案/演示对我都非常有帮助。

感谢。

2 个答案:

答案 0 :(得分:1)

经过长时间的尝试,我能够根据自己的需要实现功能。 我在这里解释要遵循的步骤。

我使用“Communicator API”和“NameCtrl”来实现

1)请参阅此链接http://msdn.microsoft.com/en-us/library/bb787231%28v=office.12%29.aspx

为什么我要说明这一点,因为要使用Microsoft Office Communicator Automation API开发应用程序,必须满足以下要求:

  
    

您的开发计算机上安装了Microsoft Office Communicator 2007。

         

Microsoft Office Communicator 2007 SDK安装在开发计算机上。 SDK可从MSDN下载。

  

2)在服务器上安装Lync2010并登录。

3)从Web应用程序添加对CommunicatorAPI.dll和CommunicatorPrivate.dll的引用

我在这里使用的通讯器图片是我从“http://www.microsoft.com/en-us/download/details.aspx?id=10503”下载的。这是一个msi文件。下载并执行。在演示中,您可以复制这些图像并添加到您的应用程序

这是完整的解决方案。

HTML

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="MARSWebCommunicator._Default" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
    <section class="featured">
        <div class="content-wrapper">
        </div>
    </section>
    <script src="Scripts/jquery-latest.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var sipUri = "chandan.kumarpanda@yourdomain.com";
        var nameCtrl = new ActiveXObject('Name.NameCtrl.1');

        $(document).ready(function () {
            sipUri = $("#<%=HiddenField1.ClientID %>").val();
            if (sipUri != "") {
                if (nameCtrl.PresenceEnabled) {
                    nameCtrl.OnStatusChange = onStatusChange;
                    nameCtrl.GetStatus(sipUri, "1");
                }
            }
        });

        function onStatusChange(name, status, id) {
            // This function is fired when the contacts presence status changes.
            // In a real world solution, you would want to update an image to reflect the users presence
            //alert(name + ", " + status + ", " + id);
        }

        function ShowOOUI() {
            nameCtrl.ShowOOUI(sipUri, 0, 15, 15);
        }

        function HideOOUI() {
            nameCtrl.HideOOUI();
        }

    </script>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    <div>
        <asp:HiddenField ID="HiddenField1" runat="server" />
    </div>
    <div id="dvContactdetails">
        <table border="1">
            <tr>
                <td>Email Id</td>
                <td>Name</td>
                <td>Status</td>
            </tr>
            <tr>
                <td>
                    <asp:DropDownList ID="drpEmails" AutoPostBack="true" runat="server" OnSelectedIndexChanged="drpEmails_SelectedIndexChanged"></asp:DropDownList></td>
                <td>
                    <asp:Image ID="Image1" onmouseover="ShowOOUI()" onmouseout="HideOOUI()" ImageUrl="presence_images/presence_16-unknown.bmp" runat="server" />
                    <asp:Label ID="lblName" runat="server" Text="Contact Name"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblStatus" runat="server" Text="Contact Status"></asp:Label></td>
            </tr>
        </table>
    </div>   
</asp:Content>

代码隐藏

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunicatorAPI;

namespace MARSWebCommunicator
{
    public partial class _Default : Page
    {
        CommunicatorAPI.Messenger communicator = null;
        List<CustomContacts> lstContactDetails;


        protected void Page_Load(object sender, EventArgs e)
        {
            lstContactDetails = new List<CustomContacts>();
            communicator = new CommunicatorAPI.Messenger();
            string mymailid = "Chandan.kumarpanda@yourdomain.com";

            var contact = GetContact(mymailid);
            int s = (int) contact.Status;
            lblStatus.Text = GetStatus(s);

            if (!Page.IsPostBack)
            {
                drpEmails.Items.Add(mymailid);
                lblName.Text = contact.SigninName.ToString();
                HiddenField1.Value = contact.SigninName.ToString();

                lstContactDetails = GetAllEmailsWithFiendlyName();
                foreach (CustomContacts aContact in lstContactDetails)
                {
                    drpEmails.Items.Add(aContact.ContactEmailId);
                }
            }
        }

        protected void drpEmails_SelectedIndexChanged(object sender, EventArgs e)
        {
            string currentmailid = drpEmails.SelectedItem.Text;
            var contact = GetContact(currentmailid);
            lblName.Text = contact.FriendlyName.ToString();
            int s = (int)contact.Status;
            lblStatus.Text = GetStatus(s);

            if (HiddenField1.Value != "")
            {
                HiddenField1.Value = "";
                HiddenField1.Value = contact.SigninName.ToString();
            }
        }

        protected string GetStatus(int s)
        {
            string status = string.Empty;
            string src = string.Empty;
            int tempstatusno = s;
            switch (s)
            {
                case 0 :
                    status = "UNKNOWN";
                    src = "presence_images/presence_16-unknown.bmp";
                    break;
                case 1:
                    status = "OFFLINE";
                    src = "presence_images/presence_16-off.bmp";
                    break;
                case 2:
                    status = "ONLINE";
                    src = "presence_images/presence_16-online.bmp";
                    break;
                case 6:
                    status = "INVISIBLE";
                    src = "presence_images/presence_16-unknown.bmp";
                    break;
                case 10:
                    status = "BUSY";
                    src = "presence_images/presence_16-busy.bmp";
                    break;
                case 14:
                    status = "BE_RIGHT_BACK";
                    src = "presence_images/presence_16-idle-busy.bmp";
                    break;
                case 18:
                    status = "IDLE";
                    src = "presence_images/presence_16-idle-online.bmp";
                    break;
                case 34:
                    status = "AWAY";
                    src = "presence_images/presence_16-away.bmp";
                    break;
                case 50:
                    status = "ON_THE_PHONE";
                    break;
                case 66:
                    status = "OUT_TO_LUNCH";
                    break;
                case 82:
                    status = "IN_A_MEETING";
                    break;
                case 98:
                    status = "OUT_OF_OFFICE";
                    break;
                case 114:
                    status = "DO_NOT_DISTURB";
                    src = "presence_images/presence_16-dnd.bmp";
                    break;
                case 130:
                    status = "IN_A_CONFERENCE";
                    break;
                case 146:
                    status = "ALLOW_URGENT_INTERRUPTIONS";
                    break;
                case 162:
                    status = "MAY_BE_AVAILABLE";
                    break;
                case 178:
                    status = "CUSTOM";
                    break;
                default:
                    status = "OFFLINE";
                    src = "presence_images/presence_16-unknown.bmp";
                    Image1.ImageUrl = src;
                    break;
            }
            Image1.ImageUrl = src;
            return status;
        }

        public IMessengerContact GetContact(string signinName)
        {
            return communicator.GetContact(signinName, communicator.MyServiceId) as IMessengerContact;
        }

        public List<CustomContacts> GetAllEmailsWithFiendlyName()
        {
            List<CustomContacts> lstContacts = new List<CustomContacts>();

            IMessengerContacts messengerContacts = (IMessengerContacts)communicator.MyContacts;
            foreach (IMessengerContact acontact in messengerContacts)
            {
                CustomContacts aContact = new CustomContacts();
                aContact.ContactName = acontact.FriendlyName.ToString();
                aContact.ContactEmailId = acontact.SigninName.ToString();

                lstContacts.Add(aContact);
            }
            return lstContacts;
        }

    }

    public class CustomContacts
    {
        public string ContactEmailId { get; set; }
        public string ContactName { get; set; }
        public string ContactStatus { get; set; }
    }
}

答案 1 :(得分:0)

您希望为通信器构建基于Web的基本前端。来自Peter的链接将有助于显示状态信息,但仅适用于您正在浏览的SharePoint页面内容中的人员列表。

为了显示Communicator联系人列表中定义的在线联系人,以及能够向他们发送消息,您需要编写大量客户端脚本,该脚本连接到本地运行的实例通讯。

开始寻找的最佳位置是Office Communicator 2007 SDK

http://www.microsoft.com/downloads/details.aspx?FamilyID=ed1cce45-cc22-46e1-bd50-660fe6d2c98c&displaylang=en

如果您在“office communicator apis”上进行网络搜索,您将获得大量可能有用的链接。

统一通信论坛也可以提供帮助

http://social.msdn.microsoft.com/Forums/en-US/category/uc