本文整理汇总了C#中Raven.Client.Document.DocumentStore.Changes方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentStore.Changes方法的具体用法?C# DocumentStore.Changes怎么用?C# DocumentStore.Changes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Client.Document.DocumentStore
的用法示例。
在下文中一共展示了DocumentStore.Changes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HowToSubscribeToDataSubscriptionChanges
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
}
}
}
示例2: Main
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();
}
}
}
示例3: CanGetNotificationAboutIndexUpdate
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);
}
}
示例4: WithWindowsAuth
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);
}
}
示例5: CanGetNotificationsFromTenant_ExplicitDatabase
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);
}
}
示例6: CanGetNotificationAboutDocumentPut
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);
}
}
示例7: CanGetNotificationAboutDocumentDelete
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();
}
}
示例8: HowToSubscribeToIndexChanges
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
}
}
示例9: WithOAuthOnSpecificDatabase
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);
}
}
}
示例10: LoadResultShoudBeUpToDateEvenIfAggresiveCacheIsEnabled
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);
}
}
}
}
示例11: CheckForAlbumChanges
/// <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();
}
示例12: HowToSubscribeToBulkInsertChanges
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
}
}
示例13: WithOAuth
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);
}
}
}
示例14: ShouldNotCrashServer
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();
}
}
示例15: StartsWithChangesThrowsWithBulkInsert
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);
}
}