Exemplo n.º 1
0
        private async Task TimerCommandsBackground()
        {
            int timerCommandIndex = 0;
            await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) =>
            {
                DateTimeOffset startTime = DateTimeOffset.Now;
                int startMessageCount    = this.Messages.Count;

                tokenSource.Token.ThrowIfCancellationRequested();

                await Task.Delay(1000 * 60 * ChannelSession.Settings.TimerCommandsInterval);

                tokenSource.Token.ThrowIfCancellationRequested();

                IEnumerable <TimerCommand> timers = ChannelSession.Settings.TimerCommands.Where(c => c.IsEnabled);
                if (timers.Count() > 0)
                {
                    timerCommandIndex    = timerCommandIndex % timers.Count();
                    TimerCommand command = timers.ElementAt(timerCommandIndex);

                    while ((this.Messages.Count - startMessageCount) < ChannelSession.Settings.TimerCommandsMinimumMessages)
                    {
                        tokenSource.Token.ThrowIfCancellationRequested();
                        await Task.Delay(1000 * 10);
                    }

                    await command.Perform();

                    timerCommandIndex++;
                }
            });
        }
Exemplo n.º 2
0
        private async Task <DeviceCommand> CallLuisAsync(string input)
        {
            var parsedMessage = await luisClient.parseInput(input);

            CommandBase command;

            switch (parsedMessage.topScoringIntent.intent)
            {
            case "Count":
                command = new CountCommand(parsedMessage.entities);
                break;

            case "Location":
                command = new LocationCommand(parsedMessage.entities);
                break;

            case "Calculation":
                command = new CalculationCommand(parsedMessage.entities);
                break;

            case "Timer":
                command = new TimerCommand(parsedMessage.entities);
                break;

            default:
                command = new NoneCommand();
                break;
            }

            return(await command.Run());
        }
Exemplo n.º 3
0
        private async Task TimerCommandsBackground()
        {
            int timerCommandIndex = 0;
            await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) =>
            {
                DateTimeOffset startTime = DateTimeOffset.Now;
                int startMessageCount    = this.Messages.Count;

                tokenSource.Token.ThrowIfCancellationRequested();

                await Task.Delay(1000 * 60 * ChannelSession.Settings.TimerCommandsInterval);

                tokenSource.Token.ThrowIfCancellationRequested();

                if (ChannelSession.Settings.TimerCommands.Count > 0)
                {
                    TimerCommand command = ChannelSession.Settings.TimerCommands[timerCommandIndex];

                    while ((this.Messages.Count - startMessageCount) < ChannelSession.Settings.TimerCommandsMinimumMessages)
                    {
                        tokenSource.Token.ThrowIfCancellationRequested();
                        await Task.Delay(1000 * 10);
                    }

                    await command.Perform();

                    timerCommandIndex++;
                    timerCommandIndex = timerCommandIndex % ChannelSession.Settings.TimerCommands.Count;
                }
            });
        }
Exemplo n.º 4
0
        public override Task ConsumeCommandSpecific(ChatCommandReceivedEvent chatCommandReceivedEvent)
        {
            string[] parameters = chatCommandReceivedEvent.CommandArgs.Split(' ');
            if (parameters.Length < 2)
            {
                return(Task.CompletedTask);
            }

            if (!int.TryParse(parameters[0], out int timeInSeconds))
            {
                return(Task.CompletedTask);
            }

            string timerName = string.Join(" ", parameters.Skip(1));

            eventBus.Publish(new TextToSpeechEvent(chatCommandReceivedEvent.User, $"Der Timer {timerName} wurde gestartet."));

            TimeSpan timerLength = TimeSpan.FromSeconds(timeInSeconds);

            DateTime     now    = DateTime.Now;
            DateTime     doneAt = now.Add(timerLength);
            TimerCommand timer  = new TimerCommand(timerName, doneAt, new DefaultTimeProvider());

            timerStore.AddTimer(timer);

            Task.Delay(timerLength).ContinueWith(o => PublishTimeEnded(timer, chatCommandReceivedEvent.User));
            return(Task.CompletedTask);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            var arguments = new CommandLineArgs(args);
            var printTime = new PrintTimeCommand();
            var timer     = new TimerCommand(arguments);
            var commands  = new ICommand[] { printTime, timer };

            new Program(arguments, commands).Run();
        }
Exemplo n.º 6
0
        public void FormattedTimeLeft_TimerWithFifteenSecondsLeft_ShouldReturnSecondsPart()
        {
            DateTime     referenceTime = fixture.PrepareReferenceTime();
            TimerCommand testObject    = fixture.CreateTestObjectWith("Test", referenceTime.AddSeconds(15));

            string timeLeft = testObject.FormattedTimeLeft;

            Assert.That(timeLeft, Is.EqualTo("15 Sek"));
        }
Exemplo n.º 7
0
        public void FormattedTimeLeft_TimerWithOneSecondLeft_ShouldUseSingular()
        {
            DateTime     referenceTime = fixture.PrepareReferenceTime();
            TimerCommand testObject    = fixture.CreateTestObjectWith("Test", referenceTime.AddSeconds(1));

            string timeLeft = testObject.FormattedTimeLeft;

            Assert.That(timeLeft, Is.EqualTo("1 Sek"));
        }
Exemplo n.º 8
0
        public void FormattedTimeLeft_TimerWithTwoMinutesAndTwentySecondsLeft_ShouldReturnMinutesAndSecondsPart()
        {
            DateTime     referenceTime = fixture.PrepareReferenceTime();
            TimerCommand testObject    = fixture.CreateTestObjectWith("Test", referenceTime.AddMinutes(2).AddSeconds(20));

            string timeLeft = testObject.FormattedTimeLeft;

            Assert.That(timeLeft, Is.EqualTo("2 Min 20 Sek"));
        }
Exemplo n.º 9
0
        public void FormattedTimeLeft_TimerWithOneMinuteLeft_ShouldReturnSingularMinutePart()
        {
            DateTime     referenceTime = fixture.PrepareReferenceTime();
            TimerCommand testObject    = fixture.CreateTestObjectWith("Test", referenceTime.AddMinutes(1));

            string timeLeft = testObject.FormattedTimeLeft;

            Assert.That(timeLeft, Is.EqualTo("1 Min"));
        }
Exemplo n.º 10
0
        public void FormattedTimeLeft_TimerWithTwelveHoursTenMinutesAndElevenSecondsLeft_ShouldReturnHoursMinutesAndSecondsPart()
        {
            DateTime     referenceTime = fixture.PrepareReferenceTime();
            TimerCommand testObject    = fixture.CreateTestObjectWith("Test", referenceTime.AddHours(12).AddMinutes(10).AddSeconds(11));

            string timeLeft = testObject.FormattedTimeLeft;

            Assert.That(timeLeft, Is.EqualTo("12 Std 10 Min 11 Sek"));
        }
Exemplo n.º 11
0
        public void FormattedTimeLeft_TimerWithOneHourThirtyTwoMinutesAndOneSecondLeft_ShouldReturnHoursMinutesAndSecondsPart()
        {
            DateTime     referenceTime = fixture.PrepareReferenceTime();
            TimerCommand testObject    = fixture.CreateTestObjectWith("Test", referenceTime.AddHours(1).AddMinutes(32).AddSeconds(1));

            string timeLeft = testObject.FormattedTimeLeft;

            Assert.That(timeLeft, Is.EqualTo("1 Std 32 Min 1 Sek"));
        }
Exemplo n.º 12
0
        private void CommandButtons_EditClicked(object sender, RoutedEventArgs e)
        {
            CommandButtonsControl commandButtonsControl = (CommandButtonsControl)sender;
            TimerCommand          command = commandButtonsControl.GetCommandFromCommandButtons <TimerCommand>(sender);

            if (command != null)
            {
                CommandWindow window = new CommandWindow(new TimerCommandDetailsControl(command));
                window.Closed += Window_Closed;
                window.Show();
            }
        }
Exemplo n.º 13
0
 private async void CommandButtons_DeleteClicked(object sender, RoutedEventArgs e)
 {
     await this.Window.RunAsyncOperation(async() =>
     {
         CommandButtonsControl commandButtonsControl = (CommandButtonsControl)sender;
         TimerCommand command = commandButtonsControl.GetCommandFromCommandButtons <TimerCommand>(sender);
         if (command != null)
         {
             ChannelSession.Settings.TimerCommands.Remove(command);
             await ChannelSession.SaveSettings();
             this.RefreshList();
         }
     });
 }
        private async Task SaveAndClose(bool isBasic)
        {
            await this.window.RunAsyncOperation(async() =>
            {
                if (string.IsNullOrEmpty(this.NameTextBox.Text))
                {
                    await DialogHelper.ShowMessage("Name is missing");
                    return;
                }

                ActionBase action = this.actionControl.GetAction();
                if (action == null)
                {
                    if (this.actionControl is ChatActionControl)
                    {
                        await DialogHelper.ShowMessage("The chat message must not be empty");
                    }
                    else if (this.actionControl is SoundActionControl)
                    {
                        await DialogHelper.ShowMessage(MixItUp.Base.Resources.EmptySoundFilePath);
                    }
                    return;
                }

                TimerCommand newCommand = new TimerCommand(this.NameTextBox.Text);
                newCommand.IsBasic      = isBasic;
                newCommand.Actions.Add(action);

                if (this.command != null)
                {
                    ChannelSession.Settings.TimerCommands.Remove(this.command);
                    newCommand.ID = this.command.ID;
                }
                ChannelSession.Settings.TimerCommands.Add(newCommand);
                this.CommandSavedSuccessfully(newCommand);

                await ChannelSession.SaveSettings();

                this.window.Close();

                if (!isBasic)
                {
                    await Task.Delay(250);
                    CommandWindow window            = new CommandWindow(new TimerCommandDetailsControl(newCommand));
                    window.CommandSaveSuccessfully += (sender, cmd) => this.CommandSavedSuccessfully(cmd);
                    window.Show();
                }
            });
        }
Exemplo n.º 15
0
 public override async Task <CommandBase> GetNewCommand()
 {
     if (await this.Validate())
     {
         if (this.command == null)
         {
             this.command = new TimerCommand(this.NameTextBox.Text);
             ChannelSession.Settings.TimerCommands.Add(this.command);
         }
         else
         {
             this.command.Name = this.NameTextBox.Text;
         }
         return(this.command);
     }
     return(null);
 }
        private async void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            await this.window.RunAsyncOperation(async() =>
            {
                if (string.IsNullOrEmpty(this.NameTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("Name is missing");
                    return;
                }

                ActionBase action = this.actionControl.GetAction();
                if (action == null)
                {
                    if (this.actionControl is ChatActionControl)
                    {
                        await MessageBoxHelper.ShowMessageDialog("The chat message must not be empty");
                    }
                    else if (this.actionControl is SoundActionControl)
                    {
                        await MessageBoxHelper.ShowMessageDialog("The sound file path must not be empty");
                    }
                    return;
                }

                TimerCommand newCommand = new TimerCommand(this.NameTextBox.Text);
                newCommand.IsBasic      = true;
                newCommand.Actions.Add(action);

                if (this.command != null)
                {
                    ChannelSession.Settings.TimerCommands.Remove(this.command);
                    newCommand.ID = this.command.ID;
                }
                ChannelSession.Settings.TimerCommands.Add(newCommand);
                this.CommandSavedSuccessfully(newCommand);

                await ChannelSession.SaveSettings();

                this.window.Close();
            });
        }
Exemplo n.º 17
0
    void Update()
    {
        if (GameplayController.Instance == null || GameplayController.Instance.IsPause || GameplayController.Instance.IsPausePopup)
        {
            return;
        }

        for (int i = 0; i < mCommands.Count; i++)
        {
            TimerCommand cmd = mCommands[i];

            if (cmd.MaskState == GameplayController.Instance.State || cmd.MaskState == GameplayController.GameState.None)
            {
                cmd.passedTime += Time.deltaTime;
                if (cmd.passedTime >= cmd.Interval)
                {
                    cmd.action.Invoke(cmd.passedTime);
                    cmd.passedTime = 0f;
                }
            }
        }
    }
Exemplo n.º 18
0
        public override async Task <CommandBase> GetNewCommand()
        {
            if (await this.Validate())
            {
                if (this.command == null)
                {
                    this.command = new TimerCommand(this.NameTextBox.Text);
                    ChannelSession.Settings.TimerCommands.Add(this.command);
                }
                else
                {
                    this.command.Name = this.NameTextBox.Text;
                }
                this.command.Unlocked = this.UnlockedControl.Unlocked;

                this.command.GroupName = !string.IsNullOrEmpty(this.CommandGroupComboBox.Text) ? this.CommandGroupComboBox.Text : null;
                if (!string.IsNullOrEmpty(this.CommandGroupComboBox.Text))
                {
                    if (!ChannelSession.Settings.CommandGroups.ContainsKey(this.CommandGroupComboBox.Text))
                    {
                        ChannelSession.Settings.CommandGroups[this.CommandGroupComboBox.Text] = new CommandGroupSettings(this.CommandGroupComboBox.Text);
                    }

                    ChannelSession.Settings.CommandGroups[this.CommandGroupComboBox.Text].Name = this.CommandGroupComboBox.Text;
                    if (!string.IsNullOrEmpty(this.GroupTimerTextBox.Text) && int.TryParse(this.GroupTimerTextBox.Text, out int timerInterval))
                    {
                        ChannelSession.Settings.CommandGroups[this.CommandGroupComboBox.Text].TimerInterval = timerInterval;
                    }
                    else
                    {
                        ChannelSession.Settings.CommandGroups[this.CommandGroupComboBox.Text].TimerInterval = 0;
                    }
                }

                return(this.command);
            }
            return(null);
        }
Exemplo n.º 19
0
 public GatewayPollTimerCommandMessage(object sender, TimerCommand command) : base(sender)
 {
     Command = command;
 }
Exemplo n.º 20
0
 public void Create(TimerCommand command)
 {
     mCommands.Add(command);
 }
Exemplo n.º 21
0
 public override void ExecuteHotkey(int index)
 {
     TimerCommand.Execute(Hotkey[index].Name);
     //base.ExecuteHotkey(index);
 }
 public BasicTimerCommandEditorControl(CommandWindow window, TimerCommand command)
     : this(window, BasicCommandTypeEnum.None)
 {
     this.command = command;
 }
 public GatewayQueueTimerCommandMessage(object sender, TimerCommand command)
     : base(sender)
 {
     this.Command = command;
 }
Exemplo n.º 24
0
    public void Create(TimerCommand command)
    {
        mCommands.Add(command);
//		Debug.Log ("Create timer action: " + command.action.Method.Name);
    }
Exemplo n.º 25
0
 public void DeleteTimer(TimerCommand timer)
 {
     timers.Remove(timer);
 }
Exemplo n.º 26
0
 public void AddTimer(TimerCommand timer)
 {
     timers.Add(timer);
 }
Exemplo n.º 27
0
 public TimerCommandDetailsControl(TimerCommand command)
 {
     this.command = command;
     InitializeComponent();
 }
Exemplo n.º 28
0
 private void PublishTimeEnded(TimerCommand timer, ChannelUser user)
 {
     eventBus.Publish(new TextToSpeechEvent(user, $"Der Timer {timer.Name} ist abgelaufen."));
     timerStore.DeleteTimer(timer);
 }
Exemplo n.º 29
0
 private void CommandTriggerTimerCallback(object sender, EventArgs e)
 {
     TimerCommand?.Execute(null);
 }