public IObservableWithTask <DocumentChangeNotification> ForDocument(string docId) { var counter = counters.GetOrAdd("docs/" + docId, s => { var documentSubscriptionTask = AfterConnection(() => { watchedDocs.TryAdd(docId); return(Send("watch-doc", docId)); }); return(new LocalConnectionState( () => { watchedDocs.TryRemove(docId); Send("unwatch-doc", docId); counters.Remove("docs/" + docId); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => string.Equals(notification.Id, docId, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <BulkInsertChangeNotification> ForBulkInsert(Guid operationId) { var id = operationId.ToString(); var counter = counters.GetOrAdd("bulk-operations/" + id, s => { watchedBulkInserts.TryAdd(id); var documentSubscriptionTask = AfterConnection(() => { if (watchedBulkInserts.Contains(id)) // might have been removed in the meantime { return(Send("watch-bulk-operation", id)); } return(Task); }); return(new LocalConnectionState( () => { watchedBulkInserts.TryRemove(id); Send("unwatch-bulk-operation", id); counters.Remove("bulk-operations/" + operationId); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <BulkInsertChangeNotification>(counter, notification => notification.OperationId == operationId); counter.OnBulkInsertChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <IndexChangeNotification> ForIndex(string indexName) { var counter = counters.GetOrAdd("indexes/" + indexName, s => { var indexSubscriptionTask = AfterConnection(() => { watchedIndexes.TryAdd(indexName); return(Send("watch-index", indexName)); }); return(new LocalConnectionState( () => { watchedIndexes.TryRemove(indexName); Send("unwatch-index", indexName); counters.Remove("indexes/" + indexName); }, indexSubscriptionTask)); }); counter.Inc(); var taskedObservable = new TaskedObservable <IndexChangeNotification>( counter, notification => string.Equals(notification.Name, indexName, StringComparison.OrdinalIgnoreCase)); counter.OnIndexChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocumentsStartingWith(string docIdPrefix) { var counter = counters.GetOrAdd("prefixes/" + docIdPrefix, s => { var documentSubscriptionTask = AfterConnection(() => { watchedPrefixes.TryAdd(docIdPrefix); return(Send("watch-prefix", docIdPrefix)); }); return(new LocalConnectionState( () => { watchedPrefixes.TryRemove(docIdPrefix); Send("unwatch-prefix", docIdPrefix); counters.Remove("prefixes/" + docIdPrefix); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => notification.Id != null && notification.Id.StartsWith(docIdPrefix, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <TransformerChangeNotification> ForAllTransformers() { var counter = Counters.GetOrAdd("all-transformers", s => { var indexSubscriptionTask = AfterConnection(() => { watchAllTransformers = true; return(Send("watch-transformers", null)); }); return(new DatabaseConnectionState( () => { watchAllTransformers = false; Send("unwatch-transformers", null); Counters.Remove("all-transformers"); }, indexSubscriptionTask)); }); var taskedObservable = new TaskedObservable <TransformerChangeNotification, DatabaseConnectionState>( counter, notification => true); counter.OnTransformerChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocumentsInCollection(string collectionName) { if (collectionName == null) { throw new ArgumentNullException("collectionName"); } var counter = counters.GetOrAdd("collections/" + collectionName, s => { var documentSubscriptionTask = AfterConnection(() => { watchedCollections.TryAdd(collectionName); return(Send("watch-collection", collectionName)); }); return(new LocalConnectionState( () => { watchedCollections.TryRemove(collectionName); Send("unwatch-collection", collectionName); counters.Remove("collections/" + collectionName); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => string.Equals(collectionName, notification.CollectionName, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocumentsOfType(string typeName) { if (typeName == null) { throw new ArgumentNullException("typeName"); } var encodedTypeName = Uri.EscapeDataString(typeName); var counter = counters.GetOrAdd("types/" + typeName, s => { var documentSubscriptionTask = AfterConnection(() => { watchedTypes.TryAdd(typeName); return(Send("watch-type", encodedTypeName)); }); return(new LocalConnectionState( () => { watchedTypes.TryRemove(typeName); Send("unwatch-type", encodedTypeName); counters.Remove("types/" + typeName); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => string.Equals(typeName, notification.TypeName, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForAllDocuments() { var counter = counters.GetOrAdd("all-docs", s => { var documentSubscriptionTask = AfterConnection(() => { watchAllDocs = true; return(Send("watch-docs", null)); }); return(new LocalConnectionState( () => { watchAllDocs = false; Send("unwatch-docs", null); counters.Remove("all-docs"); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => true); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <ReplicationConflictNotification> ForAllReplicationConflicts() { var counter = counters.GetOrAdd("all-replication-conflicts", s => { var indexSubscriptionTask = AfterConnection(() => { watchAllIndexes = true; return(Send("watch-replication-conflicts", null)); }); return(new LocalConnectionState( () => { watchAllIndexes = false; Send("unwatch-replication-conflicts", null); counters.Remove("all-replication-conflicts"); }, indexSubscriptionTask)); }); var taskedObservable = new TaskedObservable <ReplicationConflictNotification>( counter, notification => true); counter.OnReplicationConflictNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <BulkInsertChangeNotification> ForBulkInsert(Guid?operationId = null) { var id = operationId != null?operationId.ToString() : string.Empty; var counter = Counters.GetOrAdd("bulk-operations/" + id, s => { watchedBulkInserts.TryAdd(id); var documentSubscriptionTask = AfterConnection(() => { if (watchedBulkInserts.Contains(id)) // might have been removed in the meantime { return(Send("watch-bulk-operation", id)); } return(Task); }); return(new DatabaseConnectionState( () => { watchedBulkInserts.TryRemove(id); Send("unwatch-bulk-operation", id); Counters.Remove("bulk-operations/" + operationId); }, existingConnectionState => { DatabaseConnectionState _; if (Counters.TryGetValue("bulk-operations/" + id, out _)) { return _.Task; } Counters.GetOrAdd("bulk-operations/" + id, x => existingConnectionState); return AfterConnection(() => { if (watchedBulkInserts.Contains(id)) // might have been removed in the meantime { return Send("watch-bulk-operation", id); } return Task; }); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <BulkInsertChangeNotification, DatabaseConnectionState>(counter, notification => operationId == null || notification.OperationId == operationId); counter.OnBulkInsertChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocument(string docId) { var counter = GetOrAddConnectionState("docs/" + docId, "watch-doc", "unwatch-doc", () => watchedDocs.TryAdd(docId), () => watchedDocs.TryRemove(docId), docId); var taskedObservable = new TaskedObservable <DocumentChangeNotification, DatabaseConnectionState>( counter, notification => string.Equals(notification.Id, docId, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DataSubscriptionChangeNotification> ForAllDataSubscriptions() { var counter = GetOrAddConnectionState("all-data-subscriptions", "watch-data-subscriptions", "unwatch-data-subscriptions", () => watchAllDataSubscriptions = true, () => watchAllDataSubscriptions = false, null); var taskedObservable = new TaskedObservable <DataSubscriptionChangeNotification, DatabaseConnectionState>( counter, notification => true); counter.OnDataSubscriptionNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <ReplicationConflictNotification> ForAllReplicationConflicts() { var counter = GetOrAddConnectionState("all-replication-conflicts", "watch-replication-conflicts", "unwatch-replication-conflicts", () => watchAllIndexes = true, () => watchAllIndexes = false, null); var taskedObservable = new TaskedObservable <ReplicationConflictNotification, DatabaseConnectionState>( counter, notification => true); counter.OnReplicationConflictNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <IndexChangeNotification> ForIndex(string indexName) { var counter = counters.GetOrAdd("indexes/" + indexName, s => { var indexSubscriptionTask = AfterConnection(() => { connectionsData.AddOrUpdate("watch-index", indexName, (s1, s2) => s2); return(Send("watch-index", indexName)); }); return(new LocalConnectionState( () => { string value; connectionsData.TryRemove("watch-index", out value); Send("unwatch-index", indexName); counters.Remove("indexes/" + indexName); }, indexSubscriptionTask)); }); counter.Inc(); var taskedObservable = new TaskedObservable <IndexChangeNotification>( counter, notification => string.Equals(notification.Name, indexName, StringComparison.InvariantCultureIgnoreCase)); counter.OnIndexChangeNotification += taskedObservable.Send; counter.OnError = taskedObservable.Error; var disposableTask = counter.Task.ContinueWith(task => { if (task.IsFaulted) { return(null); } return((IDisposable) new DisposableAction(() => { try { connection.Dispose(); } catch (Exception) { // nothing to do here } })); }); counter.Add(disposableTask); return(taskedObservable); }
public IObservableWithTask <DataSubscriptionChangeNotification> ForDataSubscription(long subscriptionId) { var counter = GetOrAddConnectionState("subscriptions/" + subscriptionId, "watch-data-subscription", "unwatch-data-subscription", () => watchedDataSubscriptions.TryAdd(subscriptionId), () => watchedDataSubscriptions.TryRemove(subscriptionId), subscriptionId.ToString(CultureInfo.InvariantCulture)); var taskedObservable = new TaskedObservable <DataSubscriptionChangeNotification, DatabaseConnectionState>( counter, notification => notification.Id == subscriptionId); counter.OnDataSubscriptionNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <TransformerChangeNotification> ForAllTransformers() { var counter = GetOrAddConnectionState("all-transformers", "watch-transformers", "unwatch-transformers", () => watchAllTransformers = true, () => watchAllTransformers = false, null); var taskedObservable = new TaskedObservable <TransformerChangeNotification, DatabaseConnectionState>( counter, notification => true); counter.OnTransformerChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocumentsStartingWith(string docIdPrefix) { var counter = GetOrAddConnectionState("prefixes/" + docIdPrefix, "watch-prefix", "unwatch-prefix", () => watchedPrefixes.TryAdd(docIdPrefix), () => watchedPrefixes.TryRemove(docIdPrefix), docIdPrefix); var taskedObservable = new TaskedObservable <DocumentChangeNotification, DatabaseConnectionState>( counter, notification => notification.Id != null && notification.Id.StartsWith(docIdPrefix, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <OperationStatusChangeNotification> ForOperationId(long operationId) { var counter = GetOrAddConnectionState("operations/" + operationId, "watch-operation", "unwatch-operation", () => watchedOperations.TryAdd(operationId), () => watchedOperations.TryRemove(operationId), operationId.ToString(CultureInfo.InvariantCulture)); var taskedObservable = new TaskedObservable <OperationStatusChangeNotification, DatabaseConnectionState>( counter, notification => notification.OperationId == operationId); counter.OnOperationStatusChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <IndexChangeNotification> ForIndex(string indexName) { var counter = GetOrAddConnectionState("indexes/" + indexName, "watch-index", "unwatch-index", () => watchedIndexes.TryAdd(indexName), () => watchedIndexes.TryRemove(indexName), indexName); counter.Inc(); var taskedObservable = new TaskedObservable <IndexChangeNotification, DatabaseConnectionState>( counter, notification => string.Equals(notification.Name, indexName, StringComparison.OrdinalIgnoreCase)); counter.OnIndexChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocumentsInCollection(string collectionName) { if (collectionName == null) { throw new ArgumentNullException("collectionName"); } var counter = GetOrAddConnectionState("collections/" + collectionName, "watch-collection", "unwatch-collection", () => watchedCollections.TryAdd(collectionName), () => watchedCollections.TryRemove(collectionName), collectionName); var taskedObservable = new TaskedObservable <DocumentChangeNotification, DatabaseConnectionState>( counter, notification => string.Equals(collectionName, notification.CollectionName, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocumentsOfType(string typeName) { if (typeName == null) { throw new ArgumentNullException("typeName"); } var encodedTypeName = Uri.EscapeDataString(typeName); var counter = GetOrAddConnectionState("types/" + typeName, "watch-type", "unwatch-type", () => watchedTypes.TryAdd(typeName), () => watchedTypes.TryRemove(typeName), encodedTypeName); var taskedObservable = new TaskedObservable <DocumentChangeNotification, DatabaseConnectionState>( counter, notification => string.Equals(typeName, notification.TypeName, StringComparison.OrdinalIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocumentsStartingWith(string docIdPrefix) { var counter = counters.GetOrAdd("prefixes/" + docIdPrefix, s => { var documentSubscriptionTask = AfterConnection(() => { connectionsData.AddOrUpdate("watch-prefix", docIdPrefix, (s1, s2) => s2); return(Send("watch-prefix", docIdPrefix)); }); return(new LocalConnectionState( () => { string value; connectionsData.TryRemove("watch-prefix", out value); Send("unwatch-prefix", docIdPrefix); counters.Remove("prefixes/" + docIdPrefix); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => notification.Name.StartsWith(docIdPrefix, StringComparison.InvariantCultureIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError += taskedObservable.Error; var disposableTask = counter.Task.ContinueWith(task => { if (task.IsFaulted) { return(null); } return((IDisposable) new DisposableAction(() => connection.Dispose())); }); counter.Add(disposableTask); return(taskedObservable); }
public IObservableWithTask <IndexChangeNotification> ForAllIndexes() { var counter = counters.GetOrAdd("all-indexes", s => { var indexSubscriptionTask = AfterConnection(() => { connectionsData.AddOrUpdate("watch-indexes", "", (s1, s2) => s2); return(Send("watch-indexes", null)); }); return(new LocalConnectionState( () => { string value; connectionsData.TryRemove("watch-indexes", out value); Send("unwatch-indexes", null); counters.Remove("all-indexes"); }, indexSubscriptionTask)); }); var taskedObservable = new TaskedObservable <IndexChangeNotification>( counter, notification => true); counter.OnIndexChangeNotification += taskedObservable.Send; counter.OnError = taskedObservable.Error; var disposableTask = counter.Task.ContinueWith(task => { if (task.IsFaulted) { return(null); } return((IDisposable) new DisposableAction(() => connection.Dispose())); }); counter.Add(disposableTask); return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForDocument(string docId) { var counter = counters.GetOrAdd("docs/" + docId, s => { var documentSubscriptionTask = AfterConnection(() => { watchedDocs.TryAdd(docId); return(Send("watch-doc", docId)); }); return(new LocalConnectionState( () => { watchedDocs.TryRemove(docId); Send("unwatch-doc", docId); counters.Remove("docs/" + docId); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => string.Equals(notification.Id, docId, StringComparison.InvariantCultureIgnoreCase)); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError = taskedObservable.Error; var disposableTask = counter.Task.ContinueWith(task => { if (task.IsFaulted) { return(null); } return((IDisposable) new DisposableAction(() => connection.Dispose())); }); counter.Add(disposableTask); return(taskedObservable); }
public IObservableWithTask <DocumentChangeNotification> ForAllDocuments() { var counter = counters.GetOrAdd("all-docs", s => { var documentSubscriptionTask = AfterConnection(() => { watchAllDocs = true; return(Send("watch-docs", null)); }); return(new LocalConnectionState( () => { watchAllDocs = false; Send("unwatch-docs", null); counters.Remove("all-docs"); }, documentSubscriptionTask)); }); var taskedObservable = new TaskedObservable <DocumentChangeNotification>( counter, notification => true); counter.OnDocumentChangeNotification += taskedObservable.Send; counter.OnError = taskedObservable.Error; var disposableTask = counter.Task.ContinueWith(task => { if (task.IsFaulted) { return(null); } return((IDisposable) new DisposableAction(() => connection.Dispose())); }); counter.Add(disposableTask); return(taskedObservable); }