public void OnOperationResponse(OperationResponse operationResponse) { Debug.Log("返回消息:" + (OperationCode)operationResponse.OperationCode + " " + operationResponse.ToStringFull()); OperationCode code = (OperationCode)operationResponse.OperationCode; if (OperationResponseContain.ContainsKey(code)) { OperationResponseContain[code](operationResponse); } else { Debug.LogError("未注册返回消息:" + code.ToString()); } }
public static NotificationType GetCodeType(OperationCode operationCode) { var attribute = typeof(OperationCode).GetField(operationCode.ToString()) .GetCustomAttribute <OperationCodeTypeAttribute>(false); if (attribute == null) { throw new InvalidOperationException("Operation Code " + operationCode + " does not provide a Operation Code type attribute."); } return(attribute.OperationType); }
public static NotificationType GetCodeType(OperationCode operationCode) { var attribute = typeof(OperationCode).GetField(operationCode.ToString()) .GetCustomAttribute<OperationCodeTypeAttribute>(false); if (attribute == null) { throw new InvalidOperationException("Operation Code " + operationCode + " does not provide a Operation Code type attribute."); } return attribute.OperationType; }
//发送请求后服务端的响应 public void OnOperationResponse(OperationResponse operationResponse) { OperationCode opCode = (OperationCode)operationResponse.OperationCode; Request request = null; bool bSucess = RequestDict.TryGetValue(opCode, out request); if (bSucess) { request.OnOperationResponse(operationResponse); } else { Debug.Log("找不到对应的响应对象!OpCode:" + opCode.ToString()); } }
public void UnRegisterOperationResponse(OperationCode code, OpResCallback callback) { if (OperationResponseContain.ContainsKey(code)) { OperationResponseContain[code] -= callback; if (OperationResponseContain[code] == null) { OperationResponseContain.Remove(code); } } else { Debug.LogWarning("未注册消息:" + code.ToString()); } }
public void HandleMessage(Client client, ByteArray msg) { OperationType ot = (OperationType)msg.ReadInt(); OperationCode oc = (OperationCode)msg.ReadInt(); Console.WriteLine("handle message {0} {1}", ot.ToString(), oc.ToString()); if (operationMap.ContainsKey(ot) && operationMap[ot].ContainsKey(oc) && operationMap[ot][oc].Count > 0) { foreach (var handler in operationMap[ot][oc]) { handler(client.IpAndPort, ot, oc, msg); } } else { Console.WriteLine("未处理的消息: {0} {1}", ot, oc); return; } }
/// <summary> /// �Ƿ�����Ӧģ�����ӦȨ�� /// </summary> /// <param name="userInfo">�û�</param> /// <param name="userID">ְԱ����</param> /// <param name="moduleCode">ģ����</param> /// <param name="operationCode">Ȩ�ޱ��</param> /// <returns>�Ƿ���Ȩ��</returns> public bool Authorization(BaseUserInfo userInfo, String moduleCode, OperationCode operationCode) { return this.Authorization(userInfo, userInfo.ID, moduleCode, operationCode.ToString()); }
/// <summary> /// 是否有相应模块的相应权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userID">职员代码</param> /// <param name="moduleCode">模块编号</param> /// <param name="operationCode">权限编号</param> /// <returns>是否有权限</returns> public bool Authorization(BaseUserInfo userInfo, String staffID, String moduleCode, OperationCode operationCode) { return(this.Authorization(userInfo, staffID, moduleCode, operationCode.ToString())); }
private static void ParseString(string s, BytecodeProgram bytecodeProgram, string filename, int lineNumber, int columnNumber, bool isMiniMaestro) { try { if (LooksLikeLiteral(s)) { Decimal num; if (s.StartsWith("0X")) { num = (Decimal)long.Parse(s.Substring(2), NumberStyles.HexNumber); if (num > new Decimal((int)ushort.MaxValue) || num < new Decimal(0)) { throw new Exception("Value " + s + " is not in the allowed range of " + (object)(ushort)0 + " to " + (object)ushort.MaxValue + "."); } if ((Decimal)(ushort)num != num) { throw new Exception("Value " + s + " must be an integer."); } } else { num = Decimal.Parse(s); if (num > new Decimal((int)short.MaxValue) || num < new Decimal((int)short.MinValue)) { throw new Exception("Value " + s + " is not in the allowed range of " + (object)short.MinValue + " to " + (object)short.MaxValue + "."); } if ((Decimal)(short)num != num) { throw new Exception("Value " + s + " must be an integer."); } } int literal = (int)(short)(long)(num % new Decimal((int)ushort.MaxValue)); bytecodeProgram.AddLiteral(literal, filename, lineNumber, columnNumber, isMiniMaestro); return; } } catch (Exception ex) { throw new Exception("Error parsing " + s + ": " + ex.ToString()); } if (s == Keyword.GOTO.ToString()) { mode = Mode.GOTO; } else if (s == Keyword.SUB.ToString()) { mode = Mode.SUBROUTINE; } else { Match match = Regex.Match(s, "(.*):$"); if (match.Success) { bytecodeProgram.AddInstruction(BytecodeInstruction.NewLabel("USER_" + match.Groups[1].ToString(), filename, lineNumber, columnNumber)); } else if (s == Keyword.BEGIN.ToString()) { bytecodeProgram.OpenBlock(BlockType.BEGIN, filename, lineNumber, columnNumber); } else if (s == Keyword.WHILE.ToString()) { if (bytecodeProgram.GetCurrentBlockType() != BlockType.BEGIN) { throw new Exception("WHILE must be inside a BEGIN...REPEAT block"); } bytecodeProgram.AddInstruction(BytecodeInstruction.NewConditionalJumpToLabel(bytecodeProgram.GetCurrentBlockEndLabel(), filename, lineNumber, columnNumber)); } else if (s == Keyword.REPEAT.ToString()) { try { if (bytecodeProgram.GetCurrentBlockType() != BlockType.BEGIN) { throw new Exception("REPEAT must end a BEGIN...REPEAT block"); } bytecodeProgram.AddInstruction(BytecodeInstruction.NewJumpToLabel(bytecodeProgram.GetCurrentBlockStartLabel(), filename, lineNumber, columnNumber)); bytecodeProgram.CloseBlock(filename, lineNumber, columnNumber); } catch (InvalidOperationException) { throw new Exception(filename + ":" + (object)lineNumber + ":" + (object)columnNumber + ": Found REPEAT without a corresponding BEGIN"); } } else if (s == Keyword.IF.ToString()) { bytecodeProgram.OpenBlock(BlockType.IF, filename, lineNumber, columnNumber); bytecodeProgram.AddInstruction(BytecodeInstruction.NewConditionalJumpToLabel(bytecodeProgram.GetCurrentBlockEndLabel(), filename, lineNumber, columnNumber)); } else if (s == Keyword.ENDIF.ToString()) { try { if (bytecodeProgram.GetCurrentBlockType() != BlockType.IF && bytecodeProgram.GetCurrentBlockType() != BlockType.ELSE) { throw new Exception("ENDIF must end an IF...ENDIF or an IF...ELSE...ENDIF block."); } bytecodeProgram.CloseBlock(filename, lineNumber, columnNumber); } catch (InvalidOperationException) { throw new Exception(filename + ":" + (object)lineNumber + ":" + (object)columnNumber + ": Found ENDIF without a corresponding IF"); } } else if (s == Keyword.ELSE.ToString()) { try { if (bytecodeProgram.GetCurrentBlockType() != BlockType.IF) { throw new Exception("ELSE must be part of an IF...ELSE...ENDIF block."); } bytecodeProgram.AddInstruction(BytecodeInstruction.NewJumpToLabel(bytecodeProgram.GetNextBlockEndLabel(), filename, lineNumber, columnNumber)); bytecodeProgram.CloseBlock(filename, lineNumber, columnNumber); bytecodeProgram.OpenBlock(BlockType.ELSE, filename, lineNumber, columnNumber); } catch (InvalidOperationException) { throw new Exception(filename + ":" + (object)lineNumber + ":" + (object)columnNumber + ": Found ELSE without a corresponding IF"); } } else { try { OperationCode op = dictionary[s]; switch (op) { case OperationCode.LITERAL: case OperationCode.LITERAL8: case OperationCode.LITERAL_N: case OperationCode.LITERAL8_N: throw new Exception(filename + ":" + (object)lineNumber + ":" + (object)columnNumber + ": Literal commands may not be used directly in a program. Integers should be entered directly."); case OperationCode.JUMP: case OperationCode.JUMP_Z: throw new Exception(filename + ":" + (object)lineNumber + ":" + (object)columnNumber + ": Jumps may not be used directly in a program."); default: if (!isMiniMaestro && (byte)op >= (byte)50) { throw new Exception(filename + ":" + (object)lineNumber + ":" + (object)columnNumber + ": " + op.ToString() + " is only available on the Mini Maestro 12, 18, and 24."); } bytecodeProgram.AddInstruction(new BytecodeInstruction(op, filename, lineNumber, columnNumber)); break; } } catch (KeyNotFoundException) { bytecodeProgram.AddInstruction(BytecodeInstruction.NewCall(s, filename, lineNumber, columnNumber)); } } } }