private int CreateEntity(IHandlerEntryEntity entity) { int newid = -1; using (var ctx = new HappyDogShowContext()) { DogRegistration selectedDog = ctx.DogRegistrations.Where(i => i.ID == entity.Dog.Id).First(); DogShow selectedShow = ctx.DogShows.Where(i => i.ID == entity.DogShow.Id).First(); HandlerClass selectedClass = ctx.HandlerClasses.Where(i => i.ID == entity.Class.Id).First(); HandlerRegistration selectedHander = ctx.HandlerRegistrations.Where(i => i.ID == entity.Handler.Id).First(); HandlerEntry newEntity = new HandlerEntry() { Dog = selectedDog, Show = selectedShow, EnteredClass = selectedClass, Handler = selectedHander }; ctx.HandlerEntries.Add(newEntity); ctx.SaveChanges(); newid = newEntity.ID; } return(newid); }
public async override void Prepare() { DogShowList = await _dogShowService.GetDogShowListAsync <DogShowDetail>(); var data = await _dogRegistrationService.GetListAsync <DogRegistrationDetail>(); var orderedData = from d in data orderby d.RegisrationNumber ascending select d; DogRegistrations = orderedData.ToList(); HandlerClasses = await _handlerClassService.GetHandlerClassListAsync <HandlerClassEntity>(); CurrentEntity = new MultipleHandlerEntry(); foreach (IDogShowEntity dogShow in DogShowList) { HandlerEntry newEntry = new HandlerEntry(); newEntry.DogShow = dogShow; newEntry.Handler = SelectedHandlerRegistration; (CurrentEntity as MultipleHandlerEntry).HandlerEntries.Add(newEntry); (CurrentEntity as MultipleHandlerEntry).NotifyEntriesChanged(); } }
private void UpdateEntity(IHandlerEntryEntity entity) { using (var ctx = new HappyDogShowContext()) { HandlerEntry foundEntity = ctx.HandlerEntries.Where(d => d.ID == entity.Id).First(); if (foundEntity != null) { if (entity.Dog != null) { DogRegistration selectedDog = ctx.DogRegistrations.Where(i => i.ID == entity.Dog.Id).First(); foundEntity.Dog = selectedDog; } if (entity.DogShow != null) { DogShow selectedShow = ctx.DogShows.Where(i => i.ID == entity.DogShow.Id).First(); foundEntity.Show = selectedShow; } if (entity.Class != null) { HandlerClass selectedClass = ctx.HandlerClasses.Where(i => i.ID == entity.Class.Id).First(); foundEntity.EnteredClass = selectedClass; } foundEntity.Number = entity.Number; ctx.SaveChanges(); } } }
public async override void Prepare() { CurrentEntity = new HandlerEntry() { Id = data.Id, Handler = SelectedHandlerRegistration, Number = data.EntryNumber }; SelectedHandlerRegistration = await _handlerRegistrationService.GetHandlerRegistrationAsync <HandlerRegistrationDetail>(data.HandlerId); DogShowList = await _dogShowService.GetDogShowListAsync <DogShowDetail>(); var rawdata = await _dogRegistrationService.GetListAsync <DogRegistrationDetail>(); var orderedData = from d in rawdata orderby d.RegisrationNumber ascending select d; DogRegistrations = orderedData.ToList(); HandlerClasses = await _handlerClassService.GetHandlerClassListAsync <HandlerClassEntity>(); SelectedDogShow = DogShowList.Where(d => d.Id == data.ShowId).First(); SelectedDogRegistration = DogRegistrations.Where(d => d.Id == data.DogId).First(); SelectedHandlerClass = HandlerClasses.Where(d => d.Name == data.EnteredClassName).First(); }
public void PushHandler(object handler) { this.handlerHead = new HandlerEntry(handler, this.handlerHead); this.lastHandlerType = handler.GetType(); this.lastHandler = this.handlerHead.handler; this.OnEventHandlerChanged(EventArgs.Empty); }
public void PathParam_AsString_Equal(string path, string paramName, string requestPath, string result) { var entry = new HandlerEntry("GET", path, true, null); var ctx = Server.GetContext(client => client.GetAsync(requestPath)); ctx = ContextUtil.Update(ctx, entry); Assert.Equal(result, ctx.PathParam(paramName)); }
public void PathParam_AsInt_Equal(int id) { var entry = new HandlerEntry("GET", "/:id", true, null); var ctx = Server.GetContext(client => client.GetAsync($"/{id}")); ctx = ContextUtil.Update(ctx, entry); Assert.Equal(id, ctx.PathParam <int>("id")); }
public void PathParam_AsFloat_Equal(int temperature) { var entry = new HandlerEntry("GET", "/:temperature", true, null); var ctx = Server.GetContext(client => client.GetAsync($"/{temperature}")); ctx = ContextUtil.Update(ctx, entry); Assert.Equal(temperature, ctx.PathParam <float>("temperature")); }
public void PathParam_AsInt_Throws() { var entry = new HandlerEntry("GET", "/:id", true, null); var ctx = Server.GetContext(client => client.GetAsync($"/foo")); ctx = ContextUtil.Update(ctx, entry); Assert.Throws <BadRequestException>(() => ctx.PathParam <int>("id")); }
public void AddHandler(Type type, string property) { var entry = new HandlerEntry() { BaseType = type, Property = property }; handlers.Add(type, entry); }
public void AddHandler(Type type, LocalizationHandlerProc handler) { var entry = new HandlerEntry() { BaseType = type, Handler = handler }; handlers.Add(type, entry); }
public HandlerEntry Add(Func <T, Task <bool> > handler) { var entry = new HandlerEntry { Handler = handler }; _handlers.Add(entry); return(entry); }
public void Add(short opCode, PacketHandlerType handler, bool requireLogin = true) { var entry = new HandlerEntry() { RequireLogin = requireLogin, Handler = handler }; m_handlers.Add(opCode, entry); }
private void DeleteEntity(IEntityWithID entity) { using (var ctx = new HappyDogShowContext()) { HandlerEntry foundEntity = ctx.HandlerEntries.Where(d => d.ID == entity.Id).First(); if (foundEntity != null) { ctx.HandlerEntries.Remove(foundEntity); ctx.SaveChanges(); } } }
public void PopHandler(object handler) { for (HandlerEntry entry = this.handlerHead; entry != null; entry = entry.next) { if (entry.handler == handler) { this.handlerHead = entry.next; this.lastHandler = null; this.lastHandlerType = null; this.OnEventHandlerChanged(EventArgs.Empty); return; } } }
/// <include file='doc\EventHandlerService.uex' path='docs/doc[@for="EventHandlerService.PopHandler"]/*' /> /// <devdoc> /// <para> /// Pops /// the given handler off of the stack.</para> /// </devdoc> public void PopHandler(object handler) { for (HandlerEntry entry = handlerHead; entry != null; entry = entry.next) { if (entry.handler == handler) { handlerHead = entry.next; lastHandler = null; lastHandlerType = null; OnEventHandlerChanged(EventArgs.Empty); break; } } }
private HandlerEntry CreateStack() { var item1 = new HandlerEntry(new Button { Text = "I'm a button" }, null); var handler = new TextBox { Text = "I'm a textbox" }; var item2 = new HandlerEntry(handler, item1); var item3 = new HandlerEntry(new Label { Text = "I'm a label" }, item2); return(item3); }
private IHandlerEntryEntity GetEntity <T>(int id) where T : IHandlerEntryEntity, new() { IHandlerEntryEntity result = new T(); using (var ctx = new HappyDogShowContext()) { HandlerEntry foundEntry = ctx.HandlerEntries.Where(i => i.ID == id).Include(b => b.Show).First(); if (foundEntry != null) { result.Id = foundEntry.ID; result.Number = foundEntry.Number; } } return(result); }
public object GetHandler(System.Type handlerType) { if (handlerType == this.lastHandlerType) { return(this.lastHandler); } for (HandlerEntry entry = this.handlerHead; entry != null; entry = entry.next) { if ((entry.handler != null) && handlerType.IsInstanceOfType(entry.handler)) { this.lastHandlerType = handlerType; this.lastHandler = entry.handler; return(entry.handler); } } return(null); }
/// <summary> /// Removes dead entries from the handler list. /// You normally do not need to invoke this method manually, as dead entry removal runs automatically as part of the /// normal operation of the FastSmartWeakEvent. /// </summary> public void RemoveDeadEntries() { Delegate raiseDelegate = this.GetRaiseDelegateInternal(); if (raiseDelegate == null) { return; } foreach (Delegate d in raiseDelegate.GetInvocationList()) { HandlerEntry wd = d.Target as HandlerEntry; if (wd != null && wd.TargetInstance == null) { this.RemoveFromRaiseDelegate(d); } } }
/// <include file='doc\EventHandlerService.uex' path='docs/doc[@for="EventHandlerService.GetHandler"]/*' /> /// <devdoc> /// <para> /// Gets the currently active event handler of the specified type.</para> /// </devdoc> public object GetHandler(Type handlerType) { if (handlerType == lastHandlerType) { return(lastHandler); } for (HandlerEntry entry = handlerHead; entry != null; entry = entry.next) { if (entry.handler != null && handlerType.IsInstanceOfType(entry.handler)) { lastHandlerType = handlerType; lastHandler = entry.handler; return(entry.handler); } } return(null); }
public void Remove(T eh) { if (eh == null) { return; } Delegate d = (Delegate)(object)eh; object targetInstance = d.Target; if (targetInstance == null) { // delegate to static method: use directly without wrapping delegate this.RemoveFromRaiseDelegate(d); return; } MethodInfo targetMethod = d.Method; // Find+Remove the last copy of a delegate pointing to targetInstance/targetMethod Delegate raiseDelegate = this.GetRaiseDelegateInternal(); if (raiseDelegate == null) { return; } Delegate[] invocationList = raiseDelegate.GetInvocationList(); for (int i = invocationList.Length - 1; i >= 0; i--) { Delegate wrappingDelegate = invocationList[i]; HandlerEntry weakDelegate = wrappingDelegate.Target as HandlerEntry; if (weakDelegate == null) { continue; } object target = weakDelegate.TargetInstance; if (target == null) { this.RemoveFromRaiseDelegate(wrappingDelegate); } else if (target == targetInstance && weakDelegate.TargetMethod == targetMethod) { this.RemoveFromRaiseDelegate(wrappingDelegate); break; } } }
public void PopHandler_should_pop_if_handler_found_on_stack() { var service = new EventHandlerService(null); service.GetTestAccessor().LastHandlerType = typeof(Button); var stackHead = CreateStack(); var handler = stackHead.next.handler; service.GetTestAccessor().HandlerHead = stackHead; service.PopHandler(handler); var depth = 0; for (HandlerEntry entry = service.GetTestAccessor().HandlerHead; entry != null; entry = entry.next) { depth++; } Assert.Equal(1, depth); }
#pragma warning restore 420 public void Add(T eh) { if (eh != null) { RemoveDeadEntries(); object targetInstance = eh.Target; if (targetInstance == null || eh.Method.IsStatic) { // delegate to static method: use directly without wrapping delegate AddToRaiseDelegate(eh); } else { MethodInfo targetMethod = eh.Method; var wd = new HandlerEntry(this, targetInstance, targetMethod); var dynamicMethod = GetInvoker(targetMethod); wd.WrappingDelegate = dynamicMethod.CreateDelegate(typeof(T), wd); AddToRaiseDelegate(wd.WrappingDelegate); } } }
public async Task <T> WaitFor(Func <T, bool> predicate, Duration?timeout = null, CancellationToken ct = default) { var timeoutTask = Task.Delay(timeout?.ToTimeSpan() ?? TimeSpan.FromMilliseconds(-1), ct); var tcs = new TaskCompletionSource <T>(); Task <bool> Handler(T e) { var matches = predicate(e); if (matches) { tcs.SetResult(e); } return(Task.FromResult(matches)); } var entry = new HandlerEntry { Handler = Handler }; _handlers.Add(entry); // Wait for either the event task or the timeout task // If the timeout task finishes first, raise, otherwise pass event through try { var theTask = await Task.WhenAny(timeoutTask, tcs.Task); if (theTask == timeoutTask) { throw new TimeoutException(); } } finally { entry.Remove(); } return(await tcs.Task); }
#pragma warning restore 420 public void Add(T eh) { if (eh != null) { Delegate d = (Delegate)(object)eh; this.RemoveDeadEntries(); object targetInstance = d.Target; if (targetInstance != null) { MethodInfo targetMethod = d.Method; HandlerEntry wd = new HandlerEntry(this, targetInstance, targetMethod); DynamicMethod dynamicMethod = GetInvoker(targetMethod); wd.WrappingDelegate = dynamicMethod.CreateDelegate(typeof(T), wd); this.AddToRaiseDelegate(wd.WrappingDelegate); } else { // delegate to static method: use directly without wrapping delegate this.AddToRaiseDelegate(d); } } }
public void PopHandler_should_not_pop_if_handler_not_found_on_stack() { // we expect to hit Debug.Assert and unless we clear listeners we will crash to xUnit runner: // "The active test run was aborted. Reason: Test host process crashed : Assertion Failed" using (new TraceListenerlessContext()) { var service = new EventHandlerService(null); service.GetTestAccessor().LastHandlerType = typeof(Button); var stackHead = CreateStack(); service.GetTestAccessor().HandlerHead = stackHead; service.PopHandler(typeof(ComboBox)); var depth = 0; for (HandlerEntry entry = service.GetTestAccessor().HandlerHead; entry != null; entry = entry.next) { depth++; } Assert.Equal(3, depth); } }
internal static Context Update(Context ctx, HandlerEntry entry) { ctx.PathParamDict = entry.ExtractPathParams(ctx.Path()); ctx.Renderer = new BemolRenderer(entry.Config); return(ctx); }
/// <include file='doc\EventHandlerService.uex' path='docs/doc[@for="EventHandlerService.PushHandler"]/*' /> /// <devdoc> /// <para>Pushes a new event handler on the stack.</para> /// </devdoc> public void PushHandler(object handler) { handlerHead = new HandlerEntry(handler, handlerHead); OnEventHandlerChanged(EventArgs.Empty); }
/// <include file='doc\EventHandlerService.uex' path='docs/doc[@for="EventHandlerService.HandlerEntry.HandlerEntry"]/*' /> /// <devdoc> /// Creates a new handler entry objet. /// </devdoc> public HandlerEntry(object handler, HandlerEntry next) { this.handler = handler; this.next = next; }