Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
 public void ToStringTest()
 {
     var scope = new KeyScope("one");
     Assert.AreEqual(string.Format("{1}{0}{2}", KeyScope.Separator, KeyScope.Domain, "one"), scope.ToString());
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 /// <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());
Exemplo n.º 5
0
 /// <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);
 }
Exemplo n.º 6
0
 /// <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);