Exemplo n.º 1
0
        private void StartWatchingDocs()
        {
            changes.ConnectionStatusChanged += ChangesApiConnectionChanged;

            var allDocsObservable = changes.ForAllDocuments();

            putDocumentsObserver = allDocsObservable.Subscribe(notification =>
            {
                if (notification.Type == DocumentChangeTypes.Put && notification.Id.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase) == false)
                {
                    newDocuments.Set();
                }
            });

            var bulkInsertObservable = changes.ForBulkInsert();

            endedBulkInsertsObserver = bulkInsertObservable.Subscribe(notification =>
            {
                if (notification.Type == DocumentChangeTypes.BulkInsertEnded)
                {
                    newDocuments.Set();
                }
            });

            Task.WaitAll(new Task[]
            {
                allDocsObservable.Task, bulkInsertObservable.Task
            });
        }
Exemplo n.º 2
0
        public async Task AsyncWhatIsChangesApi()
        {
            using (var store = new DocumentStore())
            {
                #region changes_2
                IDatabaseChanges changes = store.Changes();
                await changes.EnsureConnectedNow();

                var subscription = changes
                                   .ForAllDocuments()
                                   .Subscribe(change => Console.WriteLine("{0} on document {1}", change.Type, change.Id));
                try
                {
                    // application code here
                }
                finally
                {
                    if (subscription != null)
                    {
                        subscription.Dispose();
                    }
                }
                #endregion
            }
        }
Exemplo n.º 3
0
        public EvictItemsFromCacheBasedOnChanges(DocumentStore store, string databaseName)
        {
            _databaseName    = databaseName;
            _changes         = store.Changes(databaseName);
            _requestExecutor = store.GetRequestExecutor(databaseName);
            var docSub = _changes.ForAllDocuments();

            _documentsSubscription = docSub.Subscribe(this);
            var indexSub = _changes.ForAllIndexes();

            _indexesSubscription = indexSub.Subscribe(this);
        }
        public EvictItemsFromCacheBasedOnChanges(string databaseName, IDatabaseChanges changes, Action <string> evictCacheOldItems)
        {
            this.databaseName       = databaseName;
            this.changes            = changes;
            this.evictCacheOldItems = evictCacheOldItems;
            var docSub = changes.ForAllDocuments();

            documentsSubscription = docSub.Subscribe(this);
            var indexSub = changes.ForAllIndexes();

            indexesSubscription = indexSub.Subscribe(this);

            connectionTask = Task.Factory.ContinueWhenAll(new Task[] { docSub.Task, indexSub.Task }, tasks => { });
        }
Exemplo n.º 5
0
        private void StartWatchingDocs()
        {
            changes.ConnectionStatusChanged += ChangesApiConnectionChanged;

            PutDocumentsObserver = changes.ForAllDocuments().Subscribe(notification =>
            {
                if (notification.Type == DocumentChangeTypes.Put && notification.Id.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase) == false)
                {
                    newDocuments.Set();
                }
            });

            EndedBulkInsertsObserver = changes.ForBulkInsert().Subscribe(notification =>
            {
                if (notification.Type == DocumentChangeTypes.BulkInsertEnded)
                {
                    newDocuments.Set();
                }
            });
        }
Exemplo n.º 6
0
        /// <summary>
        ///		An example subscription to the change-notification API.
        /// </summary>
        /// <param name="changes">
        ///		The change-notification API.
        /// </param>
        /// <param name="serverUrl">
        ///		The URL of the server targeted by the API.
        /// </param>
        /// <returns>
        ///		An <see cref="IDisposable"/> representing the subscription.
        /// </returns>
        static IDisposable SubscribeToChangesApi(IDatabaseChanges changes, string serverUrl)
        {
            if (changes == null)
            {
                throw new ArgumentNullException(nameof(changes));
            }

            if (String.IsNullOrWhiteSpace(serverUrl))
            {
                throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'serverUrl'.", nameof(serverUrl));
            }

            return(changes.ForAllDocuments()
                   .Where(
                       change => !change.Id.StartsWith("Raven/Replication")
                       )
                   .Subscribe(
                       change => Log.Information("{ServerUrl} {ChangeType}: {DocumentId} ({DocumentETag})", serverUrl, change.Type, change.Id, change.Etag),
                       error => Log.Error(error, "{ServerUrl} subscription error: {ErrorMessage}", serverUrl, error.Message),
                       () => Log.Information("[{ServerUrl}] subscription complete", serverUrl)
                       ));
        }