/// <summary> /// Creates a key within the given KeyScope. If the id parameter /// is not null, it is used as the unique component of the returned key. /// If it is null, then an integer ID is generated in the database for the given scope. /// </summary> /// <param name="scope">The scope that defines the context of the key.</param> /// <param name="id">String that serves as a unique component within the scope. If null, then an integer ID is generated by the database instead.</param> /// <returns>The new key.</returns> public Key CreateKey(KeyScope scope, string id) { if (id == null) { id = GetNextId(scope).ToString(); } return new Key(string.Format(_keyFormat, KeyScope.Separator, scope.Value, id)); }
public void ToStringTest() { var scope = new KeyScope("one"); Assert.AreEqual(string.Format("{1}{0}{2}", KeyScope.Separator, KeyScope.Domain, "one"), scope.ToString()); }
public void KeyScopeTwoSegmentsTest() { var scope = new KeyScope("one", "two"); Assert.AreEqual(string.Format("{1}{0}{2}{0}{3}", KeyScope.Separator, KeyScope.Domain, "one", "two"), scope.Value); }
/// <summary> /// Overload of <see cref="CreateKey(KeyScope, string)"/> that accepts an id of type long. /// </summary> /// <param name="scope">The scope that defines the context of the key.</param> /// <param name="id">Long integer that serves as a unique component within the scope.</param> /// <returns>The new key.</returns> public Key CreateKey(KeyScope scope, long id) => CreateKey(scope, id.ToString());
/// <summary> /// Retrieve from the persistent store the next unique ID for the given /// KeyScope. The returned value can then be used as the unique component /// of a Key within that KeyScope. /// </summary> /// <param name="scope">The KeyScope that defines the context of the key that will use the returned ID.</param> /// <returns></returns> long GetNextId(KeyScope scope) { return _connection.GetDatabase().StringIncrement(scope.NextIdKey); }
/// <summary> /// Creates a key within the given KeyScope and an ID that is generated in the database for the given scope. /// </summary> /// <param name="scope">The scope that defines the context of the key.</param> /// <returns>The new key.</returns> public Key CreateAutoKey(KeyScope scope) => CreateKey(scope, null);