protected override void OnRequest(byte OperationCode, Dictionary <byte, object> Parameters) { OperationCodes operationCode = ParseOperationCode(Parameters); var requestPacket = new RequestPacket(operationCode, Parameters); FirstHandler?.Handle(requestPacket); }
protected override void OnResponse(byte OperationCode, short ReturnCode, string DebugMessage, Dictionary <byte, object> Parameters) { OperationCodes operationCode = ParseOperationCode(Parameters); var responsePacket = new ResponsePacket(operationCode, Parameters); FirstHandler?.Handle(responsePacket); }
public void OnRequest(byte operationCode, Dictionary <byte, object> parameters) { int iCode = 0; if (int.TryParse(parameters[253].ToString(), out iCode)) { OperationCodes opCode = (OperationCodes)iCode; if (opCode.ToString().StartsWith("Move")) { return; } string loggerName = "Request." + opCode.ToString(); ILog log = LogManager.GetLogger(loggerName); log.Debug(parameters); if (_requestHandlers.ContainsKey(opCode)) { foreach (HandleOperation opHandler in _requestHandlers[opCode]) { try { opHandler(parameters, log); } catch (Exception ex) { log.Error(ex); } } } } }
private static void LogOperation(OperationCodes operationCode, ApiController controller) { if (controller.Request.Method == HttpMethod.Get) { return; } var repo = RepositoryManager.GetRepository <ISysOperationLogRepository>(); var operationLog = new SysOperationLog() { OperationCode = operationCode.ToString(), OperationName = operationCode.GetDescription(), Detail = string.Format("{0} {1}", controller.Request.Method, controller.Request.RequestUri), CreateDate = DateTime.Now, }; var identify = controller.User.Identity as BasicAuthenticationIdentity; if (identify != null) { operationLog.UserID = identify.AuthorizationOperatorInfo.OperatorID; operationLog.UserName = identify.Name; } repo.Insert(operationLog); }
/// <summary> /// Emites the given instruction /// </summary> /// <param name="index">The index of the instruction</param> /// <param name="instructionData">The data of the instruction</param> /// <param name="generatorData">The generator data</param> /// <returns>True if emited else false</returns> public bool EmitInstruction(int index, int instructionData, MethodGeneratorData generatorData) { //Read the opcode OperationCodes opCode = (OperationCodes)(instructionData & 0x3F); //Find the emiter InstructionEmiter emiter = null; if (this.instructionEmiters.TryGetValue(opCode, out emiter)) { switch (emiter.InstructionFormat) { case InstructionFormat.IFormat: this.DecodeAndEmitIFormat(index, instructionData, generatorData, emiter); break; case InstructionFormat.RFormat: this.DecodeAndEmitRFormat(index, instructionData, generatorData, emiter); break; case InstructionFormat.JFormat: this.DecodeAndEmitJFormat(index, instructionData, generatorData, emiter); break; } return(true); } else { return(false); } }
/// <summary> /// Adds the given R-format emiter to the list of instruction emiter /// </summary> /// <param name="opCode">The op code</param> /// <param name="opxCode">The opx code</param> /// <param name="emiter">The emiter</param> /// <param name="opxMask">The opx mask</param> public void AddRFormatEmiter(OperationCodes opCode, int opxCode, RFormatInstructionEmiter emiter, int opxMask = -1) { InstructionEmiter newEmiter = null; //Check if an emiter exist if (this.instructionEmiters.ContainsKey(opCode)) { //Get it newEmiter = this.instructionEmiters[opCode]; } else { //Create an new one newEmiter = new InstructionEmiter() { InstructionFormat = InstructionFormat.RFormat, RFormatInstructionEmiters = new Dictionary <int, RFormatInstructionEmiter>(), RFormatOpxMaskers = new List <int>() }; this.instructionEmiters.Add(opCode, newEmiter); } //Check if an opx code emiter exists if (!newEmiter.RFormatInstructionEmiters.ContainsKey(opxCode)) { newEmiter.RFormatInstructionEmiters.Add(opxCode, emiter); if (opxMask != -1) { newEmiter.RFormatOpxMaskers.Add(opxMask); } } }
protected OperationCodes CheckOperationCode(List <byte> msg) { OperationCodes opCode = (OperationCodes)msg[0]; msg.RemoveAt(0); return(opCode); }
protected static void CheckDefaultOperationParams(OperationResponse response, OperationCodes operationCode) { CheckParamExists(response, ParameterKeys.ERR); CheckParamExists(response, ParameterKeys.DBG); int error = (int)response.Params[(short)Lite.Operations.ParameterKeys.ERR]; Assert.AreEqual(0, error, string.Format("Response has Error. ERR={0}, DBG={1}", error, response.Params[(short)ParameterKeys.DBG])); CheckParam(response, ParameterKeys.Code, (short)operationCode); }
protected override void OnResponse(byte operationCode, short returnCode, string debugMessage, Dictionary <byte, object> parameters) { int iCode = 0; if (int.TryParse(parameters[253].ToString(), out iCode)) { OperationCodes opCode = (OperationCodes)iCode; string loggerName = "Response." + opCode.ToString(); Console.WriteLine(loggerName); } }
public void OnRequest(byte operationCode, Dictionary <byte, object> parameters) { //OperationCodes code = (OperationCodes)parameters[253]; int iCode = 0; if (!int.TryParse(parameters[253].ToString(), out iCode)) { return; } OperationCodes code = (OperationCodes)iCode; //Console.WriteLine("OnRequest: " + code); }
protected override void OnResponse(byte operationCode, short returnCode, string debugMessage, Dictionary <byte, object> parameters) { #if DEBUG LogManager.GetLogger("RAW").Debug(parameters); #endif if (operationCode == 0) { foreach (HandleOperation opHandler in _specialResponseHandlers) { try { opHandler(parameters, log); } catch (Exception ex) { log.Error(ex); } } } else { int iCode = 0; if (int.TryParse(parameters[253].ToString(), out iCode)) { OperationCodes opCode = (OperationCodes)iCode; if (opCode.ToString().StartsWith("Move")) { return; } string loggerName = "Response." + opCode.ToString(); ILog log = LogManager.GetLogger(loggerName); #if DEBUG log.Debug(parameters); #endif if (_responseHandlers.ContainsKey(opCode)) { foreach (HandleOperation opHandler in _responseHandlers[opCode]) { try { opHandler(parameters, log); } catch (Exception ex) { log.Error(ex); } } } } } }
private void ReadMessage(DeviceAddress address, OperationCodes opCode, List <byte> slipMessage) { OperationCode[address] = (byte)opCode; PlayLoad[address] = slipMessage.ToArray(); if (opCode == OperationCodes.AngleCode) { byte[] tmp = { slipMessage[1], slipMessage[0] }; AngleCode[address] = BitConverter.ToUInt16(tmp, 0); } if (DataReceived != null) { DataReceived(this, EventArgs.Empty); } }
public static HttpResponseMessage Process <T>(T t, OperationCodes operationCode, Func <HttpResponseMessage> fun, ApiController controller) { Log.InfoFormat("{0} {1}", controller.Request.Method, controller.Request.RequestUri); var sw = Stopwatch.StartNew(); IPersistanceTransaction transaction = null; HttpResponseMessage result = null; try { using (var conn = RepositoryManager.GetNewConnection()) { transaction = conn.BeginTransaction(); var identify = controller.User.Identity as BasicAuthenticationIdentity; if (identify != null && !Authencate(identify)) { throw new AuthenticationException("Authorization has been denied for this request."); } result = fun(); LogOperation(operationCode, controller); Log.Info("Commit transaction!"); transaction.Commit(); } } catch (AuthenticationException ex) { Log.Error("AuthenticationException error", ex); result = controller.Request.CreateErrorResponse(System.Net.HttpStatusCode.Unauthorized, ex.Message, ex); } catch (Exception ex) { Log.Error("Unhandled error", ex); if (transaction != null) { Log.Warn("Rollback transaction!"); transaction.Rollback(); } result = controller.Request.CreateErrorResponse(System.Net.HttpStatusCode.InternalServerError, "Internal Error", ex); } Log.InfoFormat("Response: {0}", result); Log.InfoFormat("Finish processing request, cost {0} milliseconds.", sw.ElapsedMilliseconds); return(result); }
/// <summary> /// Adds the given J-format emiter to the list of instruction emiters /// </summary> /// <param name="opCode">The op code</param> /// <param name="emiter">The emiter</param> public void AddJFormatEmiter(OperationCodes opCode, JFormatInstructionEmiter emiter) { if (!this.instructionEmiters.ContainsKey(opCode)) { //Create the emiter InstructionEmiter newEmiter = new InstructionEmiter() { InstructionFormat = InstructionFormat.JFormat, JFormatInstructionEmiter = emiter, }; //Add it this.instructionEmiters.Add(opCode, newEmiter); } }
public void OnRequest(byte operationCode, Dictionary <byte, object> parameters) { //OperationCodes code = (OperationCodes)parameters[253]; int iCode = 0; if (!int.TryParse(parameters[253].ToString(), out iCode)) { return; } OperationCodes code = (OperationCodes)iCode; //Console.WriteLine("OnRequest: " + code); switch (code) { case OperationCodes.opMove: onLocalPlayerMovement(parameters); break; } }
public void OnResponse(byte operationCode, short returnCode, Dictionary <byte, object> parameters) { // return; int iCode = 0; if (!int.TryParse(parameters[253].ToString(), out iCode)) { return; } OperationCodes code = (OperationCodes)iCode; switch (code) { case OperationCodes.Join: { onJoinResponse(parameters); } break; } }
public OperationHandler(OperationCodes opCode, OperationType opType = OperationType.Request, bool special = false) { OpCode = opCode; OpType = opType; Special = special; }
protected static void CheckDefaultEventParams(EventReceivedEventArgs eventArgs, OperationCodes operationCode, int actorNumber) { CheckEventParam(eventArgs, ParameterKeys.Code, (byte)operationCode); CheckEventParam(eventArgs, ParameterKeys.ActorNr, actorNumber); }
internal ResponseHandler(OperationCodes operationCode, Action <TOperation> action) { this.operationCode = operationCode; this.action = action; }
public CustomRequestHandler(OperationCodes operationCode) : base((short)operationCode) { _operationCode = operationCode; }
private void RequestHandler_OnEvent(OperationCodes code, Dictionary <byte, object> dict) { Event?.Invoke((ushort)code, dict); }
public OperationCodeAttribute(OperationCodes operationCode) { OperationCode = operationCode; }
internal RequestPacket(OperationCodes operationCode, Dictionary <byte, object> Parameters) { OperationCode = operationCode; this.Parameters = Parameters; }
/// <summary> /// Returns the op code /// </summary> public static int Code(this OperationCodes opCode) { return((int)opCode); }
public static AlbionParser AddResponseHandler <TOperation>(this AlbionParser albionParser, OperationCodes operationCode, Action <TOperation> action) where TOperation : BaseOperation { var handler = new ResponseHandler <TOperation>(operationCode, action); albionParser.AddHandler(handler); return(albionParser); }
public OperationHandler(OperationCodes opCode, OperationType opType = OperationType.Request) { OpCode = opCode; OpType = opType; }
public void Initialize(HashSet <EventCodes> targetedEvents, HashSet <OperationCodes> targetedOperations, bool handleSpecial = true) { if (!_initialized) { lock (this) { new Thread(delegate() { this.CreateListener(); }).Start(); var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray(); var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList(); toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path)))); var methods = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(AlbionMarshaller.EventHandler), false).Length > 0) .ToArray()).ToArray(); foreach (MethodInfo method in methods) { var del = (HandleEvent)Delegate.CreateDelegate(typeof(HandleEvent), method); foreach (CustomAttributeData attributeData in method.CustomAttributes) { EventCodes eventCode = (EventCodes)attributeData.ConstructorArguments[0].Value; if (targetedEvents == null || targetedEvents.Contains(eventCode)) { if (!_eventHandlers.ContainsKey(eventCode)) { _eventHandlers.Add(eventCode, new List <HandleEvent>()); } _eventHandlers[eventCode].Add(del); } } } methods = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(OperationHandler), false).Length > 0) .ToArray()).ToArray(); foreach (MethodInfo method in methods) { var del = (HandleOperation)Delegate.CreateDelegate(typeof(HandleOperation), method); foreach (CustomAttributeData attributeData in method.CustomAttributes) { OperationCodes opCode = (OperationCodes)attributeData.ConstructorArguments[0].Value; OperationType opType = (OperationType)attributeData.ConstructorArguments[1].Value; bool special = (bool)attributeData.ConstructorArguments[2].Value; if ((handleSpecial && special) || (targetedOperations == null || targetedOperations.Contains(opCode))) { if (opType == OperationType.Request) { if (special) { _specialRequestHandlers.Add(del); } else { if (!_requestHandlers.ContainsKey(opCode)) { _requestHandlers.Add(opCode, new List <HandleOperation>()); } _requestHandlers[opCode].Add(del); } } else { if (special) { _specialResponseHandlers.Add(del); } else { if (!_responseHandlers.ContainsKey(opCode)) { _responseHandlers.Add(opCode, new List <HandleOperation>()); } _responseHandlers[opCode].Add(del); } } } } } methods = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes() .SelectMany(t => t.GetMethods()) .Where(m => m.GetCustomAttributes(typeof(SpecialHandler), false).Length > 0) .ToArray()).ToArray(); foreach (MethodInfo method in methods) { var del = (HandleSpecial)Delegate.CreateDelegate(typeof(HandleSpecial), method); _specialHandler = del; } // Technically not initialized but everything after this is internal only _initialized = true; } } }