Beispiel #1
0
            /// <inheritdoc/>
            public override Boolean Equals(Object obj)
            {
                KeyToken other = obj as KeyToken;

                if (other == null)
                {
                    return(false);
                }
                return(_hash == other._hash);
            }
Beispiel #2
0
            public override string ToString()
            {
                StringBuilder buf = new StringBuilder();

                buf.Append(getStmtPrefix());
                buf.AppendFormat("{0}{1}", KeyToken.ToCode(), this.Condition.ToString());
                buf.AppendLine();
                buf.Append(Body.ToString());
                buf.AppendLine();
                return(buf.ToString());
            }
Beispiel #3
0
            public override string ToString()
            {
                //return Raw.ToString();
                StringBuilder buf = new StringBuilder();

                //buf.Append(GetStmtPrefix());
                buf.AppendFormat("{0}{1}", KeyToken.ToCode(), this.ElseIfExp.ToString());
                buf.AppendLine();
                buf.Append(Body.ToString());
                buf.AppendLine();
                return(buf.ToString());
            }
Beispiel #4
0
 public CBind(string keyStr, Commando[] commands) : base(CommandType.bind)
 {
     this.original_KeyStr = keyStr;
     this.key = getKeyToken(keyStr);
     this.commands = commands;
 }
 /// <summary>
 /// The key emitted by the View Map function
 /// </summary>
 public TKey Key <TKey>()
 {
     return(KeyToken.ToObject <TKey>());
 }
Beispiel #6
0
 public CBind(string keyStr, Commando[] commands) : base(CommandType.bind)
 {
     this.original_KeyStr = keyStr;
     this.key             = getKeyToken(keyStr);
     this.commands        = commands;
 }
Beispiel #7
0
        private void AsyncCallback(IAsyncResult ar)
        {
            if (ar.AsyncState is AsyncStateOne state)
            {
                try
                {
                    int received = state.WorkSocket.EndReceiveFrom(ar, ref state.UdpEndPoint);
                    //释放连接关联
                    state.WorkSocket = null;
                    //马上开始重新接收,提供性能保障
                    RefreshReceive();
                    //处理数据
                    if (received >= HslCommunicationCode.HeadByteLength)
                    {
                        //检测令牌
                        if (NetSupport.IsTwoBytesEquel(state.BytesContent, 12, KeyToken.ToByteArray(), 0, 16))
                        {
                            state.IpEndPoint = (IPEndPoint)state.UdpEndPoint;
                            int contentLength = BitConverter.ToInt32(state.BytesContent, HslCommunicationCode.HeadByteLength - 4);
                            if (contentLength == received - HslCommunicationCode.HeadByteLength)
                            {
                                byte[] head    = new byte[HslCommunicationCode.HeadByteLength];
                                byte[] content = new byte[contentLength];

                                Array.Copy(state.BytesContent, 0, head, 0, HslCommunicationCode.HeadByteLength);
                                if (contentLength > 0)
                                {
                                    Array.Copy(state.BytesContent, 32, content, 0, contentLength);
                                }

                                //解析内容
                                content = NetSupport.CommandAnalysis(head, content);

                                int protocol = BitConverter.ToInt32(head, 0);
                                int customer = BitConverter.ToInt32(head, 4);
                                //丢给数据中心处理
                                DataProcessingCenter(state, protocol, customer, content);
                            }
                            else
                            {
                                //否则记录到日志
                                LogNet?.WriteWarn(LogHeaderText, $"接收到异常数据,应接收长度:{(BitConverter.ToInt32(state.BytesContent, 4) + 8)} 实际接收:{received}");
                            }
                        }
                        else
                        {
                            LogNet?.WriteWarn(LogHeaderText, StringResources.TokenCheckFailed);
                        }
                    }
                    else
                    {
                        LogNet?.WriteWarn(LogHeaderText, $"接收到异常数据,长度不符合要求,实际接收:{received}");
                    }
                }
                catch (ObjectDisposedException ex)
                {
                    //主程序退出的时候触发
                }
                catch (Exception ex)
                {
                    LogNet?.WriteException(LogHeaderText, StringResources.SocketEndReceiveException, ex);
                    //重新接收,此处已经排除掉了对象释放的异常
                    RefreshReceive();
                }
                finally
                {
                    //state = null;
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// 往队列中添加一个Token
        /// </summary>
        /// <param name="lineNumber">Token所在行号</param>
        /// <param name="item">Token源字符串</param>
        private void AddToken(int lineNumber, Match item)
        {
            Token  token    = null;
            string strValue = item.Value.Trim();
            var    groups   = item.Groups;

            if (groups["com"].Success)
            {
                // 注释,忽略掉
            }
            else if (groups["id"].Success)
            {
                // 标识符
                token = new IdToken(lineNumber, strValue);
            }
            else if (groups["num"].Success)
            {
                // 整形字面量
                bool succ = false;
                if (strValue.StartsWith("(-"))
                {
                    // 负数
                    string fixedStrValue = strValue.Substring(2, strValue.Length - 3);
                    if (int.TryParse(fixedStrValue, out int val))
                    {
                        token = new NumToken(lineNumber, -val);
                        succ  = true;
                    }
                }
                else if (int.TryParse(strValue, out int val))
                {
                    token = new NumToken(lineNumber, val);
                    succ  = true;
                }
                if (!succ)
                {
                    // 解析未成功
                    throw new ParseException("解析整形字面量失败");
                }
            }
            else if (groups["str"].Success)
            {
                // 字符串字面量
                token = new StrToken(lineNumber, strValue.Substring(1, strValue.Length - 2));
            }
            else if (groups["pun"].Success)
            {
                // 运算符
                token = new PunToken(lineNumber, strValue);
            }
            else if (groups["key"].Success)
            {
                // 关键字
                token = new KeyToken(lineNumber, strValue);
            }
            else if (groups["sep"].Success)
            {
                // 分号和括号
                token = new SepToken(lineNumber, strValue);
            }
            else if (groups["other"].Success)
            {
                // 不能识别的字符
                throw new ParseException(new StrToken(lineNumber, strValue), "非法字符");
            }
            if (token != null)
            {
                m_tokenQueue.Add(token);
                //Utils.LogInfo("添加了Token: " + token.GetText());
            }
        }