public async Task Refresh()
        {
            await RefreshImagesList();
            await RefreshContainerList();

            StageChanged?.Invoke();
        }
Esempio n. 2
0
        private void stageChanged(Stage oldValue, Stage newValue)
        {
            var args = new StageChangedEventArgs {
                OldStage = oldValue, NewStage = newValue
            };

            StageChanged?.Invoke(this, args);
        }
Esempio n. 3
0
 private IAction InitialDispatcher(IAction action)
 {
     lock (syncLock) {
         var cloned = ObjectExtensions.Copy(state);
         state = reducer(cloned, action);
     }
     StageChanged?.Invoke();
     return(action);
 }
Esempio n. 4
0
        private void ChangeStage(Stage stage)
        {
            // Interrupt and fast-forward the current stage process, if it had no time to iterate completely.
            FastForward();

            Stage = stage;
            SetCurrentStageProcess();
            process.Start();

            StageChanged?.Invoke(this, new ActivationStateChangedEventArgs(stage));
        }
Esempio n. 5
0
    private void IncreaseStage()
    {
        _stage++;
        int currentMaxStage = saver.MaxStage;

        if (_stage > currentMaxStage)
        {
            saver.SaveMaxStage(_stage);
        }
        saver.SaveCurrentScore(_score);
        saver.SaveCurrentStage(_stage);
        StageChanged?.Invoke(_stage);
    }
Esempio n. 6
0
        private void ChangeStage(Stage stage)
        {
            // Interrupt and fast-forward the current stage process, if it had no time to iterate completely.
            FastForward();

            Stage = stage;
            Owner.InvokeProcessStart();
            update = Owner.InvokeProcessUpdate();

            if (StageChanged != null)
            {
                StageChanged.Invoke(this, new ActivationStateChangedEventArgs(stage));
            }
        }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task Disconnect()
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            connected = false;

            lock (monitor)
            {
                foreach (DockerLogReader logReader in logReaders.Values)
                {
                    logReader.Stop();
                }
                logReaders.Clear();
                images.Clear();
                containers.Clear();
            }

            StageChanged?.Invoke();
        }
        public async Task Run(
            [QueueTrigger(Queues.Notifications)] StageChanged stageChanged,
            [Blob(Blobs.Schedule)] string scheduleBlob,
            [Blob(Blobs.StageChangedPeopleToNotify)] string peopleToNotifyBlob,
            ILogger log)
        {
            var schedule       = JsonConvert.DeserializeObject <List <ScheduleEntry> >(scheduleBlob);
            var peopleToNotify = JsonConvert.DeserializeObject <List <Person> >(peopleToNotifyBlob);

            log.LogInformation($"Notifying {peopleToNotify.Count} people");
            var currentDay  = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(2)).Day;
            var currentHour = DateTimeOffset.UtcNow.ToOffset(TimeSpan.FromHours(2)).Hour;

            // send sms's
            foreach (var person in peopleToNotify)
            {
                var personsSchedule = schedule
                                      .Where(s => s.Stage == stageChanged.CurrentStage && s.Area == person.Area && s.Day == currentDay && s.StartingHour >= currentHour)
                                      .OrderBy(x => x.StartingHour)
                                      .ToList();
                var message = $"Loadshedding is now stage {stageChanged.CurrentStage} (was {stageChanged.PreviousStage}). ";
                if (stageChanged.CurrentStage > 0)
                {
                    if (personsSchedule.Any())
                    {
                        message += $"Area {person.Area} at {string.Join(", ", personsSchedule.Select(p => $"{p.StartingHour}:00"))}";
                    }
                    else
                    {
                        message += $"No more loadsheeding for area {person.Area}";
                    }
                }

                await _twilioService.SendSms(person.Number, message);
            }
        }
Esempio n. 9
0
        private void DoWork()
        {
            /* Check frozen. */
            if (FreezableClock.IsFrozen && !_pausedEvent.WaitOne())
            {
                return;
            }

            var now = ProgramTime;

            /* Do sleep waiting while greater than 2 x sleep period */
            var sleepWaitPeriod = SleepWaitPeriod;

            if (sleepWaitPeriod.Ticks > 0)
            {
                while (!_stageSkipped.Value && FreezableClock.Unit.ConvertTo((long)(_nextUpdateTime - now), TimeUnit.Tick) > sleepWaitPeriod.Ticks * 2)
                {
                    Thread.Sleep(sleepWaitPeriod);
                    now = ProgramTime;
                }
            }

            /* Do busy waiting while less than 2 x sleep period */
            while (now < _nextUpdateTime && !_stageSkipped.Value)
            {
                if (FreezableClock.IsFrozen)
                {
                    return;                          /* Exit busy waiting while paused */
                }
                now = ProgramTime;
            }

            /* Actual processing procedures */
            do
            {
                /* Reset skip state */
                _stageSkipped.Reset();

                /* Get next stage, exit on null (END REACHED) */
                Stage stage = null;
                try
                {
                    for (;;) /* Loop only for skip */
                    {
                        stage = _stageProvider.Next();
                        now   = ProgramTime;
                        var eventArgs = new StageChangedEventArgs(now, stage);
                        StageChanged?.Invoke(this, eventArgs);
                        if (stage == null)
                        {
                            eventArgs.Action = StageAction.Terminate;
                        }
                        switch (eventArgs.Action)
                        {
                        case StageAction.Terminate:     /* Terminate entire program */
                            goto StopProgram;

                        case StageAction.Skip:     /* Skip current stage directly */
                            continue;

                        case StageAction.Pause:     /* Pause at the start of the stage */
                            Pause();
                            goto BreakOuterLoop;

                        default:     /* Accepted */
                            goto BreakOuterLoop;
                        }

BreakOuterLoop:
                        break;
                    }
                }
                catch (ThreadAbortException) { throw; } /* Aborted by stopping underlying runner */
                catch (Exception e) /* Process unhandled exception */
                {
                    var eventArgs = new ExceptionEventArgs(e);
                    UnhandledException?.Invoke(this, eventArgs);
                    if (!eventArgs.Handled)
                    {
                        throw new Exception("Unhandled exception", e);
                    }
                }

                /* Update time */
                if (stage != null)
                {
                    _nextUpdateTime = now + stage.Duration;
                }
                continue;

                /* Stop */
StopProgram:
                Stop();
                return;
            } while (now >= _nextUpdateTime || _stageSkipped.Value); /* Check if need to move next */
        }
Esempio n. 10
0
 private void ChangeStage(bool playing)
 {
     PlayingStage = playing;
     StageChanged?.Invoke();
 }
Esempio n. 11
0
 private void ChangeStage(ModelStage stage)
 {
     Stage = stage;
     StageChanged?.Invoke(Stage);
 }
Esempio n. 12
0
 private void ChangeStage(GameStage stage)
 {
     this.stage = stage;
     StageChanged?.Invoke(stage);
 }
Esempio n. 13
0
 private void HandleStageFinished(object sender, StageCallbackEventArgs e)
 {
     StageChanged?.Invoke();
 }
Esempio n. 14
0
 public void ChangeStage(GameStage stage)
 {
     Stage = stage;
     StageChanged?.Invoke(stage);
 }
Esempio n. 15
0
        //---------------------------------------------------------------------------

        private void OnStageChanged()
        {
            StageChanged?.Invoke();
        }