/// <summary> /// Outputs a plan or shopping list for a given character to a stream writer. /// </summary> /// <param name="context">context of the request</param> /// <param name="requestPath">url of the request</param> /// <param name="sw">stream writer to output to</param> /// <param name="character">character to use</param> private static void GeneratePlanOrShoppingOutput(string context, string requestPath, TextWriter sw, Character character) { sw.WriteLine("<h1>Hello, {0}</h1>", HttpUtility.HtmlEncode(character.Name)); sw.WriteLine("<a href=\"/characters\">List all characters</a><hr/>"); sw.WriteLine("<a href=\"{0}\">Character overview</a>", context); Regex regex = new Regex( @"\/(owned\/(?'skillId'[^\/]+)\/(?'markOwned'[^\/]+)\/)?(?'requestType'shopping|plan)\/(?'planName'[^\/]+)(.*)", RegexOptions.CultureInvariant | RegexOptions.Compiled); Match match = regex.Match(requestPath); if (match.Success) { string requestType = match.Groups["requestType"].Value; bool shopping = requestType.Equals("shopping", StringComparison.OrdinalIgnoreCase); string planName = HttpUtility.UrlDecode(match.Groups["planName"].Value); int skillId; bool setAsOwned; if (match.Groups["skillId"].Success && match.Groups["markOwned"].Success && Int32.TryParse(match.Groups["skillId"].Value, out skillId) && Boolean.TryParse(match.Groups["markOwned"].Value, out setAsOwned)) { Skill skill = character.Skills.FirstOrDefault(x => x.ID == skillId); if (skill != null) { sw.WriteLine("<h2>Skillbook shopping result</h2>"); skill.IsOwned = setAsOwned; sw.WriteLine("<a href=\"\" onclick=\"CCPEVE.showInfo({0})\">{1}</a> is now marked as {2} owned.", skill.ID, HttpUtility.HtmlEncode(skill.Name), skill.IsOwned ? String.Empty : "not"); } else { // Display an error message sw.WriteLine("<h2>Error Message</h2>"); sw.WriteLine("Skill with id '{0}' could not be found", skillId); } sw.WriteLine("<hr/>"); } Plan plan = character.Plans[planName]; if (plan == null) { // Display an error message sw.WriteLine("<h2>Error Message</h2>"); sw.WriteLine("A plan named \"{0}\" does not exist.", HttpUtility.HtmlEncode(planName)); } else { sw.WriteLine("<h2>Plan: {0}</h2>", HttpUtility.HtmlEncode(plan.Name)); PlanExportSettings x = new PlanExportSettings { // Only if not shopping EntryTrainingTimes = !shopping, // Only if not shopping EntryStartDate = !shopping, // Only if not shopping EntryFinishDate = !shopping, // Only if not shopping FooterTotalTime = !shopping, // Only if not shopping FooterDate = !shopping, FooterCount = true, ShoppingList = shopping, EntryCost = true, FooterCost = true, Markup = MarkupType.Html }; sw.Write(PlanIOHelper.ExportAsText(plan, x, ExportActions(context, requestType, plan))); } } else { sw.WriteLine("<h2>Error Message</h2>"); sw.WriteLine("Invalid request"); } sw.WriteLine("<br/><br/><a href=\"{0}\">Character overview</a>", context); sw.WriteLine("<hr/><a href=\"/characters\">List all characters</a>"); }
/// <summary> /// Occurs when an option change. /// </summary> private void OptionChange() { UpdateOptions(); tbPreview.Text = PlanIOHelper.ExportAsText(m_plan, m_planTextOptions); }