Beispiel #1
0
        /// <summary>
        /// Performs the dictionary lookup and translates the text key based on the selected
        /// configuration.
        /// </summary>
        /// <returns>Text value for the builder's text key.</returns>
        public string Make()
        {
            var result = Tx.T(text, count, arguments.ToDictionary(p => p.Key, p => p.Value));

            if (upperCase)
            {
                result = Tx.UpperCase(result);
            }
            if (colon)
            {
                result += Tx.Colon();
            }
            if (quoteNested)
            {
                result = Tx.QuoteNested(result);
            }
            if (quote)
            {
                result = Tx.Quote(result);
            }
            if (parentheses)
            {
                result = Tx.Parentheses(result);
            }
            return(result);
        }
Beispiel #2
0
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string text;

            // Return the text key only in design mode. Nothing better to do for now.
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                switch (relKind)
                {
                case RelativeTimeKind.None:
                    text = Tx.Time(DateTime.Now, details);
                    break;

                case RelativeTimeKind.PointInTime:
                    text = Tx.RelativeTime(DateTime.Now.AddHours(2).AddMinutes(34));
                    break;

                case RelativeTimeKind.CurrentTimeSpan:
                    text = Tx.TimeSpan(DateTime.Now.AddHours(2).AddMinutes(34));
                    break;

                case RelativeTimeKind.TimeSpan:
                    text = Tx.TimeSpan(TimeSpan.FromHours(2) + TimeSpan.FromMinutes(34));
                    break;

                default:
                    text = "{Error: Invalid relKind}";                               // Should not happen
                    break;
                }
            }
            else
            {
                // values[0] is the dictionary Dummy binding, don't use it
                // values[1] is the timer Dummy binding, don't use it

                // Read the time value from binding number three.
                if (values[2] == DependencyProperty.UnsetValue)
                {
                    return(DependencyProperty.UnsetValue);
                }

                DateTime ConvertToDateTime(object obj) =>
                obj is DateTimeOffset dtos ? dtos.LocalDateTime : System.Convert.ToDateTime(obj);

                DateTime dt;
                TimeSpan ts;
                switch (relKind)
                {
                case RelativeTimeKind.None:
                    dt   = ConvertToDateTime(values[2]);
                    text = Tx.Time(dt, details);
                    break;

                case RelativeTimeKind.PointInTime:
                    dt   = ConvertToDateTime(values[2]);
                    text = Tx.RelativeTime(dt);
                    break;

                case RelativeTimeKind.CurrentTimeSpan:
                    dt   = ConvertToDateTime(values[2]);
                    text = Tx.TimeSpan(dt);
                    break;

                case RelativeTimeKind.TimeSpan:
                    if (values[2] is TimeSpan)
                    {
                        ts   = (TimeSpan)values[2];
                        text = Tx.TimeSpan(ts);
                    }
                    else
                    {
                        text = "";
                    }
                    break;

                default:
                    text = "{Error: Invalid relKind}";                               // Should not happen
                    break;
                }
            }

            if (upperCase)
            {
                text = Tx.UpperCase(text);
            }

            return(text);
        }