예제 #1
0
        /// <summary>
        /// Trim all texts.
        /// </summary>
        /// <param name="I18NText">A text.</param>
        public static I18NText TrimAll(this I18NText I18NText)
        {
            if (I18NText == null)
            {
                return(null);
            }

            return(new I18NText(I18NText.Select(text => new KeyValuePair <LanguageCode, String>(
                                                    text.Key,
                                                    text.Value?.Trim()
                                                    ))));
        }
예제 #2
0
        /// <summary>
        /// Return a substring of the given maximum length.
        /// </summary>
        /// <param name="I18NText">A text.</param>
        /// <param name="Length">The maximum length of the substring.</param>
        public static I18NText SubstringMax(this I18NText I18NText, Int32 Length)
        {
            if (I18NText == null)
            {
                return(null);
            }

            return(new I18NText(I18NText.Select(text => new KeyValuePair <LanguageCode, String>(
                                                    text.Key,
                                                    text.Value.Substring(0, Math.Min(text.Value.Length, Length))
                                                    ))));
        }
예제 #3
0
        /// <summary>
        /// Create a valid charging station identification based on the given parameters.
        /// </summary>
        /// <param name="OperatorId">The identification of an operator.</param>
        /// <param name="Address">The address of the charging station.</param>
        /// <param name="GeoLocation">An optional geo location of the charging station.</param>
        /// <param name="SubOperatorName">An optional name of the charging station suboperator.</param>
        /// <param name="ChargingStationName">An optional multi-language name of the charging station.</param>
        /// <param name="Length">The maximum size of the generated charging station identification suffix [12 &lt; n &lt; 50].</param>
        /// <param name="Mapper">A delegate to modify a generated charging station identification suffix.</param>
        public static ChargingStation_Id Generate(Operator_Id OperatorId,
                                                  Address Address,
                                                  GeoCoordinates?GeoLocation   = null,
                                                  String SubOperatorName       = null,
                                                  I18NText ChargingStationName = null,
                                                  Byte Length = 15,
                                                  Func <String, String> Mapper = null)
        {
            if (Length < 12)
            {
                Length = 12;
            }

            if (Length > 50)
            {
                Length = 50;
            }

            var Suffix = new SHA256CryptoServiceProvider().
                         ComputeHash(Encoding.UTF8.GetBytes(
                                         String.Concat(
                                             OperatorId.ToString(),
                                             Address.ToString(),
                                             GeoLocation?.ToString() ?? "",
                                             SubOperatorName ?? "",
                                             ChargingStationName?.ToJSON()?.ToString(Formatting.None) ?? ""
                                             )
                                         )).
                         ToHexString().
                         SubstringMax(Length).
                         ToUpper();

            return(Parse(Mapper != null
                            ? Mapper(Suffix)
                            : Suffix));
        }
예제 #4
0
 /// <summary>
 /// Return the first string of a multi-language string.
 /// </summary>
 public static String FirstText(this I18NText Text)
 => Text != null && Text.Any()
            ? Text.First().Value
            : null;
예제 #5
0
 /// <summary>
 /// The multi-language string is neither null nor empty.
 /// </summary>
 public static Boolean IsNeitherNullNorEmpty(this I18NText Text)
 => Text != null && Text.Any();
예제 #6
0
 /// <summary>
 /// The multi-language string is empty.
 /// </summary>
 public static Boolean IsNullOrEmpty(this I18NText Text)
 => Text == null || !Text.Any();
예제 #7
0
        /// <summary>
        /// Convert the given String into a multi-language text.
        /// </summary>
        /// <param name="Text">A string.</param>
        /// <param name="Language">A language.</param>
        public static I18NText ToI18NText(this String Text,
                                          LanguageCode?Language = null)

        => Text.IsNotNullOrEmpty()
                   ? I18NText.Create(Language ?? LanguageCode.en, Text)
                   : null;