Ejemplo n.º 1
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            if (intent.Action != null && intent.Action.Equals("STOP_TIMER"))
            {
                // Open app and
                MessagingCenter.Send <object>(this, "StopTime");
            }
            else
            {
                this._timeSpanToStringConverter = new TimeSpanToStringConverter();

                this._isRuning = true;

                // Work has finished, now dispatch anotification to let the user know.
                this._notificationBuilder = new Notification.Builder(this)
                                            .SetSmallIcon(Resource.Drawable.icon)
                                            .SetContentTitle(Title)
                                            .SetContentText(this._timeSpanToStringConverter.Convert(DateTime.UtcNow.Subtract(StartDateTime), null, null, null).ToString())
                                            .SetOngoing(true)
                                            //.SetContentIntent(PendingIntent.GetActivity(Forms.Context, 0, intent, PendingIntentFlags.UpdateCurrent));
                                            .AddAction(StopTimerAction());

                var notificationManager = (NotificationManager)GetSystemService(NotificationService);

                Task.Run(async() => await Update());
                notificationManager.Notify(NOTIFICATION_ID, this._notificationBuilder.Build());
            }

            return(StartCommandResult.NotSticky);
        }
        public void TestConvertToString(TimeSpan value, string expected)
        {
            var converter = new TimeSpanToStringConverter();
            var result    = (string)converter.Convert(value, typeof(string), null, CultureInfo.InvariantCulture);

            Assert.Equal(result, expected);
        }
        public void TimeSpanToStringConverter_PerElements()
        {
            var con = new TimeSpanToStringConverter();

            con.Mode = TimeSpanToStringMode.PerElements;

            var res = con.Convert(TimeSpan.Parse("1.18:53:58.1234567"), CultureInfo.CurrentCulture);

            Assert.Contains($"1 {Strings.day}", res);
            Assert.Contains($"18 {Strings.hours}", res);
            Assert.Contains($"53 {Strings.minutes}", res);
            Assert.Contains($"58 {Strings.seconds}", res);
            Assert.Contains($"123 {Strings.milliseconds}", res);

            con.NumberOfElements = 3;

            res = con.Convert(TimeSpan.Parse("1.18:53:58.1234567"), CultureInfo.CurrentCulture);
            Assert.Contains($"1 {Strings.day}", res);
            Assert.Contains($"18 {Strings.hours}", res);
            Assert.Contains($"53 {Strings.minutes}", res);
            Assert.DoesNotContain($"58 {Strings.seconds}", res);
            Assert.DoesNotContain($"123 {Strings.milliseconds}", res);

            res = con.Convert(TimeSpan.Parse("0.18:53:58.1234567"), CultureInfo.CurrentCulture);
            Assert.DoesNotContain($"0 {Strings.day}", res);
            Assert.Contains($"18 {Strings.hours}", res);
            Assert.Contains($"53 {Strings.minutes}", res);
            Assert.Contains($"58 {Strings.seconds}", res);
            Assert.DoesNotContain($"123 {Strings.milliseconds}", res);
        }
        public void TimeSpanToStringConverter_First()
        {
            var con = new TimeSpanToStringConverter();

            con.Mode = TimeSpanToStringMode.PerElements;
            //con.NumberOfElements = 3;
            output.WriteLine($"1.18:53:58.1234567 => {con.Convert(TimeSpan.Parse("1.18:53:58.1234567"), null, CultureInfo.CurrentCulture)}");
            output.WriteLine($"0.18:53:58.1234567 => {con.Convert(TimeSpan.Parse("0.18:53:58.1234567"), null, CultureInfo.CurrentCulture)}");
            output.WriteLine($"0.00:53:58.1234567 => {con.Convert(TimeSpan.Parse("0.00:53:58.1234567"), null, CultureInfo.CurrentCulture)}");
        }
Ejemplo n.º 5
0
        public static TimeSpan?ParseTimeSpan(string s)
        {
            var timeSpanToStringConverter = new TimeSpanToStringConverter();

            try {
                return((TimeSpan?)ConvertWith(s, timeSpanToStringConverter));
            }
            catch (ArgumentException) {
                throw new ArgumentException("Failed to parse time span.");
            }
        }
    public void Write()
    {
        //Arrange
        var converter = new TimeSpanToStringConverter();

        using var stream = new MemoryStream();
        using var writer = new Utf8JsonWriter(stream);

        var options = KSqlDbJsonSerializerOptions.CreateInstance();

        var timeSpan = new TimeSpan(1, 1, 11);

        //Act
        converter.Write(writer, timeSpan, options);
        writer.Flush();

        //Assert
        stream.ToArray().Length.Should().NotBe(0);
    }
Ejemplo n.º 7
0
        public DebugOutputFilterStrategy()
        {
            if (Application.Current != null)
            {
                _timeSpanToStringConverter = Application.Current.Resources["TimeSpanToStringConverter"] as TimeSpanToStringConverter;
                _dateTimeToStringConverter = Application.Current.Resources["DateTimeToStringConverter"] as DateTimeToStringConverter;
                _enumToStringConverter     = Application.Current.Resources["EnumToStringConverter"] as EnumToStringConverter;
            }

            if (_timeSpanToStringConverter == null)
            {
                _timeSpanToStringConverter = new TimeSpanToStringConverter();
            }

            if (_dateTimeToStringConverter == null)
            {
                _dateTimeToStringConverter = new DateTimeToStringConverter();
            }

            if (_enumToStringConverter == null)
            {
                _enumToStringConverter = new EnumToStringConverter();
            }
        }
 private TimeSpanToReadableTextConverter()
 {
     _converter = new TimeSpanToStringConverter();
 }