private void BuildDataMap() { _stringDic.Clear(); _dicMap.Clear(); foreach (int enumI in Enum.GetValues(typeof(TValue))) { string stringKey = ((int)enumI).ToString(); string stringVal = Enum.GetName(typeof(TValue), enumI); TValue enumVal = (TValue)Enum.ToObject(typeof(TValue), enumI); if (Exclude != null && Exclude.Contains(enumVal)) { continue; } if (DisplayNames != null && DisplayNames.ContainsKey(enumVal)) { _stringDic.Add(stringKey, DisplayNames[enumVal]); } else { _stringDic.Add(stringKey, stringVal); } _dicMap.Add(stringKey, enumVal); } }
/// <summary> /// Get the display name for the specified key name. /// If no display name is stored for the key the /// key value itself will be returned. /// </summary> /// <param name="key"></param> /// <returns></returns> public string GetDisplayName(string key) { if (DisplayNames.ContainsKey(key)) { return(DisplayNames[key]); } else { return(key); } }
/// <summary> /// Convert this data set to a delimiter-separated string, /// suitable for writing out to a text file. /// </summary> /// <returns></returns> public override string ToString() { var sb = new StringBuilder(); // Title bar sb.Append("[KEY NAME]"); sb.Append(Delimiter); sb.Append("[DISPLAY NAME]"); sb.Append(Delimiter); sb.Append("[TOOLTIP]"); sb.AppendLine(); foreach (var kvp in DisplayNames) { sb.Append(kvp.Key); sb.Append(Delimiter); sb.Append(kvp.Value); if (ToolTips.ContainsKey(kvp.Key)) { sb.Append(Delimiter); sb.Append(ToolTips[kvp.Key]); } sb.AppendLine(); } // Write any tooltips that were missed foreach (var kvp in ToolTips) { if (!DisplayNames.ContainsKey(kvp.Key)) { sb.Append(kvp.Key); sb.Append(Delimiter); sb.Append(Delimiter); sb.Append(kvp.Value); sb.AppendLine(); } } return(sb.ToString()); }
public void threadLoop() { ulong?lastMessage = null; do { try { IEnumerable <IMessage> messages; int lim = Math.Clamp(Remaining, 1, 100); if (lastMessage == null) { messages = Channel.GetMessagesAsync(lim).FlattenAsync().Result; } else { messages = Channel.GetMessagesAsync(lastMessage.Value, Direction.Before, lim).FlattenAsync().Result; } lastMessage = messages.LastOrDefault()?.Id; var any = false; foreach (var msg in messages) { if (!(msg is IUserMessage usm)) { continue; } if (msg.Author.IsBot && !IncludeBots) { continue; } if (msg.Author.IsWebhook) { continue; } any = true; if (!DisplayNames.ContainsKey(msg.Author.Id)) { DisplayNames[msg.Author.Id] = $"{msg.Author.Username}#{msg.Author.Discriminator}"; } Add(usm); Remaining--; Update(); if (Remaining <= 0 || Token.IsCancellationRequested) { break; } } if (!any) { Remaining = -1; } if (Remaining <= 0 || Token.IsCancellationRequested) { break; } } catch (Exception ex) { Program.LogMsg("Stats", ex); try { Status.ModifyAsync(x => x.Content = $"Error occured whilst handling this: {ex}"); } catch { } } } while (Remaining > 0 && !Token.IsCancellationRequested && AllStats.TotalSent < Maximum); Task.Delay(10_000, Program.GetToken()).Wait(); LastSentUpdate = null; Update(); }
public static string GetDisplayName(string clrName) { return(DisplayNames.ContainsKey(clrName) ? DisplayNames[clrName] : null); }