public UserDataViewModel(DbDataReader dataReader, IChannelSettings settings) : this(uint.Parse(dataReader["ID"].ToString()), dataReader["UserName"].ToString()) { this.ViewingMinutes = int.Parse(dataReader["ViewingMinutes"].ToString()); if (dataReader.ColumnExists("CurrencyAmounts")) { Dictionary <Guid, int> currencyAmounts = JsonConvert.DeserializeObject <Dictionary <Guid, int> >(dataReader["CurrencyAmounts"].ToString()); if (currencyAmounts != null) { foreach (var kvp in currencyAmounts) { if (settings.Currencies.ContainsKey(kvp.Key)) { this.SetCurrencyAmount(settings.Currencies[kvp.Key], kvp.Value); } } } } if (dataReader.ColumnExists("InventoryAmounts")) { Dictionary <Guid, Dictionary <string, int> > inventoryAmounts = JsonConvert.DeserializeObject <Dictionary <Guid, Dictionary <string, int> > >(dataReader["InventoryAmounts"].ToString()); if (inventoryAmounts != null) { foreach (var kvp in inventoryAmounts) { if (settings.Inventories.ContainsKey(kvp.Key)) { UserInventoryViewModel inventory = settings.Inventories[kvp.Key]; this.InventoryAmounts[inventory] = new UserInventoryDataViewModel(this, inventory, kvp.Value); } } } } if (dataReader.ColumnExists("CustomCommands") && !string.IsNullOrEmpty(dataReader["CustomCommands"].ToString())) { this.CustomCommands.AddRange(SerializerHelper.DeserializeFromString <List <ChatCommand> >(dataReader["CustomCommands"].ToString())); } if (dataReader.ColumnExists("Options") && !string.IsNullOrEmpty(dataReader["Options"].ToString())) { JObject optionsJObj = JObject.Parse(dataReader["Options"].ToString()); if (optionsJObj.ContainsKey("EntranceCommand") && optionsJObj["EntranceCommand"] != null) { this.EntranceCommand = SerializerHelper.DeserializeFromString <CustomCommand>(optionsJObj["EntranceCommand"].ToString()); } this.IsSparkExempt = this.GetOptionValue <bool>(optionsJObj, "IsSparkExempt"); this.IsCurrencyRankExempt = this.GetOptionValue <bool>(optionsJObj, "IsCurrencyRankExempt"); this.GameWispUserID = this.GetOptionValue <uint>(optionsJObj, "GameWispUserID"); this.PatreonUserID = this.GetOptionValue <string>(optionsJObj, "PatreonUserID"); this.ModerationStrikes = this.GetOptionValue <uint>(optionsJObj, "ModerationStrikes"); this.CustomTitle = this.GetOptionValue <string>(optionsJObj, "CustomTitle"); } }
private static object Read(DbDataReader reader, string field, Type type) { if (!reader.ColumnExists(field)) { return(null); } if (type == typeof(Guid)) { return(ReadGuid(reader, field)); } if (type == typeof(Guid?)) { return(ReadGuidNull(reader, field)); } if (type == typeof(byte)) { return(ReadByte(reader, field)); } if (type == typeof(short)) { return(ReadInt16(reader, field)); } if (type == typeof(int)) { return(ReadInt32(reader, field)); } if (type == typeof(int?)) { return(ReadInt32Null(reader, field)); } if (type == typeof(bool)) { return(ReadBool(reader, field)); } if (type == typeof(bool?)) { return(ReadBoolNull(reader, field)); } if (type == typeof(DateTime)) { return(ReadDateTime(reader, field)); } if (type == typeof(DateTime?)) { return(ReadDateTimeNull(reader, field)); } if (type == typeof(long)) { return(ReadInt64(reader, field)); } if (type == typeof(long?)) { return(ReadInt64Null(reader, field)); } if (type == typeof(decimal)) { return(ReadDecimal(reader, field)); } if (type == typeof(decimal?)) { return(ReadDecimalNull(reader, field)); } if (type == typeof(string)) { return(ReadStringNull(reader, field)); } if (type == typeof(double)) { return(ReadDouble(reader, field)); } if (type.IsNullableEnum()) { return(ReadInt32Null(reader, field)); } if (type.IsEnum) { return(ReadInt32(reader, field)); } return(null); }