private void deleteServiceFromScheduleBtn_Click(object sender, EventArgs e) { try { DialogResult result = MessageBox.Show("Are you sure you want to Delete service from schedule?", "Delete Service", MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.Yes) { foreach (DataGridViewRow row in scheduleInfoGrid.SelectedRows) { var scheduleData = from s in _scheduledServices where s.Key.GetHashCode() == Convert.ToInt32(row.Cells["shceduledID"].Value) select s.Key; if (_scheduledServices[scheduleData.First()].LegacyInstance.State == Easynet.Edge.Core.Services.ServiceState.Uninitialized) { SchedulingData schedulingDate = scheduleData.First(); _scheduler.DeleteScpecificServiceInstance(schedulingDate); row.Cells["deleted"].Value = true; row.DefaultCellStyle.BackColor = GetColorByState(legacy.ServiceState.Aborting, legacy.ServiceOutcome.Aborted, true); } else { MessageBox.Show(string.Format("You can't delete service instance with state {0}", _scheduledServices[scheduleData.First()].LegacyInstance.State)); } } //GetScheduleServices(); } } catch (Exception ex) { Easynet.Edge.Core.Utilities.Log.Write("SchedulingControlForm", ex.Message, ex, Easynet.Edge.Core.Utilities.LogMessageType.Error); } }
public override void ScheduleLocalNotification(NotificationData notification, SchedulingData schedule) { UIApplication.SharedApplication.InvokeOnMainThread(delegate { if (notification != null) { UILocalNotification localNotification = this.PrepareLocalNotification(notification); if (schedule != null) { localNotification.FireDate = IPhoneUtils.DateTimeToNSDate(DateTime.SpecifyKind(schedule.FireDate, DateTimeKind.Local)); SystemLogger.Log(SystemLogger.Module.PLATFORM, "Scheduling local notification at " + schedule.FireDate.ToLongTimeString() + ", with a repeat interval of: " + schedule.RepeatInterval); NSCalendarUnit repeatInterval = 0; // The default value is 0, which means don't repeat. if (schedule.RepeatInterval.Equals(RepeatInterval.HOURLY)) { repeatInterval = NSCalendarUnit.Hour; } else if (schedule.RepeatInterval.Equals(RepeatInterval.DAILY)) { repeatInterval = NSCalendarUnit.Day; } else if (schedule.RepeatInterval.Equals(RepeatInterval.WEEKLY)) { repeatInterval = NSCalendarUnit.Week; } else if (schedule.RepeatInterval.Equals(RepeatInterval.MONTHLY)) { repeatInterval = NSCalendarUnit.Month; } else if (schedule.RepeatInterval.Equals(RepeatInterval.YEARLY)) { repeatInterval = NSCalendarUnit.Year; } localNotification.RepeatInterval = repeatInterval; UIApplication.SharedApplication.ScheduleLocalNotification(localNotification); SystemLogger.Log(SystemLogger.Module.PLATFORM, "Local Notification scheduled successfully [" + localNotification.FireDate.ToString() + "]"); SystemLogger.Log(SystemLogger.Module.PLATFORM, "Current scheduled #num of local notifications: " + this.GetCurrentScheduledLocalNotifications()); } else { SystemLogger.Log(SystemLogger.Module.PLATFORM, "No suitable scheduling data object received for scheduling this local notification"); } } else { SystemLogger.Log(SystemLogger.Module.PLATFORM, "No suitable data object received for presenting local notification"); } }); }
public void SelectThreads() { ThreadReselectionRequested = false; for (int core = 0; core < CpuCoresCount; core++) { KThread thread = SchedulingData.ScheduledThreads(core).FirstOrDefault(); CoreContexts[core].SelectThread(thread); } for (int core = 0; core < CpuCoresCount; core++) { // If the core is not idle (there's already a thread running on it), // then we don't need to attempt load balancing. if (SchedulingData.ScheduledThreads(core).Any()) { continue; } int[] srcCoresHighestPrioThreads = new int[CpuCoresCount]; int srcCoresHighestPrioThreadsCount = 0; KThread dst = null; // Select candidate threads that could run on this core. // Give preference to threads that are not yet selected. foreach (KThread thread in SchedulingData.SuggestedThreads(core)) { if (thread.CurrentCore < 0 || thread != CoreContexts[thread.CurrentCore].SelectedThread) { dst = thread; break; } srcCoresHighestPrioThreads[srcCoresHighestPrioThreadsCount++] = thread.CurrentCore; } // Not yet selected candidate found. if (dst != null) { // Priorities < 2 are used for the kernel message dispatching // threads, we should skip load balancing entirely. if (dst.DynamicPriority >= 2) { SchedulingData.TransferToCore(dst.DynamicPriority, core, dst); CoreContexts[core].SelectThread(dst); } continue; } // All candidates are already selected, choose the best one // (the first one that doesn't make the source core idle if moved). for (int index = 0; index < srcCoresHighestPrioThreadsCount; index++) { int srcCore = srcCoresHighestPrioThreads[index]; KThread src = SchedulingData.ScheduledThreads(srcCore).ElementAtOrDefault(1); if (src != null) { // Run the second thread on the queue on the source core, // move the first one to the current core. KThread origSelectedCoreSrc = CoreContexts[srcCore].SelectedThread; CoreContexts[srcCore].SelectThread(src); SchedulingData.TransferToCore(origSelectedCoreSrc.DynamicPriority, core, origSelectedCoreSrc); CoreContexts[core].SelectThread(origSelectedCoreSrc); } } } }
private void PreemptThread(int prio, int core) { IEnumerable <KThread> scheduledThreads = SchedulingData.ScheduledThreads(core); KThread selectedThread = scheduledThreads.FirstOrDefault(x => x.DynamicPriority == prio); // Yield priority queue. if (selectedThread != null) { SchedulingData.Reschedule(prio, core, selectedThread); } IEnumerable <KThread> SuitableCandidates() { foreach (KThread thread in SchedulingData.SuggestedThreads(core)) { int srcCore = thread.CurrentCore; if (srcCore >= 0) { KThread highestPrioSrcCore = SchedulingData.ScheduledThreads(srcCore).FirstOrDefault(); if (highestPrioSrcCore != null && highestPrioSrcCore.DynamicPriority < 2) { break; } if (highestPrioSrcCore == thread) { continue; } } // If the candidate was scheduled after the current thread, then it's not worth it. if (selectedThread == null || selectedThread.LastScheduledTime >= thread.LastScheduledTime) { yield return(thread); } } } // Select candidate threads that could run on this core. // Only take into account threads that are not yet selected. KThread dst = SuitableCandidates().FirstOrDefault(x => x.DynamicPriority == prio); if (dst != null) { SchedulingData.TransferToCore(prio, core, dst); selectedThread = dst; } // If the priority of the currently selected thread is lower than preemption priority, // then allow threads with lower priorities to be selected aswell. if (selectedThread != null && selectedThread.DynamicPriority > prio) { Func <KThread, bool> predicate = x => x.DynamicPriority >= selectedThread.DynamicPriority; dst = SuitableCandidates().FirstOrDefault(predicate); if (dst != null) { SchedulingData.TransferToCore(dst.DynamicPriority, core, dst); } } ThreadReselectionRequested = true; }
private void PreemptThread(int Prio, int Core) { IEnumerable <KThread> ScheduledThreads = SchedulingData.ScheduledThreads(Core); KThread SelectedThread = ScheduledThreads.FirstOrDefault(x => x.DynamicPriority == Prio); //Yield priority queue. if (SelectedThread != null) { SchedulingData.Reschedule(Prio, Core, SelectedThread); } IEnumerable <KThread> SuitableCandidates() { foreach (KThread Thread in SchedulingData.SuggestedThreads(Core)) { int SrcCore = Thread.CurrentCore; if (SrcCore >= 0) { KThread HighestPrioSrcCore = SchedulingData.ScheduledThreads(SrcCore).FirstOrDefault(); if (HighestPrioSrcCore != null && HighestPrioSrcCore.DynamicPriority < 2) { break; } if (HighestPrioSrcCore == Thread) { continue; } } //If the candidate was scheduled after the current thread, then it's not worth it. if (SelectedThread == null || SelectedThread.LastScheduledTicks >= Thread.LastScheduledTicks) { yield return(Thread); } } } //Select candidate threads that could run on this core. //Only take into account threads that are not yet selected. KThread Dst = SuitableCandidates().FirstOrDefault(x => x.DynamicPriority == Prio); if (Dst != null) { SchedulingData.TransferToCore(Prio, Core, Dst); SelectedThread = Dst; } //If the priority of the currently selected thread is lower than preemption priority, //then allow threads with lower priorities to be selected aswell. if (SelectedThread != null && SelectedThread.DynamicPriority > Prio) { Func <KThread, bool> Predicate = x => x.DynamicPriority >= SelectedThread.DynamicPriority; Dst = SuitableCandidates().FirstOrDefault(Predicate); if (Dst != null) { SchedulingData.TransferToCore(Dst.DynamicPriority, Core, Dst); } } ThreadReselectionRequested = true; }