Example #1
0
 public void Update(PersonInfo personInfo)
 {
     try
     {
         client = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
         Console.WriteLine("用户:" + personInfo.UserRealName + "心跳更新!");
         lock (InstObj)
         {
             foreach (var p in ServerOperation.people)
             {
                 if (p.Value.PersonInfo == personInfo)
                 {
                     ServerOperation.people.Remove(client);
                 }
             }
             EndpointAddress IP       = OperationContext.Current.Channel.RemoteAddress;
             var             endpoint = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
             OperationContext.Current.Channel.Closing += new EventHandler(Channel_Closing);//注册客户端关闭触发事件
             ServerOperation.people[client]            = new Person(personInfo, endpoint.Address, endpoint.Port);
             client.ShowMessage(personInfo.UserRealName);
         }
     }
     catch
     {
     }
 }
Example #2
0
        /// <summary>
        /// 客户端关闭事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Channel_Closed(object sender, EventArgs e)
        {
            ICallBackServices client = sender as ICallBackServices;

            FormService.GetInstance().ListClient.Remove(client);
            FormService.GetInstance().SetClientNum();
        }
Example #3
0
 /// <summary>
 /// 客户端发送消息
 /// </summary>
 /// <param name="message"></param>
 public void ClientSendMessage(string message)
 {
     try
     {
         ICallBackServices client         = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
         LoginInOutInfo    loginInOutInfo = JsonConvert.DeserializeObject <LoginInOutInfo>(message);
         if (loginInOutInfo.Type == "LoginIn")
         {
             SystemVar.UrlStr    = loginInOutInfo.UrlStr;
             SystemVar.UserToken = loginInOutInfo.Token;
             if (!string.IsNullOrEmpty(SystemVar.UserToken))
             {
                 CheckWordHelper.WordModels = CheckWordHelper.GetAllCheckWordByToken(SystemVar.UserToken, SystemVar.UrlStr);
             }
         }
         else
         {
             SystemVar.UserToken = "";
         }
     }
     catch (Exception ex)
     {
         WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message);
     }
 }
Example #4
0
        /// <summary>
        /// 客户端发送消息
        /// </summary>
        /// <param name="message"></param>
        public void ClientSendMessage(string message)
        {
            ICallBackServices client         = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
            string            sessionid      = OperationContext.Current.SessionId;                      //获取当前机器Sessionid--------------------------如果多个客户端在同一台机器,就使用此信息。
            string            ClientHostName = OperationContext.Current.Channel.RemoteAddress.Uri.Host; //获取当前机器名称-----多个客户端不在同一台机器上,就使用此信息。

            FormService.GetInstance().SetDisplayMessage(string.Format("客户端:{0}\r\n{1}\r\n{2}", message, sessionid, ClientHostName));
            client.SendMessage("你好,我是服务器");
        }
Example #5
0
 /// <summary>
 /// 客户端关闭事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Channel_Closed(object sender, EventArgs e)
 {
     try
     {
         ICallBackServices client = sender as ICallBackServices;
         MessageService.GetInstance().ListClient.Remove(client);
     }
     catch (Exception ex)
     { }
 }
Example #6
0
        /// <summary>
        /// 客户端注册
        /// </summary>
        public void Register()
        {
            ICallBackServices client         = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
            string            sessionid      = OperationContext.Current.SessionId;                      //获取当前机器Sessionid--------------------------如果多个客户端在同一台机器,就使用此信息。
            string            ClientHostName = OperationContext.Current.Channel.RemoteAddress.Uri.Host; //获取当前机器名称-----多个客户端不在同一台机器上,就使用此信息。

            FormService.GetInstance().SetDisplayMessage(string.Format("客户端上线:\r\n{0}\r\n{1}", sessionid, ClientHostName));
            FormService.GetInstance().ListClient.Add(client);
            OperationContext.Current.Channel.Closed += new EventHandler(Channel_Closed);
            FormService.GetInstance().SetClientNum();
        }
Example #7
0
 /// <summary>
 /// 客户端上线
 /// </summary>
 public void Register(string name)
 {
     try
     {
         ICallBackServices client = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
         MessageService.GetInstance().ListClient.Add(client);
         OperationContext.Current.Channel.Closed += new EventHandler(Channel_Closed);
     }
     catch (Exception ex)
     { }
 }
Example #8
0
        public static List <Person> People     = new List <Person>(); //记录客户端
        public void Register(string username)
        {
            ICallBackServices client    = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
            string            sessionid = OperationContext.Current.SessionId;

            OperationContext.Current.Channel.Closing += new EventHandler(Channel_Closing);//注册客户端关闭触发事件
            Person p = new Person(username, sessionid, client);

            People.Add(p);
            hubadd.Publish("刷新");
            p.CallBackmessage.Myname(p);
        }
Example #9
0
        /// <summary>
        /// Register client's name and closing event
        /// </summary>
        /// <param name="userName">Client's userName</param>
        ///
        public void Register(string userName)
        {
            ICallBackServices callBack  = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
            string            sessionid = OperationContext.Current.SessionId;

            OperationContext.Current.Channel.Closing += new EventHandler(Channel_Closing); // Regist client's closing event

            DicHostSessionid.Add(sessionid, callBack);                                     //If type is seesion id, add it
            DicHostUserid.Add(userName, sessionid);

            isNewUser = true;
        }
Example #10
0
        /// <summary>
        /// 客户端发送消息
        /// </summary>
        /// <param name="message"></param>
        public void ClientSendMessage(string message)
        {
            ICallBackServices client = OperationContext.Current.GetCallbackChannel <ICallBackServices>();

            //获取当前机器Sessionid :适用于多个客户端在同一台机器。
            string sessionid = OperationContext.Current.SessionId;
            //获取当前机器名称: 适用于一个客户端在一台机器上。
            string ClientHostName = OperationContext.Current.Channel.RemoteAddress.Uri.Host;

            string storeno = ConsoleFrm.GetInstance().clientList.Where(item => item.SessionID.Equals(sessionid)).FirstOrDefault().StoreNo;

            ConsoleFrm.GetInstance().SetDisplayMessage(string.Format("客户端[{0}]:{1}\r\n{2}\r\n{3}", storeno, message, sessionid, ClientHostName));

            //client.SendMessage("服务已受理");
        }
Example #11
0
        public void Register()
        {
            ICallBackServices client = OperationContext.Current.GetCallbackChannel <ICallBackServices>();
            //获取当前机器Sessionid--------------------------如果多个客户端在同一台机器,就使用此信息。
            string sessionid = OperationContext.Current.SessionId;
            //获取当前机器名称-----多个客户端不在同一台机器上,就使用此信息。
            string ClientHostName = OperationContext.Current.Channel.RemoteAddress.Uri.Host;

            //注册客户端关闭触发事件
            OperationContext.Current.Channel.Closing += new EventHandler(Channel_Closing);
            if (SendMessageType.ToUpper() == "SESSIONID")
            {
                DicHostSess.Add(sessionid, client);//添加
            }
            else
            {
                DicHost.Add(ClientHostName, client); //添加
            }
        }
Example #12
0
        /// <summary>
        /// 客户端关闭事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Channel_Closed(object sender, EventArgs e)
        {
            ICallBackServices client = sender as ICallBackServices;

            if (ConsoleFrm.GetInstance().ListClient != null && ConsoleFrm.GetInstance().ListClient.Count > 0)
            {
                foreach (var d in ConsoleFrm.GetInstance().ListClient)
                {
                    if (d.Value == (ICallBackServices)sender)//删除此关闭的客户端信息
                    {
                        ConsoleFrm.GetInstance().ListClient.Remove(d.Key);

                        ClientInfo cl = ConsoleFrm.GetInstance().clientList.Find(item => item.SessionID.Equals(d.Key));
                        if (cl != null)
                        {
                            cl.IsRun = false;
                        }
                        ConsoleFrm.GetInstance().SetClientNum();

                        break;
                    }
                }
            }
        }
Example #13
0
        /// <summary>
        /// 客户端注册
        /// </summary>
        public void Register(string data)
        {
            ICallBackServices client = OperationContext.Current.GetCallbackChannel <ICallBackServices>();

            //获取当前机器Sessionid :适用于多个客户端在同一台机器。
            string sessionid = OperationContext.Current.SessionId;
            //获取当前机器名称: 适用于一个客户端在一台机器上。
            string ClientHostName = OperationContext.Current.Channel.RemoteAddress.Uri.Host;

            ConsoleFrm.GetInstance().SetDisplayMessage(string.Format("客户端上线:{0}\r\n{1}\r\n{2}", data, sessionid, ClientHostName));
            ConsoleFrm.GetInstance().ListClient.Add(sessionid, client);

            ClientInfo user = new ClientInfo();

            user.SessionID      = sessionid;
            user.ClientHostName = ClientHostName;
            user.IsRun          = true;
            user.StoreNo        = data;

            ConsoleFrm.GetInstance().clientList.Add(user);

            OperationContext.Current.Channel.Closed += new EventHandler(Channel_Closed);
            ConsoleFrm.GetInstance().SetClientNum();
        }