Esempio n. 1
0
        public TimerStatus[] GetActiveTimers(string cid)
        {
            TimerStatus[] tlist = { };
            try
            {
                if (HttpContext.Cache["active_timer_list_" + cid.ToString()] != null)
                {
                    Dictionary <int, bool> tdic = (Dictionary <int, bool>)HttpContext.Cache["active_timer_list_" + cid.ToString()];
                    tlist = new TimerStatus[tdic.Count];
                    int i = 0;
                    foreach (var item in tdic)
                    {
                        tlist[i] = new TimerStatus {
                            MS_Id = item.Key, value = item.Value
                        };
                        i++;
                    }
                }
            } catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }

            return(tlist);
        }
Esempio n. 2
0
 // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
 private void CheckIsCurrentTalk(TimerStatus status)
 {
     if (status.TalkId == null)
     {
         throw new Exception("Unexpected talk status!");
     }
 }
Esempio n. 3
0
 // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
 private void CheckIsRunning(TimerStatus status)
 {
     if (!status.IsRunning)
     {
         throw new Exception("Unexpected timer status!");
     }
 }
Esempio n. 4
0
 // Start is called before the first frame update
 public void Start()
 {
     _timerStatus = timerObject.GetComponent <TimerStatus>();
     GenerateCombos();
     SetRandomCombo();
     Debug.Log(string.Join <string>(", ", _actualCombo));
 }
 public override void OnElevatorArrive()
 {
     if (TimerContext.StartType == StartEventType.ElevatorArrive)
     {
         CurrentStatus = TimerStatus.CountingDelay;
         SyncReplicator();
     }
 }
Esempio n. 6
0
File: Timer.cs Progetto: oldas1/ztm
        void Stop()
        {
            Scheduler.Stop(this.schedule);
            this.stopwatch.Stop();
            this.stopGuard.Dispose();

            this.status = TimerStatus.Stopped;
        }
Esempio n. 7
0
        private TimeSpan?CalculateNextStartTime(TimerStatus status, DateTime now)
        {
            if (_optionsService.Options.MidWeekOrWeekend == MidWeekOrWeekend.MidWeek)
            {
                return(CalculateNextStartTimeMidWeek(status, now));
            }

            return(CalculateNextStartTimeWeekend(status, now));
        }
Esempio n. 8
0
 public TimerItem(long interval, long delay, long callTime, long timerId, bool loop, EventHandleFun fun, EventArgs args)
 {
     m_interval = interval;
     m_delay    = delay;
     m_callTime = callTime;
     m_timerId  = timerId;
     m_bLoop    = loop;
     m_func     = fun;
     m_args     = args;
     m_status   = TimerStatus.BORNING;
 }
Esempio n. 9
0
        /// <summary>
        /// Stop the timer.
        /// Adds a new entry to the lap list.
        /// </summary>
        public void Stop()
        {
            if (this.status == TimerStatus.stopped)
            {
                // ignore duplicate stop command
                return;
            }

            this.status = TimerStatus.stopped;
            this.laplist.Add(DateTime.Now);
        }
Esempio n. 10
0
        /// <summary>
        /// Starts the timer.
        /// This resets the lap list.
        /// </summary>
        public void Start()
        {
            if (this.status == TimerStatus.running)
            {
                // ignore duplicate start command
                return;
            }

            this.status  = TimerStatus.running;
            this.laplist = new Common.LapList();
            this.laplist.Add(DateTime.Now);
        }
 public void PauzeTimer()
 {
     paused = !paused;
     if (paused)
     {
         status = TimerStatus.Paused;
     }
     else
     {
         StartTimer();
     }
 }
Esempio n. 12
0
 public void Reset()
 {
     newTimer.Stop();
     Hour            = "00";
     Min             = "00";
     Sec             = "00";
     tic             = 0;
     ticM            = 0;
     ticH            = 0;
     TimerStatusTask = TimerStatus.Stopped;
     SaveEnable      = false;
 }
        protected BatchReporterBase(BatchReporterOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            options.Validate();

            _options = options;
            _status  = new TimerStatus(options.FlushInterval, options.MinBackoffPeriod, options.MaxBackoffPeriod);
            _timer   = new PortableTimer(_ => OnTick(), OnError);
        }
Esempio n. 14
0
        public void Start()
        {
            PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
            if (startTime == 0)
            {
                startTime = DateTime.Now.Minute;
            }

            if (TimerStatusTask == TimerStatus.Stopped)
            {
                this.newTimer          = new DispatcherTimer();
                this.newTimer.Interval = TimeSpan.FromSeconds(1);
                this.newTimer.Tick    += (o, s) =>
                {
                    this.tic += ((DispatcherTimer)(o)).Interval.Seconds;

                    if (this.tic == 60)
                    {
                        this.tic = 0;
                        Sec      = "00";
                        Min      = (ticM == 60 ? ticM = 0 : ticM += 1).ToString();

                        if (this.ticM == 60)
                        {
                            Sec       = "0";
                            this.ticM = 0;
                            Min       = "00";
                            Hour      = (ticH == 60 ? ticH = 0 : ticH += 1).ToString();
                        }

                        Min  = Min.Length == 1 ? "0" + Min : Min;
                        Hour = Hour.Length == 1 ? "0" + Hour : Hour;
                    }
                    else
                    {
                        Sec = this.tic.ToString();
                    }
                    Sec = Sec.Length == 1 ? "0" + Sec : Sec;

                    SaveEnable = false;
                };

                newTimer.Start();
                TimerStatusTask = TimerStatus.Running;
            }
            else
            {
                Pause();
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 根据传入的参数决定该显示哪些按钮和文字,隐藏哪些按钮和文字
        /// </summary>
        /// <param name="status">枚举类型标识计时器的状态</param>
        private void SwitchButtonsVisibility(TimerStatus status)
        {
            #region 隐藏所有控件
            globalUIControl.CanSeeStartTimerGrid          = false;
            globalUIControl.CanSeeRunningTimerStackPanel  = false;
            globalUIControl.CanSeePausedTimerStackPanel   = false;
            globalUIControl.CanSeeEndTimerStackPanel      = false;
            globalUIControl.CanSeeTimePickerGrid          = false;
            globalUIControl.CanSeeTimeLeftStackPanel      = false;
            globalUIControl.CanSeeFeatureButtonsPanelGrid = true;
            globalUIControl.CanSeeTimeOutTextBlock        = false;
            #endregion
            timerStatus = status;

            switch (status)
            {
            case TimerStatus.Start:
                globalUIControl.CanSeeStartTimerGrid = true;
                globalUIControl.CanSeeTimePickerGrid = true;
                break;

            case TimerStatus.Running:
                globalUIControl.CanSeeRunningTimerStackPanel = true;
                globalUIControl.CanSeeTimeLeftStackPanel     = true;
                break;

            case TimerStatus.Paused:
                globalUIControl.CanSeePausedTimerStackPanel = true;
                globalUIControl.CanSeeTimePickerGrid        = true;
                break;

            case TimerStatus.End:
                globalUIControl.CanSeeEndTimerStackPanel      = true;
                globalUIControl.CanSeeTimeLeftStackPanel      = true;
                globalUIControl.CanSeeFeatureButtonsPanelGrid = false;
                break;

            case TimerStatus.Overtime:
                globalUIControl.CanSeeEndTimerStackPanel      = true;
                globalUIControl.CanSeeTimeLeftStackPanel      = true;
                globalUIControl.CanSeeFeatureButtonsPanelGrid = false;
                globalUIControl.CanSeeTimeOutTextBlock        = true;
                break;

            default:
                break;
            }
        }
Esempio n. 16
0
 private void PauseResume(object sender = null, EventArgs e = null)
 {
     if (CurrentTimerStatus != TimerStatus.Paused)
     {
         Timer.Stop();
         _timerStatusBeforePause = CurrentTimerStatus;
         CurrentTimerStatus      = TimerStatus.Paused;
         _btnPauseResume.Text    = "Resume";
     }
     else
     {
         CurrentTimerStatus = _timerStatusBeforePause;
         Timer.Start();
         _btnPauseResume.Text = "Pause";
     }
 }
        private void RefreshTimeTimer_Tick(object sender, object e)
        {
            EndTime = DateTime.Now;
            if (TimerStatus == TimerStatus.Observing || TimerStatus == TimerStatus.Holding)
            {
                switch (appSettings.DisplayMode)
                {
                case DisplayModeEnum.Hidden:
                    DisplayTime(TimerStatus.ToString());
                    break;

                default:
                    var timeLeft = 15 - ((int)(EndTime - StartTime).TotalSeconds);
                    if (timeLeft <= -2)
                    {
                        DisplayTime("DNF");
                    }
                    else if (timeLeft <= 0)
                    {
                        DisplayTime("+2");
                    }
                    else
                    {
                        DisplayTime(timeLeft.ToString());
                    }
                    break;
                }
            }
            else if (TimerStatus == TimerStatus.Timing)
            {
                switch (appSettings.DisplayMode)
                {
                case DisplayModeEnum.RealTime:
                    DisplayTime(Result.GetFormattedString((EndTime - StartTime).TotalSeconds));
                    break;

                case DisplayModeEnum.ToSecond:
                    DisplayTime(((int)(EndTime - StartTime).TotalSeconds).ToString());
                    break;

                default:
                    DisplayTime("Solving");
                    break;
                }
            }
        }
Esempio n. 18
0
        private TimeSpan?CalculateNextStartTimeWeekend(TimerStatus status, DateTime now)
        {
            if (status.TalkId == null)
            {
                return(null);
            }

            _timerService.GetStatus();
            var talkType = (TalkTypesAutoMode)status.TalkId;

            switch (talkType)
            {
            case TalkTypesAutoMode.PublicTalk:
                return(now.TimeOfDay.Add(GetAboutXMinutes(4)));    // for interim segment
            }

            return(null);
        }
Esempio n. 19
0
        public void Pause()
        {
            if (TimerStatusTask == TimerStatus.Running)
            {
                newTimer.Stop();
                TimerStatusTask = TimerStatus.Paused;

                SaveEnable = true;
            }
            else if (TimerStatusTask == TimerStatus.Paused)
            {
                TimerStatusTask = TimerStatus.Stopped;
                Start();
            }
            else
            {
                TimerStatusTask = TimerStatus.Running;
                Start();
            }
        }
Esempio n. 20
0
        private TimeSpan?CalculateNextStartTimeMidWeek(TimerStatus status, DateTime now)
        {
            if (status.TalkId == null)
            {
                return(null);
            }

            _timerService.GetStatus();
            var talkType = (TalkTypesAutoMode)status.TalkId;

            switch (talkType)
            {
            case TalkTypesAutoMode.OpeningComments:
            case TalkTypesAutoMode.TreasuresTalk:
            case TalkTypesAutoMode.DiggingTalk:
                return(now.TimeOfDay.Add(GetAboutXSeconds(20)));

            case TalkTypesAutoMode.Reading:
                return(now.TimeOfDay.Add(GetAboutXSeconds(80)));

            case TalkTypesAutoMode.MinistryItem1:
            case TalkTypesAutoMode.MinistryItem2:
            case TalkTypesAutoMode.MinistryItem3:
            case TalkTypesAutoMode.MinistryItem4:
                var lastMinistryItemBeforeSong = GetLastMinistryItem();
                var item = _scheduleService.GetTalkScheduleItem((int)talkType);
                CheckItem(item);
                return(item == lastMinistryItemBeforeSong
                        ? now.TimeOfDay.Add(GetAboutXMinutes(4))
                        : now.TimeOfDay.Add(GetAboutXSeconds(item.IsStudentTalk ? 80 : 20)));

            case TalkTypesAutoMode.LivingPart1:
            case TalkTypesAutoMode.LivingPart2:
            case TalkTypesAutoMode.CongBibleStudy:
                return(now.TimeOfDay.Add(GetAboutXSeconds(20)));

            default:
                return(null);
            }
        }
Esempio n. 21
0
        private void setTimerStatus(TimerStatus status)
        {
            timerStatus = status;
            switch (status)
            {
            case TimerStatus.POWER_ON:
                labelStatus.Text = "Waiting for Power-On...";
                break;

            case TimerStatus.RACE_CALIBRATION:
                labelStatus.Text = "Race Calibration";
                break;

            case TimerStatus.WAITING:
                labelStatus.Text = "Waiting...";
                break;

            case TimerStatus.TIMER_RUNNING:
                labelStatus.Text = "Timer Running";
                break;
            }
        }
Esempio n. 22
0
        private async Task <TimerStatus> ElaborateStatus(DateTime date)
        {
            var status = new TimerStatus();

            var timer = await _timerAccess.GetLastAsyncOfDate(UserName, new List <int> {
                (int)TimerTypes.Enter, (int)TimerTypes.EnterLunch, (int)TimerTypes.Exit, (int)TimerTypes.ExitLunch
            }, date);

            if (timer != null)
            {
                switch (timer.TimerTypeId)
                {
                case (int)TimerTypes.Enter:
                    status.EnterLunch = true;
                    status.Exit       = true;
                    break;

                case (int)TimerTypes.EnterLunch:
                    status.ExitLunch = true;
                    status.Exit      = true;
                    break;

                case (int)TimerTypes.ExitLunch:
                    status.EnterLunch = true;
                    status.Exit       = true;
                    break;

                case (int)TimerTypes.Exit:
                    status.Enter = true;
                    break;
                }
            }
            else
            {
                status.Enter = true;
            }
            return(status);
        }
        public override void OnSetup()
        {
            SNetMessage.OnPlayerJoinedSession += OnPlayerJoinedSession;

            Replicator = new TimedObjectiveReplicator();
            Replicator.Setup(ReplicatorType.LevelInstance, ReplicatorCHType.GameReceiveCritical);
            Replicator.StateChanged += () =>
            {
                if (CurrentStatus != Replicator.Status || CurrentStep != Replicator.Step)
                {
                    CurrentStatus = Replicator.Status;
                    Timer         = Replicator.InitTimerTime;
                    CurrentStep   = Replicator.Step;
                }
            };

            if (!TryGetConfig(ObjectiveData.persistentID)) //check config
            {
                UnloadSelf();
                return;
            }

            if ((TimerContext.Steps?.Length ?? 0) <= 0)
            {
                Logger.Warning("This Mission doesn't have valid Step Setting for TimedObjective Config");
                UnloadSelf();
                return;
            }

            if (TimerContext.Steps.Any(step => step.Duration <= 0.0f))
            {
                Logger.Warning("This Mission doesn't have valid Duration for Timer Setting: Duration Can't be below Zero");
                UnloadSelf();
                return;
            }

            RegisterUpdateEvent(OnUpdate);
        }
Esempio n. 24
0
File: Timer.cs Progetto: oldas1/ztm
        public void Start(TimeSpan due, TimeSpan?period, object context)
        {
            if (!Scheduler.IsValidDuration(due))
            {
                throw new ArgumentOutOfRangeException(nameof(due), due, "The value is not valid.");
            }

            if (period != null && !Scheduler.IsValidDuration(period.Value))
            {
                throw new ArgumentOutOfRangeException(nameof(period), period, "The value is not valid.");
            }

            if (Status != TimerStatus.Created)
            {
                throw new InvalidOperationException("The timer is already started.");
            }

            // Prepare to schedule callback.
            this.stopGuard    = new ShutdownGuard();
            this.oneShotState = (period != null) ? 0 : 1;
            this.status       = TimerStatus.Started; // We need to change status here due to scheduling might elapsed immediately.

            // Schedule callback.
            try
            {
                this.stopwatch.Restart();
                this.schedule = Scheduler.Schedule(due, period, OnElapsed, context);
            }
            catch
            {
                this.stopwatch.Stop();
                this.status       = TimerStatus.Created;
                this.oneShotState = 0;
                this.stopGuard.Dispose();
                this.stopGuard = null;
                throw;
            }
        }
        public void ExecuteOnce(Action action, TimeSpan timeUntilExecution)
        {
            if (timeUntilExecution < TimeSpan.Zero)
            {
                throw new ArgumentException("Must be non-negative", "timeUntilExecution");
            }

            lock (_lock)
            {
                // Removes processed oneTimeTimers
                var timersToRemove = new List <TimerStatus>();
                for (var x = 0; x < _oneTimeTimers.Count; x++)
                {
                    var execution = _oneTimeTimers[x];
                    if (execution.HasRun)
                    {
                        timersToRemove.Add(execution);
                    }
                }
                foreach (var ttr in timersToRemove)
                {
                    _oneTimeTimers.Remove(ttr);
                }

                // Create a new timer that will mark itself as complete after it executes. The timer needs to be stored somewhere so that it won't be GC'd before it runs.
                var newExecution   = new TimerStatus();
                var flaggingAction = new Action(() =>
                {
                    action();
                    newExecution.HasRun = true;
                });
                var timer = CreateExecuteOnceTimer(flaggingAction, timeUntilExecution);
                newExecution.Timer = timer;

                _oneTimeTimers.Add(newExecution);
            }
        }
Esempio n. 26
0
 private void SetButtonsState(TimerStatus status)
 {
     if (status == TimerStatus.Started)
     {
         butStartTimer.IsEnabled = false;
         butStopTimer.IsEnabled = true;
     }
     else
     {
         butStartTimer.IsEnabled = true;
         butStopTimer.IsEnabled = false;
     }
 }
 public void StartTimer()
 {
     paused = false;
     status = TimerStatus.Started;
 }
Esempio n. 28
0
 public void Reset()
 {
     this.status = TimerStatus.stopped;
     this.Start();
 }
Esempio n. 29
0
 public double stop()
 {
     _time = (DateTime.Now - _start).TotalSeconds;
     _status = TimerStatus.Stopped;
     return _time;
 }
Esempio n. 30
0
        private async void Initialize()
        {
            IReliableDictionary <string, DateTime> reliableDictionary;

            using (var tx = _stateManager.CreateTransaction())
            {
                reliableDictionary =
                    await _stateManager.GetOrAddAsync <IReliableDictionary <string, DateTime> >(_reliableDictName);

                await tx.CommitAsync();
            }
            Interval   = 1000;
            _tickCache = new ConditionalValue <DateTime>();
            Elapsed   += async(sender, e) =>
            {
                try
                {
                    using (var tx = _stateManager.CreateTransaction())
                    {
                        _cancellationToken.ThrowIfCancellationRequested();
                        ConditionalValue <DateTime> tick;
                        if (_tickCache.HasValue)
                        {
                            tick = new ConditionalValue <DateTime>(true, _tickCache.Value);
                        }
                        else
                        {
                            tick = await reliableDictionary.TryGetValueAsync(tx, "tick", TimeSpan.FromMilliseconds(500), _cancellationToken);
                        }
                        if (tick.HasValue)
                        {
                            _tickCache = new ConditionalValue <DateTime>(true, tick.Value);
                        }
                        else
                        {
                            await
                            reliableDictionary.SetAsync(tx, "tick", DateTime.Now, TimeSpan.FromMilliseconds(500),
                                                        _cancellationToken);

                            _tickCache = new ConditionalValue <DateTime>(true, DateTime.Now);
                        }
                        var timeSpan = tick.HasValue ? DateTime.Now - tick.Value : TimeSpan.Zero;
                        // if (Math.Abs(timeSpan.TotalMilliseconds - ReliableInterval) < ReliableIntervalTolerance)
                        if (timeSpan.TotalMilliseconds >= ReliableInterval)
                        {
                            var args = new ReliableElapsedEventArgs
                            {
                                ReliableSignalTime = e.SignalTime
                            };
                            await reliableDictionary.TryUpdateAsync(tx, "tick", e.SignalTime, tick.Value, TimeSpan.FromMilliseconds(500), _cancellationToken);

                            _tickCache = new ConditionalValue <DateTime>(true, e.SignalTime);
                            OnReliableElapsed(args);
                        }
                        await tx.CommitAsync();

                        tx.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    if (ex is OperationCanceledException)
                    {
                        ServiceEventSource.Current.Message(
                            $"Cancellation requested. Disabling timer: {_reliableDictName}, " +
                            $"Exception: {ex.Message}, " +
                            $"{_context.ServiceName.ToString()}, " +
                            $"{_context.ServiceTypeName}, " +
                            $"{_context.ReplicaId}, " +
                            $"{_context.PartitionId}, " +
                            $"{_context.CodePackageActivationContext.ApplicationName}, " +
                            $"{_context.CodePackageActivationContext.ApplicationTypeName}, " +
                            $"{_context.NodeContext.NodeName}, ");
                        Enabled     = false;
                        FastTimerOn = false;
                        SlowTimerOn = false;
                        Status      = TimerStatus.Paused;
                    }
                }
            };
        }
Esempio n. 31
0
        private double _time; // in seconds

        public Timer(string name)
        {
            _name = name;
            _status = TimerStatus.Initialized;
        }
 public void StopTimer()
 {
     currentTime = 0.0f;
     status      = TimerStatus.Stopped;
     timerEnded.Invoke(currentTime);
 }
 public TimerStatusChangedMessage(TimerStatus i_timerStatus) : base(MessageType.TimerStatusChanged)
 {
     g_timerStatus = i_timerStatus;
 }
	public TimerStatusChangedMessage( TimerStatus i_timerStatus ) : base(MessageType.TimerStatusChanged)
	{
		g_timerStatus = i_timerStatus;
	}
Esempio n. 35
0
 public void start()
 {
     _start = DateTime.Now;
     _status = TimerStatus.Started;
 }