Exemple #1
0
        /// <summary>
        /// Builds the string representation for this string, just for one part of the time
        /// (may be the days, the hours, the mins, etc).
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="p"></param>
        /// <param name="dto"></param>
        /// <param name="dstr"></param>
        private static void BuildDescriptiveFragment(StringBuilder sb, int p, DescriptiveTextOptions dto, string dstr)
        {
            if (((dto & DescriptiveTextOptions.IncludeZeroes) == DescriptiveTextOptions.None) && p == 0)
            {
                return;
            }

            if ((dto & DescriptiveTextOptions.IncludeCommas) != DescriptiveTextOptions.None)
            {
                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
            }

            if ((dto & DescriptiveTextOptions.SpaceBetween) != DescriptiveTextOptions.None)
            {
                if (sb.Length > 0)
                {
                    sb.Append(' ');
                }
            }

            sb.Append(p.ToString(CultureConstants.DefaultCulture));

            if ((dto & DescriptiveTextOptions.SpaceText) != DescriptiveTextOptions.None)
            {
                sb.Append(' ');
            }

            if ((dto & DescriptiveTextOptions.FirstLetterUppercase) != DescriptiveTextOptions.None)
            {
                dstr = char.ToUpper(dstr[0], CultureConstants.DefaultCulture) + dstr.Substring(1);
            }

            if ((dto & DescriptiveTextOptions.UppercaseText) != DescriptiveTextOptions.None)
            {
                dstr = dstr.ToUpper(CultureConstants.DefaultCulture);
            }

            if ((dto & DescriptiveTextOptions.FullText) != DescriptiveTextOptions.None)
            {
                if (p == 1)
                {
                    dstr = dstr.Substring(0, dstr.Length - 1);
                }

                sb.Append(dstr);
            }
            else
            {
                sb.Append(dstr[0]);
            }
        }
Exemple #2
0
        /// <summary>
        /// Convert a timespan into English text.
        /// </summary>
        /// <param name="ts">The timespan.</param>
        /// <param name="dto">Formatting options.</param>
        /// <returns>Timespan formatted as English text.</returns>
        public static string TimeSpanToDescriptiveText(TimeSpan ts, DescriptiveTextOptions dto, bool includeSeconds)
        {
            StringBuilder sb = new StringBuilder();

            BuildDescriptiveFragment(sb, ts.Days, dto, "days");
            BuildDescriptiveFragment(sb, ts.Hours, dto, "hours");
            BuildDescriptiveFragment(sb, ts.Minutes, dto, "minutes");
            if (includeSeconds)
            {
                BuildDescriptiveFragment(sb, ts.Seconds, dto, "seconds");
            }
            if (sb.Length == 0)
            {
                sb.Append("(none)");
            }
            return(sb.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Builds the string representation for this string, just for one part of the time (may be the days, the hours, the mins, etc)
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="p"></param>
        /// <param name="dto"></param>
        /// <param name="dstr"></param>
        private static void BuildDescriptiveFragment(StringBuilder sb, int p, DescriptiveTextOptions dto, string dstr)
        {
            if (((dto & DescriptiveTextOptions.IncludeZeroes) == 0) && p == 0)
            {
                return;
            }
            if ((dto & DescriptiveTextOptions.IncludeCommas) != 0)
            {
                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
            }
            if ((dto & DescriptiveTextOptions.SpaceBetween) != 0)
            {
                sb.Append(" ");
            }

            sb.Append(p.ToString());
            if ((dto & DescriptiveTextOptions.SpaceText) != 0)
            {
                sb.Append(' ');
            }
            if ((dto & DescriptiveTextOptions.UppercaseText) != 0)
            {
                dstr = dstr.ToUpper();
            }
            if ((dto & DescriptiveTextOptions.FullText) != 0)
            {
                if (p == 1)
                {
                    dstr = dstr.Substring(0, dstr.Length - 1);
                }
                sb.Append(dstr);
            }
            else
            {
                sb.Append(dstr[0]);
            }
        }
Exemple #4
0
 /// <summary>
 /// Convert a timespan into English text.
 /// </summary>
 /// <param name="ts">The timespan.</param>
 /// <param name="dto">Formatting options.</param>
 /// <returns>Timespan formatted as English text.</returns>
 public static string TimeSpanToDescriptiveText(TimeSpan ts, DescriptiveTextOptions dto)
 {
     return(TimeSpanToDescriptiveText(ts, dto, true));
 }
Exemple #5
0
        /// <summary>
        /// Builds the string representation for this string, just for one part of the time
        /// (may be the days, the hours, the mins, etc).
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="p"></param>
        /// <param name="dto"></param>
        /// <param name="dstr"></param>
        private static void BuildDescriptiveFragment(StringBuilder sb, int p, DescriptiveTextOptions dto, string dstr)
        {
            if (((dto & DescriptiveTextOptions.IncludeZeroes) == DescriptiveTextOptions.None) && p == 0)
                return;

            if ((dto & DescriptiveTextOptions.IncludeCommas) != DescriptiveTextOptions.None)
            {
                if (sb.Length > 0)
                    sb.Append(", ");
            }

            if ((dto & DescriptiveTextOptions.SpaceBetween) != DescriptiveTextOptions.None)
            {
                if (sb.Length > 0)
                    sb.Append(' ');
            }

            sb.Append(p.ToString(CultureConstants.DefaultCulture));

            if ((dto & DescriptiveTextOptions.SpaceText) != DescriptiveTextOptions.None)
                sb.Append(' ');

            if ((dto & DescriptiveTextOptions.FirstLetterUppercase) != DescriptiveTextOptions.None)
                dstr = char.ToUpper(dstr[0], CultureConstants.DefaultCulture) + dstr.Substring(1);

            if ((dto & DescriptiveTextOptions.UppercaseText) != DescriptiveTextOptions.None)
                dstr = dstr.ToUpper(CultureConstants.DefaultCulture);

            if ((dto & DescriptiveTextOptions.FullText) != DescriptiveTextOptions.None)
            {
                if (p == 1)
                    dstr = dstr.Substring(0, dstr.Length - 1);

                sb.Append(dstr);
            }
            else
                sb.Append(dstr[0]);
        }
Exemple #6
0
        /// <summary>
        /// Convert a timespan into English text.
        /// </summary>
        /// <param name="ts">The timespan.</param>
        /// <param name="dto">Formatting options.</param>
        /// <param name="includeSeconds"></param>
        /// <returns>Timespan formatted as English text.</returns>
        public static string ToDescriptiveText(this TimeSpan ts, DescriptiveTextOptions dto, bool includeSeconds = true)
        {
            StringBuilder sb = new StringBuilder();

            BuildDescriptiveFragment(sb, ts.Days, dto, "days");
            BuildDescriptiveFragment(sb, ts.Hours, dto, "hours");
            BuildDescriptiveFragment(sb, ts.Minutes, dto, "minutes");

            if (includeSeconds)
                BuildDescriptiveFragment(sb, ts.Seconds, dto, "seconds");

            if (sb.Length == 0)
                sb.Append("(none)");

            return sb.ToString();
        }
Exemple #7
0
        /// <summary>
        /// Adds the footer.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="boldEnd">The bold end.</param>
        /// <param name="index">The index.</param>
        /// <param name="endTime">The end time.</param>
        /// <param name="builder">The builder.</param>
        /// <param name="lineFeed">The line feed.</param>
        /// <param name="plan">The plan.</param>
        /// <param name="boldStart">The bold start.</param>
        private static void AddFooter(PlanExportSettings settings, string boldEnd, int index, DateTime endTime, StringBuilder builder,
                                      string lineFeed, BasePlan plan, string boldStart)
        {
            if (!settings.FooterCount && !settings.FooterTotalTime && !settings.FooterDate && !settings.FooterCost)
            {
                return;
            }

            builder.AppendLine(lineFeed);
            bool needComma = false;

            // Skills count
            if (settings.FooterCount)
            {
                builder
                .Append($"{boldStart}{plan.GetUniqueSkillsCount()}{boldEnd} " +
                        $"unique skill{(plan.GetUniqueSkillsCount() == 1 ? string.Empty : "s")}, ")
                .Append($"{boldStart}{index}{boldEnd} skill level{(index == 1 ? string.Empty : "s")}");

                needComma = true;
            }

            // Plan's training duration
            if (settings.FooterTotalTime)
            {
                const DescriptiveTextOptions TimeFormat =
                    DescriptiveTextOptions.FullText | DescriptiveTextOptions.IncludeCommas | DescriptiveTextOptions.SpaceText;

                if (needComma)
                {
                    builder.Append("; ");
                }

                needComma = true;

                builder.Append($"Total time: {boldStart}{plan.TotalTrainingTime.ToDescriptiveText(TimeFormat)}{boldEnd}");
            }

            // End training date
            if (settings.FooterDate)
            {
                if (needComma)
                {
                    builder.Append("; ");
                }

                needComma = true;

                builder.Append($"Completion: {boldStart}{endTime.ToUniversalTime().DateTimeToTimeString()}{boldEnd} UTC");
            }

            // Total books cost
            if (settings.FooterCost)
            {
                if (needComma)
                {
                    builder.Append("; ");
                }

                string formattedIsk = FormattableString.Invariant($"{plan.NotKnownSkillBooksCost:N0}");
                builder.Append($"Cost: {boldStart}{formattedIsk}{boldEnd} ISK");
            }

            // Warning about skill costs
            builder.Append(lineFeed);
            if (settings.FooterCost || settings.EntryCost)
            {
                builder.Append("N.B. Skill costs are based on CCP's database and are indicative only");
            }
        }
Exemple #8
0
        /// <summary>
        /// Adds the training time.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="shoppingListCandidate">if set to <c>true</c> [shopping list candidate].</param>
        /// <param name="entry">The entry.</param>
        /// <param name="builder">The builder.</param>
        private static void AddTrainingTime(PlanExportSettings settings, bool shoppingListCandidate, PlanEntry entry, StringBuilder builder)
        {
            if (!settings.EntryTrainingTimes && !settings.EntryStartDate && !settings.EntryFinishDate &&
                (!settings.EntryCost || !shoppingListCandidate))
            {
                return;
            }

            const DescriptiveTextOptions TimeFormat = DescriptiveTextOptions.FullText
                                                      | DescriptiveTextOptions.IncludeCommas
                                                      | DescriptiveTextOptions.SpaceText;

            builder.Append(" (");
            bool needComma = false;

            // Training time
            if (settings.EntryTrainingTimes)
            {
                needComma = true;
                builder.Append(entry.TrainingTime.ToDescriptiveText(TimeFormat));
            }

            // Training start date
            if (settings.EntryStartDate)
            {
                if (needComma)
                {
                    builder.Append("; ");
                }

                needComma = true;

                builder.Append($"Start: {entry.StartTime.ToUniversalTime().DateTimeToTimeString()} UTC");
            }

            // Training end date
            if (settings.EntryFinishDate)
            {
                if (needComma)
                {
                    builder.Append("; ");
                }

                needComma = true;

                builder.Append($"Finish: {entry.EndTime.ToUniversalTime().DateTimeToTimeString()} UTC");
            }

            // Skill cost
            if (settings.EntryCost && shoppingListCandidate)
            {
                if (needComma)
                {
                    builder.Append("; ");
                }

                builder.Append(FormattableString.Invariant($"Cost: {entry.Skill.Cost:N0} ISK"));
            }

            builder.Append(')');
        }
 /// <summary>
 /// Convert a timespan into English text.
 /// </summary>
 /// <param name="ts">The timespan.</param>
 /// <param name="dto">Formatting options.</param>
 /// <returns>Timespan formatted as English text.</returns>
 public static string ToDescriptiveText(this TimeSpan ts, DescriptiveTextOptions dto)
 {
     return ToDescriptiveText(ts, dto, true);
 }