コード例 #1
0
        /// <summary>
        /// Get an <see cref="IReliableIndexedDictionary{TKey, TValue}"/> with the given name if it exists, or creates one with its indexes and returns it if it doesn't already exist.
        /// </summary>
        /// <remarks>
        /// The index definitions indicate the indexes that should be created, or which should exist with this reliable collection.  The index definitions should be
        /// consistent when creating/reading/removing reliable collections, and should not be changed after creation.  Doing so can cause the index to become out of sync
        /// with the primary reliable collection, which will cause runtime exceptions.
        /// </remarks>
        public static async Task <IReliableIndexedDictionary <TKey, TValue> > GetOrAddIndexedAsync <TKey, TValue>(this IReliableStateManager stateManager, ITransaction tx, string name, TimeSpan timeout, params IIndexDefinition <TKey, TValue>[] indexes)
            where TKey : IComparable <TKey>, IEquatable <TKey>
        {
            var dictionary = await stateManager.GetOrAddAsync <IReliableDictionary2 <TKey, TValue> >(tx, name, timeout).ConfigureAwait(false);

            return(await stateManager.GetOrAddIndexedAsync(tx, timeout, dictionary, GetBaseIndexUri(name), indexes).ConfigureAwait(false));
        }
コード例 #2
0
        /// <summary>
        /// Get an <see cref="IReliableIndexedDictionary{TKey, TValue}"/> with the given name if it exists, or creates one with its indexes and returns it if it doesn't already exist.
        /// </summary>
        /// <remarks>
        /// The index definitions indicate the indexes that should be created, or which should exist with this reliable collection.  The index definitions should be
        /// consistent when creating/reading/removing reliable collections, and should not be changed after creation.  Doing so can cause the index to become out of sync
        /// with the primary reliable collection, which will cause runtime exceptions.
        /// </remarks>
        public static async Task <IReliableIndexedDictionary <TKey, TValue> > GetOrAddIndexedAsync <TKey, TValue>(this IReliableStateManager stateManager, string name, TimeSpan timeout, params IIndexDefinition <TKey, TValue>[] indexes)
            where TKey : IComparable <TKey>, IEquatable <TKey>
        {
            using (var tx = stateManager.CreateTransaction())
            {
                var result = await stateManager.GetOrAddIndexedAsync(tx, name, timeout, indexes);

                await tx.CommitAsync().ConfigureAwait(false);

                return(result);
            }
        }
コード例 #3
0
        public void TestInitialize()
        {
            userDictionaryManager = new MockReliableStateManager();

            IReliableDictionary2 <UserName, Basic.Common.UserProfile> users =
                userDictionaryManager.GetOrAddAsync <IReliableDictionary2 <UserName, Basic.Common.UserProfile> >("users").Result;
            var indexed_users = userDictionaryManager.GetOrAddIndexedAsync <UserName, Basic.Common.UserProfile>("indexed_users",
                                                                                                                FilterableIndex <UserName, Basic.Common.UserProfile, string> .CreateQueryableInstance("Email"),
                                                                                                                FilterableIndex <UserName, Basic.Common.UserProfile, int> .CreateQueryableInstance("Age")).Result;

            for (int i = 0; i < 5; i++)
            {
                using (var tx = userDictionaryManager.CreateTransaction())
                {
                    var user = new Basic.Common.UserProfile
                    {
                        Name = new UserName
                        {
                            First = $"First{i}",
                            Last  = $"Last{i}",
                        },
                        Email   = $"user-{i}@example.com",
                        Age     = 20 + i / 3,
                        Address = new Basic.Common.Address
                        {
                            AddressLine1 = $"1{i} Main St.",
                            City         = "Seattle",
                            State        = "WA",
                            Zipcode      = 98117,
                        },
                    };


                    users.SetAsync(tx, user.Name, user, TimeSpan.FromSeconds(4), new CancellationToken());
                    indexed_users.SetAsync(tx, user.Name, user, TimeSpan.FromSeconds(4), new CancellationToken());
                    tx.CommitAsync();
                }
            }

            Assert.IsTrue(userDictionaryManager.TryGetAsync <IReliableDictionary2 <UserName, Basic.Common.UserProfile> >("users").Result.HasValue);
            Assert.IsTrue(userDictionaryManager.TryGetIndexedAsync <UserName, Basic.Common.UserProfile>("indexed_users",
                                                                                                        FilterableIndex <UserName, Basic.Common.UserProfile, string> .CreateQueryableInstance("Email"),
                                                                                                        FilterableIndex <UserName, Basic.Common.UserProfile, int> .CreateQueryableInstance("Age")).Result.HasValue);
        }
コード例 #4
0
 /// <summary>
 /// Get an <see cref="IReliableIndexedDictionary{TKey, TValue}"/> with the given name if it exists, or creates one with its indexes and returns it if it doesn't already exist.
 /// </summary>
 /// <remarks>
 /// The index definitions indicate the indexes that should be created, or which should exist with this reliable collection.  The index definitions should be
 /// consistent when creating/reading/removing reliable collections, and should not be changed after creation.  Doing so can cause the index to become out of sync
 /// with the primary reliable collection, which will cause runtime exceptions.
 /// </remarks>
 public static Task <IReliableIndexedDictionary <TKey, TValue> > GetOrAddIndexedAsync <TKey, TValue>(this IReliableStateManager stateManager, Uri name, params IIndexDefinition <TKey, TValue>[] indexes)
     where TKey : IComparable <TKey>, IEquatable <TKey>
 {
     return(stateManager.GetOrAddIndexedAsync(name, DefaultTimeout, indexes));
 }