当前位置: 首页>>代码示例>>C#>>正文


C# IDocumentStore.OpenAsyncSession方法代码示例

本文整理汇总了C#中IDocumentStore.OpenAsyncSession方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentStore.OpenAsyncSession方法的具体用法?C# IDocumentStore.OpenAsyncSession怎么用?C# IDocumentStore.OpenAsyncSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDocumentStore的用法示例。


在下文中一共展示了IDocumentStore.OpenAsyncSession方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Get

        public static UserManager<WikiDownUser> Get(IDocumentStore documentStore)
        {
            if (documentStore == null)
            {
                throw new ArgumentNullException("documentStore");
            }

            var session = documentStore.OpenAsyncSession();
            session.Advanced.UseOptimisticConcurrency = true;

            var userStore = new WikiDownRavenUserStore(session);
            return new UserManager<WikiDownUser>(userStore);
        }
开发者ID:sebnilsson,项目名称:WikiDown,代码行数:13,代码来源:UserManagerHelper.cs

示例2: FetchServerDatabases

		public static async Task FetchServerDatabases(ServerRecord server, IDocumentStore documentStore)
		{
			using (var session = documentStore.OpenAsyncSession())
			{
				await session.StoreAsync(server);
				await FetchServerDatabasesAsync(server, session);
				await session.SaveChangesAsync();
			}

			if (server.IsOnline && server.IsUnauthorized && server.CredentialsId == null)
			{
				using (var session = documentStore.OpenAsyncSession())
				{
					await session.StoreAsync(server);

					var credentialses = await session.Query<ServerCredentials>()
					                                 .Take(16)
					                                 .ToListAsync();

					foreach (var credentials in credentialses)
					{
						server.CredentialsId = credentials.Id;
						await FetchServerDatabasesAsync(server, session);
						if (server.IsUnauthorized)
						{
							server.CredentialsId = null;
						}
						if (server.IsOnline == false)
						{
							break;
						}
					}

					await session.SaveChangesAsync();
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:37,代码来源:HealthMonitorTask.cs

示例3: StoreCompaniesAsync

        private static async Task StoreCompaniesAsync(IDocumentStore documentStore)
        {
            var myCompany = new Company
            {
                Name = "Hibernating Rhinos",
                Employees = new List<Employee>
                    {
                                new Employee
                                    {
                                        Name = "Ayende Rahien"
                                    }                    
                    },
                Country = "Israel"
            };

            // Store the company in our RavenDB server
            using (var session = documentStore.OpenAsyncSession())
            {
                session.Store(myCompany);
                await session.SaveChangesAsync();
            }
        }
开发者ID:naraga,项目名称:experiment-RavenVsNhMssql,代码行数:22,代码来源:Program.cs

示例4: AssertLoadUsersWithIncludesAsync

        private void AssertLoadUsersWithIncludesAsync(IDocumentStore documentStore, string mainShard)
        {
            var userRoles = new[]
            {
                new UserRole {Name = "User Role A", Shard = mainShard},
                new UserRole {Name = "User Role B", Shard = mainShard}
            };
            var user = new User
            {
                Name = "User A",
                UserRoles = userRoles.Select(q => q.Id).ToList(),
                Shard = mainShard
            };

            var userId = user.Id;
            using (var session = documentStore.OpenSession())
            {
                session.Store(user);
                foreach (var userRole in userRoles)
                {
                    session.Store(userRole);
                }
                session.SaveChanges();
            }

            AsyncHelpers.RunSync(async() =>
            {
                using (var session = documentStore.OpenAsyncSession())
                {
                    var userFromDb = await session.Include<User, UserRole>(x => x.UserRoles).LoadAsync(userId);

                    var userFromSession = await session.LoadAsync<User>(userId);

                    Assert.NotNull(userFromDb);
                    Assert.NotNull(userFromSession);
                    Assert.NotNull(await session.LoadAsync<UserRole>(userFromSession.UserRoles.First()));
                    Assert.NotNull(await session.LoadAsync<UserRole>(userFromSession.UserRoles.Last()));
                }
            });
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:40,代码来源:RavenDB-5256.cs

示例5: AssertLoadMultipleUsersWithIncludesAsync

        private void AssertLoadMultipleUsersWithIncludesAsync(IDocumentStore documentStore, string mainShard)
        {
            var userRoles = new[]
            {
                new UserRole {Name = "User Role A", Shard = mainShard},
                new UserRole {Name = "User Role B", Shard = mainShard}
            };
            var roleIds = userRoles.Select(q => q.Id).ToList();
            var users = new[]
            {
                new User
                {
                    Name = "User A",
                    UserRoles = roleIds,
                    Shard = mainShard
                },
                new User
                {
                    Name = "User B",
                    UserRoles = new List<Guid> {roleIds[0]},
                    Shard = mainShard
                }
            };
            var userIds = users.Select(q => q.Id).ToList();
            using (var session = documentStore.OpenSession())
            {
                foreach (var user in users)
                {
                    session.Store(user);
                }
                foreach (var userRole in userRoles)
                {
                    session.Store(userRole);
                }
                session.SaveChanges();
            }

            var type = typeof (UserRole);
            var keys =
                roleIds.Select(
                    q => documentStore.Conventions.FindFullDocumentKeyFromNonStringIdentifier(q, type, false)).ToList();

            AsyncHelpers.RunSync(async () =>
            {
                using (var session = documentStore.OpenAsyncSession())
                {
                    var userRolesFromDb = await session.LoadAsync<UserRole>(roleIds.Cast<ValueType>());

                    foreach (var key in keys)
                    {
                        Assert.True(session.Advanced.IsLoaded(key));
                    }

                    Assert.NotEmpty(userRolesFromDb);
                    foreach (var userRole in userRolesFromDb)
                    {
                        Assert.NotNull(userRole);
                    }

                    var usersFromDb =
                        await session.Include<User, UserRole>(x => x.UserRoles).LoadAsync(userIds.Cast<ValueType>());
                    Assert.NotEmpty(usersFromDb);
                    foreach (var user in usersFromDb)
                    {
                        Assert.NotNull(user);
                    }

                    foreach (var key in keys)
                    {
                        Assert.True(session.Advanced.IsLoaded(key));
                    }
                    var userRolesFromSession = await session.LoadAsync<UserRole>(roleIds.Cast<ValueType>());

                    Assert.NotEmpty(userRolesFromSession);
                    foreach (var userRole in userRolesFromSession)
                    {
                        Assert.NotNull(userRole);
                    }
                }
            });
        }
开发者ID:IdanHaim,项目名称:ravendb,代码行数:81,代码来源:RavenDB-5256.cs

示例6: WaitForReplication

 private async Task WaitForReplication(IDocumentStore store2)
 {
     for (int i = 0; i < RetriesCount; i++)
     {
         using (var session = store2.OpenAsyncSession())
         {
             var company = await session.LoadAsync<Company>("companies/1");
             if (company != null)
                 break;
             Thread.Sleep(100);
         }
     }
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:13,代码来源:WritesDuringFailover.cs

示例7: Prefill

        private async Task<List<TestSagaData>> Prefill(IDocumentStore store, ConventionType seedType)
        {
            var snooper = StoreSnooper.Install(store);

            Console.WriteLine($"Filling database with saga data, using {seedType} conventions");

            var names = new Dictionary<ConventionType, string>
            {
                {ConventionType.RavenDefault, "TestSagaDatas"},
                {ConventionType.NSBDefault, "TestSaga"},
                {ConventionType.Customer, "ataDagaStseT"}
            };
            var name = names[seedType];

            var sagas = Enumerable.Range(1001, 10)
                .Select(orderId => new TestSagaData
                {
                    Id = Guid.NewGuid(),
                    OrderId = orderId,
                    OriginalMessageId = Guid.NewGuid().ToString(),
                    Originator = "SomeSaga",
                    Counter = 1
                })
                .ToList();


            foreach (var saga in sagas)
            {
                snooper.Clear();

                var persister = new SagaPersister();

                Console.WriteLine($"Storing SagaId {saga.Id}");
                using (var session = store.OpenAsyncSession())
                {
                    await persister.Save(saga, new SagaCorrelationProperty("OrderId", saga.OrderId), new RavenDBSynchronizedStorageSession(session, false), null);
                    await session.SaveChangesAsync();
                }
                var keysStored = snooper.KeysStored.ToList();

                foreach (var key in keysStored)
                {
                    Console.WriteLine($"  * Document created: {key}");
                }

                Assert.AreEqual(2, snooper.KeyCount);
                Assert.Contains($"{name}/{saga.Id}", keysStored);
            }

            return sagas;
        }
开发者ID:areicher,项目名称:NServiceBus.RavenDB,代码行数:51,代码来源:InconsistentSagaIdConventions.cs

示例8: ExecuteTestAsynchronously

		private void ExecuteTestAsynchronously(IDocumentStore store, List<Facet> facetsToUse)
		{
			Setup(store, facetsToUse);

			using(var s = store.OpenAsyncSession())
			{
				var expressions = new Expression<Func<Camera, bool>>[]
				{
					x => x.Cost >= 100 && x.Cost <= 300,
					x => x.DateOfListing > new DateTime(2000, 1, 1),
					x => x.Megapixels > 5.0m && x.Cost < 500,
					x => x.Manufacturer == "abc&edf"
				};

				foreach(var exp in expressions)
				{
					var facetQueryTimer = Stopwatch.StartNew();
					var task = s.Query<Camera>("CameraCost")
						.Where(exp)
						.ToFacetsAsync("facets/CameraFacets");
					task.Wait();
					facetQueryTimer.Stop();
					var facetResults = task.Result;
					var filteredData = _data.Where(exp.Compile()).ToList();
					CheckFacetResultsMatchInMemoryData(facetResults, filteredData);
				}
			}
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:28,代码来源:FacetedIndex.cs

示例9: TryDeleteDocumentAsync

        static async Task<bool> TryDeleteDocumentAsync(IDocumentStore store, Guid documentId, CountdownEvent documentLoaded,
            CountdownEvent documentDeleted)
        {
            try
            {
                using (var session = store.OpenAsyncSession())
                {
                    var document = await session.LoadAsync<DemoDocument>(documentId);

                    documentLoaded.Signal(1);
                    documentLoaded.Wait();

                    session.Delete(document);

                    documentDeleted.Signal(1);
                    documentDeleted.Wait();

                    await session.SaveChangesAsync();
                    return true;
                }
            }
            catch (ConcurrencyException e)
            {
                Console.WriteLine(e);
                return false;
            }
        }
开发者ID:areicher,项目名称:NServiceBus.RavenDB,代码行数:27,代码来源:When_removing_timeouts_from_storage.cs

示例10: CreateSeedDataAsync

        private static async Task CreateSeedDataAsync(IEnumerable<IEnumerable> seedData, IDocumentStore documentStore)
        {
            if (documentStore == null)
            {
                throw new ArgumentNullException("documentStore");
            }

            if (seedData == null)
            {
                throw new ArgumentNullException("seedData");
            }

            using (var asyncDocumentSession = documentStore.OpenAsyncSession())
            {
                // First, check to make sure we don't have any data.
                if (documentStore.DatabaseCommands.GetStatistics().CountOfDocuments > 0)
                {
                    // We have documents, so nothing to worry about :)
                    return;
                }

                // Store each collection of fake seeded data.
                Trace.TraceInformation("Seeding Data :-");
                foreach (var collection in seedData)
                {
                    var count = 0;
                    var entityName = "Unknown";

                    foreach (var entity in collection)
                    {
                        count++;
                        if (count <= 1)
                        {
                            entityName = entity.GetType().ToString();
                        }
                        await asyncDocumentSession.StoreAsync(entity);
                    }
                    Trace.TraceInformation("   --- {0} {1}", count, entityName);
                }
                Trace.TraceInformation("   Done!");

                // Commit this transaction.
                await asyncDocumentSession.SaveChangesAsync();

                // Make sure all our indexes are not stale.
                documentStore.WaitForStaleIndexesToComplete();
            }
        }
开发者ID:PureKrome,项目名称:WorldDomination.RavenDb,代码行数:48,代码来源:DocumentStoreExtensions.cs


注:本文中的IDocumentStore.OpenAsyncSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。