public HowToSubscribeToDataSubscriptionChanges()
		{
			using (var store = new DocumentStore())
			{
				{
					#region data_subscription_changes_2

					IDisposable subscription = store
						.Changes()
						.ForAllDataSubscriptions()
						.Subscribe(
							change =>
							{
								var subscriptionId = change.Id;

								switch (change.Type)
								{
									case DataSubscriptionChangeTypes.SubscriptionOpened:
										// do something
										break;
									case DataSubscriptionChangeTypes.SubscriptionReleased:
										// do something
										break;
								}
							});

					#endregion
				}
				{
					#region data_subscription_changes_4

					var subscriptionId = 3;

					IDisposable subscription = store
						.Changes()
						.ForDataSubscription(subscriptionId)
						.Subscribe(
							change =>
							{
								switch (change.Type)
								{
									case DataSubscriptionChangeTypes.SubscriptionOpened:
										// do something
										break;
									case DataSubscriptionChangeTypes.SubscriptionReleased:
										// do something
										break;
								}
							});

					#endregion
				}
			}
		}
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            using(var store = new DocumentStore
                {
                    Url = "http://localhost:8080",
                    DefaultDatabase = "Wow",
                    Conventions =
                        {
                            FailoverBehavior = FailoverBehavior.ReadFromAllServers
                        }
                }.Initialize())
            {
                store.Changes().ForAllDocuments()
                    .Subscribe(notification =>
                        {
                            Console.WriteLine(notification.Name + " " + notification.Type + " " + notification.Etag);
                        });

                while (true)
                {
                    var spo = Stopwatch.StartNew();
                    using(var s = store.OpenSession())
                    {
                        var load = s.Load<RavenJObject>("books/1");
                        Console.WriteLine(load.Value<string>("Name"));
                    }
                    Console.WriteLine(spo.ElapsedMilliseconds);
                    Console.ReadKey();
                }

            }
        }
Ejemplo n.º 3
0
		public void CanGetNotificationAboutIndexUpdate()
		{
			using (GetNewServer())
			using (var store = new DocumentStore
			{
				Url = "http://localhost:8079"
			}.Initialize())
			{
				var list = new BlockingCollection<IndexChangeNotification>();
				var taskObservable = store.Changes();
				taskObservable.Task.Wait();
				taskObservable
					.ForIndex("Raven/DocumentsByEntityName")
					.Subscribe(list.Add);

				using (var session = store.OpenSession())
				{
					session.Store(new ClientServer.Item(), "items/1");
					session.SaveChanges();
				}

				IndexChangeNotification changeNotification;
				Assert.True(list.TryTake(out changeNotification, TimeSpan.FromSeconds(2)));

				Assert.Equal("Raven/DocumentsByEntityName", changeNotification.Name);
				Assert.Equal(changeNotification.Type, IndexChangeTypes.MapCompleted);
			}
		}
Ejemplo n.º 4
0
		public void WithWindowsAuth()
		{
			using (GetNewServer())
			using (var store = new DocumentStore
			{
				Url = "http://localhost:8079",
			}.Initialize())
			{
				var list = new BlockingCollection<DocumentChangeNotification>();
				var taskObservable = store.Changes();
				taskObservable.Task.Wait();
				var documentSubscription = taskObservable.ForDocument("items/1");
				documentSubscription.Task.Wait();
				documentSubscription
					.Subscribe(list.Add);

				using (var session = store.OpenSession())
				{
					session.Store(new ClientServer.Item(), "items/1");
					session.SaveChanges();
				}

				DocumentChangeNotification changeNotification;
				Assert.True(list.TryTake(out changeNotification, TimeSpan.FromSeconds(2)));

				Assert.Equal("items/1", changeNotification.Id);
				Assert.Equal(changeNotification.Type, DocumentChangeTypes.Put);
			}
		}
Ejemplo n.º 5
0
		public void CanGetNotificationsFromTenant_ExplicitDatabase()
		{
			using (GetNewServer())
			using (var store = new DocumentStore
			{
				Url = "http://localhost:8079",
			}.Initialize())
			{
				store.DatabaseCommands.EnsureDatabaseExists("test");
				var list = new BlockingCollection<DocumentChangeNotification>();
				var taskObservable = store.Changes("test");
				taskObservable.Task.Wait();
				taskObservable
					.ForDocument("items/1")
					.Subscribe(list.Add);

				using (var session = store.OpenSession("test"))
				{
					session.Store(new ClientServer.Item(), "items/1");
					session.SaveChanges();
				}

				DocumentChangeNotification DocumentChangeNotification;
				Assert.True(list.TryTake(out DocumentChangeNotification, TimeSpan.FromSeconds(15)));

				Assert.Equal("items/1", DocumentChangeNotification.Id);
				Assert.Equal(DocumentChangeNotification.Type, DocumentChangeTypes.Put);
			}

		}
Ejemplo n.º 6
0
		public void CanGetNotificationAboutDocumentPut()
		{
			using(GetNewServer())
			{using (var store = new DocumentStore
			{
				Url = "http://localhost:8079",
				Conventions =
					{
						FailoverBehavior = FailoverBehavior.FailImmediately
					}
			}.Initialize())
			{
				var list = new BlockingCollection<DocumentChangeNotification>();
				var taskObservable = store.Changes();
				taskObservable.Task.Wait();
				var observableWithTask = taskObservable.ForDocument("items/1");
				observableWithTask.Task.Wait();
				observableWithTask.Subscribe(list.Add);

				using (var session = store.OpenSession())
				{
					session.Store(new Item(), "items/1");
					session.SaveChanges();
				}

				DocumentChangeNotification documentChangeNotification;
				Assert.True(list.TryTake(out documentChangeNotification, TimeSpan.FromSeconds(3)));

				Assert.Equal("items/1", documentChangeNotification.Id);
				Assert.Equal(documentChangeNotification.Type, DocumentChangeTypes.Put);
				Assert.NotNull(documentChangeNotification.Etag);
			}
				Thread.Sleep(1000);
			}
		}
Ejemplo n.º 7
0
        public void CanGetNotificationAboutDocumentDelete()
        {
            using (GetNewServer())
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8079"
            }.Initialize())
            {
                var list = new BlockingCollection<DocumentChangeNotification>();
                var taskObservable = store.Changes();
                taskObservable.Task.Wait();
                var observableWithTask = taskObservable.ForDocument("items/1");
                observableWithTask.Task.Wait();
                observableWithTask
                    .Where(x => x.Type == DocumentChangeTypes.Delete)
                    .Subscribe(list.Add);

                using (var session = store.OpenSession())
                {
                    session.Store(new Item(), "items/1");
                    session.SaveChanges();
                }

                store.DatabaseCommands.Delete("items/1", null);

                DocumentChangeNotification DocumentChangeNotification;
                Assert.True(list.TryTake(out DocumentChangeNotification, TimeSpan.FromSeconds(2)));

                Assert.Equal("items/1", DocumentChangeNotification.Id);
                Assert.Equal(DocumentChangeNotification.Type, DocumentChangeTypes.Delete);

                ((RemoteDatabaseChanges) taskObservable).DisposeAsync().Wait();
            }
        }
		public HowToSubscribeToIndexChanges()
		{
			using (var store = new DocumentStore())
			{
				#region index_changes_2
				IDisposable subscription = store
					.Changes()
					.ForIndex("Orders/All")
					.Subscribe(
						change =>
						{
							switch (change.Type)
							{
								case IndexChangeTypes.IndexAdded:
									// do something
									break;
								case IndexChangeTypes.IndexDemotedToAbandoned:
									// do something
									break;
								case IndexChangeTypes.IndexDemotedToDisabled:
									// do something
									break;
								case IndexChangeTypes.IndexDemotedToIdle:
									// do something
									break;
								case IndexChangeTypes.IndexMarkedAsErrored:
									// do something
									break;
								case IndexChangeTypes.IndexPromotedFromIdle:
									// do something
									break;
								case IndexChangeTypes.IndexRemoved:
									// do something
									break;
								case IndexChangeTypes.MapCompleted:
									// do something
									break;
								case IndexChangeTypes.ReduceCompleted:
									// do something
									break;
								case IndexChangeTypes.RemoveFromIndex:
									// do something
									break;
							}
						});
				#endregion
			}

			using (var store = new DocumentStore())
			{
				#region index_changes_4
				IDisposable subscription = store
					.Changes()
					.ForAllIndexes()
					.Subscribe(change => Console.WriteLine("{0} on index {1}", change.Type, change.Name));
				#endregion
			}
		}
Ejemplo n.º 9
0
        public void WithOAuthOnSpecificDatabase()
        {
            using (var server = GetNewServer(enableAuthentication:true))
            {
                server.SystemDatabase.Documents.Put("Raven/Databases/OAuthTest", null, RavenJObject.FromObject(new DatabaseDocument
                {
                    Disabled = false,
                    Id = "Raven/Databases/OAuthTest",
                    Settings = new IdentityDictionary<string, string>
                    {
                        {"Raven/DataDir", "~\\Databases\\OAuthTest"}
                    }
                }), new RavenJObject(), null);

                server.SystemDatabase.Documents.Put("Raven/ApiKeys/test", null, RavenJObject.FromObject(new ApiKeyDefinition
                {
                    Name = "test",
                    Secret = "test",
                    Enabled = true,
                    Databases = new List<ResourceAccess>
                    {
                        new ResourceAccess {TenantId = "OAuthTest"},
                    }
                }), new RavenJObject(), null);

                using (var store = new DocumentStore
                {
                    ApiKey = "test/test",
                    DefaultDatabase = "OAuthTest",
                    Url = "http://localhost:8079",
                    Conventions = { FailoverBehavior = FailoverBehavior.FailImmediately }
                }.Initialize())
                {
                    var list = new BlockingCollection<DocumentChangeNotification>();
                    var taskObservable = store.Changes();
                    taskObservable.Task.Wait();
                    var documentSubscription = taskObservable.ForDocument("items/1");
                    documentSubscription.Task.Wait();
                    documentSubscription
                        .Subscribe(list.Add);

                    using (var session = store.OpenSession())
                    {
                        session.Store(new ClientServer.Item(), "items/1");
                        session.SaveChanges();
                    }

                    DocumentChangeNotification changeNotification;
                    Assert.True(list.TryTake(out changeNotification, TimeSpan.FromSeconds(2)));

                    Assert.Equal("items/1", changeNotification.Id);
                    Assert.Equal(changeNotification.Type, DocumentChangeTypes.Put);
                }
            }
        }
Ejemplo n.º 10
0
		public void LoadResultShoudBeUpToDateEvenIfAggresiveCacheIsEnabled()
		{
			using (GetNewServer())
			using (var store = new DocumentStore { Url = "http://localhost:8079" }.Initialize())
			{
				store.Conventions.ShouldSaveChangesForceAggresiveCacheCheck = false;
				using (var session = store.OpenSession())
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});
					session.SaveChanges();
				}

				using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
				{

					// make sure that object is cached
					using (var session = store.OpenSession())
					{
						store.Changes().Task.Result.WaitForAllPendingSubscriptions();

						var users = session.Load<User>(new[] {"users/1"});

						Assert.Equal("John", users[0].Name);
					}
					((DocumentStore)store).GetObserveChangesAndEvictItemsFromCacheTask().Wait();

					// change object
					using (var session = store.OpenSession())
					{
						session.Store(new User()
						{
							Id = "users/1",
							Name = "Adam"
						});
						session.SaveChanges();
					}


					Assert.True(SpinWait.SpinUntil(() =>store.JsonRequestFactory.NumberOfCacheResets > 0, 10000));

					using (var session = store.OpenSession())
					{
						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("Adam", users[0].Name);
					}
				}
			}
		}
Ejemplo n.º 11
0
        /// <summary>
        /// Write to the console if an Album document changes.
        /// </summary>
        /// <param name="documentStore"></param>
        private static void CheckForAlbumChanges(DocumentStore documentStore)
        {
            documentStore.Changes().ForDocumentsStartingWith("Albums/")
                .Subscribe(change =>
                    {
                        if (change.Type == DocumentChangeTypes.Put)
                        {
                            Console.WriteLine("An Album has changed on the server!!");
                        }
                    });

            Console.WriteLine("Running :)");
            Console.Read();
        }
		public HowToSubscribeToBulkInsertChanges()
		{
			using (var store = new DocumentStore())
			{
				#region bulk_insert_changes_2
				using (BulkInsertOperation bulkInsert = store.BulkInsert())
				{
					IDisposable subscribtion = store
						.Changes()
						.ForBulkInsert(bulkInsert.OperationId)
						.Subscribe(change =>
						{
							switch (change.Type)
							{
								case DocumentChangeTypes.BulkInsertStarted:
									// do something
									break;
								case DocumentChangeTypes.BulkInsertEnded:
									// do something
									break;
								case DocumentChangeTypes.BulkInsertError:
									// do something
									break;
							}
						});

					try
					{
						for (int i = 0; i < 1000 * 1000; i++)
						{
							bulkInsert.Store(new Employee
							{
								FirstName = "FirstName #" + i,
								LastName = "LastName #" + i
							});
						}
					}
					finally
					{
						if (subscribtion != null)
							subscribtion.Dispose();
					}
				}
				#endregion
			}
		}
Ejemplo n.º 13
0
		public void WithOAuth()
		{
			using (var server = GetNewServer())
			{
				server.Database.Put("Raven/ApiKeys/test", null, RavenJObject.FromObject(new ApiKeyDefinition
				{
					Name = "test",
					Secret = "test",
					Enabled = true,
					Databases = new List<DatabaseAccess>
					{
						new DatabaseAccess {TenantId = "*"},
					}
				}), new RavenJObject(), null);

				using (var store = new DocumentStore
				{
					ApiKey = "test/test",
					Url = "http://localhost:8079",
					Conventions = { FailoverBehavior = FailoverBehavior.FailImmediately }
				}.Initialize())
				{
					var list = new BlockingCollection<DocumentChangeNotification>();
					var taskObservable = store.Changes();
					taskObservable.Task.Wait();
					var documentSubscription = taskObservable.ForDocument("items/1");
					documentSubscription.Task.Wait();
					documentSubscription
						.Subscribe(list.Add);

					using (var session = store.OpenSession())
					{
						session.Store(new ClientServer.Item(), "items/1");
						session.SaveChanges();
					}

					DocumentChangeNotification changeNotification;
					Assert.True(list.TryTake(out changeNotification, TimeSpan.FromSeconds(2)));

					Assert.Equal("items/1", changeNotification.Id);
					Assert.Equal(changeNotification.Type, DocumentChangeTypes.Put);
				}
			}
		}
		public void ShouldNotCrashServer()
		{
			using (GetNewServer())
			using (var store = new DocumentStore
			{
				Url = "http://localhost:8079",
				Conventions =
					{
						FailoverBehavior = FailoverBehavior.FailImmediately
					}
			})
			{
				store.Initialize();
				var taskObservable = store.Changes("does-not-exists");
				Assert.Throws<AggregateException>(() => taskObservable.Task.Wait(TimeSpan.FromSeconds(5)));
				// ensure the db still works
				store.DatabaseCommands.GetStatistics();
			}
		}
Ejemplo n.º 15
0
        public void StartsWithChangesThrowsWithBulkInsert()
        {
            using (GetNewServer())
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8079"
            }.Initialize())
            {
                Exception e = null;
                store.Changes().ForDocumentsStartingWith("something").Subscribe(notification => { }, exception => e = exception);

                using (var session = store.BulkInsert())
                {
                    session.Store(new Company(), "else/1");
                }

                Assert.Null(e);
            }
        } 
Ejemplo n.º 16
0
		public IEnumerable<Task> ShouldGetNotifications()
		{
			var dbname = GenerateNewDatabaseName();
			
			var tcs = new TaskCompletionSource<DocumentChangeNotification>();
			using (var documentStore = new DocumentStore
			{
				Url = Url + Port,
			}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var taskObservable = documentStore.Changes(dbname);

				yield return taskObservable.Task;

				var observableWithTask = taskObservable.ForDocument("companies/1");

				yield return observableWithTask.Task;

				observableWithTask
					.Subscribe(tcs.SetResult);

				var entity1 = new Company { Name = "Async Company #1" };
				using (var session_for_storing = documentStore.OpenAsyncSession(dbname))
				{
					session_for_storing.Store(entity1,"companies/1");
					yield return session_for_storing.SaveChangesAsync();
				}

				Task.Factory.StartNew(() =>
				{
					Thread.Sleep(5000);
					tcs.TrySetCanceled();
				});

				yield return tcs.Task;

				Assert.AreEqual("companies/1", tcs.Task.Result.Id);
			}
		}
		public HowToSubscribeToReplicationConflictsChanges()
		{
			using (var store = new DocumentStore())
			{
				#region replication_conflicts_changes_2
				IDisposable subscribtion = store.Changes()
					.ForAllReplicationConflicts()
					.Subscribe(conflict =>
					{
						if (conflict.ItemType == ReplicationConflictTypes.DocumentReplicationConflict)
						{
							Console.WriteLine("Conflict detected for {0}. Ids of conflicted docs: {1}. " +
											  "Type of replication operation: {2}",
											  conflict.Id,
											  string.Join(", ", conflict.Conflicts),
											  conflict.OperationType);
						}
					});
				#endregion
			}
		}
Ejemplo n.º 18
0
		public IEnumerable<Task> CanCreateAndDisposeUsingBulk()
		{
			using (var store = new DocumentStore { Url = Url + Port }.Initialize())
			{
				using (var op = store.AsyncDatabaseCommands.GetBulkInsertOperation(new BulkInsertOptions(), store.Changes()))
				{
					op.Write("items/1", new RavenJObject(), new RavenJObject());
				}

				using (var session = store.OpenAsyncSession())
				{
					var task = session.LoadAsync<User>("users/1");

					yield return task;

					var user = task.Result;

					Assert.IsNotNull(user);
					Assert.AreEqual("Fitzchak", user.Name);
				}
			}
		}
Ejemplo n.º 19
0
		public WhatIsChangesApi()
		{
			using (var store = new DocumentStore())
			{
				#region changes_2
				IDisposable subscribtion = store
					.Changes()
					.ForAllDocuments()
					.Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));

				try
				{
					// application code here
				}
				finally
				{
					if (subscribtion != null)
						subscribtion.Dispose();
				}
				#endregion
			}
		}
Ejemplo n.º 20
0
		private static void Main(string[] args)
		{
            using (var s = new DocumentStore
            {
                Url = "http://localhost.fiddler:8080",
                DefaultDatabase = "test"
            }.Initialize())
            {
                (from change in s.Changes().ForDocumentsStartingWith("companies/")
                 where change.Type == DocumentChangeTypes.Put
                 select change.Id)
                 .Subscribe(state => Console.WriteLine("Item changed: " + state));

                while (true)
                {
                    var cmd = Console.ReadLine();
                    GC.Collect(2);
                    GC.WaitForPendingFinalizers();
                }
            }
			
		}
Ejemplo n.º 21
0
        public static void Main(string[] args)
        {

            using (var store = new DocumentStore
            {
                Url = "http://127.0.0.1:8080",
                DefaultDatabase = "FooBar123"
            })
            {
                store.Initialize();
//                store.DatabaseCommands.GlobalAdmin.DeleteDatabase("FooBar123", true);
//                store.DatabaseCommands.GlobalAdmin.CreateDatabase(new DatabaseDocument
//                {
//                    Id = "FooBar123",
//                    Settings =
//                    {
//                        { "Raven/DataDir", "~\\FooBar123" }
//                    }
//                });
//
//                BulkInsert(store, 1024);
                var changesList = new List<IDatabaseChanges>();

                changesList.Add(store.Changes());


                var mre = new ManualResetEventSlim();
                Task.Run(() =>
                {
                    while (mre.IsSet == false)
                        Thread.Sleep(100);
                }).Wait();

                Console.ReadLine();
                mre.Set();				
            }
        }
Ejemplo n.º 22
0
        public void CanGetNotificationsFromTenant_AndNotFromAnother()
        {
            using (GetNewServer())
            using (var store = new DocumentStore
            {
                Url = url,
            }.Initialize())
            {
                store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("test");
                store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists("another");
                var list = new BlockingCollection<DocumentChangeNotification>();
                store.Changes("test").Task.Result
                    .ForDocument("items/1").Task.Result
                    .Subscribe(list.Add);

                using (var session = store.OpenSession("another"))
                {
                    session.Store(new ClientServer.Item(), "items/2");
                    session.SaveChanges();
                }

                using (var session = store.OpenSession("test"))
                {
                    session.Store(new ClientServer.Item(), "items/1");
                    session.SaveChanges();
                }

                DocumentChangeNotification DocumentChangeNotification;
                Assert.True(list.TryTake(out DocumentChangeNotification, TimeSpan.FromSeconds(15)));

                Assert.Equal("items/1", DocumentChangeNotification.Id);
                Assert.Equal(DocumentChangeNotification.Type, DocumentChangeTypes.Put);

                Assert.False(list.TryTake(out DocumentChangeNotification, TimeSpan.FromMilliseconds(250)));
            }
        }
		public HowToSubscribeToTransformerChanges()
		{
			using (var store = new DocumentStore())
			{
				#region transformer_changes_2
				IDisposable subscribtion = store
					.Changes()
					.ForAllTransformers()
					.Subscribe(
						change =>
						{
							switch (change.Type)
							{
								case TransformerChangeTypes.TransformerAdded:
									// do something
									break;
								case TransformerChangeTypes.TransformerRemoved:
									// do something
									break;
							}
						});
				#endregion
			}
		}
Ejemplo n.º 24
0
        public void ShouldKeepPullingDocsAfterServerRestart()
        {
            var dataPath = NewDataPath("RavenDB_2627_after_restart");

            IDocumentStore store = null;
            try
            {
                var serverDisposed = false;

                var server = GetNewServer(dataDirectory: dataPath, runInMemory: false);

                store = new DocumentStore()
                {
                    Url = "http://*****:*****@id"));
            }
            finally
            {
                if(store != null)
                    store.Dispose();
            }
        }
Ejemplo n.º 25
0
		public void CacheClearingShouldTakeIntoAccountTenantDatabases()
		{
			using (GetNewServer())
			using (var store = new DocumentStore { Url = "http://localhost:8079"}.Initialize())
			{
				store.Conventions.ShouldSaveChangesForceAggresiveCacheCheck = false;

				store.DatabaseCommands.EnsureDatabaseExists("Northwind_1");
				store.DatabaseCommands.EnsureDatabaseExists("Northwind_2");

				using (var session = store.OpenSession("Northwind_1"))
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});
					session.SaveChanges();
				}

				using (var session = store.OpenSession("Northwind_2"))
				{
					session.Store(new User()
					{
						Id = "users/1",
						Name = "John"
					});
					session.SaveChanges();
				}

				using (store.AggressivelyCacheFor(TimeSpan.FromMinutes(5)))
				{
					// make sure that object is cached
					using (var session = store.OpenSession("Northwind_1"))
					{
						store.Changes().Task.Result.WaitForAllPendingSubscriptions();

						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("John", users[0].Name);
					}

					((DocumentStore)store).GetObserveChangesAndEvictItemsFromCacheTask().Wait();
					using (var session = store.OpenSession("Northwind_2"))
					{
						store.Changes().Task.Result.WaitForAllPendingSubscriptions();

						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("John", users[0].Name);
					}

					// change object on Northwind_1 ONLY
					using (var session = store.OpenSession("Northwind_1"))
					{
						session.Store(new User()
						{
							Id = "users/1",
							Name = "Adam"
						});
						session.SaveChanges();
					}


					Assert.True(SpinWait.SpinUntil(() => store.JsonRequestFactory.NumberOfCacheResets > 0, 10000));

					using (var session = store.OpenSession("Northwind_1"))
					{
						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("Adam", users[0].Name);
					}

					using (var session = store.OpenSession("Northwind_2"))
					{
						var users = session.Load<User>(new[] { "users/1" });

						Assert.Equal("John", users[0].Name);
					}
				}
			}
		}
Ejemplo n.º 26
0
	    public override async Task ImportData(SmugglerImportOptions importOptions, SmugglerOptions options, Stream stream)
		{
            SetSmugglerOptions(options);

			SmugglerJintHelper.Initialize(options);

            using (store = CreateStore(importOptions.To))
			{
				Task disposeTask;

				try
				{
					operation = new ChunkedBulkInsertOperation(store.DefaultDatabase, store, store.Listeners, new BulkInsertOptions
					{
						BatchSize = options.BatchSize,
						OverwriteExisting = true
					}, store.Changes(), options.ChunkSize);

					operation.Report += text => ShowProgress(text);

                    await base.ImportData(importOptions, options, stream);
				}
				finally
				{
					 disposeTask = operation.DisposeAsync();
				}

				if (disposeTask != null)
				{
					await disposeTask;
				}
			}
		}
		public HowToSubscribeToDocumentChanges()
		{
			using (var store = new DocumentStore())
			{
				#region document_changes_2
				IDisposable subscribtion = store
					.Changes()
					.ForDocument("employees/1")
					.Subscribe(
						change =>
						{
							switch (change.Type)
							{
								case DocumentChangeTypes.Put:
									// do something
									break;
								case DocumentChangeTypes.Delete:
									// do something
									break;
							}
						});
				#endregion
			}

			using (var store = new DocumentStore())
			{
				#region document_changes_4
				IDisposable subscribtion = store
					.Changes()
					.ForDocumentsInCollection<Employee>()
					.Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
				#endregion
			}

			using (var store = new DocumentStore())
			{
				#region document_changes_5
				string collectionName = store.Conventions.GetTypeTagName(typeof(Employee));
				IDisposable subscribtion = store
					.Changes()
					.ForDocumentsInCollection(collectionName)
					.Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
				#endregion
			}

			using (var store = new DocumentStore())
			{
				#region document_changes_7
				IDisposable subscribtion = store
					.Changes()
					.ForDocumentsOfType<Employee>()
					.Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
				#endregion
			}

			using (var store = new DocumentStore())
			{
				#region document_changes_8
				string typeName = store.Conventions.FindClrTypeName(typeof(Employee));
				IDisposable subscribtion = store
					.Changes()
					.ForDocumentsOfType(typeName)
					.Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
				#endregion
			}

			using (var store = new DocumentStore())
			{
				#region document_changes_1_0
				IDisposable subscribtion = store
					.Changes()
					.ForDocumentsStartingWith("employees/1") // employees/1, employees/10, employees/11, etc.
					.Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
				#endregion
			}

			using (var store = new DocumentStore())
			{
				#region document_changes_1_2
				IDisposable subscribtion = store
					.Changes()
					.ForAllDocuments() // employees/1, orders/1, customers/1, etc.
					.Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
				#endregion
			}
		}