internal void Dispatch(EventBase evt, [NotNull] IPanel panel, DispatchMode dispatchMode) { evt.MarkReceivedByDispatcher(); if (evt.eventTypeId == IMGUIEvent.TypeId()) { Event e = evt.imguiEvent; if (e.rawType == EventType.Repaint) { return; } } if (dispatchImmediately || (dispatchMode == DispatchMode.Immediate)) { ProcessEvent(evt, panel); } else { evt.Acquire(); m_Queue.Enqueue(new EventRecord { m_Event = evt, m_Panel = panel, m_StackTrace = panel is BaseVisualElementPanel p && p.panelDebug != null && p.panelDebug.hasAttachedDebuggers ? new StackTrace() : null });
internal void Dispatch(EventBase evt, IPanel panel, DispatchMode dispatchMode) { evt.MarkReceivedByDispatcher(); bool flag = evt.eventTypeId == EventBase <IMGUIEvent> .TypeId(); if (flag) { Event imguiEvent = evt.imguiEvent; bool flag2 = imguiEvent.rawType == EventType.Repaint; if (flag2) { return; } } bool flag3 = this.dispatchImmediately || dispatchMode == DispatchMode.Immediate; if (flag3) { this.ProcessEvent(evt, panel); } else { evt.Acquire(); this.m_Queue.Enqueue(new EventDispatcher.EventRecord { m_Event = evt, m_Panel = panel }); } }
static public void OnBroadcasting(string eventType, DispatchMode mode) { if (mode == DispatchMode.RequireListener && !eventTable.ContainsKey(eventType)) { throw new DispatcherInternal.BroadcastException(string.Format("Broadcasting message {0} but no listener found.", eventType)); } }
public static NatCamDispatch Prepare(DispatchMode Mode, MonoBehaviour TimesliceProvider = null, int Rate = 15) { NatCamDispatch dispatch = new NatCamDispatch { mode = Mode, mainThread = Thread.CurrentThread, timesliceProvider = TimesliceProvider, invocation = new Queue(), update = new Queue(), execution = new Queue(), running = true }; dispatch.workerThread = Mode == DispatchMode.Asynchronous ? new Thread(() => dispatch.Routine <Camera>(dispatch.Update, Rate)) : null; dispatch.targetThread = Mode == DispatchMode.Asynchronous ? dispatch.workerThread : dispatch.mainThread; if (Mode == DispatchMode.Synchronous) { if (dispatch.timesliceProvider) { dispatch.routine = Routine <Camera>(dispatch.Update, new WaitForEndOfFrame()).Invoke(dispatch.timesliceProvider); } else { Camera.onPostRender += dispatch.Update; } } else { dispatch.workerThread.Start(); } Debug.Log("NatCam: Initialized " + Mode + " Dispatcher"); return(dispatch); }
public RedPacketGrabActivity(int redPacketCount, decimal totalAmount, DispatchMode dispatchMode, string message) { this.RedPacketCount = redPacketCount; this.TotalAmount = totalAmount; this.Mode = DispatchMode.Fixed; this.Message = message; }
internal void Dispatch(EventBase evt, [NotNull] IPanel panel, DispatchMode dispatchMode) { evt.MarkReceivedByDispatcher(); if (evt.eventTypeId == IMGUIEvent.TypeId()) { Event e = evt.imguiEvent; if (e.rawType == EventType.Repaint) { return; } } if (dispatchImmediately || (dispatchMode == DispatchMode.Immediate)) { ProcessEvent(evt, panel); } else { evt.Acquire(); m_Queue.Enqueue(new EventRecord { m_Event = evt, m_Panel = panel }); } }
public static void Subscribe <TIntegrationEventHandler, TIntegrationEvent>(DispatchMode broadcastMode = DispatchMode.Unicast, string groupName = null) where TIntegrationEvent : IntegrationEvent where TIntegrationEventHandler : IEventHandler <TIntegrationEvent> { var descriptor = PrepareDescriptor <TIntegrationEventHandler, TIntegrationEvent>(broadcastMode, groupName); consumerExecutorDescriptors.Add(descriptor); }
internal void Blur(Focusable focusable, bool bIsFocusDelegated = false, DispatchMode dispatchMode = DispatchMode.Default) { var ownsFocus = m_PendingFocusCount > 0 ? IsPendingFocus(focusable) : IsFocused(focusable); if (ownsFocus) { SwitchFocus(null, bIsFocusDelegated, dispatchMode); } }
internal void SendEvent(EventBase e, DispatchMode dispatchMode = DispatchMode.Default) { UnityEngine.Debug.Assert(this.dispatcher != null); EventDispatcher expr_16 = this.dispatcher; if (expr_16 != null) { expr_16.Dispatch(e, this, dispatchMode); } }
public static MemoryList Create(int size, DispatchMode mode) { switch (mode) { case DispatchMode.FIFO: return(new FIFOMemoryList(size)); case DispatchMode.LRU: return(new LRUMemoryList(size)); case DispatchMode.OPT: return(new OPTMemoryList(size)); default: throw new ArgumentException(); } }
/// <summary> /// 使用给定指令序列和内存块数进行制定模式的测试 /// </summary> /// <param name="mc">内存块数</param> /// <param name="cmd">指令序列</param> /// <param name="mode">调度模式</param> /// <returns>缺页率</returns> public static double RunTest(int mc, int[] cmd, DispatchMode mode) { List <PageItem> table = new List <PageItem>(); //页表 MemoryList memory = MemoryListFactory.Create(mc, mode); //初始化内存和调度模式 for (int i = 0; i < cmd.Length / 10; i++) { table.Add(new PageItem() { Page = i }); } var accCount = 0; //命中次数 var failCount = 0; //缺页次数 for (int i = 0; i < cmd.Length; i++) { var next = table[cmd[i] / 10]; if (next.InMemory) { //指令在内存中,命中 accCount++; if (mode == DispatchMode.LRU) { //若使用LRU调度模式,清空内存驻留时间 var mem = memory.GetMemByPage(next.Page); mem.Time = 0; } } else { //指令不在内存中,缺页中断,调页 failCount++; MemBlock mem = null; //可用内存单元 int? dis = null; //移出页页号 mem = memory.GetMem(out dis, cmd, i); next.InMemory = true; mem.Page = next.Page; //目标页进入内存 mem.Time = 0; //清空内存驻留时间 if (dis != null) { //若有页被调出,将其在页表中的标志位设置false table[(int)dis].InMemory = false; } } memory.Refresh(); //刷新内存状态 #if DEBUG Console.WriteLine("当前指令 -> {0}", cmd[i]); memory.Show(); #endif } return(failCount * 100.0 / (failCount + accCount)); }
public DelegateHandler(Action <object, IServiceLocator> fullAction, object key, DispatchMode mode, IReadOnlyCollection <Type> messageTypes) { if (messageTypes.Count == 0) { throw new Exception("Empty list of subscribed messages for delegate handler. Should be at least one message."); } _fullAction = fullAction ?? throw new ArgumentNullException(nameof(fullAction)); _messageTypes = new List <Type>(messageTypes); _dispatchMode = mode; // If key wasn't specified, use delegate instance as key. _key = key ?? fullAction; }
public DelegateHandler(Action<Object, IServiceLocator> fullAction, Object key, DispatchMode mode, Type[] messageTypes) { if (fullAction == null) throw new ArgumentNullException("fullAction"); if (messageTypes.Length == 0) throw new Exception("Empty list of subscribed messages for delegate handler. Should be at least one message."); _fullAction = fullAction; _messageTypes = new List<Type>(messageTypes); _dispatchMode = mode; // If key wasn't specified, use delegate instance as key. _key = key ?? fullAction; }
static public void Broadcast(string eventType, DispatchMode mode) { DispatcherInternal.OnBroadcasting(eventType, mode); Delegate d; if (eventTable.TryGetValue(eventType, out d)) { Callback callback = d as Callback; if (callback != null) { callback(); } else { throw DispatcherInternal.CreateBroadcastSignatureException(eventType); } } }
public DelegateHandler(Action <Object, IServiceLocator> fullAction, Object key, DispatchMode mode, Type[] messageTypes) { if (fullAction == null) { throw new ArgumentNullException("fullAction"); } if (messageTypes.Length == 0) { throw new Exception("Empty list of subscribed messages for delegate handler. Should be at least one message."); } _fullAction = fullAction; _messageTypes = new List <Type>(messageTypes); _dispatchMode = mode; // If key wasn't specified, use delegate instance as key. _key = key ?? fullAction; }
public void Should_choose_correct_message_dispatcher_when_build_cluster(DispatchMode dispatchMode) { // arrange config.DispatchMode = dispatchMode; config.StorageAccounts = new List <StorageAccountConfig>() { new StorageAccountConfig() { ConnectionString = "conn", Queues = new List <QueueConfig>() { new QueueConfig { Name = "queue1" }, new QueueConfig { Name = "queue2" } } } }; // act var actual = builder.Build(); }
private static ConsumerExecutorDescriptor PrepareDescriptor <TIntegrationEventHandler, TIntegrationEvent>(DispatchMode broadcastMode, string groupName) where TIntegrationEventHandler : IEventHandler <TIntegrationEvent> where TIntegrationEvent : IntegrationEvent { var consExecDesc = new ConsumerExecutorDescriptor(); consExecDesc.ServiceTypeInfo = typeof(IEventHandler <TIntegrationEvent>).GetTypeInfo(); consExecDesc.MethodInfo = typeof(TIntegrationEventHandler).GetMethod("HandleAsync"); consExecDesc.ImplTypeInfo = typeof(TIntegrationEventHandler).GetTypeInfo(); consExecDesc.Attribute = new CapSubscribeAttribute(typeof(TIntegrationEvent).FullName); if (broadcastMode == DispatchMode.Broadcast && string.IsNullOrEmpty(groupName) == false) { consExecDesc.Attribute.Group = $"{typeof(TIntegrationEvent).FullName}-{groupName}"; } else { consExecDesc.Attribute.Group = typeof(TIntegrationEvent).FullName; } consExecDesc.MethodInfo.GetParameters() .Select(parameter => new ParameterDescriptor { Name = parameter.Name, ParameterType = parameter.ParameterType, }) .ToList() .ForEach(pDesc => consExecDesc.Parameters = new List <ParameterDescriptor> { pDesc }); return(consExecDesc); }
internal void SendEvent(EventBase e, DispatchMode dispatchMode = DispatchMode.Queued) { Debug.Assert(dispatcher != null); dispatcher?.Dispatch(e, this, dispatchMode); }
void AboutToGrabFocus(Focusable focusable, Focusable willTakeFocusFrom, FocusChangeDirection direction, DispatchMode dispatchMode) { using (FocusInEvent e = FocusInEvent.GetPooled(focusable, willTakeFocusFrom, direction, this)) { focusable.SendEvent(e, dispatchMode); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - // 3. Generic registration (Action with IServiceLocator) // - - - - - - - - - - - - - - - - - - - - - - - - - - - /// <summary> /// Register named delegate that subscribed to single message TMessage with specified DispatchMode. /// </summary> /// <typeparam name="TMessage">Message type this handler subscribed to</typeparam> /// <param name="action">Delegate instance</param> public static DispatcherConfiguration RegisterHandler <TMessage>(this DispatcherConfiguration configuration, Action <TMessage> action, String uniqueName = null, DispatchMode dispatchMode = DispatchMode.InterfaceDescendants) { return(RegisterHandler(configuration, m => action((TMessage)m), uniqueName, dispatchMode, new[] { typeof(TMessage) })); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - // 1. General registration (Action without IServiceLocator) // - - - - - - - - - - - - - - - - - - - - - - - - - - - /// <summary> /// Register named general delegate <see cref="Action{Object}"/> subscribed on list of messages, with specified DispatchMode /// </summary> /// <param name="action">Delegate instance</param> /// <param name="uniqueName">Unique name that can be used to identify this handler</param> /// <param name="mode">Dispatching mode. Default value is DispatchMode.InterfaceDescendants</param> /// <param name="messageTypes">List of message types this handler subscribed on</param> public static DispatcherConfiguration RegisterHandler(this DispatcherConfiguration configuration, Action <Object> action, String uniqueName, DispatchMode mode, params Type[] messageTypes) { IHandler handler = new DelegateHandler(action, uniqueName, mode, messageTypes); configuration.Builder.Register(handler); return(configuration); }
/// <summary> /// Register handler that subscribed to three messages. /// </summary> /// <typeparam name="TMessage1">First message type this handler subscribed to</typeparam> /// <typeparam name="TMessage2">Second message type this handler subscribed to</typeparam> /// <typeparam name="TMessage3">Third message type this handler subscribed to</typeparam> /// <param name="action">Delegate instance</param> public static DispatcherConfiguration RegisterHandler <TMessage1, TMessage2, TMessage3>(this DispatcherConfiguration configuration, Action <Object, IServiceLocator> action, String uniqueName = null, DispatchMode dispatchMode = DispatchMode.InterfaceDescendants) { return(RegisterHandler(configuration, action, uniqueName, dispatchMode, new[] { typeof(TMessage1), typeof(TMessage2), typeof(TMessage3) })); }
internal abstract void SendEvent(EventBase e, DispatchMode dispatchMode);
void ReleaseFocus(Focusable focusable, Focusable willGiveFocusTo, FocusChangeDirection direction, DispatchMode dispatchMode) { using (BlurEvent e = BlurEvent.GetPooled(focusable, willGiveFocusTo, direction, this)) { focusable.SendEvent(e, dispatchMode); } }
public MessageInvoker(DispatchMode mode, Type messageTYpe, IEventHandler handler) { Mode = mode; MessageType = messageTYpe; Handler = handler; }
internal static IServiceCollection SubscribeEventBus <TIntegrationEventHandler, TIntegrationEvent>(this IServiceCollection services, DispatchMode broadcastMode = DispatchMode.Unicast, string groupName = null) where TIntegrationEventHandler : IEventHandler <TIntegrationEvent> where TIntegrationEvent : IntegrationEvent { services.AddScoped(typeof(IEventHandler <TIntegrationEvent>), typeof(TIntegrationEventHandler)); EventBusConsumerServiceSelector.Subscribe <TIntegrationEventHandler, TIntegrationEvent>(broadcastMode, groupName); return(services); }
internal void SwitchFocus(Focusable newFocusedElement, bool bIsFocusDelegated = false, DispatchMode dispatchMode = DispatchMode.Default) { SwitchFocus(newFocusedElement, FocusChangeDirection.unspecified, bIsFocusDelegated, dispatchMode); }
void GrabFocus(Focusable focusable, Focusable willTakeFocusFrom, FocusChangeDirection direction, bool bIsFocusDelegated, DispatchMode dispatchMode) { using (FocusEvent e = FocusEvent.GetPooled(focusable, willTakeFocusFrom, direction, this, bIsFocusDelegated)) { focusable.SendEvent(e, dispatchMode); } }
internal void SwitchFocus(Focusable newFocusedElement, FocusChangeDirection direction, bool bIsFocusDelegated = false, DispatchMode dispatchMode = DispatchMode.Default) { m_LastFocusedElement = newFocusedElement; var oldFocusedElement = m_PendingFocusCount > 0 ? m_LastPendingFocusedElement : GetLeafFocusedElement(); if (oldFocusedElement == newFocusedElement) { return; } if (newFocusedElement == null || !newFocusedElement.canGrabFocus) { if (oldFocusedElement != null) { m_LastPendingFocusedElement = null; m_PendingFocusCount++; // ReleaseFocus will always trigger DoFocusChange AboutToReleaseFocus(oldFocusedElement, null, direction, dispatchMode); ReleaseFocus(oldFocusedElement, null, direction, dispatchMode); } } else if (newFocusedElement != oldFocusedElement) { // Retarget event.relatedTarget so it is in the same tree as event.target. var retargetedNewFocusedElement = (newFocusedElement as VisualElement)?.RetargetElement(oldFocusedElement as VisualElement) ?? newFocusedElement; var retargetedOldFocusedElement = (oldFocusedElement as VisualElement)?.RetargetElement(newFocusedElement as VisualElement) ?? oldFocusedElement; m_LastPendingFocusedElement = newFocusedElement; m_PendingFocusCount++; // GrabFocus will always trigger DoFocusChange, but ReleaseFocus won't if (oldFocusedElement != null) { AboutToReleaseFocus(oldFocusedElement, retargetedNewFocusedElement, direction, dispatchMode); } AboutToGrabFocus(newFocusedElement, retargetedOldFocusedElement, direction, dispatchMode); if (oldFocusedElement != null) { // Since retargetedNewFocusedElement != null, so ReleaseFocus will not trigger DoFocusChange ReleaseFocus(oldFocusedElement, retargetedNewFocusedElement, direction, dispatchMode); } GrabFocus(newFocusedElement, retargetedOldFocusedElement, direction, bIsFocusDelegated, dispatchMode); } }
public RedPacketGrabActivity(int redPacketCount, decimal totalAmount, DispatchMode dispatchMode) : this(redPacketCount, totalAmount, dispatchMode, string.Empty) { }