using System; using System.Diagnostics; using System.IO; using System.Web.UI; using System.Xml.Serialization; using Newtonsoft.Json; using Swarmops.Interface.Objects; using Swarmops.Logic.Swarm; // ReSharper disable once CheckNamespace namespace Swarmops.Controls.Base { public partial class MainMenu : ControlV5Base { public MainMenuItem[] MainMenuData { get; set; } private string _regularLocalized; private string _regularsLocalized; private string _regularshipLocalized; protected void Page_Load (object sender, EventArgs e) { ParticipantTitle regular = CurrentOrganization.RegularLabel; _regularLocalized = Participant.Localized (regular); _regularsLocalized = Participant.Localized (regular, TitleVariant.Plural); _regularshipLocalized = Participant.Localized (regular, TitleVariant.Ship); // TODO: Put a small cache on this // TODO: Put plugins on it XmlSerializer serializer = new XmlSerializer (typeof (MainMenuItem[])); using (TextReader reader = new StreamReader (Server.MapPath ("~/MainMenu-v5.xml"))) { MainMenuData = (MainMenuItem[]) serializer.Deserialize (reader); } } protected override void Render (HtmlTextWriter output) { output.Write (""); } private void WriteMenuItem (MainMenuItem menuItem, HtmlTextWriter output) { output.Write ("
  • ", menuItem.Type); string localizedText = "RESOURCE NOT FOUND"; string prettyNavUrl = menuItem.NavigateUrl ?? string.Empty; if (!Debugger.IsAttached) { prettyNavUrl = prettyNavUrl.Replace ("/Pages/v5/", "/").Replace (".aspx", ""); } if (!String.IsNullOrEmpty (menuItem.ResourceKey)) { object resourceObject = GetGlobalResourceObject ("Menu5", "Menu5_" + menuItem.ResourceKey); if (resourceObject != null) { localizedText = resourceObject.ToString(); } } localizedText = localizedText.Replace ("[Regular]", _regularLocalized); // TODO IF APPLICABLE - add other [Regulars] [Regularship] etc. localizedText = Server.HtmlEncode (localizedText); // muy importante if (menuItem.Type == MenuItemType.BuildNumber) { localizedText = Swarmops.Logic.Support.Formatting.SwarmopsVersion; } string iconSize = "40px"; if (File.Exists (Server.MapPath ("~/Images/PageIcons/" + menuItem.ImageUrl + "-20px.png"))) { iconSize = "20px"; } switch (menuItem.Type) { // TODO: More types here, and check with the CSS. Some work to get good looking case MenuItemType.Link: output.Write ( "{2}", menuItem.ImageUrl, prettyNavUrl, localizedText, iconSize); break; case MenuItemType.Disabled: case MenuItemType.BuildNumber: string imageUrl = "/Images/PageIcons/" + menuItem.ImageUrl + "-" + iconSize + ".png"; if (String.IsNullOrEmpty (menuItem.ImageUrl)) { imageUrl = "/Images/PageIcons/transparency-16px.png"; // doesn't matter in slightest if browser resizes to 20px } output.Write ("{1}", imageUrl, localizedText); break; case MenuItemType.Submenu: output.Write ("" + localizedText + ""); break; case MenuItemType.Separator: output.Write (" 
    "); break; default: throw new NotImplementedException(); } if (menuItem.Children.Length > 0) { output.Write (""); } output.Write ("
  • "); } } }