protected override void Execute(CodeActivityContext context) { IEnumerable <DpcHandle> dpchandles; DpcHandle currentDPC = new DpcHandle(); bool ishighimportancedpc; bool dpclocked = false; DateTime currentdatetimeutc = DateTime.UtcNow; using (DispatchEngineContainer dec = new DispatchEngineContainer()) { ishighimportancedpc = dec.DpcQueue.Any(dpc => dpc.Importance == Importance.High); if (ishighimportancedpc) { dpchandles = dec.DpcQueue.Where(dpc => dpc.Importance == Importance.High).ToArray(); } else { dpchandles = dec.DpcQueue.ToArray(); } foreach (var dpc in dpchandles) { dpc.TimeStamp = currentdatetimeutc; try { dec.SaveChanges(); dec.Entry(dpc).Reload(); currentDPC = dpc; dpclocked = true; } catch (DbUpdateConcurrencyException ex) { // TODO: log exception & increment counter } if (dpclocked) { break; } } } if (dpclocked) { if (ishighimportancedpc) { Dispatcher.PlanSchedulingPool(currentDPC); } else { Dispatcher.RunDispatch(currentDPC); } } }
protected override void Execute(CodeActivityContext context) { IEnumerable <IrqHandle> interrupts; IrqHandle currentIRQ = new IrqHandle(); bool isdispatchirq = false; bool irqlocked = false; DateTime currentdatetimeutc = DateTime.UtcNow; using (DispatchEngineContainer dec = new DispatchEngineContainer()) { isdispatchirq = dec.IrqQueue.Any(i => i.Level == IRQL.Dispatch); if (isdispatchirq) { interrupts = dec.IrqQueue.Where(irq => irq.Level == IRQL.Dispatch).ToArray(); } else { interrupts = dec.IrqQueue.ToArray(); } foreach (var irqhandle in interrupts) { irqhandle.TimeStamp = currentdatetimeutc; try { dec.SaveChanges(); dec.Entry(irqhandle).Reload(); currentIRQ = irqhandle; irqlocked = true; } catch (DbUpdateConcurrencyException ex) { // TODO: log exception & increment counter } if (irqlocked) { break; } } } if (irqlocked) { if (isdispatchirq) { Dispatch dispatch; bool isdispatchcallback; bool isdispatchready; using (DispatchEngineContainer dec = new DispatchEngineContainer()) { dispatch = dec.Dispatches.Single(d => d.Id == currentIRQ.DispatchID); isdispatchcallback = DispatchStatus.Callback == dispatch.StatusID; // we should check status pending to prevent completed/failed from running again isdispatchready = currentdatetimeutc > dispatch.StartDateTimeUtc && DispatchStatus.Pending == dispatch.StatusID; } if (isdispatchcallback) { Dispatcher.RelocateCallbackDispatch(currentIRQ); } else if (isdispatchready) { Dispatcher.MarkDispatchReady(currentIRQ); } else { Dispatcher.SweepSchedulingPool(currentIRQ); } } else { Schedule schedule = null; bool isscheduleadded; using (DispatchEngineContainer dec = new DispatchEngineContainer()) { try { schedule = dec.Schedules.Single(s => s.Id == currentIRQ.ScheduleID); } catch { // TODO: log exception & increment counter } isscheduleadded = !dec.SchedulingPool.Any(s => s.ScheduleID == currentIRQ.ScheduleID); } if (schedule != null) { if (isscheduleadded) { Dispatcher.MarkNewSchedule(currentIRQ); } else { Dispatcher.SweepSchedulingPool(currentIRQ); } } else { // bug fix to handle interrupts for schedules that has been deleted using (DispatchEngineContainer dec = new DispatchEngineContainer()) { // remove current interrupt dec.IrqQueue.Attach(currentIRQ); dec.IrqQueue.Remove(currentIRQ); dec.SaveChanges(); } } } } }