public void MergedDictionaryHasSevenEntries() { var merged = _TestData.MergeLeft(new Dictionary <int, string> { { 6, "Six" }, { 7, "Seven" } }); Assert.AreEqual(merged.Count, 7); }
//-------------------------------------------------------------------------- // // Methods // //-------------------------------------------------------------------------- #region GetParameters /// <summary> /// format the properties for the querystring /// </summary> /// <returns></returns> public override Dictionary<string, string> GetParameters() { var ps = new Dictionary<string, string>(); // apply all of the options to a single hash if (GeneralOptions != null) ps = ps.MergeLeft(GeneralOptions.GetParameters()); if (LocaleOptions != null) ps = ps.MergeLeft(LocaleOptions.GetParameters()); if (LocationOptions != null) ps = ps.MergeLeft(LocationOptions.GetParameters()); return ps; }
/// <summary> /// Render input string by token replacement before send email /// </summary> /// <param name="st"></param> /// <returns></returns> private static void SendMail_RenderBeforeSend(ref string body, ref string title, Dictionary <string, string> input = null) { // prepare the Dictionary if (input == null) { input = new Dictionary <string, string>(); } var parameters = new Dictionary <string, string>(); parameters.Add(EnumMaillingListTokens.current_date_time.ToString(), DateTime.Now.ToLongDateString()); // merge 2 dictionary into one Dictionary <string, string> final_input = parameters.MergeLeft(input); // body = SendMail_RenderBeforeSend_Regex(body, final_input); title = SendMail_RenderBeforeSend_Regex(title, final_input); // for domain host url replace var domain_name = ConfigurationManager.AppSettings.Get("PaypalWebsiteURL"); body = body.Replace("href=\"/", "href=\"" + domain_name); body = body.Replace("src=\"/", "src=\"" + domain_name); body = body.Replace("href='/", "href='" + domain_name); body = body.Replace("src='/", "src='" + domain_name); }
public string Styles(string styleLibraryName, bool outputDefaults = false) { // LR: Load the style library Dictionary <string, string> styleLibrary = this.StyleLibraries.GetStyleLibrary(styleLibraryName); if (!outputDefaults) { return(InlineCss(styleLibrary)); } // LR: Default CSS Component Properties Dictionary <string, string> defaultStyles = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> attribute in Attributes) { if (string.IsNullOrWhiteSpace(attribute.Value)) { continue; } if (!CssHelper.IsCssProperty(attribute.Key)) { // Console.WriteLine($"[IsCssProperty] => Omitted {attribute.Key} as it's not a CssProperty"); continue; } defaultStyles.Add(attribute.Key, attribute.Value); } // LR: Merge style library into default styles. // CAUTION: This will include unessary properties to be outputted to CSS. return(InlineCss(defaultStyles.MergeLeft(styleLibrary))); }
/// <summary> /// Lays out the given map by converting the room's individual connections into absolute positions /// </summary> /// <param name="CurrentRoom">The room to start at</param> /// <param name="CurrentPoint">The position that the current room should be at</param> /// <param name="UnmappedRooms">The list of the unmapped rooms, indexed by ID</param> /// <returns>A mapping of room IDs to their room's positions</returns> public static Dictionary <int, RoomLayoutMapping> GetRoomLayout(Room CurrentRoom, Vector2 CurrentPoint, Dictionary <int, Room> UnmappedRooms, double RoomBaseApothem, int RoomNumSides, float TargetRoomWidth, float TargetRoomHeight) { Log.Info("GetRoomLayout called for room " + CurrentRoom.RoomID + " at point " + CurrentPoint + " with " + UnmappedRooms.Count + " unmapped rooms"); // TODO: Use the cave's validation logic to validate cave // Start with an empty result Dictionary <int, RoomLayoutMapping> NewMappedRooms = new Dictionary <int, RoomLayoutMapping>(); // Iterate over the connections (the index in the array indicates the side) for (int ConnectionDirection = 0; ConnectionDirection < CurrentRoom.AdjacentRooms.Length; ConnectionDirection++) { // Get the ID of the current room int ConnectedRoomId = CurrentRoom.AdjacentRooms[ConnectionDirection]; Room NextRoom; // Only process the room if it hasn't been processed already if (UnmappedRooms.TryGetValue(ConnectedRoomId, out NextRoom)) { // If we have gotten to this next room by reference but the next room // does not have a connection back to the first one, warn of issues! if (!NextRoom.AdjacentRooms.Contains(CurrentRoom.RoomID)) { Log.Warn("Room " + CurrentRoom.RoomID + " claims it is connected to room " + NextRoom.RoomID + ", but the inverse connection was not found!"); } RoomLayoutMapping NextMapping = new RoomLayoutMapping { Room = NextRoom, Image = Random.Next(MapRenderer.NumRoomTextures), PitImage = NextRoom.HasPit ? MiscUtils.RandomIndex(MapRenderer.NumPitTextures) : -1, // TODO: Render gold quantity GoldImage = MiscUtils.RandomIndex(MapRenderer.NumGoldTextures), BatImage = MiscUtils.RandomIndex(MapRenderer.NumBatTextures) }; // Get the point for the next room NextMapping.RoomPosition = CurrentPoint + GetOffsetForSide(ConnectionDirection, RoomBaseApothem * 2, RoomNumSides); // Get the list of poses for the non-connection overlays (closed doors) NextMapping.ClosedDoorMappings = MapDoorsForRoom(NextRoom.AdjacentRooms, NextMapping.RoomPosition, RoomBaseApothem, RoomNumSides, TargetRoomWidth, TargetRoomHeight); // Remove the room now that we have calculated its position // we don't want the next call to index it again UnmappedRooms.Remove(ConnectedRoomId); // Recurse through the connections of the next room Dictionary <int, RoomLayoutMapping> MappedRooms = GetRoomLayout(NextRoom, NextMapping.RoomPosition, UnmappedRooms, RoomBaseApothem, RoomNumSides, TargetRoomWidth, TargetRoomHeight); // Add the current room to the deeper map MappedRooms.Add(NextRoom.RoomID, NextMapping); // Merge the result with the results from the other connections NewMappedRooms = NewMappedRooms.MergeLeft(MappedRooms); } } return(NewMappedRooms); }
public void MergeLeftWithOverwrites() { var source = new Dictionary<string, string> { { "key", "value" } }; var candidate = source.MergeLeft(true, new Dictionary<string, string> { { "key", "value2" } }, new Dictionary<string, string> { { "newKey", "newValue" } }); Assert.IsNotNull(candidate); Assert.AreEqual(2, candidate.Count); Assert.AreEqual("value2", candidate["key"]); Assert.AreEqual("newValue", candidate["newKey"]); }
//-------------------------------------------------------------------------- // // Methods // //-------------------------------------------------------------------------- #region GetParameters /// <summary> /// format the properties for the querystring /// </summary> /// <returns></returns> public override Dictionary <string, string> GetParameters() { var ps = new Dictionary <string, string>(); // apply all of the options to a single hash if (GeneralOptions != null) { ps = ps.MergeLeft(GeneralOptions.GetParameters()); } if (LocaleOptions != null) { ps = ps.MergeLeft(LocaleOptions.GetParameters()); } if (LocationOptions != null) { ps = ps.MergeLeft(LocationOptions.GetParameters()); } return(ps); }
/// <summary> /// Render input string by token replacement before send email /// </summary> /// <param name="st"></param> /// <returns></returns> protected void SendMail_RenderBeforeSend(ref string body, ref string title, Dictionary <string, string> input = null) { // prepare the Dictionary if (input == null) { input = new Dictionary <string, string>(); } var parameters = new Dictionary <string, string>(); parameters.Add(EnumMaillingListTokens.current_date_time.ToString(), DateTime.Now.ToLongDateString()); parameters.Add(EnumMaillingListTokens.user_ipaddress.ToString(), InternalService.CurrentUserIP); if (CurrentUser != null) { parameters.Add(EnumMaillingListTokens.user_name.ToString(), CurrentUser.DisplayName); parameters.Add(EnumMaillingListTokens.user_username.ToString(), CurrentUser.UserName); parameters.Add(EnumMaillingListTokens.user_email.ToString(), CurrentUser.Email); } else { parameters.Add(EnumMaillingListTokens.user_name.ToString(), ""); parameters.Add(EnumMaillingListTokens.user_username.ToString(), ""); parameters.Add(EnumMaillingListTokens.user_email.ToString(), ""); } var domain_name = InternalService.CurrentWebsiteDomainURL; parameters.Add(EnumMaillingListTokens.website_domain.ToString(), domain_name); if (CurrentWebsite != null) { parameters.Add(EnumMaillingListTokens.website_name.ToString(), CurrentWebsite.Name); parameters.Add(EnumMaillingListTokens.website_admin_email.ToString(), CurrentWebsite.Email_Admin); parameters.Add(EnumMaillingListTokens.website_info_email.ToString(), CurrentWebsite.Email_Support); parameters.Add(EnumMaillingListTokens.website_contact_email.ToString(), CurrentWebsite.Email_Contact); } else { parameters.Add(EnumMaillingListTokens.website_name.ToString(), CurrentWebsite.Name); parameters.Add(EnumMaillingListTokens.website_admin_email.ToString(), CurrentWebsite.Email_Admin); parameters.Add(EnumMaillingListTokens.website_info_email.ToString(), CurrentWebsite.Email_Support); parameters.Add(EnumMaillingListTokens.website_contact_email.ToString(), CurrentWebsite.Email_Contact); } // merge 2 dictionary into one Dictionary <string, string> final_input = parameters.MergeLeft(input); // body = SendMail_RenderBeforeSend_Regex(body, final_input); title = SendMail_RenderBeforeSend_Regex(title, final_input); // for domain host url replace body = body.Replace("href=\"/", "href=\"" + domain_name); body = body.Replace("src=\"/", "src=\"" + domain_name); body = body.Replace("href='/", "href='" + domain_name); body = body.Replace("src='/", "src='" + domain_name); }
public override void OnLoad() { alertStrings = LoadConfig("config/preload_alerts.txt"); SetupPredefinedConfigs(); Graphics.InitImage("preload-start.png"); Graphics.InitImage("preload-end.png"); Graphics.InitImage("preload-new.png"); if (File.Exists(PRELOAD_ALERTS_PERSONAL)) { alertStrings = alertStrings.MergeLeft(LoadConfig(PRELOAD_ALERTS_PERSONAL)); } else { File.Create(PRELOAD_ALERTS_PERSONAL); } }
public void MergeLeftWithOverwrites() { var source = new Dictionary <string, string> { { "key", "value" } }; var candidate = source.MergeLeft(true, new Dictionary <string, string> { { "key", "value2" } }, new Dictionary <string, string> { { "newKey", "newValue" } }); Assert.IsNotNull(candidate); Assert.AreEqual(2, candidate.Count); Assert.AreEqual("value2", candidate["key"]); Assert.AreEqual("newValue", candidate["newKey"]); }
public PreloadAlertPlugin(GameController gameController, Graphics graphics, PreloadAlertSettings settings, SettingsHub settingsHub) : base(gameController, graphics, settings) { this.settingsHub = settingsHub; alerts = new HashSet <PreloadConfigLine>(); alertStrings = LoadConfig(PRELOAD_ALERTS); if (File.Exists(PRELOAD_ALERTS_PERSONAL)) { alertStrings = alertStrings.MergeLeft(LoadConfig(PRELOAD_ALERTS_PERSONAL)); } else { File.WriteAllText(PRELOAD_ALERTS_PERSONAL, string.Empty); } GameController.Area.AreaChange += OnAreaChange; AreaNameColor = Settings.AreaTextColor; SetupPredefinedConfigs(); }
public Dictionary <string, string> GetUserOptions(string userName) { using (var command = DatabaseProvider.DbProviderFactory.CreateCommand()) { Dictionary <string, string> defaultOptions = GetDefaultOptions(); Dictionary <string, string> userOptions = new Dictionary <string, string>(); InitializeGetUserOptions(command, userName); using (var reader = DatabaseProvider.ExecuteReader(command)) { while (reader.Read()) { userOptions.Add(reader.GetColumnValue <string>("Key"), reader.GetColumnValue <string>("Value")); } } userOptions = defaultOptions.MergeLeft(userOptions); return(userOptions); } }
public void MergeDictionaries() { var parent = new Dictionary <string, string> { { "1", "1" }, { "2", "2" }, { "4", "4" } }; var child = new Dictionary <string, string> { { "2", "3" }, { "3", "3" } }; var lastChild = new Dictionary <string, string> { { "3", "4" }, { "4", "5" }, { "5", "5" } }; var merged = parent.MergeLeft(child).MergeLeft(lastChild); Assert.That(merged["1"], Is.EqualTo("1")); Assert.That(merged["2"], Is.EqualTo("3")); Assert.That(merged["3"], Is.EqualTo("4")); Assert.That(merged["4"], Is.EqualTo("5")); Assert.That(merged["5"], Is.EqualTo("5")); }
public Dictionary <string, string> GetClientOptions(string userName) { DbCommand command; IDataReader reader; Dictionary <string, string> defaultOptions = GetDefaultOptions(); Dictionary <string, string> clientOptions = new Dictionary <string, string>(); command = DatabaseProvider.DbProviderFactory.CreateCommand(); InitializeGetClientOptions(command, userName); reader = DatabaseProvider.ExecuteReader(command); while (reader.Read()) { clientOptions.Add(reader.GetColumnValue <string>("Key"), reader.GetColumnValue <string>("Value")); } // // Merge the options together to get client specific options // clientOptions = defaultOptions.MergeLeft(clientOptions); return(clientOptions); }
public MonsterTracker(GameController gameController, Graphics graphics, MonsterTrackerSettings settings) : base(gameController, graphics, settings) { alreadyAlertedOf = new HashSet <long>(); alertTexts = new Dictionary <EntityWrapper, MonsterConfigLine>(); modAlerts = LoadConfig(MOD_ALERTS); typeAlerts = LoadConfig(TYPE_ALERTS); if (File.Exists(MOD_ALERTS_PERSONAL)) { modAlerts = modAlerts.MergeLeft(LoadConfig(MOD_ALERTS_PERSONAL)); } else { File.WriteAllText(MOD_ALERTS_PERSONAL, string.Empty); } if (File.Exists(TYPE_ALERTS_PERSONAL)) { typeAlerts = typeAlerts.MergeLeft(LoadConfig(TYPE_ALERTS_PERSONAL)); } else { File.WriteAllText(TYPE_ALERTS_PERSONAL, string.Empty); } Func <bool> monsterSettings = () => Settings.Monsters; iconCreators = new Dictionary <MonsterRarity, Func <EntityWrapper, Func <string, string>, CreatureMapIcon> > { { MonsterRarity.White, (e, f) => new CreatureMapIcon(e, f("ms-red.png"), monsterSettings, settings.WhiteMobIcon) }, { MonsterRarity.Magic, (e, f) => new CreatureMapIcon(e, f("ms-blue.png"), monsterSettings, settings.MagicMobIcon) }, { MonsterRarity.Rare, (e, f) => new CreatureMapIcon(e, f("ms-yellow.png"), monsterSettings, settings.RareMobIcon) }, { MonsterRarity.Unique, (e, f) => new CreatureMapIcon(e, f("ms-purple.png"), monsterSettings, settings.UniqueMobIcon) } }; GameController.Area.AreaChange += area => { alreadyAlertedOf.Clear(); alertTexts.Clear(); }; }
public async Task <Dictionary <string, List <string> > > SearchPNLAsync(String query = "") { var pasList = await MdApi.GetDictionaryAsync(); if (String.IsNullOrEmpty(query) || query.Length <= 2) { return(pasList); } var matchedKeys = pasList.Where(x => WildCardMatch(query.ToLowerInvariant(), x.Key.ToLowerInvariant())); var MatchedRecords = new Dictionary <String, List <String> >(); foreach (var r in pasList) { var matched = r.Value.Where(x => WildCardMatch(query.ToLowerInvariant(), x.ToLowerInvariant())); if (matched.Count() > 0) { MatchedRecords.TryAdd(r.Key, matched.ToList()); } } return(MatchedRecords.MergeLeft(matchedKeys.ToDictionary(x => x.Key, x => x.Value))); }
public override void SetupStyles() { bool isFullWidth = IsFullWidth(); Dictionary <string, string> background = HasBackground() ? new Dictionary <string, string> { { "background", GetBackground() }, // background size, repeat and position has to be seperate since yahoo does not support shorthand background css property { "background-position", GetBackgroundString() }, { "background-repeat", GetAttribute("background-repeat") }, { "background-size", GetAttribute("background-size") }, } : new Dictionary <string, string> { { "background", GetAttribute("background-color") }, { "background-color", GetAttribute("background-color") }, }; StyleLibraries.AddStyleLibrary("tableFullwidth", isFullWidth ? background.MergeLeft( new Dictionary <string, string> { { "width", "100%" }, { "border-radius", GetAttribute("border-radius") }, }) : new Dictionary <string, string> { { "width", "100%" }, { "border-radius", GetAttribute("border-radius") }, }); StyleLibraries.AddStyleLibrary("table", !isFullWidth ? background.MergeLeft( new Dictionary <string, string> { { "width", "100%" }, { "border-radius", GetAttribute("border-radius") }, }) : new Dictionary <string, string> { { "width", "100%" }, { "border-radius", GetAttribute("border-radius") }, }); StyleLibraries.AddStyleLibrary("td", new Dictionary <string, string>() { { "border", GetAttribute("border") }, { "border-bottom", GetAttribute("border-bottom") }, { "border-left", GetAttribute("border-left") }, { "border-right", GetAttribute("border-right") }, { "border-top", GetAttribute("border-top") }, { "direction", GetAttribute("direction") }, { "font-size", "0px" }, { "padding", GetAttribute("padding") }, { "padding-bottom", GetAttribute("padding-bottom") }, { "padding-left", GetAttribute("padding-left") }, { "padding-right", GetAttribute("padding-right") }, { "padding-top", GetAttribute("padding-top") }, { "text-align", GetAttribute("text-align") }, }); StyleLibraries.AddStyleLibrary("div", isFullWidth ? new Dictionary <string, string> { { "margin", "0px auto" }, { "border-radius", GetAttribute("border-radius") }, { "max-width", $"{GetContainerOuterWidth()}px" }, } : background.MergeLeft(new Dictionary <string, string> { { "margin", "0px auto" }, { "border-radius", GetAttribute("border-radius") }, { "max-width", $"{GetContainerOuterWidth()}px" } })); StyleLibraries.AddStyleLibrary("innerDiv", new Dictionary <string, string>() { { "line-height", "0" }, { "font-size", "0" } }); }