コード例 #1
0
        void Parent_GetArgs(object sender, Communicate.Base.Base.ReciveArgs reciveArgs)
        {
            lock (lockObject)
            {
                Communicate.Communicate parent = (Communicate.Communicate)sender;
                int    len = parent.DataRecive;
                byte[] buff;
                if (len > 0 && this.Read <byte[]>(len, out buff))
                {
                    SSMeter.SSReadMeter.ReadDataStyle   rs = SSMeter.SSReadMeter.ReadDataStyle.Parse(buff);
                    SSMeter.SSReadMeter.ReadResultStyle rr = new SSMeter.SSReadMeter.ReadResultStyle(Class.TypeUse.TypeList.Int, rs.Random, true, null);
                    if (rs == null)
                    {
                        All.Class.Error.Add("SSLockClient.Loop无校验或校验不通过");
                        return;
                    }
                    if (!rs.Symbol.ContainsKey("GUID"))
                    {
                        All.Class.Error.Add("SSLockMain接收的字符串没有GUID识别码");
                        return;
                    }
                    if (!Queue.Contain(rs.Symbol["GUID"]))
                    {
                        allClientReturnStatue.Add(rs.Symbol["GUID"], ReturnStatueList.无请求);
                        allClientRequestStatue.Add(rs.Symbol["GUID"], SSLockClient.SetStatueList.无动作);
                        Queue.Init(0, rs.Symbol["GUID"]);
                    }
                    if (!rs.Symbol.ContainsKey("Code"))
                    {
                        All.Class.Error.Add("SSLockMain接收的字符串没有Code命令码");
                        return;
                    }

                    allClientRequestStatue[rs.Symbol["GUID"]] = (SSLockClient.SetStatueList)rs.Symbol["Code"].ToInt();

                    rr.Result = true;
                    rr.Value  = new List <int>()
                    {
                        (int)allClientReturnStatue[rs.Symbol["GUID"]]
                    };
                    Dictionary <string, string> parm = new Dictionary <string, string>();
                    parm.Add("RemotIP", reciveArgs.RemotIP);
                    parm.Add("RemotPort", reciveArgs.RemotPort.ToString());
                    parent.Send <byte[]>(rr.GetBytes <int>(), parm);
                }
            }
        }
コード例 #2
0
ファイル: SSLockClient.cs プロジェクト: lanicon/HK_NewLab
        private bool Loop()
        {
            try
            {
                lock (lockObject)
                {
                    Dictionary <string, string> buff = new Dictionary <string, string>();
                    buff.Add("Code", string.Format("{0}", (int)currentSetStatue));
                    buff.Add("GUID", clientGuid);
                    SSMeter.SSReadMeter.ReadDataStyle rd = new SSMeter.SSReadMeter.ReadDataStyle(Class.TypeUse.TypeList.Int, buff);
                    byte[] readBuff;
                    if (WriteAndRead <byte[], byte[]>(rd.GetBytes(), 7, out readBuff))
                    {
                        SSMeter.SSReadMeter.ReadResultStyle rs = SSMeter.SSReadMeter.ReadResultStyle.Parse(readBuff);
                        if (rs == null || rs.Random != rd.Random || !rs.Result)
                        {
                            All.Class.Error.Add("SSLockClient.Loop无校验或校验不通过");
                            return(false);
                        }
                        List <int> result = (List <int>)rs.Value;
                        if (result[0] < 0 || result[0] >= Enum.GetNames(typeof(GetStatueList)).Length)
                        {
                            All.Class.Error.Add("SSLockClient.Loop无效的命令");
                            return(false);
                        }
                        switch ((SSLockMain.ReturnStatueList)result[0])
                        {
                        case SSLockMain.ReturnStatueList.无请求:
                            if ((int)currentGetStatue != (int)GetStatueList.无状态)
                            {
                                currentGetStatue = GetStatueList.无状态;
                                All.Class.Log.Add("SSLockClient.状态->无状态/无请求");
                                if (NeedClientReset != null)
                                {
                                    NeedClientReset(this, new EventArgs());
                                }
                            }
                            break;

                        case SSLockMain.ReturnStatueList.允许:
                            if ((int)currentGetStatue != (int)GetStatueList.允许执行)
                            {
                                currentGetStatue = GetStatueList.允许执行;
                                All.Class.Log.Add("SSLockClient.状态->允许执行");
                                if (NeedClientSwitch != null)
                                {
                                    NeedClientSwitch(this, new EventArgs());
                                }
                            }
                            break;

                        case SSLockMain.ReturnStatueList.等待:
                            if ((int)currentGetStatue != (int)GetStatueList.等待执行)
                            {
                                currentGetStatue = GetStatueList.等待执行;
                                All.Class.Log.Add("SSLockClient.状态->等待执行");
                            }
                            break;
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                All.Class.Error.Add(e);
                return(false);
            }
            return(true);
        }