如何使用c#和eStreamchat在聊天应用程序中获取桌面通知?

时间:2015-01-20 09:02:25

标签: c#

我是C#和.net编程的新手。其实我正在使用eStreamchat应用程序进行聊天。它的工作正常。但我需要在聊天应用程序中进行一些更改,如果用户在聊天应用程序中获取任何消息但是我无法在eStreamchat应用程序中更改它,则应该提供桌面通知。我有一个编码在Windows窗体应用程序中获取通知,但我如何将其与eStreamchat集成。 eStreamchat是一个Web应用程序。请任何人可以帮助我...请告诉我如何将此代码与上面的eStream聊天网络应用程序集成我告诉我生成通知我的代码是这样的有三种形式,如form1.cs,notification.cs和TransDialog的.cs。编码如下:

public class TransDialog : System.Windows.Forms.Form   
{
    #region Constructor
    public TransDialog()
    {
        InitializeComponents();
    }
    public TransDialog(bool disposeAtEnd)
    {
        m_bDisposeAtEnd = disposeAtEnd;
        InitializeComponents();
    }
    void InitializeComponents()
    {
        this.components = new System.ComponentModel.Container();
        this.m_clock =  new Timer(this.components);
        this.m_clock.Interval = 100;
        this.SuspendLayout();
        //m_clock
        this.m_clock.Tick += new EventHandler(Animate);
        //TransDialog
        this.Load += new EventHandler(TransDialog_Load);
        this.Closing += new CancelEventHandler(TransDialog_Closing);
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    #endregion

    #region Event handlers
    private void TransDialog_Load(object sender, EventArgs e)
    {
        this.Opacity = 0.0;
        m_bShowing = true;

        m_clock.Start();
    }

    private void TransDialog_Closing(object sender, CancelEventArgs e)
    {
        if (!m_bForceClose)
        {
            m_origDialogResult = this.DialogResult;
            e.Cancel = true;
            m_bShowing = false;
            m_clock.Start();
        }
        else
        {
            this.DialogResult = m_origDialogResult;
        }
    }

    #endregion

    #region Private methods
    private void Animate(object sender, EventArgs e)
    {
        if (m_bShowing)
        {
            if (this.Opacity < 1)
            {
                this.Opacity += 0.1;
            }
            else
            {
                m_clock.Stop();
            }
        }
        else
        {
            if (this.Opacity > 0)
            {
                this.Opacity -= 0.1;
            }
            else
            {
                m_clock.Stop();
                m_bForceClose = true;
                this.Close();
                if (m_bDisposeAtEnd)
                    this.Dispose();
            }
        }
    }

    #endregion

    #region overrides
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    #endregion

    #region private variables
    private System.ComponentModel.IContainer components = null;
    private Timer m_clock;
    private bool m_bShowing = true;
    private bool m_bForceClose = false;
    private DialogResult m_origDialogResult;
    private bool m_bDisposeAtEnd = false;
    #endregion // private variables

    private void InitializeComponent()
    {
        this.SuspendLayout();
        // 
        // TransDialog
        // 
        this.ClientSize = new System.Drawing.Size(284, 262);
        this.Name = "TransDialog";
        this.Load += new System.EventHandler(this.TransDialog_Load_1);
        this.ResumeLayout(false);

    } 

notification.cs

public class Notification : TransDialog
{
    #region Ctor, init code and dispose
    public Notification()
        : base(true)
    {
        InitializeComponent();
    }

    protected override void Dispose( bool disposing )
    {
        if( disposing )
        {
            if(components != null)
            {
                components.Dispose();
            }
        }
        base.Dispose( disposing );
    }
    #endregion // Ctor and init code

    #region Event handler
    private void Notification_Load(object sender, System.EventArgs e)
    {
        int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
        int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
        this.Left = screenWidth - this.Width;
        this.Top = screenHeight - this.Height;

        timer1.Enabled = true;

        string link = "http://www.geocities.com/basuabhinaba";
        linkLabel1.Links.Add(0, link.Length, link);
    }

    private void timer1_Tick(object sender, System.EventArgs e)
    {
        this.Close();
    }

    private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
    {
        string link = e.Link.LinkData.ToString();
        if (link != null && link.Length > 0)
            System.Diagnostics.Process.Start(link);
    }
    #endregion // Event handler

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Notification));
        this.label1 = new System.Windows.Forms.Label();
        this.pictureBox1 = new System.Windows.Forms.PictureBox();
        this.timer1 = new System.Windows.Forms.Timer(this.components);
        this.linkLabel1 = new System.Windows.Forms.LinkLabel();
        this.SuspendLayout();
        // 
        // label1
        // 
        this.label1.Location = new System.Drawing.Point(112, 48);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(96, 16);
        this.label1.TabIndex = 0;
        this.label1.Text = "You\'ve got email";
        // 
        // pictureBox1
        // 
        this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
        this.pictureBox1.Location = new System.Drawing.Point(8, 8);
        this.pictureBox1.Name = "pictureBox1";
        this.pictureBox1.Size = new System.Drawing.Size(88, 72);
        this.pictureBox1.TabIndex = 1;
        this.pictureBox1.TabStop = false;
        // 
        // timer1
        // 
        this.timer1.Interval = 3000;
        this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
        // 
        // linkLabel1
        // 
        this.linkLabel1.Location = new System.Drawing.Point(112, 24);
        this.linkLabel1.Name = "linkLabel1";
        this.linkLabel1.Size = new System.Drawing.Size(104, 16);
        this.linkLabel1.TabIndex = 2;
        this.linkLabel1.TabStop = true;
        this.linkLabel1.Text = "Check the web site";
        this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
        // 
        // Notification
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.BackColor = System.Drawing.Color.White;
        this.ClientSize = new System.Drawing.Size(234, 88);
        this.Controls.Add(this.linkLabel1);
        this.Controls.Add(this.pictureBox1);
        this.Controls.Add(this.label1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
        this.Name = "Notification";
        this.Text = "Notification";
        this.TopMost = true;
        this.Load += new System.EventHandler(this.Notification_Load);
        this.ResumeLayout(false);

    }
    #endregion

    #region Designer generated variables
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.PictureBox pictureBox1;
    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.LinkLabel linkLabel1;
    private System.ComponentModel.IContainer components;
    #endregion
}

Form1.cs的

public class Form1 : TransDialog
{
    private System.Windows.Forms.Button button1;
    private System.ComponentModel.Container components = null;

    #region Ctor init and dispose code
    public Form1()
        : base (true)
    {
        InitializeComponent();
    }

    protected override void Dispose( bool disposing )
    {
        if( disposing )
        {
            if (components != null) 
            {
                components.Dispose();
            }
        }
        base.Dispose( disposing );
    }
    #endregion

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.button1 = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(88, 32);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(112, 24);
        this.button1.TabIndex = 0;
        this.button1.Text = "Show Notification";
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // Form1
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(320, 102);
        this.Controls.Add(this.button1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.ResumeLayout(false);

    }
    #endregion

    #region Event handler
    private void button1_Click(object sender, System.EventArgs e)
    {
        Notification notifForm = new Notification();
        notifForm.Show();
    }
    #endregion

    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }
}

4 个答案:

答案 0 :(得分:0)

如果我理解正确,您需要在Web应用程序和桌面应用程序之间建立一些通信渠道。 AFAIK没有直接的方式将消息从Web发送到桌面,因此您需要一些中间层。我建议你使用以下方案:
答:
1. WEB向db写入一些标记+消息
2.桌面每秒检查是否有一些标记,如果发现它读取消息 b(实际上是a的变化):
1. Web向xml写入一些标记+消息
2.桌面在搜索标记时读取xml,如果找到读取消息 C:
1.在C#中创建TCP侦听器,它是TcpListener
2.添加TcpClient
3.组织他们之间的沟通。其中一个有用的例子是:http://www.codeproject.com/Articles/20972/Notification-Client-and-Server-Written-in-C
d:非常可靠的方法是RabbitMQ http://www.rabbitmq.com具有相当好的性能

答案 1 :(得分:0)

让我试试。我想你是在谈论http://www.estreamchat.com。在那里它提到它的源代码可以下载https://github.com/eStream/eStreamChat。下载源代码后,我发现了以下内容:project eStreamChat。在项目eStreamChat里面有一个ChatEngine.svc文件。这意味着您可以将其作为服务引用。您可以在部分参考文献中右键单击项目,然后选择添加服务参考enter image description here

来执行此操作

在那里你可以选择你当前的项目,或者如果你已经在某处部署了estreamchat,那么你可以从该区域中选择它。在ChangEngine.svc.cs里面有JoinChatRoom,LeaveChatRoom,GetEvents,SendMessage,SendCommand,BroadcastVideo,StopVideoBroadcast等方法。

在您参考服务后,您将能够使用estreamchat

添加加入表格

答案 2 :(得分:0)

请尝试以下更改:
1.解压缩到接口IChatEngine类ChatEngine。 ChatEngine.svc.cs应如下所示:

/* This file is part of eStreamChat.
 * 
 * eStreamChat is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version. 
 * 
 * eStreamChat is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with eStreamChat. If not, see <http://www.gnu.org/licenses/>.
 */
using System;
using System.Configuration;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text.RegularExpressions;
using System.Web;
using eStreamChat.Classes;
using eStreamChat.Interfaces;
using System.Net;
using System.Collections.Generic;
using Microsoft.Practices.Unity;

namespace eStreamChat
{
    [ServiceContract]
    public interface IChatEngine
    {
        [OperationContract]
        ChatEngine.JoinChatRoomResult JoinChatRoom(string chatRoomId, string href);

        [OperationContract]
        void LeaveChatRoom(string chatRoomId, string token, string messengerTargetUserId);

        [OperationContract]
        ChatEngine.EventsResult GetEvents(string chatRoomId, string token, long fromTimestamp, string messengerTargetUserId);

        [OperationContract]
        ChatEngine.SendMessageResult SendMessage(string chatRoomId, string token, string toUserId, string message, 
                                                      bool bold = false, bool italic = false, bool underline = false, string fontName = null, int? fontSize = null,
                                                      string color = null);

        [OperationContract]
        ChatEngine.SendMessageResult SendCommand(string chatRoomId, string token, string targetUserId, string command);

        [OperationContract]
        string BroadcastVideo(string prevGuid, string token, int chatRoomId, string targetUserId);

        [OperationContract]
        void StopVideoBroadcast(string token, int chatRoomId);

        void StopVideoBroadcast(string userId, string chatRoomId);
    }


    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ChatEngine : IChatEngine
    {
        private static IChatRoomProvider chatRoomProvider;
        private static IChatRoomStorage chatRoomStorage;
        private static IChatUserProvider chatUserProvider;
        private static IChatSettings chatSettingsProvider;
        private static IMessengerPresenceProvider messengerProvider;

        private static bool importsSatisfied = false;

        public ChatEngine()
        {
            if (!importsSatisfied)
            {
                lock (Global.CompositionLock)
                {
                    chatRoomProvider = Global.Container.Resolve<IChatRoomProvider>();
                    chatRoomStorage = Global.Container.Resolve<IChatRoomStorage>();
                    chatUserProvider = Global.Container.Resolve<IChatUserProvider>();
                    chatSettingsProvider = Global.Container.Resolve<IChatSettings>();
                    if (Global.Container.IsRegistered<IMessengerPresenceProvider>())
                        messengerProvider = Global.Container.Resolve<IMessengerPresenceProvider>();
                }
                importsSatisfied = true;
            }

            CleanTimedOutUsers.Initialize(chatUserProvider, chatRoomStorage);
        }


        public JoinChatRoomResult JoinChatRoom(string chatRoomId, string href)
        {
            if (href != null) HttpContext.Current.Items["href"] = href;

            var result = new JoinChatRoomResult
                             {
                                 FileTransferEnabled = chatSettingsProvider.EnableFileTransfer,
                                 VideoChatEnabled = chatSettingsProvider.EnableVideoChat,
                                 FlashMediaServer = chatSettingsProvider.FlashMediaServer
                             };

            User user;
            try
            {
                user = chatUserProvider.GetCurrentlyLoggedUser();
            }
            catch (System.Security.SecurityException err)
            {
                result.Error = err.Message;
                return result;
            }

            if (user == null)
            {
                string loginUrl = chatUserProvider.GetLoginUrl(href);
                result.Error = "You need to login in order to use the chat!";
                if (loginUrl != null)
                {
                    result.Error += " Redirecting to login page...";
                    result.RedirectUrl = loginUrl;
                }
                return result;
            }

            Room room = chatRoomProvider.GetChatRoom(chatRoomId);

            if (room == null)
            {
                result.Error = "The specified chat room does not exist!";
                return result;
            }

            #region Messenger
            var url = (new Uri(href));
            var queryKeyValues = HttpUtility.ParseQueryString(url.Query);
            var isInitiator = queryKeyValues["init"];
            var targetUserId = queryKeyValues["target"];
            bool alreadyConnected = href.IndexOf('#') == -1 ? false : (href.Substring(href.IndexOf('#')) == "#connected");
            #endregion

            string reason;

            //if messenger
            if (room.Id == "-2")
            {
                //check chat access only for the initiators
                if (isInitiator == "1" && !chatRoomProvider.HasChatAccess(user.Id, room.Id, out reason))
                {
                    if (String.IsNullOrEmpty(reason))
                        result.Error = "You don't have access to the messenger.";
                    else
                        result.Error = reason;

                    return result;
                }
            }
            else
            {
                if (!chatRoomProvider.HasChatAccess(user.Id, room.Id, out reason))
                {
                    if (String.IsNullOrEmpty(reason))
                        result.Error = String.Format("You don't have access to chat room '{0}'.", room.Name);
                    else
                        result.Error = reason;

                    return result;
                }
            }

            // Ignore max users limit for messengerRoom (roomId = -2)
            if (room.Id != "-2" && chatRoomStorage.GetUsersInRoom(room.Id).Length >= room.MaxUsers)
            {
                result.Error = String.Format("The chat room '{0}' is full. Please try again later.", room.Name);

                return result;
            }

            chatRoomStorage.AddUserToRoom(room.Id, user.Id);
            chatRoomStorage.AddMessage(room.Id, new Message
                                                    {
                                                        Content =
                                                            string.Format("User {0} has joined the chat.",
                                                                          user.DisplayName),
                                                        FromUserId = user.Id,
                                                        ToUserId = String.IsNullOrEmpty(targetUserId) ? null : targetUserId,
                                                        MessageType = MessageTypeEnum.UserJoined,
                                                        Timestamp = Miscellaneous.GetTimestamp()
                                                    });

            #region Messenger

            //delete all messages when starting messenger (not reloading it)
            if (isInitiator != null && !alreadyConnected)
            {
                chatRoomStorage.DeleteAllMessagesFor(room.Id, user.Id);
            }

            if (!alreadyConnected && isInitiator == "1" && !String.IsNullOrWhiteSpace(targetUserId))
            {
                try
                {
                    var targetUser = chatUserProvider.GetUser(targetUserId);

                    //Not sure that MessengerUrl should be constructed here?! timestamp and hash are tied to
                    //the implementation
                    var timestamp = DateTime.Now.ToFileTimeUtc();
                    var hash = Miscellaneous.CalculateChatAuthHash(targetUserId, user.Id, timestamp.ToString());

                    var request = new ChatRequest
                                      {
                                          FromThumbnailUrl = user.ThumbnailUrl,
                                          FromProfileUrl = user.ProfileUrl,
                                          FromUserId = user.Id,
                                          FromUsername = user.DisplayName,
                                          ToUserId = targetUserId,
                                          ToUsername = targetUser.DisplayName,
                                          MessengerUrl =
                                              String.Format("{0}?init=0&id={1}&target={2}&timestamp={3}&hash={4}",
                                                            url.GetLeftPart(UriPartial.Path), targetUserId, user.Id,
                                                            timestamp, hash)
                                      };

                    messengerProvider.AddChatRequest(request);
                }
                catch (System.Security.SecurityException) { }
            }
            #endregion

            result.ChatRoomName = room.Name;
            result.ChatRoomTopic = room.Topic;
            result.Users = chatRoomStorage.GetUsersInRoom(room.Id).Select(chatUserProvider.GetUser).ToArray();
            result.Token = chatRoomStorage.GenerateUserToken(user.Id);
            result.UserId = user.Id;
            result.IsAdmin = chatUserProvider.IsChatAdmin(user.Id, room.Id);

            StopVideoBroadcast(user.Id, room.Id);
            result.Broadcasts = chatRoomStorage.GetBroadcasts(room.Id, user.Id);

            return result;
        }


        public void LeaveChatRoom(string chatRoomId, string token, string messengerTargetUserId)
        {
            string userId = chatRoomStorage.GetUserIdByToken(token);
            if (userId == null) return;
            var user = chatUserProvider.GetUser(userId);

            Room room = chatRoomProvider.GetChatRoom(chatRoomId);
            if (room == null) return;

            //do not leave the room if messenger. The user will eventually time out when all the 
            // messenger windows are closed.
            if (chatRoomId != "-2")
                chatRoomStorage.RemoveUserFromRoom(room.Id, user.Id);

            chatRoomStorage.AddMessage(room.Id, new Message
                                                    {
                                                        Content =
                                                            string.Format("User {0} has left the chat.",
                                                                          user.DisplayName),
                                                        FromUserId = user.Id,
                                                        ToUserId = messengerTargetUserId,
                                                        MessageType = MessageTypeEnum.UserLeft,
                                                        Timestamp = Miscellaneous.GetTimestamp()
                                                    });

            StopVideoBroadcast(userId, room.Id);
        }


        public EventsResult GetEvents(string chatRoomId, string token, long fromTimestamp, string messengerTargetUserId)
        {
            var result = new EventsResult();
            string userId = chatRoomStorage.GetUserIdByToken(token);
            if (userId == null)
            {
                result.Error = "Chat disconnected!";
                return result;
            }

            chatRoomStorage.UpdateOnline(chatRoomId, userId);

            //get all the messages for the current user
            IEnumerable<Message> messages = chatRoomStorage.GetMessages(chatRoomId, userId, fromTimestamp);

            //if in messenger mode then filter messages to be only from the target user or from the current user himself
            if (messengerTargetUserId != null)
            {
                messages = messages.Where(m => m.FromUserId == userId || m.FromUserId == messengerTargetUserId);
            }

            //get only joined, left and kicked messages for ignored users
            result.Messages = messages.Where(m =>!chatUserProvider.IsUserIgnored(userId, m.FromUserId) ||
                                                m.MessageType == MessageTypeEnum.UserJoined ||
                                                m.MessageType == MessageTypeEnum.UserLeft ||
                                                m.MessageType == MessageTypeEnum.Kicked).ToArray();

            var joinMessages = messages.Where(m => m.MessageType == MessageTypeEnum.UserJoined);
            var leaveMessages = messages.Where(m => m.MessageType == MessageTypeEnum.UserLeft || m.MessageType == MessageTypeEnum.Kicked);

            var joinedUsers = joinMessages.Where(j => !leaveMessages.Any(l => l.FromUserId == j.FromUserId && l.Timestamp > j.Timestamp)).Select(
                                m => chatUserProvider.GetUser(m.FromUserId)).ToArray();
            var leftUsers = leaveMessages.Where(l => !joinMessages.Any(j => j.FromUserId == l.FromUserId && j.Timestamp > l.Timestamp)).Select(
                                m => chatUserProvider.GetUser(m.FromUserId)).ToArray();

            result.UsersJoined = joinedUsers;
            result.UsersLeft = leftUsers;

            if (ConfigurationManager.AppSettings["PollingInterval"] != null)
                result.CallInterval = Convert.ToInt32(ConfigurationManager.AppSettings["PollingInterval"]);

            return result;
        }


        public SendMessageResult SendMessage(string chatRoomId, string token, string toUserId, string message, 
            bool bold = false, bool italic = false, bool underline = false, string fontName = null, int? fontSize = null,
            string color = null)
        {
            var result = new SendMessageResult();
            string userId = chatRoomStorage.GetUserIdByToken(token);
            if (userId == null)
            {
                result.Error = "Chat disconnected!";
                return result;
            }

            if (!chatRoomStorage.IsUserInRoom(chatRoomId, userId))
            {
                result.Error = "Chat disconnected!";
                return result;
            }

            // TODO: Process message (trim, filter)
            if (!string.IsNullOrEmpty(color))
                color = Regex.Replace(color, @"[^\w\#]", String.Empty); // Strip dangerous input
            var formatOptions = new MessageFormatOptions
                                           {
                                               Bold = bold,
                                               Italic = italic,
                                               Underline = underline,
                                               Color = color,
                                               FontName = fontName,
                                           };
            if (fontSize.HasValue) formatOptions.FontSize = fontSize.Value;
            chatRoomStorage.AddMessage(chatRoomId, new Message
                                                       {
                                                           Content = WebUtility.HtmlEncode(message),
                                                           FromUserId = userId,
                                                           ToUserId = toUserId,
                                                           MessageType = MessageTypeEnum.User,
                                                           Timestamp = Miscellaneous.GetTimestamp(),
                                                           FormatOptions = formatOptions
                                                       });

            return result;
        }


        public SendMessageResult SendCommand(string chatRoomId, string token, string targetUserId, string command)
        {
            var result = new SendMessageResult();
            string userId = chatRoomStorage.GetUserIdByToken(token);
            if (userId == null)
            {
                result.Error = "Chat disconnected!";
                return result;
            }

            if (!chatRoomStorage.IsUserInRoom(chatRoomId, userId))
            {
                result.Error = "Chat disconnected!";
                return result;
            }

            var user = chatUserProvider.GetUser(userId);
            var targetUser = chatUserProvider.GetUser(targetUserId);

            if (command == "ignore")
            {
                chatUserProvider.IgnoreUser(userId, targetUserId);
            }
            else if (command == "kick")
            {
                if (chatUserProvider.IsChatAdmin(userId, chatRoomId) && chatRoomStorage.IsUserInRoom(chatRoomId, targetUserId))
                {
                    chatRoomStorage.RemoveUserFromRoom(chatRoomId, targetUserId);

                    chatRoomStorage.AddMessage(chatRoomId, new Message
                    {
                        Content =
                            string.Format("User {0} has been kicked off the room by {1}.",
                                          targetUser.DisplayName, user.DisplayName),
                        FromUserId = targetUserId,
                        MessageType = MessageTypeEnum.Kicked,
                        Timestamp = Miscellaneous.GetTimestamp()
                    });
                }
            }
            else if (command == "ban")
            {
                if (chatUserProvider.IsChatAdmin(userId, chatRoomId) && chatRoomStorage.IsUserInRoom(chatRoomId, targetUserId))
                {
                    chatRoomStorage.RemoveUserFromRoom(chatRoomId, targetUserId);

                    chatRoomStorage.AddMessage(chatRoomId, new Message
                    {
                        Content =
                            string.Format("User {0} has been kicked off the room by {1} (Banned).",
                                          targetUser.DisplayName, user.DisplayName),
                        FromUserId = targetUserId,
                        MessageType = MessageTypeEnum.Kicked,
                        Timestamp = Miscellaneous.GetTimestamp()
                    });

                    chatRoomProvider.BanUser(chatRoomId, userId, targetUserId);
                }
            }
            else if (command == "slap")
            {
                chatRoomStorage.AddMessage(chatRoomId, new Message
                {
                    Content =
                        string.Format("{0} slaps {1} around with a large trout.",
                                      user.DisplayName, targetUser.DisplayName),
                    FromUserId = userId,
                    MessageType = MessageTypeEnum.System,
                    Timestamp = Miscellaneous.GetTimestamp()
                });
            }

            return result;
        }


        public string BroadcastVideo(string prevGuid, string token, int chatRoomId, string targetUserId)
        {
            if (!chatSettingsProvider.EnableVideoChat) return null;

            string userId = chatRoomStorage.GetUserIdByToken(token);
            string guid = prevGuid ?? Guid.NewGuid().ToString();

            chatRoomStorage.AddMessage(chatRoomId.ToString(), new Message
            {
                Content = guid,
                FromUserId = userId,
                ToUserId = targetUserId,
                MessageType = MessageTypeEnum.VideoBroadcast,
                Timestamp = Miscellaneous.GetTimestamp()
            });

            chatRoomStorage.RegisterBroadcast(chatRoomId.ToString(), userId, targetUserId, guid);
            return guid;
        }


        public void StopVideoBroadcast(string token, int chatRoomId)
        {
            string userId = chatRoomStorage.GetUserIdByToken(token);

            StopVideoBroadcast(userId, chatRoomId.ToString());
        }

        public void StopVideoBroadcast(string userId, string chatRoomId)
        {
            if (chatRoomStorage.UnregisterUserBroadcasts(chatRoomId, userId))
            {
                chatRoomStorage.AddMessage(chatRoomId, new Message
                {
                    FromUserId = userId,
                    MessageType = MessageTypeEnum.StopVideoBroadcast,
                    Timestamp = Miscellaneous.GetTimestamp()
                });
            }
        }

        #region Nested type: EventsResult

        public class EventsResult
        {
            public string Error;
            public Message[] Messages;
            public User[] UsersJoined;
            public User[] UsersLeft;
            public int? CallInterval;
        }

        #endregion

        #region Nested type: JoinChatRoomResult


        public class JoinChatRoomResult
        {
            public string ChatRoomName;
            public string ChatRoomTopic;
            public string Error;
            public string RedirectUrl;
            public string Token;
            public string UserId;
            public User[] Users;
            public bool IsAdmin;
            public bool FileTransferEnabled;
            public bool VideoChatEnabled;
            public string FlashMediaServer;
            public Dictionary<string, string> Broadcasts;
        }

        #endregion

        #region Nested type: SendMessageResult

        public class SendMessageResult
        {
            public string Error;
        }

        #endregion
    }
}

答案 3 :(得分:0)

在web.config中添加/修改以下几行:

<services>
      <service name="eStreamChat.ChatEngine">
        <endpoint address="" behaviorConfiguration="eStreamChat.ChatEngineBehavior" binding="webHttpBinding" contract="eStreamChat.IChatEngine" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>