コード例 #1
0
        protected override async Task Handle()
        {
            if (NotificationDevices.Count == 0)
            {
                return;
            }

            if (_evt.IsOpenEvent)
            {
                if (NumberOfNotifications < 1)
                {
                    NumberOfNotifications = 1;
                }
                if (String.IsNullOrEmpty(NotificationFormat))
                {
                    NotificationFormat = @"{0} has been open {1} minutes.";
                }

                for (int i = 0; i < NumberOfNotifications; i++)
                {
                    await WaitForCancellationAsync(HowLong);

                    await NotificationDevices.Speak(String.Format(NotificationFormat,
                                                                  _evt.DisplayName, HowLong.TotalMinutes * (i + 1), HowLong.TotalSeconds * (i + 1)));

                    // There's an unused string parameter being passed into String.Format.
                    // That way the deriving class can set the NotificationFormat to mention
                    // either "seconds" or "minutes."
                }
            }
            else if (_evt.IsClosedEvent && NotifyOnClose)
            {
                await NotificationDevices.Speak($"{_evt.DisplayName} is closed.");
            }
        }
コード例 #2
0
        public override async Task Handle(CancellationToken token)
        {
            if (_evt.IsOpenEvent)
            {
                if (NumberOfNotifications < 1)
                {
                    NumberOfNotifications = 1;
                }
                if (String.IsNullOrEmpty(NotificationFormat))
                {
                    NotificationFormat = @"{0} has been open {1} minutes.";
                }

                for (int i = 0; i < NumberOfNotifications; i++)
                {
                    await Task.Delay(HowLong, token);

                    NotificationDevices.Speak(String.Format(NotificationFormat,
                                                            _evt.DisplayName, HowLong.TotalMinutes * (i + 1), HowLong.TotalSeconds * (i + 1)));
                    // Yes, there's an extra parameter being passed into String.Format.
                    // I wanted to ensure the NotificationFormat has some flexibility
                    // insofar as the text that is passed in.
                }
            }
            else if (_evt.IsClosedEvent && NotifyOnClose)
            {
                NotificationDevices.Speak($"{_evt.DisplayName} is closed.");
            }
        }