private bool QueryScheduledAction(SchedulerAction action, string msg) { string actionType = string.Empty; switch (action) { case SchedulerAction.Shutdown: actionType = Translator.Translate("TXT_SHUTDOWN_PC"); break; case SchedulerAction.StandBy: actionType = Translator.Translate("TXT_STANDBY_PC"); break; case SchedulerAction.Hibernate: actionType = Translator.Translate("TXT_HIBERNATE_PC"); break; case SchedulerAction.None: default: return false; } //RestoreWindowFromTray(); string info = Translator.Translate("TXT_PROCEED_SCHEDULED_ACTION", actionType, msg); TimerWaitingDialog dlg = new TimerWaitingDialog( "TXT_SCHEDULED_ACTION_PROCEED", info, 60 * ProTONEConfig.SchedulerWaitTimerProceed); DialogResult res = dlg.ShowDialog(); return (res == DialogResult.Yes); }
private void CheckForPlaylistEvent() { if (MediaRenderer.DefaultInstance.PlaylistAtEnd) { MediaRenderer.DefaultInstance.PlaylistAtEnd = false; if (!_isPlaylistEvent.WaitOne(50, true)) { _isPlaylistEvent.Set(); if (PlaylistEventEnabled) { SchedulerAction sat = (SchedulerAction)ProTONEConfig.PlaylistEventHandler; // Apply the language ID on the timer scheduler thread, // otherwise the translator will default to English Translator.SetInterfaceLanguage(AppConfig.LanguageID); string msg = Translator.Translate("TXT_PLAYLIST_END_MSG"); Logger.LogInfo("The playlist has reached the end. Action to execute: " + sat); PreProcessEvent(sat, msg); } } } else { _isPlaylistEvent.Reset(); } }
public void Reschedule(Threading.ISchedulableThread caller, SchedulerAction action) { var scheduler = threadScheduler; int min = scheduler[0].Count; int minId = 0; int max = scheduler[0].Count; int maxId = 0; for (int i = 0; i < scheduler.Length; i++) { var cnt = scheduler[i].Count; if (min > cnt) { min = cnt; minId = i; } else if (max <= cnt) { max = cnt; maxId = i; } } bestThread = scheduler[minId]; worstThread = scheduler[maxId]; }
async void SaveProjectBudgetLine(EmployeeSchedulerLocal proBudgetLine, SchedulerAction action) { busyIndicator.IsBusy = true; var result = ErrorCodes.NoSucces; switch (action) { case SchedulerAction.Delete: result = await api.Delete(proBudgetLine); break; case SchedulerAction.Insert: result = await api.Insert(proBudgetLine); break; case SchedulerAction.Modify: result = await api.Update(proBudgetLine); break; } busyIndicator.IsBusy = false; if (result != ErrorCodes.Succes) { UnicontaMessageBox.Show(result.ToString(), Uniconta.ClientTools.Localization.lookup("Error"), MessageBoxButton.OK); } }
public void Reschedule(ISchedulableThread owner, SchedulerAction action) { if (threadScheduler.IsBuilding == false) { //We need this lock as our underlying heap implementation //is not thread safe atm, in the future TODO: this will change //as we will move to other DS or use fine grained or lock free heaps. if (Monitor.TryEnter(locker)) { threadScheduler.IsBuilding = true; threadScheduler.Update(owner.SchedulableIndex, owner); Monitor.Exit(locker); threadScheduler.IsBuilding = false; } } }
private void PreProcessEvent(SchedulerAction action, string msg) { _action = action; _canProceed.Reset(); ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessEvent)); if (ProTONEConfig.SchedulerWaitTimerProceed > 0) { _action = SchedulerAction.None; if (action != SchedulerAction.None) { Logger.LogInfo("Asking the user how to continue with action: " + action); bool res = false; MainThread.Send(delegate(object x) { res = QueryScheduledAction(action, msg); }); if (res) { Logger.LogInfo("The user has chosen to continue with the action"); _action = action; } else { Logger.LogInfo("The user has chosen to abort the action"); } } } _canProceed.Set(); }
/// <summary> /// Atempts to rebuild the pririty queue, to contain correct information /// about priorities. /// </summary> /// <param name="threadPoolThread">boolean value idnicating that we want threads that /// were created in a threadpool.</param> internal static void Reschedule(bool threadPoolThread, ISchedulableThread @this, SchedulerAction action) { if (threadPoolThread) { //we don't need to lock this section as generally we are ok //with the race as it will not cause any errors but putting a simple //flag arround it should be enough to prevent most races. threadScheduler.Reschedule(@this, action); return; } artificialThreadScheduler.Reschedule(@this, action); }
public void Reschedule(ISchedulableThread owner, SchedulerAction action) { if (isBuilding == False) { //We need this lock as our underlying implementation //is not thread safe atm, in the future TODO: this will change //as we will move to other DS or use fine grained locks. int local = isBuilding; if (Interlocked.CompareExchange(ref isBuilding, 1, local) == 0) { var copy = threadScheduler[owner.SchedulableIndex]; if (action == SchedulerAction.Enqueue || action == SchedulerAction.Steal) { var indexPlus = owner.SchedulableIndex + 1; while (threadScheduler.Length - 1 != owner.SchedulableIndex) { var plusThread = threadScheduler[indexPlus]; if (copy.CompareTo(plusThread) > 0) { plusThread.SchedulableIndex--; threadScheduler[owner.SchedulableIndex] = plusThread; threadScheduler[indexPlus] = copy; owner.SchedulableIndex++; indexPlus = owner.SchedulableIndex + 1; } else { break; } } } else if (action == SchedulerAction.Dequeue) { var indexMinus = owner.SchedulableIndex - 1; while (owner.SchedulableIndex != 0) { var minusThread = threadScheduler[indexMinus]; if (copy.CompareTo(minusThread) < 0) { minusThread.SchedulableIndex++; threadScheduler[owner.SchedulableIndex] = minusThread; threadScheduler[indexMinus] = copy; owner.SchedulableIndex--; indexMinus = owner.SchedulableIndex - 1; } else { break; } } } isBuilding = False; } } }
private void CheckForScheduledEvent() { bool matchDay = false; bool matchHour = false; DateTime now = DateTime.Now; TimeSpan diff = now.TimeOfDay.Subtract(ProTONEConfig.ScheduledEventTime); if (Math.Abs(diff.TotalSeconds) <= 3f) { matchHour = true; if (diff.TotalSeconds < 0) { int sleep = (int)(Math.Abs(diff.TotalSeconds) * 1000); Thread.Sleep(sleep); } } Weekday scheduledWeekDay = (Weekday)ProTONEConfig.ScheduledEventDays; if (scheduledWeekDay == Weekday.Everyday) { matchDay = true; } else { switch (now.DayOfWeek) { case DayOfWeek.Monday: matchDay = (scheduledWeekDay & Weekday.Monday) == Weekday.Monday; break; case DayOfWeek.Tuesday: matchDay = (scheduledWeekDay & Weekday.Tuesday) == Weekday.Tuesday; break; case DayOfWeek.Wednesday: matchDay = (scheduledWeekDay & Weekday.Wednesday) == Weekday.Wednesday; break; case DayOfWeek.Thursday: matchDay = (scheduledWeekDay & Weekday.Thursday) == Weekday.Thursday; break; case DayOfWeek.Friday: matchDay = (scheduledWeekDay & Weekday.Friday) == Weekday.Friday; break; case DayOfWeek.Saturday: matchDay = (scheduledWeekDay & Weekday.Saturday) == Weekday.Saturday; break; case DayOfWeek.Sunday: matchDay = (scheduledWeekDay & Weekday.Sunday) == Weekday.Sunday; break; } } if (matchDay && matchHour) { if (!_isScheduledEvent.WaitOne(50, true)) { _isScheduledEvent.Set(); if (ProTONEConfig.EnableScheduledEvent) { SchedulerAction sat = (SchedulerAction)ProTONEConfig.ScheduledEventHandler; // Apply the language ID on the timer scheduler thread, // otherwise the translator will default to English Translator.SetInterfaceLanguage(AppConfig.LanguageID); string msg = Translator.Translate("TXT_SCHEDULED_EVENT_MSG"); Logger.LogInfo("The scheduled moment has occurred. Action to execute: " + sat); PreProcessEvent(sat, msg); } } } else { _isScheduledEvent.Reset(); } }
public static void NotifyCreated(SchedulerAction obj) { obj.ParameterType = (ObjectClass)NamedObjects.Base.Classes.Zetbox.Basic.Workflow.ScheduledActionDefinition.Find(obj.Context); obj.ImplementorName = typeof(Zetbox.Workflow.Common.Workflow.CommonInvocations.Action).GetSimpleName(); obj.MemberName = "Schedule"; }