예제 #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
        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);
            }
        }
        /// <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
 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);
    }
 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
            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))));
        }
 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
        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
    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;
        }
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     TimerItem timerForm = new TimerItem(m_items);
     timerForm.Show();
     Imported.ItemsSource = m_items;
     this.UpdateLayout();
 }
        /// <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);
            }
        }