public static PublicUrlVersion0 FromInternal(StoredUrl internalVal) { return(new PublicUrlVersion0() { Value = internalVal.Url, Id = internalVal.Id, }); }
public async Task <StoredUrl> PostUrlAsync(string value) { if (InMemoryStore == null) { throw new Exception("Internal Memory invalid state"); } var retryCount = 0; string id; bool unique = false; do { id = IdGenerator.GenerateId(); if (!InMemoryStore.ContainsKey(id)) { unique = true; break; } retryCount++; } while (retryCount < IdCreationRetryCount); if (!unique) { throw new Exception("unable to generate unique ID. all of them are used up :/"); } var internalUrl = new StoredUrl() { Url = value, Id = id, LastAccessed = DateTime.Now }; InMemoryStore[id] = internalUrl; return(internalUrl); }