Exemple #1
0
        void appServer_SessionClosed(ESOPSession session, SuperSocket.SocketBase.CloseReason value)
        {
            txtMsg.Invoke(new EventHandler(delegate
            {
                txtMsg.Items.Add(string.Format("用户{0}断开链接...当前连接数:{1} ", session.Name, appServer.SessionCount));
            }));
            var client = clients.Where(a => a.Name == session.Name).FirstOrDefault();

            if (client != null)
            {
                clients.Remove(client);
            }
            // LastRequestInfo.Remove(session.Name);
        }
Exemple #2
0
        private void appServer_NewRequestReceived(ESOPSession session, StringRequestInfo requestInfo)
        {
            switch (requestInfo.Key.ToUpper())
            {
            case ("ECHO"):
                session.Send(requestInfo.Body);
                break;

            case ("LOGIN"):
                if (string.IsNullOrWhiteSpace(session.Name))
                {
                    session.Name = requestInfo.Body.Trim();
                    // session.Send("OK");
                    DataProtocol protocol = new DataProtocol(0, session.Name + "登录成功");
                    string       pro      = protocol.ToString();
                    session.Send(pro);
                    ClientEntity client = new ClientEntity()
                    {
                        Name = session.Name, IP = session.RemoteEndPoint.Address.ToString()
                    };
                    clients.Add(client);
                    txtMsg.Invoke(new EventHandler(delegate
                    {
                        txtMsg.Items.Add(string.Format("用户{0}登录...当前连接数:{1} ", session.Name, appServer.SessionCount));
                        dataGridView1.DataSource = clients;
                    }));
                    if (LastRequestInfo.ContainsKey(session.Name))
                    {
                        using (ESOPEntities entity = new ESOPEntities())
                        {
                            var devidData   = LastRequestInfo[session.Name].Parameters.ToList();
                            var publishId   = devidData[0];
                            var publishData = entity.tb_F_PublishTask.Where(a => a.Id == publishId).FirstOrDefault();
                            if (publishData == null)
                            {
                                throw new ApplicationException(string.Format("任务{0}不存在", publishId));
                            }
                            var PartName = entity.tb_M_Product.Where(a => a.PartNo == publishData.PartNo).Select(a => a.ParName).FirstOrDefault() ?? "";
                            //var devidData = LastRequestInfo.Parameters.ToList();
                            var docName = publishData.DocId;

                            var          docData   = entity.tb_F_Doc.Where(a => a.Id == docName).FirstOrDefault() ?? new tb_F_Doc();
                            var          devData   = entity.tb_S_Device.Where(a => a.DevId == session.Name).FirstOrDefault() ?? new tb_S_Device();
                            DataProtocol protocol2 = new DataProtocol(1, docName, docData.PageCount ?? 0, devData.State2, docData.DocName + "," + PartName);
                            string       pro2      = protocol2.ToString();
                            //ProtocolHelper helper = new ProtocolHelper(pro);

                            //DataProtocol protocol2 = helper.GetProtocol();
                            session.Send(pro2);
                        }
                    }
                }
                break;

            case ("SEND"):                                    //从管理平台发送指令到客户端
                //LastRequestInfo = requestInfo;
                var devid2 = requestInfo.Parameters.ToList(); //第一个参数为要显示的文档名称,后面跟着的参数为对应要发送的机台
                using (ESOPEntities entity = new ESOPEntities())
                {
                    var publishId   = devid2[0];
                    var publishData = entity.tb_F_PublishTask.Where(a => a.Id == publishId).FirstOrDefault();
                    if (publishData == null)
                    {
                        throw new ApplicationException(string.Format("任务{0}不存在", publishId));
                    }

                    //var docid =  devid2[0];
                    var docid    = publishData.DocId;
                    var docData  = entity.tb_F_Doc.Where(a => a.Id == docid).FirstOrDefault() ?? new tb_F_Doc();
                    var PartName = entity.tb_M_Product.Where(a => a.PartNo == publishData.PartNo).Select(a => a.ParName).FirstOrDefault() ?? "";
                    //var PubLishData = entity.tb_F_PublishTask.Where(a=>a.Id==)
                    //var devIdData = entity.tb_S_Device.Where(a=>a.d)
                    for (int i = 1; i < devid2.Count; i++)
                    {
                        string name    = devid2[i];
                        var    devData = entity.tb_S_Device.Where(a => a.DevId == name).FirstOrDefault() ?? new tb_S_Device();

                        var clients = appServer.GetSessions(a => a.Name == name).ToList();    //.FirstOrDefault();
                        foreach (var client in clients)
                        {
                            if (client != null)
                            {
                                if (LastRequestInfo.ContainsKey(name))
                                {
                                    LastRequestInfo[name] = requestInfo;
                                }
                                else
                                {
                                    LastRequestInfo.Add(name, requestInfo);
                                }
                                DataProtocol protocol = new DataProtocol(1, docid, docData.PageCount ?? 0, devData.State2, docData.DocName + "," + PartName);
                                string       pro      = protocol.ToString();
                                //ProtocolHelper helper = new ProtocolHelper(pro);

                                //DataProtocol protocol2 = helper.GetProtocol();
                                client.Send(pro);
                            }
                        }
                    }
                }
                break;
            }
        }
Exemple #3
0
 private void appServer_NewSessionConnected(ESOPSession session)
 {
     // session.Send("Welcome to SuperSocket Telnet Server");
 }