public SupperShortIdGenerator(IdBase radix, DateTime baseDate) { if (baseDate < _baseDate) { throw new ArgumentOutOfRangeException("baseDate", "The base date should be later than 1/1/2016"); } _radix = radix; _baseDate = baseDate; }
public virtual async Task Update(IdBase o) { var existing = await Entries.FirstOrDefaultAsync(x => x.Id == o.Id) ?? throw new BadRequestException("Record not found"); var updated = o.ConvertTo <T>(); Context.Entry(existing).CurrentValues.SetValues(updated); await Context.SaveChangesAsync(); }
/// <summary> /// Convert a number to another base system /// </summary> public static string Convert(UInt64 number, IdBase radix) { switch (radix) { case IdBase.Hexadecimal: return number.ToString("X"); case IdBase.Hexatrigesimal: return Convert(number, Characters.Hexatrigesimal); case IdBase.Sexagesimal: return Convert(number, Characters.Sexagesimal); case IdBase.Duosexagesimal: return Convert(number, Characters.Duosexagesimal); case IdBase.WebId: return Convert(number, Characters.ShortIdTable); } throw new Exception("Not handle " + radix); }
public static string NewId(IDictionary<ulong, IList<long>> cache, ulong current, IdBase radix) { // If all keys are precedent values, we should remove them from the dictionary // Otherwise cache contains current in the keys. // To ignore duplicated ID(s), we try to increase values in the list on each generation. if (cache.Count == 0) { cache.Add(current, new List<long>()); } else if (cache.Keys.Max() < current) { cache.Clear(); cache.Add(current, new List<long>()); } else { // OK, do nothing } string secondPart; if (cache[current].Any()) { var maxValue = cache[current].Max(); cache[current].Add(maxValue + 1); secondPart = maxValue.ToString(CultureInfo.InvariantCulture); } else { cache[current].Add(0); secondPart = string.Empty; } var nextValueFormatted = string.Format("{0}{1}", current, secondPart); return NumberToString.Convert(UInt64.Parse(nextValueFormatted), radix); }
public static IdDto ToIdDto(this IdBase id) { return(new IdDto(id.Id)); }
internal static IdDto ToIdDto(this IdBase id) { return(new IdDto(id.Id)); }
public SupperShortIdGenerator(IdBase radix) : this(radix, new DateTime(2016, 1, 1)) { }