public AgentHub(
     IChatRoom chatRoomService,
     IHubContext <ChatHub> chatHub)
 {
     _chatRoomService = chatRoomService;
     _chatHub         = chatHub;
 }
        public Participant(string name, IChatRoom chatRoom)
        {
            this._name     = name;
            this._chatRoom = chatRoom;

            this._chatRoom.RegisterParticipant(this);
        }
Ejemplo n.º 3
0
        public IChatRoom GetChatRoom(string id)
        {
            IChatRoom icr = default;

            m_Dict_ChatRoom.TryGetValue(id, out icr);
            return(icr);
        }
Ejemplo n.º 4
0
        public IChatRoom GetRoom(string roomId)
        {
            IChatRoom result = null;

            _rooms.TryGetValue(roomId, out result);
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <int> Join(ChatUser_Data user)
        {
            var iret = 1;
            var cu   = this.GetChatUser(user.Id);

            if (cu == null)
            {
                cu = await CreateIChatUser(user);
            }
            IChatRoom cr = null;

            if (user.ChatRoomId == string.Empty)
            {
                cr = await CreateIChatRoom();
            }
            else
            {
                cr = GetChatRoom(user.ChatRoomId);
                if (cr != null)
                {
                    iret = -2;//已经在房间中
                    return(iret);
                }
                else
                {
                    cr = await CreateIChatRoom();
                }
            }

            iret = await cr.Join(user);

            return(iret);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 服务端向客户端广播信息
 /// </summary>
 /// <param name="chatRoom"></param>
 private void Broadcast(IChatRoom chatRoom)
 {
     foreach (var online in OnLineUsers.Values)
     {
         online.CallBack(chatRoom);
     }
 }
Ejemplo n.º 7
0
        public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e)
        {
            if (e.SourceException == null)
            {
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}",
                                  e.EventType,
                                  e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString());
            }
            else
            {
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}",
                                  e.EventType,
                                  e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(),
                                  e.SourceException);
            }

            if (e.EventType == GenuineEventType.GeneralServerRestartDetected)
            {
                // server has been restarted so it does not know that we have been subscribed to
                // messages and ours nickname
                lock (ChatClient.IChatServerLock)
                {
                    ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom),
                                                                              RemoteHostUri + "/ChatServer.rem");
                    ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                }
            }
        }
Ejemplo n.º 8
0
 public ConversationViewModel(string name, IChatRoom room, bool roomMode = true)
 {
     RoomMode          = roomMode;
     _uniqueName       = name;
     _room             = room;
     AllowClosePanel   = !RoomMode;
     PanelCaption      = room.Description ?? name;
     PanelCaptionImage = ImageResources.DCLDefault16.GetBitmapImage();
     // разрешаем/запрещаем писать сообщения в чаты
     CanPostMessage = !RoomMode || !PublicGroupName.EqIgnoreCase(_uniqueName) || IoC.Instance.Resolve <ISecurityChecker>().Check(ChatPublicWrightName);
     Subscribe();
     ConversationItems = new ObservableCollection <JidItem>(_room.GetUsers().Select(i => new JidItem()
     {
         UserName = i, GroupName = _uniqueName
     }));
     UserListFields =
         new ObservableCollection <DataField>(new[]
     {
         new DataField()
         {
             FieldName = "UserName", SourceName = "UserName", Caption = "Контакты", FieldType = typeof(string)
         }
     });
     NewChatCommand = new DelegateCustomCommand(OnPrivateChatWindow, () => true);
     RefreshContent();
 }
Ejemplo n.º 9
0
        public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e)
        {
            if (e.SourceException == null)
            {
                Console.WriteLine("Global event: {0}\r\nUrl: {1}", e.EventType,
                                  e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString());
            }
            else
            {
                Console.WriteLine("Global event: {0}\r\nUrl: {1}\r\nException: {2}", e.EventType,
                                  e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString(),
                                  e.SourceException);
            }

            if (e.EventType == GenuineEventType.GeneralServerRestartDetected)
            {
                // server has been restarted so it does not know that we need messages and ours nickname
                lock (ChatClient.IChatServerLock)
                {
                    ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom),
                                                                              ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                    ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                }
            }
        }
 public FetchStockQuoteRequestHandler(IStockService stockService,
                                      IChatRoom chatRoom,
                                      IDateTime dateTimeService)
 {
     _stockService    = stockService;
     _chatRoom        = chatRoom;
     _dateTimeService = dateTimeService;
 }
Ejemplo n.º 11
0
 private void LoadRoom()
 {
     Console.WriteLine($"Loading Room {IsLoading}");
     ThisRoom  = State.GetRoom(RoomId);
     IsLoading = false;
     Console.WriteLine($"Loading Room Complete {IsLoading}");
     StateHasChanged();
 }
Ejemplo n.º 12
0
 public ChatController(
     IAuthSvc authSvc,
     IChatRoom chatRoom,
     IDateTimeSvc dateTimeSvc)
 {
     this.authSvc = authSvc;
     this.chatRoom = chatRoom;
     this.dateTimeSvc = dateTimeSvc;
 }
Ejemplo n.º 13
0
        void conversation_PrivateRoom(string user, IChatRoom room, bool activate)
        {
            var cm = GetConversationModel(user, room, false);

            if (activate)
            {
                CurrentConversationItem = cm;
            }
        }
Ejemplo n.º 14
0
      public ChatRoomViewModel(IChatClient client, IChatRoom chatRoom)
      {
         m_dispatcher = Dispatcher.CurrentDispatcher;
         
         m_client = client;
         m_chatRoom = chatRoom;
         ChatLog = new ChatLogViewModel(m_client.Username);

         Members = new ObservableCollection<RoomMember>();
      }
 public SendMessageRequestHandler(IChatRoom chatRoom,
                                  IChatUow chatUow,
                                  IDateTime dateTimeService,
                                  IMediator mediator)
 {
     _chatRoom        = chatRoom;
     _chatUow         = chatUow;
     _dateTimeService = dateTimeService;
     _mediator        = mediator;
 }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            // wait for the server
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            // setup .NET Remoting
            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);
            RemotingConfiguration.Configure("Client.exe.config");
            //GlobalLoggerContainer.Logger = new BinaryLog(@"c:\tmp\client.log");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            Console.WriteLine("Please enter a nickname:");
            ChatClient.Nickname = Console.ReadLine();

            // bind client's receiver
            RemotingServices.Marshal(ChatClient.Instance, "MessageReceiver.rem");

            for (;;)
            {
                try
                {
                    // subscribe to the chat event
                    lock (ChatClient.IChatServerLock)
                    {
                        ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom),
                                                                                  ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                        ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                    }

                    for (;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                        {
                            return;
                        }

                        ChatClient.IChatRoom.SendMessage(str);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 17
0
 public ChatModerator(IMediator mediator, IChatRoom moderatorChatRoom, IEnumerable <string> badWords)
     : base(
         mediator: mediator,
         name: nameof(ChatModerator),
         messageWriter: new EmptyMessageWriter()
         )
 {
     _mediator          = mediator ?? throw new ArgumentNullException(nameof(mediator));
     _moderatorChatRoom = moderatorChatRoom ?? throw new ArgumentNullException(nameof(moderatorChatRoom));
     _badWords          = badWords ?? throw new ArgumentNullException(nameof(badWords));
 }
Ejemplo n.º 18
0
 public HubController(
     IClient client,
     IChatRoom room,
     ICommandBus commandBus,
     IQueryBus queryBus)
 {
     _client = client;
     _room = room;
     _commandBus = commandBus;
     _queryBus = queryBus;
 }
Ejemplo n.º 19
0
 public ChatHub(
     IChatRoom chatRoomService,
     IHubContext <AgentHub> agentHub,
     IServiceProvider sp,
     IHttpContextAccessor httpContext)
 {
     _chatRoomService = chatRoomService;
     _agentHub        = agentHub;
     _sp          = sp;
     _httpContext = httpContext;
 }
Ejemplo n.º 20
0
        public override async Task OnActivateAsync()
        {
            Log.Debug($"{typeof(MainEntryGrain)}OnActivateAsync");
            m_ChatRoom = await GetIChatRoom();

            m_IGateWay = await GetIGateWay();

            m_IHello = GrainFactory.GetGrain <IHello>(0);

            RegisterTimer(Update_Timer, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            await base.OnActivateAsync();
        }
Ejemplo n.º 21
0
 public static void GenuineChannelsEventHandler(object sender, GlobalEventArgs e)
 {
     Console.WriteLine("Global event: {0}, Url: {1}, Exception: {2}", e.EventType, e.Url, e.SourceException);
     if (e.EventType == GlobalEventTypes.GTcpConnectionClosed &&
         e.SourceException is OperationException &&
         ((OperationException)e.SourceException).OperationErrorMessage.ErrorIdentifier.IndexOf("ServerHasBeenRestarted") > -1)
     {
         // server has been restarted so we have to register our listener again
         IChatRoom iChatRoom = (IChatRoom)Activator.GetObject(typeof(IChatRoom), "gtcp://127.0.0.1:8737/ChatRoom.rem");
         iChatRoom.AttachClient(ChatClient.Instance);
     }
 }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);
            RemotingConfiguration.Configure("Client.exe.config");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            Console.WriteLine("Please enter nickname of this client:");
            ChatClient.Nickname = Console.ReadLine();

            //**** Attach a receiver to the court
            IReturnItself iReturnItself = (IReturnItself)Activator.GetObject(typeof(IChatRoom),
                                                                             ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ReturnItself.rem");

            CourtCollection.Attach("/Chat/GlobalRoom", ChatClient.Instance, iReturnItself.ReturnItself());

            for (;;)
            {
                try
                {
                    IChatServer iChatServer = (IChatServer)Activator.GetObject(typeof(IChatServer),
                                                                               ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                    ChatClient.IChatRoom = iChatServer.EnterToChatRoom(ChatClient.Instance, ChatClient.Nickname);

                    for (;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                        {
                            return;
                        }

                        ChatClient.IChatRoom.SendMessage(str);
                        Console.WriteLine("Message \"{0}\" has been sent.", str);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 23
0
        public IChatRoom AddChatRoom(IChatRoom chatRoom)
        {
            var foundChatRoom = ChatRooms.FirstOrDefault(i => (i.ChatRoomName == chatRoom.ChatRoomName && i.ChatRoomMode == chatRoom.ChatRoomMode) || (i.ChatRoomID == chatRoom.ChatRoomID));

            if (foundChatRoom == null)
            {
                _chatRooms.Add(chatRoom);
                return(chatRoom);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {
            // wait for the server
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            // setup .NET Remoting
            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            RemotingConfiguration.Configure("Client.exe.config");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            for (;;)
            {
                try
                {
                    // subscribe to the chat event
                    IChatRoom iChatRoom = (IChatRoom)Activator.GetObject(typeof(IChatRoom),
                                                                         ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatRoom.rem");
                    iChatRoom.AttachClient(ChatClient.Instance);

                    for (;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        // read a string
                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                        {
                            return;
                        }

                        // and send it to all other clients
                        iChatRoom.SendMessage(str);
                        Console.WriteLine("Message \"{0}\" has been sent to all clients.", str);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 25
0
        protected override async Task OnParametersSetAsync()
        {
            await base.OnParametersSetAsync();

            if (!ChatRoom.Equals(LastRoom))
            {
                LoadingMessages = true;

                LastRoom = ChatRoom;
                RoomWatcher?.Stop();
                NoMoreOldMessages = false;
                IsFetchingOlder   = false;
                Messages          = new List <IChatMessage>();
                StartRoomWatcher();

                LoadingMessages = false;
            }
        }
Ejemplo n.º 26
0
        public override bool Init()
        {
            m_ClusterClient = InitialiseClient();

            m_MainEntry = m_ClusterClient.GetGrain <IMainEntry>(0);

            m_SiloGateWay_Obs = new SiloGateWay_Obs();
            m_IGateWay_Obs    = m_ClusterClient.CreateObjectReference <IGateWay_Obs>(m_SiloGateWay_Obs).Result;

            m_IGateWay = m_MainEntry.GetIGateWay().Result;

            m_IGateWay.SubscribeAsync(m_IGateWay_Obs).Wait();

            m_ChatRoom = m_MainEntry.GetIChatRoom().Result;


            return(base.Init());
        }
Ejemplo n.º 27
0
        private ConversationViewModel GetConversationModel(string userName, IChatRoom room = null, bool roomMode = true)
        {
            var cm = ConversationItems.FirstOrDefault(i => i.GetUniqueName().EqIgnoreCase(userName));

            if (cm != null)
            {
                return(cm);
            }
            var r = room ?? _jabber.GetRoom(userName);

            if (r == null)
            {
                return(null);
            }
            var conversation = new ConversationViewModel(userName, room, roomMode);

            DispatcherHelper.BeginInvoke(new Action(() => ConversationItems.Add(conversation)));
            return(conversation);
        }
Ejemplo n.º 28
0
        public JsonResult Send(ChatSendMessageRequest msg)
        {
            var       chatServer = ServiceLocator.GetInstance <IChatServer>();
            IChatRoom room       = null;

            if (msg.RoomId.HasValue())
            {
                room = chatServer.GetRoom(msg.RoomId);
            }
            if (room == null)
            {
                room = chatServer.GetRoomFor(msg.From, msg.To, true);
            }
            room.PostMessage(msg.SenderKey, msg.From, msg.Message);
            return(Json(new ChatSendMessageResult()
            {
                RoomId = room.RoomId
            }, JsonRequestBehavior.DenyGet));
        }
Ejemplo n.º 29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GlobalEventContainer.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);
            RemotingConfiguration.Configure("Client.exe.config");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            for (;;)
            {
                try
                {
                    IChatRoom iChatRoom = (IChatRoom)Activator.GetObject(typeof(IChatRoom), "gtcp://127.0.0.1:8737/ChatRoom.rem");
                    iChatRoom.AttachClient(ChatClient.Instance);

                    for (;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                        {
                            return;
                        }

                        iChatRoom.SendMessage(str);
                        Console.WriteLine("Message \"{0}\" has been sent.", str);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// 服务端调用客户端的方法
        /// </summary>
        /// <param name="chatRoom"></param>
        private void ReceivedMessage(IChatRoom chatRoom)
        {
            // 服务端调用客户端时会触发InvokeRequired
            if (InvokeRequired)
            {
                Action <IChatRoom> action = ReceivedMessage;
                BeginInvoke(action, chatRoom);
            }

            // 通过BeginInvoke跳回UI线程
            else
            {
                switch (chatRoom)
                {
                case User user:
                    AddUser(user);
                    break;

                case SystemMessage systemMessage:

                    // RemoveUserId不为0,则有用户执行了登出
                    if (systemMessage.RemoveUserId != 0)
                    {
                        RemoveUser(systemMessage.RemoveUserId);
                    }
                    else
                    {
                        AddMessage(new ChatMessage()
                        {
                            SendUser = User.SystemUser,
                            SendTime = systemMessage.SengTime,
                            Text     = systemMessage.Text
                        });
                    }
                    break;

                case ChatMessage message:
                    AddMessage(message);
                    break;
                }
            }
        }
Ejemplo n.º 31
0
        public void SendMessage(string chatRoomId, string message)
        {
            IChatRoom chatRoom = null;

            if (chatRoomId != "" && chatRoomId != "0" && chatRoomId != "null")
            {
                chatRoom = ChatManager.GetChatRoomByID(new Guid(chatRoomId));

                if (chatRoom != null)
                {
                    var chatUser = new ChatUser(Session.SessionID);

                    if (chatRoom.GetUserInChatRoom(chatUser) != null)
                    {
                        chatRoom.AddMessage(chatUser, message);
                    }
                }
            }

            WriteJSON(StringHelper.ObjectToJson(chatRoom));
        }
Ejemplo n.º 32
0
        public override void gereClient(TcpClient comm)
        {
            stream = comm.GetStream();
            while (comm.Connected)
            {
                Message msg = getMessage();
                Message replyMsg;
                if (msg == null)
                {
                    return;
                }

                switch (msg.head.type)
                {
                case "LIST_TOPICS":
                    replyMsg = new Message(new Header("Server", "LIST_TOPICS_REPLY"), listTopics());
                    sendMessage(replyMsg);
                    break;

                case "CREATE_TOPICS":
                    createTopic(msg.data);
                    break;

                case "JOIN_TOPIC":
                    IChatRoom chatRoom = joinTopic(msg.data);
                    int       port     = ((ServerChatRoom)chatRoom).port;
                    replyMsg = new Message(new Header("Server", "JOIN_REPLY"), port.ToString());
                    Console.WriteLine("The server respond the port is " + replyMsg.data);
                    sendMessage(replyMsg);
                    break;

                default:
                    Console.WriteLine("default GuestTopic called :" + msg.head.type);
                    break;
                }
            }
        }
Ejemplo n.º 33
0
        public void CreatePrivateChatRoomWith(string otherChatUserId)
        {
            var       me         = ChatManager.ChatUsers.FirstOrDefault(i => i.SessionID == Session.SessionID);
            var       chatUserId = new Guid(otherChatUserId);
            var       otherUser  = ChatManager.ChatUsers.FirstOrDefault(i => i.ChatUserID == chatUserId);
            IChatRoom chatroom   = null;

            if (me != null && otherUser != null && me.ChatUserID != otherUser.ChatUserID && me.NickName != otherUser.NickName)
            {
                var foundChatRoom = ChatManager.GetChatRoomWithUsers(RoomMode.Private, new List <ChatUser>()
                {
                    me, otherUser
                });

                chatroom = ChatManager.GetOrCreateChatRoom(RoomMode.Private, me.NickName + "," + otherUser.NickName, me);

                if (chatroom != null)
                {
                    chatroom.JoinChatRoom(otherUser);
                }
            }

            WriteJSON(StringHelper.ObjectToJson(chatroom));
        }
Ejemplo n.º 34
0
        public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e)
        {
            if (e.SourceException == null)
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}",
                    e.EventType,
                    e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString());
            else
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}",
                    e.EventType,
                    e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(),
                    e.SourceException);

            if (e.EventType == GenuineEventType.GeneralServerRestartDetected)
            {
                // server has been restarted so it does not know that we have been subscribed to
                // messages and ours nickname
                lock(ChatClient.IChatServerLock)
                {
                    ChatClient.IChatServer = (IChatServer) Activator.GetObject(typeof(IChatRoom),
                        ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                    ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                }
            }
        }
Ejemplo n.º 35
0
        static void Main(string[] args)
        {
            // wait for the server
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            // setup .NET Remoting
            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);
            //GlobalLoggerContainer.Logger = new BinaryLog(@"c:\tmp\client.log", false);
            RemotingConfiguration.Configure("Client.exe.config");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            Console.WriteLine("Please enter a nickname:");
            ChatClient.Nickname = Console.ReadLine();

            // bind client's receiver
            RemotingServices.Marshal(ChatClient.Instance, "MessageReceiver.rem");

            for(;;)
            {
                try
                {
                    // subscribe to the chat event
                    lock(ChatClient.IChatServerLock)
                    {
                        ChatClient.IChatServer = (IChatServer) Activator.GetObject(typeof(IChatRoom),
                            ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                        ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                    }

                    for(;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                            return ;

                        ChatClient.IChatRoom.SendMessage(str);
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine("\r\n\r\n---Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
Ejemplo n.º 36
0
 public void JoinRoom(IChatRoom item)
 {
     m_applicationViewModel.OpenRoom(item);
 }