private Byt3Handler GetHandler(Byt3HandlerLookupType type, AHandler fallback) { ACalled = BCalled = CCalled = DCalled = false; Byt3Handler handler = new Byt3Handler(type, fallback); return(handler); }
public override bool Equals(Either <T1, T2> obj) { AHandler o = obj as AHandler; if (o == null) { return(false); } return(EqualityComparer <T1> .Default.Equals(this.value, o.value)); }
public override bool Equals(object obj) { AHandler o = obj as AHandler; if (o == null) { return(false); } return(Equals(o)); }
static void Main(string[] args) { var mediator = new Mediator(); var weather = new BHandler("WeatherHandler"); var home = new AHandler("HomeHandler"); mediator.AddHandler(weather); mediator.AddHandler(home); weather.Mediator = mediator; home.Mediator = mediator; home.Handle(); }
public void AHandlerTests() { var counter = Substitute.For <IStructSizeCounter>(); counter.GetSize(typeof(Envelope)).Returns(4); var aHandler = new AHandler(); var reader = new MessageReader(aHandler, counter, GetABId); var bytes = stackalloc byte[10]; var chunk = new ByteChunk(bytes, 10); Assert.AreEqual(0, aHandler.Counter); reader.MessageHandlerImpl(ATypeId, chunk); Assert.AreEqual(1, aHandler.Counter); reader.MessageHandlerImpl(BTypeId, chunk); Assert.AreEqual(1, aHandler.Counter); }
public object Execute(List <Instruction> Instructions) { try { for (int i = 0; i < Instructions.Count; i++) { Instruction instruction = Instructions[i]; AHandler handler = RegisteredOpCodes[instruction.OpCode]; handler.ExecuteOpCode(VStack, instruction); } return(VStack.VM.Count != 0 ? VStack.VM.Pop() : null); } finally { VStack.VM.Clear(); GC.Collect(); } }
public void When_spinned_once_then_dispatches_one_batch() { const int batchSize = 10; const int aCount = 3; const int bCount = 4; var buffer = Substitute.For <IRingBuffer>(); var aHandler = new AHandler(); var bHandler = new BHandler(); buffer.Read(Arg.Any <MessageHandler>(), Arg.Is(batchSize)).Returns(ci => { var handler = ci.ArgAt <MessageHandler>(0); for (var i = 0; i < aCount; i++) { handler(MessageAId, ByteChunk.Empty); } for (var i = 0; i < bCount; i++) { handler(MessageBId, ByteChunk.Empty); } return(aCount + bCount); }); var runner = new Runner(buffer, new StructSizeCounter(), t => ids[t], batchSize, aHandler, bHandler); BatchInfo batch; runner.SpinOnce(out batch); Assert.AreEqual(1, buffer.ReceivedCalls().Count()); Assert.AreEqual(batchSize, batch.RequestedNumberOfMessages); Assert.AreEqual(aCount + bCount, batch.ProcessedNumberOfMessages); Assert.Less(0, batch.StopWatchTicksSpentOnProcessing); Assert.AreEqual(aCount, aHandler.Counter); Assert.AreEqual(bCount, bHandler.Counter); Assert.True(aHandler.BatchFinished); Assert.True(bHandler.BatchFinished); }
public void AcceptHandler(string param3, AHandler handler);
/// <summary> /// Creates a handler object and adds it to the internal list. /// </summary> /// <param name="sHandlerName">The name of the handler to load.</param> private static void LoadHandler(string sHandlerName) { Debug.WriteLine("Loading handler: " + sHandlerName, "HandlerFactory.LoadHandler"); try { HandlerConfig oHandlerConfig = m_oLoggerConfig.Handlers.Find(delegate(HandlerConfig obj) { return(obj.Name.Equals(sHandlerName, StringComparison.OrdinalIgnoreCase)); }); if (oHandlerConfig == null) { Debug.WriteLine("A handler with the name '" + sHandlerName + "' could not be found. Loading default handler for this handler name."); m_colHanderList.Add(sHandlerName, new WindowsEventHandler()); //throw new Exception("The configuration for the handler '" + sHandlerName + "' was not found. Check the 'Handlers' section of loggerconfig.xml and make sure the log handler is registered there."); } else { System.Reflection.Assembly assembly = Assembly.LoadFrom(m_sRootFolder + oHandlerConfig.Assembly); Type t = assembly.GetType(oHandlerConfig.Type); if (t == null) { throw new Exception("Unable to load the type '" + oHandlerConfig.Type + "' for the handler '" + sHandlerName + "'. Check the 'Handlers' section of loggerconfig.xml and make sure the correct type is specified in the Type tag."); } AHandler oPlugin = (AHandler)Activator.CreateInstance(t); oPlugin.Init(oHandlerConfig); m_colHanderList.Add(sHandlerName, oPlugin); } //switch (sHandlerName) //{ // case "FileHandler": // { // //m_colHanderList.Add(sHandlerName, new FileHandler()); // System.Reflection.Assembly assembly = Assembly.LoadFrom("Logger.dll"); // Type t = assembly.GetType("Utils.Log.Handlers.FileHandler"); // AHandler oPlugin = (AHandler)Activator.CreateInstance(t); // HandlerConfig oHandlerConfig = m_oLoggerConfig.Handlers.Find(delegate(HandlerConfig obj) { return obj.Name.Equals(sHandlerName, StringComparison.OrdinalIgnoreCase); }); // if (oHandlerConfig != null) // oPlugin.Init(oHandlerConfig); // else // throw new Exception("The configuration for the handler '" + sHandlerName + "' was not found. Check the 'Handlers' section of loggerconfig.xml and make sure the log handler is registered there"); // m_colHanderList.Add(sHandlerName, oPlugin); // break; // } // case "WindowsEventHandler": // m_colHanderList.Add(sHandlerName, new WindowsEventHandler()); // break; // case "SQLDBHandler": // m_colHanderList.Add(sHandlerName, new SQLDBHandler()); // break; // default: //WindowsEventHandler // Debug.WriteLine("A handler with the name '" + sHandlerName + "' could not be found. Loading default handler for this handler name."); // m_colHanderList.Add(sHandlerName, new WindowsEventHandler()); // break; //} } catch (Exception exp) { if (!EventLog.SourceExists(m_sAppName)) { EventLog.CreateEventSource(m_sAppName, "Application"); } EventLog oEventLog = new EventLog(); oEventLog.Source = m_sAppName; oEventLog.WriteEntry("Error loading handler: " + exp.Message, EventLogEntryType.Error, 0); if (exp.InnerException != null) { oEventLog.WriteEntry("Error loading handler (inner exception):" + exp.InnerException.Message, EventLogEntryType.Error, 0); } //while (exp.InnerException != null) //{ // exp = exp.InnerException; // oEventLog.WriteEntry("Error loading handler (inner exception):" + exp.Message, EventLogEntryType.Error, 0); //} oEventLog.Close(); } }