Пример #1
0
        /// <summary>
        /// Exports the plan under a text format.
        /// </summary>
        /// <param name="planToExport">The plan to export.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="exportActions">The export actions.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// planToExport
        /// or
        /// settings
        /// </exception>
        /// <exception cref="System.NotImplementedException"></exception>
        /// <exception cref="System.ArgumentNullException">planToExport or settings</exception>
        public static string ExportAsText(Plan planToExport, PlanExportSettings settings,
            Action<StringBuilder, PlanEntry, PlanExportSettings> exportActions = null)
        {
            planToExport.ThrowIfNull(nameof(planToExport));

            settings.ThrowIfNull(nameof(settings));

            PlanScratchpad plan = new PlanScratchpad(planToExport.Character, planToExport);
            plan.Sort(planToExport.SortingPreferences);
            plan.UpdateStatistics();

            StringBuilder builder = new StringBuilder();
            Character character = (Character)plan.Character;

            // Initialize constants
            string lineFeed = Environment.NewLine;
            string boldStart = String.Empty;
            string boldEnd = String.Empty;

            switch (settings.Markup)
            {
                case MarkupType.Forum:
                    boldStart = "[b]";
                    boldEnd = "[/b]";
                    break;
                case MarkupType.Html:
                    lineFeed = $"<br />{Environment.NewLine}";
                    boldStart = "<b>";
                    boldEnd = "</b>";
                    break;
                case MarkupType.Undefined:
                case MarkupType.None:
                    break;
                default:
                    throw new NotImplementedException();
            }

            // Header
            if (settings.IncludeHeader)
            {
                builder.Append(boldStart)
                    .Append($"{(settings.ShoppingList ? "Shopping list " : "Skill plan ")} for {character.Name}")
                    .Append(boldEnd)
                    .Append(lineFeed)
                    .Append(lineFeed);
            }

            // Scroll through entries
            int index = 0;
            DateTime endTime = DateTime.Now;
            foreach (PlanEntry entry in plan)
            {
                // Skip is we're only build a shopping list
                bool shoppingListCandidate = !(entry.CharacterSkill.IsKnown || entry.Level != 1 || entry.CharacterSkill.IsOwned);
                if (settings.ShoppingList && !shoppingListCandidate)
                    continue;

                // Remapping point
                if (!settings.ShoppingList && (entry.Remapping != null) && settings.RemappingPoints)
                {
                    builder
                        .Append($"***{entry.Remapping}***")
                        .Append(lineFeed);
                }

                // Entry's index
                index++;
                if (settings.EntryNumber)
                    builder.Append($"{index}. ");

                // Name
                builder.Append(boldStart);
                AddName(settings, entry, builder);
                builder.Append(boldEnd);

                // Training time
                AddTrainingTime(settings, shoppingListCandidate, entry, builder);

                exportActions?.Invoke(builder, entry, settings);

                builder.Append(lineFeed);

                // End time
                endTime = entry.EndTime;
            }

            // Footer
            AddFooter(settings, boldEnd, index, endTime, builder, lineFeed, plan, boldStart);

            // Returns the text representation.
            return builder.ToString().TrimEnd(Environment.NewLine.ToCharArray());
        }
Пример #2
0
        /// <summary>
        /// Exports the plan under a text format.
        /// </summary>
        /// <param name="planToExport">The plan to export.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="exportActions">The export actions.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">
        /// planToExport
        /// or
        /// settings
        /// </exception>
        /// <exception cref="System.NotImplementedException"></exception>
        /// <exception cref="System.ArgumentNullException">planToExport or settings</exception>
        public static string ExportAsText(Plan planToExport, PlanExportSettings settings,
                                          Action <StringBuilder, PlanEntry, PlanExportSettings> exportActions = null)
        {
            planToExport.ThrowIfNull(nameof(planToExport));

            settings.ThrowIfNull(nameof(settings));

            PlanScratchpad plan = new PlanScratchpad(planToExport.Character, planToExport);

            plan.Sort(planToExport.SortingPreferences);
            plan.UpdateStatistics();

            StringBuilder builder   = new StringBuilder();
            Character     character = (Character)plan.Character;

            // Initialize constants
            string lineFeed  = Environment.NewLine;
            string boldStart = string.Empty;
            string boldEnd   = string.Empty;

            switch (settings.Markup)
            {
            case MarkupType.Forum:
                boldStart = "[b]";
                boldEnd   = "[/b]";
                break;

            case MarkupType.Html:
                lineFeed  = $"<br />{Environment.NewLine}";
                boldStart = "<b>";
                boldEnd   = "</b>";
                break;

            case MarkupType.Undefined:
            case MarkupType.None:
                break;

            default:
                throw new NotImplementedException();
            }

            // Header
            if (settings.IncludeHeader)
            {
                builder.Append(boldStart)
                .Append($"{(settings.ShoppingList ? "Shopping list " : "Skill plan ")} for {character.Name}")
                .Append(boldEnd)
                .Append(lineFeed)
                .Append(lineFeed);
            }

            // Scroll through entries
            int      index   = 0;
            DateTime endTime = DateTime.Now;

            foreach (PlanEntry entry in plan)
            {
                // Skip is we're only build a shopping list
                bool shoppingListCandidate = !(entry.CharacterSkill.IsKnown || entry.Level != 1 || entry.CharacterSkill.IsOwned);
                if (settings.ShoppingList && !shoppingListCandidate)
                {
                    continue;
                }

                // Remapping point
                if (!settings.ShoppingList && (entry.Remapping != null) && settings.RemappingPoints)
                {
                    builder
                    .Append($"***{entry.Remapping}***")
                    .Append(lineFeed);
                }

                // Entry's index
                index++;
                if (settings.EntryNumber)
                {
                    builder.Append($"{index}. ");
                }

                // Name
                builder.Append(boldStart);
                AddName(settings, entry, builder);
                builder.Append(boldEnd);

                // Training time
                AddTrainingTime(settings, shoppingListCandidate, entry, builder);

                exportActions?.Invoke(builder, entry, settings);

                builder.Append(lineFeed);

                // End time
                endTime = entry.EndTime;
            }

            // Footer
            AddFooter(settings, boldEnd, index, endTime, builder, lineFeed, plan, boldStart);

            // Returns the text representation.
            return(builder.ToString().TrimEnd(Environment.NewLine.ToCharArray()));
        }