コード例 #1
0
        public void AddTimer(int seconds, string text)
        {
            BLIO.Log("Attempting to add a timer for " + seconds + " seconds.");
            TimerItem tmrItem = new TimerItem(DateTime.Now.AddSeconds(seconds), text, timerIdCounter);

            tmrItem.updateAllowed = true;
            tmrItem.StartTimer();
            timers.Add(tmrItem);

            //Generate a new BunifuFlatbutton, but with the template markup
            BunifuFlatButton timerButton = CloneButton();


            timerButton.Text = " Timer " + timerIdCounter;

            //Link every new button click to this event.
            timerButton.Click += TimerButton_Click;
            BLIO.Log("Button cloned & event listener linked");

            //Add the new button to top panel
            pnlRunningTimers.Controls.Add(timerButton);

            currentTimerItem = tmrItem;

            //Up the Id so that the next timer has a higher id
            timerIdCounter++;

            EnableButton(timerButton);
            BLIO.Log("Timer added!");
        }
コード例 #2
0
ファイル: TimersModule.cs プロジェクト: Husteln/ThunderED
        private async Task SendNotification(TimerItem timer, ulong channel)
        {
            try
            {
                var remains = timer.GetRemains();
                var stage   = timer.GetStageName();
                var mode    = timer.GetModeName();
                var embed   = new EmbedBuilder()
                              .WithTitle(LM.Get("timerNotifyTitle", string.IsNullOrEmpty(timer.timerLocation) ? "-" : timer.timerLocation))
                              .AddInlineField(LM.Get("timersType"), string.IsNullOrEmpty(mode) ? "-" : mode)
                              .AddInlineField(LM.Get("timersStage"), string.IsNullOrEmpty(stage) ? "-" : stage)
                              .AddInlineField(LM.Get("timersOwner"), string.IsNullOrEmpty(timer.timerOwner) ? "-" : timer.timerOwner)
                              .AddInlineField(LM.Get("timersRemaining"), string.IsNullOrEmpty(remains) ? "-" : remains)
                              .AddField(LM.Get("timersNotes"), string.IsNullOrEmpty(timer.timerNotes) ? "-" : timer.timerNotes);
                if (!string.IsNullOrEmpty(Settings.Resources.ImgTimerAlert))
                {
                    embed.WithThumbnailUrl(Settings.Resources.ImgTimerAlert);
                }

                await APIHelper.DiscordAPI.SendMessageAsync(APIHelper.DiscordAPI.GetChannel(channel), "@everyone", embed.Build()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);
            }
        }
コード例 #3
0
        /// <summary>
        /// note: need to have acquired the lock
        /// </summary>
        /// <param name="item"></param>
        private void AddItemToList(TimerItem item)
        {
            int index      = 0;
            int itemsCount = _timerItems.Count;

            if (itemsCount >= _maxItems)
            {
                throw new ArgumentException("Already reached max number of timer elements.");
            }

            for (int i = 0; i < itemsCount; i++)
            {
                TimerItem currentItem = (TimerItem)_timerItems[i];
                if (currentItem.TimeoutTicks > item.TimeoutTicks)
                {
                    index = i;
                    break;
                }
            }

            _timerItems.Insert(index, item);
            if (index == 0)
            {
                int dueTime = (int)((item.TimeoutTicks - DateTime.Now.Ticks) / TimeSpan.TicksPerMillisecond);
                if (dueTime < 0)
                {
                    dueTime = 0;
                }
                _timer.Change(dueTime, System.Threading.Timeout.Infinite);
            }
        }
コード例 #4
0
        private async Task SendNotification(TimerItem timer, ulong channel)
        {
            try
            {
                var remains = timer.GetRemains();
                var stage   = timer.GetStageName();
                var mode    = timer.GetModeName();
                var embed   = new EmbedBuilder()
                              .WithTitle(LM.Get("timerNotifyTitle", string.IsNullOrEmpty(timer.timerLocation) ? "-" : timer.timerLocation))
                              .AddField(LM.Get("timersType"), string.IsNullOrEmpty(mode) ? "-" : mode, true)
                              .AddField(LM.Get("timersStage"), string.IsNullOrEmpty(stage) ? "-" : stage, true)
                              .AddField(LM.Get("timersOwner"), string.IsNullOrEmpty(timer.timerOwner) ? "-" : timer.timerOwner, true)
                              .AddField(LM.Get("timersRemaining"), string.IsNullOrEmpty(remains) ? "-" : remains, true)
                              .AddField(LM.Get("timersNotes"), string.IsNullOrEmpty(timer.timerNotes) ? "-" : timer.timerNotes);
                if (!string.IsNullOrEmpty(Settings.Resources.ImgTimerAlert))
                {
                    embed.WithThumbnailUrl(Settings.Resources.ImgTimerAlert);
                }

                var ch = APIHelper.DiscordAPI.GetChannel(channel);
                if (ch == null)
                {
                    await LogHelper.LogWarning($"Discord channel {channel} not found!", Category);
                }
                else
                {
                    await APIHelper.DiscordAPI.SendMessageAsync(ch, Settings.TimersModule.DefaultMention ?? " ", embed.Build()).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);
            }
        }
コード例 #5
0
 public static void EraseTimerCallback(TimerItem item)
 {
     if (delTasks.IndexOf(item) == -1)
     {
         delTasks.Add(item);
     }
 }
コード例 #6
0
    public void Update(int dt)
    {
        foreach (KeyValuePair <int, TimerItem> pair in this.timer_map)
        {
            int       timer_idx  = pair.Key;
            TimerItem timer_item = pair.Value;
            if (timer_item.Update(dt))
            {
                if (!timer_item.IsLoop())
                {
                    this.timer_map.Remove(timer_idx);
                }
                TimerAction action = timer_item.GetAction();
                object      data   = timer_item.GetData();

                try
                {
                    action(data);
                }
                catch
                {
                }
            }
        }
    }
コード例 #7
0
        /// <summary>
        /// Handle discovery message from peer node
        /// </summary>
        /// <param name="node"></param>
        public void HandleDiscoveryReply(UInt16 node)
        {
            // reset timeout counter
            lock (_data)
            {
                int count = _data.Count;
                for (int i = 0; i < count; i++)
                {
                    TimerItem item = _data[i] as TimerItem;
                    if (item.shortAddr == node)
                    {
                        item.timeoutCounter = 0;
                        return;
                    }
                }

                // add node to list
                {
                    TimerItem item = new TimerItem();
                    item.shortAddr      = node;
                    item.timeoutCounter = 0;
                    lock (_data)
                    {
                        _data.Add(item);
                    }

                    _callbacks.NodeChanged(node, true);
                }
            }
        }
コード例 #8
0
        private static void SwapTimerItem(int index1, int index2)
        {
            TimerItem tempItem = TimerList[index1];

            TimerList[index1] = TimerList[index2];
            TimerList[index2] = tempItem;
        }
コード例 #9
0
        private static TimerItem RemoveTimerItem()
        {
            int _lastIndex = TimerList.Count - 1;

            SwapTimerItem(0, _lastIndex);
            TimerItem item = TimerList[_lastIndex];

            TimerList.RemoveAt(_lastIndex);
            int _index      = 0;
            int _childIndex = _index * 2 + 1;

            while (_childIndex < TimerList.Count)
            {
                if (_childIndex + 1 < TimerList.Count && TimerList[_childIndex] > TimerList[_childIndex + 1])
                {
                    ++_childIndex;
                }
                if (TimerList[_childIndex] < TimerList[_index])
                {
                    SwapTimerItem(_index, _childIndex);
                    _index      = _childIndex;
                    _childIndex = _index * 2 + 1;
                }
                else
                {
                    break;
                }
            }
            return(item);
        }
コード例 #10
0
 public AddTimerPage(TimerItem timer)
 {
     InitializeComponent();
     title               = timer.Title;
     timespan            = timer.TimeSpan;
     this.BindingContext = this;
 }
コード例 #11
0
        public void By_default_return_continue_workflow_action()
        {
            var workflow = new WorkflowWithTimer();

            var workflowAction = _timerFiredEvent.Interpret(workflow);

            Assert.That(workflowAction, Is.EqualTo(WorkflowAction.ContinueWorkflow(TimerItem.New(Identity.Timer(_timerName), null))));
        }
コード例 #12
0
 public static void Register(object objectItem, float delayTime, Action callback)
 {
     if (!timerList.ContainsKey(objectItem))
     {
         TimerItem timerItem = new TimerItem(TimerManager.time, delayTime, callback);
         timerList.Add(objectItem, timerItem);
     }
 }
コード例 #13
0
        public void By_default_schedule_timer_to_fire_immediately()
        {
            var timerItem = TimerItem.New(_timerIdentity, null);

            var decision = timerItem.GetScheduleDecisions();

            Assert.That(decision, Is.EqualTo(new [] { new ScheduleTimerDecision(_timerIdentity, new TimeSpan()) }));
        }
コード例 #14
0
ファイル: TimerManager.cs プロジェクト: jackdevelop/ThreeCard
 public static void Register(object objectItem, float delayTime, Action callback)
 {
     if(!timerList.ContainsKey(objectItem))
     {
         TimerItem timerItem = new TimerItem(TimerManager.time, delayTime, callback);
         timerList.Add(objectItem, timerItem);
     }
 }
コード例 #15
0
        private TimerItem CreateTimerItemFor(IEnumerable <HistoryEvent> eventGraph)
        {
            var workflowHistoryEvents = new WorkflowHistoryEvents(eventGraph);
            var workflow = new Mock <IWorkflow>();

            workflow.SetupGet(w => w.WorkflowHistoryEvents).Returns(workflowHistoryEvents);
            return(TimerItem.New(_timerIdentity, workflow.Object));
        }
コード例 #16
0
            private TimeSpan m_fileSaveTimeSpan = new TimeSpan(0, 1, 0); // Every 1 hr, try to save XML file.
            #endregion

            #region Public interface

            public RnlXmlFileImplementation(AppPlatform platform)
                : base(platform)
            {
                m_filePath               = ApplicationConfiguration.RnlFile;
                m_directory              = new Dictionary <string, string>();
                m_fileSaveTimer          = new TimerItem(platform.TimerWheel, m_fileSaveTimeSpan);
                m_fileSaveTimer.Expired += FileSaveTimerExpired;
            }
コード例 #17
0
    public int AddTimer(int interval, TimerAction action, object data = null, bool is_loop = false)
    {
        TimerItem timer_item = new TimerItem(interval, action, data, is_loop);
        int       timer_id   = this.GetTimerId();

        this.timer_map[timer_id] = timer_item;
        return(timer_id);
    }
コード例 #18
0
 internal uint RegisterItem(long timeoutTick, FragmentationMessage message)
 {
     lock (_lock)
     {
         TimerItem item = new TimerItem(timeoutTick, message);
         AddItemToList(item);
         return(item.Id);
     }
 }
コード例 #19
0
        public void Can_be_configured_to_schedule_timer_to_fire_after_timeout()
        {
            var timerItem = TimerItem.New(_timerIdentity, null);

            timerItem.FireAfter(TimeSpan.FromSeconds(3));
            var decision = timerItem.GetScheduleDecisions();

            Assert.That(decision, Is.EqualTo(new [] { new ScheduleTimerDecision(_timerIdentity, TimeSpan.FromSeconds(3)) }));
        }
コード例 #20
0
        public void Should_return_the_scheduling_decision_for_workflow_item()
        {
            var workflowItem   = TimerItem.New(Identity.Timer("Somename"), _workflow.Object);
            var workflowAction = WorkflowAction.Schedule(workflowItem);

            var decisions = workflowAction.GetDecisions();

            Assert.That(decisions, Is.EquivalentTo(workflowItem.GetScheduleDecisions()));
        }
コード例 #21
0
        public void By_default_schedule_timer_to_fire_immediately()
        {
            var timerItem = TimerItem.New(_timerIdentity, _workflow.Object);

            var decisions = timerItem.ScheduleDecisions().ToArray();

            Assert.That(decisions.Length, Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(_timerIdentity.ScheduleId(), TimeSpan.Zero);
        }
コード例 #22
0
ファイル: AcdAgentMatchMaker.cs プロジェクト: mujiansu/Lync
            internal void StopTimer()
            {
                TimerItem timer = _TmrItem;

                if (timer != null)
                {
                    timer.Stop();
                }
            }
コード例 #23
0
        public void Can_be_returned_as_workflow_action_when_scheduling_the_timer()
        {
            var workflow = new WorkflowToReturnScheduleTimerAction();
            var completedActivityEvent = CreateCompletedActivityEvent(ActivityName, ActivityVersion, PositionalName);

            var workflowAction = completedActivityEvent.Interpret(workflow);

            Assert.That(workflowAction, Is.EqualTo(WorkflowAction.JumpTo(TimerItem.New(Identity.Timer("SomeTimer"), null))));
        }
コード例 #24
0
        public void Should_return_schedule_workflow_action_if_timer_is_fired_to_reschedule_a_timer_item()
        {
            var workflow        = new WorkflowWithTimer();
            var rescheduleTimer = CreateRescheduleTimerFiredEvent(Identity.Timer(_timerName), _fireAfter);

            var workflowAction = rescheduleTimer.Interpret(workflow);

            Assert.That(workflowAction, Is.EqualTo(WorkflowAction.Schedule(TimerItem.New(Identity.Timer(_timerName), null))));
        }
コード例 #25
0
 internal uint RegisterItem(long timeoutTick, FragmentationMessage message)
 {
     lock (_lock)
     {
         TimerItem item = new TimerItem(timeoutTick, message);
         AddItemToList(item);
         return item.Id;
     }
 }
コード例 #26
0
        public void Returns_the_scheduling_decision_for_workflow_item()
        {
            var workflowItem   = TimerItem.New(Identity.Timer("Somename"), _workflow.Object);
            var workflowAction = WorkflowAction.JumpTo(null, workflowItem);

            var decisions = workflowAction.Decisions(Mock.Of <IWorkflow>());

            Assert.That(decisions, Is.EquivalentTo(workflowItem.ScheduleDecisions()));
        }
コード例 #27
0
        private void TimerButton_Click(object sender, EventArgs e)
        {
            //Right click delete
            if (e.GetType().Equals(typeof(MouseEventArgs)))
            {
                MouseEventArgs mouse = (MouseEventArgs)e;
                if (mouse.Button == MouseButtons.Right)
                {
                    TimerMenuStrip.Show(Cursor.Position);
                }
            }

            BLIO.Log("TimerButton clicked!");
            //Get selected TimerItem
            BunifuFlatButton clickedButton = (BunifuFlatButton)sender;

            BLIO.Log("^^^^ (" + clickedButton.Text + ")");
            //Remove all the text apart from the id and store it
            int id = Convert.ToInt32(clickedButton.Text.Replace("Timer", "").Replace(" ", ""));

            foreach (TimerItem itm in timers)
            {
                if (itm.ID == id)
                {
                    currentTimerItem = itm;

                    if (currentTimerItem.IsRunning())
                    {
                        tmrCountdown.Start();
                    }
                    else
                    {
                        tmrCountdown.Stop();
                    }


                    BLIO.Log("Setting values of (UCTimer) numericupdowns");
                    TimeSpan time = TimeSpan.FromSeconds((double)currentTimerItem.SecondsRemaining);
                    numSeconds.Value = time.Seconds;
                    numMinutes.Value = time.Minutes;
                    numHours.Value   = time.Hours;
                }
            }

            //Show play or pause depending on if the selected timer is running or not
            if (currentTimerItem.IsRunning())
            {
                btnPauseResumeTimer.Iconimage = Properties.Resources.pause_2x1;
            }
            else
            {
                btnPauseResumeTimer.Iconimage = Properties.Resources.Play;
            }

            EnableButton(clickedButton);
        }
コード例 #28
0
        public void Can_be_configured_to_schedule_timer_to_fire_after_timeout_using_lambda()
        {
            var timerItem = TimerItem.New(_timerIdentity, _workflow.Object);

            timerItem.FireAfter(_ => TimeSpan.FromSeconds(4));
            var decisions = timerItem.ScheduleDecisions().ToArray();

            Assert.That(decisions.Length, Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(4));
        }
コード例 #29
0
        public void Fire_after_lambda_handler_override_the_fire_after_timeout()
        {
            var timerItem = TimerItem.New(_timerIdentity, _workflow.Object);

            timerItem.FireAfter(_ => TimeSpan.FromSeconds(3)).FireAfter(TimeSpan.FromSeconds(4));
            var decisions = timerItem.ScheduleDecisions().ToArray();

            Assert.That(decisions.Length, Is.EqualTo(1));
            decisions[0].AssertWorkflowItemTimer(_timerIdentity.ScheduleId(), TimeSpan.FromSeconds(3));
        }
コード例 #30
0
ファイル: WorkflowTests.cs プロジェクト: yasinkultur/guflow
        public void Timerof_test()
        {
            var eventGraph             = _builder.TimerFiredGraph(Identity.Timer("Timer1"), TimeSpan.FromSeconds(2));
            var activityCompletedEvent = new TimerFiredEvent(eventGraph.First(), eventGraph);
            var workflow = new TestWorkflow();

            var activity = workflow.GetTimerOf(activityCompletedEvent);

            Assert.That(activity, Is.EqualTo(TimerItem.New(Identity.Timer("Timer1"), workflow)));
        }
コード例 #31
0
        public void Return_empty_when_when_condition_is_evaluated_to_false()
        {
            var timerItem = TimerItem.New(_timerIdentity, Mock.Of <IWorkflow>());

            timerItem.When(t => false);

            var decisions = timerItem.GetScheduleDecisions();

            Assert.That(decisions, Is.Empty);
        }
コード例 #32
0
        public void Returns_cancel_timer_decision_for_timer_item_when_it_is_active()
        {
            SetupWorkflowToReturns(_builder.TimerStartedGraph(Identity.Timer("TimerName"), TimeSpan.FromSeconds(2)));
            var timerItem      = TimerItem.New(Identity.Timer("TimerName"), _workflow.Object);
            var workflowAction = WorkflowAction.Cancel(timerItem);

            var decisions = workflowAction.GetDecisions();

            Assert.That(decisions, Is.EqualTo(new[] { new CancelTimerDecision(Identity.Timer("TimerName")) }));
        }
コード例 #33
0
ファイル: TimerManager.cs プロジェクト: jackdevelop/ThreeCard
    public static void Run()
    {
        // 设置时间值
        TimerManager.time = Time.time;

        TimerItem[] objectList = new TimerItem[timerList.Values.Count];
        timerList.Values.CopyTo(objectList, 0);

        // 锁定
        foreach(TimerItem timerItem in objectList)
        {
            if(timerItem != null) timerItem.Run(TimerManager.time);
        }
    }
コード例 #34
0
        /// <summary>
        /// Handle discovery message from peer node
        /// </summary>
        /// <param name="node"></param>
        public void HandleDiscoveryReply(UInt16 node)
        {
            // reset timeout counter
            lock (_data)
            {
                int count = _data.Count;
                for (int i = 0; i < count; i++)
                {
                    TimerItem item = _data[i] as TimerItem;
                    if (item.shortAddr == node)
                    {
                        item.timeoutCounter = 0;
                        return;
                    }
                }

                // add node to list
                {
                    TimerItem item = new TimerItem();
                    item.shortAddr = node;
                    item.timeoutCounter = 0;
                    lock (_data)
                    {
                        _data.Add(item);
                    }

                    _callbacks.NodeChanged(node, true);
                }
            }
        }
コード例 #35
0
        /// <summary>
        /// allocate a short address and update set of available nodes
        /// </summary>
        /// <param name="extAddr">the extended address of the target node</param>
        /// <param name="shortAddr">the allocated short address</param>
        /// <returns>true on success</returns>
        public override bool AllocateAddress(UInt64 extAddr, out UInt16 shortAddr)
        {
            bool res = base.AllocateAddress(extAddr, out shortAddr);
            if (res)
            {
                // save current address mapping
                base.Save();
                // add node to list
                TimerItem item = null;
                // - check if entry already exists
                lock (_data)
                {
                    int count = _data.Count;
                    for (int i = 0; i < count; i++)
                    {
                        item = _data[i] as TimerItem;
                        if (item.shortAddr == shortAddr)
                        {
                            item.timeoutCounter = 0;
                            break;
                        }

                        item = null;
                    }
                }

                if (item != null)
                {
                    // if an existing node requests an address, it has reset.
                    // inform users by toggling its presence
                    _callbacks.NodeChanged(shortAddr, false);
                }
                else
                {
                    // - create new entry
                    item = new TimerItem();
                    item.shortAddr = shortAddr;
                    item.timeoutCounter = 0;
                    lock (_data)
                    {
                        _data.Add(item);
                    }
                }

                _callbacks.NodeChanged(shortAddr, true);
            }

            return res;
        }
コード例 #36
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     TimerItem timerForm = new TimerItem(m_items);
     timerForm.Show();
     Imported.ItemsSource = m_items;
     this.UpdateLayout();
 }
コード例 #37
0
        /// <summary>
        /// note: need to have acquired the lock
        /// </summary>
        /// <param name="item"></param>
        private void AddItemToList(TimerItem item)
        {
            int index = 0;
            int itemsCount = _timerItems.Count;
            if (itemsCount >= _maxItems)
                throw new ArgumentException("Already reached max number of timer elements.");

            for (int i = 0; i < itemsCount; i++)
            {
                TimerItem currentItem = (TimerItem)_timerItems[i];
                if (currentItem.TimeoutTicks > item.TimeoutTicks)
                {
                    index = i;
                    break;
                }
            }

            _timerItems.Insert(index, item);
            if (index == 0)
            {
                int dueTime = (int)((item.TimeoutTicks - DateTime.Now.Ticks) / TimeSpan.TicksPerMillisecond);
                if (dueTime < 0) { dueTime = 0; }
                _timer.Change(dueTime, System.Threading.Timeout.Infinite);
            }
        }