コード例 #1
0
        public ActionResult CollectMCS(string ip, int port, string arrangeStr)
        {
            MCSServer mcsServer = new MCSServer();

            mcsServer.ArrangeStr = arrangeStr;
            mcsServer.MCS_IP     = ip;
            mcsServer.MCS_Port   = port;
            mcsServer.MCS_IP     = System.Configuration.ConfigurationManager.AppSettings["LocalIP"].ToString();
            lock (CommonFlag.lockobject)
            {
                if (cacheManage.GetCache <IList <MCSServer> >("MCSServers") == null)
                {
                    IList <MCSServer> mcsServers = new List <MCSServer>();
                    mcsServers.Add(mcsServer);
                    cacheManage.AddCache <IList <MCSServer> >("MCSServers", mcsServers);
                }
                else
                {
                    if (cacheManage.GetCache <IList <MCSServer> >("MCSServers").Count > 0)
                    {
                        for (int i = cacheManage.GetCache <IList <MCSServer> >("MCSServers").Count - 1; i >= 0; i--)
                        {
                            if (cacheManage.GetCache <IList <MCSServer> >("MCSServers")[i].MCS_IP == mcsServer.MCS_IP &&
                                cacheManage.GetCache <IList <MCSServer> >("MCSServers")[i].MCS_Port == mcsServer.MCS_Port)
                            {
                                cacheManage.GetCache <IList <MCSServer> >("MCSServers").RemoveAt(i);
                            }
                        }
                    }
                    cacheManage.GetCache <IList <MCSServer> >("MCSServers").Add(mcsServer);
                }
            }
            return(Json("ok", JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public void AddMsgIntoSendBuffer(MCSServer mcsServer, MsgRecord msgRecord)
        {
            if (!exeSendMsgRecords1Buffer.ContainsKey(msgRecord.MsgID))
            {
                MsgRecordModel msgRecordmodel = new MsgRecordModel();
                msgRecordmodel.IsSended             = msgRecord.IsSended;
                msgRecordmodel.MCS_IP               = mcsServer.MCS_IP;
                msgRecordmodel.MCS_Port             = mcsServer.MCS_Port;
                msgRecordmodel.MDS_IP               = CommonVariables.MDSIP;
                msgRecordmodel.MDS_Port             = CommonVariables.MDSPort;
                msgRecordmodel.MsgContent           = msgRecord.MsgContent;
                msgRecordmodel.MsgID                = msgRecord.MsgID;
                msgRecordmodel.MsgRecipientGroupID  = msgRecord.MsgRecipientGroupID;
                msgRecordmodel.MsgRecipientObjectID = msgRecord.MsgRecipientObjectID;
                msgRecordmodel.MsgSenderName        = msgRecord.MsgSenderName;
                msgRecordmodel.MsgSenderObjectID    = msgRecord.MsgSenderObjectID;
                msgRecordmodel.MsgType              = msgRecord.MsgType;
                msgRecordmodel.reTryCount           = 1;
                msgRecordmodel.SendTime             = msgRecord.SendTime;
                msgRecordmodel.ExeSendTime          = DateTime.Now.ToString(CommonFlag.F_DateTimeFormat);

                CommonVariables.Listener.SendMsg(msgRecordmodel.MCS_IP, msgRecordmodel.MCS_Port,
                                                 CommonFlag.F_MCSVerfiyMDSMSG + JsonConvert.SerializeObject(msgRecord), msgRecordmodel.MsgID);
                exeSendMsgRecords1Buffer.Add(msgRecordmodel.MsgID, msgRecordmodel);
            }
        }
コード例 #3
0
        private string HandleMMSVerifyUAGetUAInfo(string data, MMSListenerUDPToken token)
        {
            ClientModel clientStatusModel = JsonConvert.DeserializeObject <ClientModel>(data.Remove(0, CommonFlag.F_MMSVerifyUAGetUAInfo.Length));

            if (clientStatusModel == null)
            {
                return(string.Empty);
            }

            if (string.IsNullOrEmpty(clientStatusModel.ObjectID) || string.IsNullOrEmpty(clientStatusModel.UpdateTime))
            {
                return(string.Empty);
            }


            IList <ContactData> contactDatas = PreparContactData(clientStatusModel.ObjectID, clientStatusModel.UpdateTime, token.ContactPersonService);

            if (contactDatas != null && contactDatas.Count > 0)
            {
                clientStatusModel.Client_IP   = token.IP;
                clientStatusModel.Client_Port = token.Port;
                MCSServer server = CommonVariables.CommonFunctions.FindMCSServer(CommonVariables.MCSServers, clientStatusModel.ObjectID);
                CommonVariables.UAInfoContorl.UpdateClientModel(clientStatusModel, server);
                CommonVariables.UAInfoContorl.AddContactDataIntoBuffer(contactDatas, clientStatusModel.Client_IP, clientStatusModel.Client_Port, ServerType.MCS);

                return(contactDatas.Count.ToString());
            }
            return(string.Empty);
        }
コード例 #4
0
        public MCSServer FindMCSServer(IList <MCSServer> servers, String objectID)
        {
            MCSServer server = null;

            foreach (MCSServer tempserver in servers)
            {
                if (tempserver.ArrangeStr.Contains(objectID.Substring(0, 1)))
                {
                    return(tempserver);
                }
            }
            return(server);
        }
コード例 #5
0
        private string HandleMDSVerifyMCSMSG(string data, MDSListenerUDPToken token)
        {
            string    tempStr   = data.Remove(0, CommonFlag.F_MDSVerifyMCSMSG.Length);
            MsgRecord msgReocod = JsonConvert.DeserializeObject <MsgRecord>(tempStr);

            if (msgReocod != null)
            {
                if (!string.IsNullOrEmpty(msgReocod.MsgRecipientObjectID))
                {
                    CommonVariables.MessageContorl.AddMSgRecordIntoBuffer(msgReocod);

                    MCSServer server = CommonVariables.CommonFunctions.FindMCSServer(CommonVariables.MCSServers,
                                                                                     msgReocod.MsgRecipientObjectID);

                    CommonVariables.MessageContorl.AddMsgIntoSendBuffer(server, msgReocod);
                }
                return(CommonFlag.F_MCSVerfiyFBMDSMSG + msgReocod.MsgID);
            }
            return(string.Empty);
        }
コード例 #6
0
        private string HandleMMSVerifyUA(string data, MMSListenerUDPToken token)
        {
            ContactPerson tempContactPerson = null;
            ClientModel   clientStatusModel = JsonConvert.DeserializeObject <ClientModel>(data.Remove(0, CommonFlag.F_MMSVerifyUA.Length));

            CommonVariables.LogTool.Log("UA:" + clientStatusModel.ObjectID + " connected  " + clientStatusModel.LatestTime);
            //Find MCS
            MCSServer server = CommonVariables.CommonFunctions.FindMCSServer(CommonVariables.MCSServers, clientStatusModel.ObjectID);

            if (server == null)
            {
                return("MMS:can not find MCS server");
            }

            clientStatusModel.MCS_IP   = server.MCS_IP;
            clientStatusModel.MCS_Port = server.MCS_Port;
            tempContactPerson          = token.ContactPersonService.FindContactPerson(clientStatusModel.ObjectID);
            if (tempContactPerson == null)
            {
                return("MMS:did not exist this user");
            }

            if (clientStatusModel.LatestTime.CompareTo(tempContactPerson.LatestTime) <= 0)
            {
                clientStatusModel.LatestTime = tempContactPerson.LatestTime;
            }
            else
            {
                tempContactPerson.LatestTime = clientStatusModel.LatestTime;
                token.ContactPersonService.UpdateContactPerson(tempContactPerson);
            }

            clientStatusModel.UpdateTime = tempContactPerson.UpdateTime;

            base.SendMsg(server.MCS_IP, server.MCS_Port,
                         CommonFlag.F_MCSReceiveMMSUAUpdateTime + JsonConvert.SerializeObject(clientStatusModel), clientStatusModel.ObjectID);
            CommonVariables.UAInfoContorl.UpdateClientModel(clientStatusModel, server);
            //Send MCS
            return(JsonConvert.SerializeObject(clientStatusModel));
        }
コード例 #7
0
        public void UpdateClientModel(ClientModel clientModel, MCSServer server)
        {
            if (clientModels.ContainsKey(clientModel.ObjectID))
            {
                clientModels[clientModel.ObjectID].Client_IP   = clientModel.Client_IP;
                clientModels[clientModel.ObjectID].Client_Port = clientModel.Client_Port;
                if (string.IsNullOrEmpty(clientModels[clientModel.ObjectID].MCS_IP))
                {
                    clientModels[clientModel.ObjectID].MCS_IP   = server.MCS_IP;
                    clientModels[clientModel.ObjectID].MCS_Port = server.MCS_Port;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(clientModel.MCS_IP))
                {
                    clientModel.MCS_IP   = server.MCS_IP;
                    clientModel.MCS_Port = server.MCS_Port;
                }

                clientModels.Add(clientModel.ObjectID, clientModel);
            }
        }
コード例 #8
0
        public void SendMsgToMCS(MCSServer mcsServer, MsgRecord msgRecord)
        {
            String strmsg = CommonFlag.F_MCSVerfiyMDSMSG + CommonVariables.serializer.Serialize(msgRecord);

            asyncSocketClient.SendMsg(mcsServer.MCS_IP, mcsServer.MCS_Port, strmsg, msgRecord.MsgID, HandMCSReturnData);
        }