Beispiel #1
0
        private IAsyncDocumentSession OpenAsyncSessionInternal(OpenSessionOptions options)
        {
            AssertInitialized();
            EnsureNotClosed();

            var sessionId = Guid.NewGuid();
            currentSessionId = sessionId;
            try
            {
                var asyncDatabaseCommands = SetupCommandsAsync(AsyncDatabaseCommands, options.Database, options.Credentials, options);
                if (AsyncDatabaseCommands == null)
                    throw new InvalidOperationException("You cannot open an async session because it is not supported on embedded mode");

                var session = new AsyncDocumentSession(options.Database, this, asyncDatabaseCommands, Listeners, sessionId)
                {
                    DatabaseName = options.Database ?? DefaultDatabase ?? MultiDatabase.GetDatabaseName(Url)
                };
                AfterSessionCreated(session);
                return session;
            }
            finally
            {
                currentSessionId = null;
            }
        }
Beispiel #2
0
		/// <summary>
		/// Opens the async session.
		/// </summary>
		/// <returns></returns>
		public IAsyncDocumentSession OpenAsyncSession()
		{
			if (DatabaseCommands == null)
				throw new InvalidOperationException("You cannot open a session before initialising the document store. Did you forgot calling Initialise?");
			if (AsyncDatabaseCommands == null)
				throw new InvalidOperationException("You cannot open an async session because it is not supported on embedded mode");

			var session = new AsyncDocumentSession(this, storeListeners, deleteListeners);
			session.Stored += OnSessionStored;
			return session;
		}
Beispiel #3
0
		private IAsyncDocumentSession OpenAsyncSessionInternal(string dbName, IAsyncDatabaseCommands asyncDatabaseCommands)
		{
			AssertInitialized();
			EnsureNotClosed();

			var sessionId = Guid.NewGuid();
			currentSessionId = sessionId;
			try
			{
				if (AsyncDatabaseCommands == null)
					throw new InvalidOperationException("You cannot open an async session because it is not supported on embedded mode");

                var session = new AsyncDocumentSession(dbName, this, asyncDatabaseCommands, Listeners, sessionId)
				{
				    DatabaseName = dbName ?? DefaultDatabase
				};
				AfterSessionCreated(session);
				return session;
			}
			finally
			{
				currentSessionId = null;
			}
		}
Beispiel #4
0
        /// <summary>
        /// Opens the async session.
        /// </summary>
        /// <returns></returns>
        public IAsyncDocumentSession OpenAsyncSession()
        {
            if (AsyncDatabaseCommands == null)
                throw new InvalidOperationException(
                    "You cannot open an async session because it is not supported on embedded mode");

            var session = new AsyncDocumentSession(this);
            session.Stored += OnSessionStored;
            return session;
        }
Beispiel #5
0
 public IAsyncDocumentSession OpenAsyncSession(string databaseName)
 {
     this.EnsureNotClosed();
       Guid id = Guid.NewGuid();
       DocumentStore.currentSessionId = new Guid?(id);
       try
       {
     if (this.AsyncDatabaseCommands == null)
       throw new InvalidOperationException("You cannot open an async session because it is not supported on embedded mode");
     AsyncDocumentSession asyncDocumentSession = new AsyncDocumentSession(this, this.AsyncDatabaseCommands.ForDatabase(databaseName), this.listeners, id);
     this.AfterSessionCreated((InMemoryDocumentSessionOperations) asyncDocumentSession);
     return (IAsyncDocumentSession) asyncDocumentSession;
       }
       finally
       {
     DocumentStore.currentSessionId = new Guid?();
       }
 }
        public async Task GivenAFakeModel_StoreAsync_StoresTheModel()
        {
            // Arrange.
            var fakeModel1 = new FakeModel
            {
                Name      = "Anabel",
                Age       = 25,
                CreatedOn = DateTime.UtcNow
            };

            DataToBeSeeded = new List <IEnumerable> {
                new[] { fakeModel1 }
            };

            // Now fake data to store -after- the default data is store
            await AsyncDocumentSession.StoreAsync(new FakeModel
            {
                Name      = "Lily",
                Age       = 5,
                CreatedOn = DateTime.UtcNow
            });

            await AsyncDocumentSession.StoreAsync(new FakeModel
            {
                Name      = "Jett",
                Age       = 7,
                CreatedOn = DateTime.UtcNow
            });

            // Act.
            // Note: First save.
            await AsyncDocumentSession.SaveChangesAsync();

            // 2nd save (to see if the Id's are in order -- ie. reusing the same client).
            await AsyncDocumentSession.StoreAsync(new FakeModel
            {
                Name      = "Jenson",
                Age       = 3,
                CreatedOn = DateTime.UtcNow
            });

            await AsyncDocumentSession.SaveChangesAsync();

            // 3rd save with a different Session.
            await AsyncDocumentSessions("pewpew").StoreAsync(new FakeModel
            {
                Name      = "PewPew",
                Age       = 69,
                CreatedOn = DateTime.UtcNow
            });
            await AsyncDocumentSessions("pewpew").SaveChangesAsync();


            // Assert.
            var models = await AsyncDocumentSessions("hi").Query <FakeModel>().ToListAsync();

            Assert.Equal("FakeModels/1", models[0].Id);
            Assert.Equal("Anabel", models[0].Name);
            Assert.Equal("FakeModels/2", models[1].Id);
            Assert.Equal("Lily", models[1].Name);
            Assert.Equal("FakeModels/3", models[2].Id);
            Assert.Equal("Jett", models[2].Name);
            Assert.Equal("FakeModels/4", models[3].Id);
            Assert.Equal("Jenson", models[3].Name);
            Assert.Equal("FakeModels/5", models[4].Id);
            Assert.Equal("PewPew", models[4].Name);
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AsyncMultiLoaderWithInclude{T}"/> class.
 /// </summary>
 /// <param name="session">The session.</param>
 public AsyncMultiLoaderWithInclude(AsyncDocumentSession session)
 {
     this.session = session;
 }