gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 04:37:10 25 4
gpt4 key购买 nike

我面临着一个严重的问题。我想在 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 实现?

任何解决方案/演示都会对我有很大帮助。

谢谢。

最佳答案

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

我使用“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 is installed on your development machine.

Microsoft Office Communicator 2007 SDK is installed on the development machine. The SDK is available for download from 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; }
}
}

关于c# - 如何让所有用户从 Office Communicator 转到 asp.net 网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20754448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com