Пример #1
0
 public IDisposable DocumentChange(Type documentType, Action <DocumentChangeNotification> action)
 {
     return(_documentStore
            .Changes(_config.Database)
            .ForDocumentsStartingWith(GetId(documentType, ""))
            .Subscribe(new RepositoryObserver <DocumentChangeNotification>(action)));
 }
        public async Task <Subscription <T> > OpenAsync <T>(long id, SubscriptionConnectionOptions options, string database = null) where T : class
        {
            if (options == null)
            {
                throw new InvalidOperationException("Cannot open a subscription if options are null");
            }

            if (options.BatchOptions == null)
            {
                throw new InvalidOperationException("Cannot open a subscription if batch options are null");
            }

            if (options.BatchOptions.MaxSize.HasValue && options.BatchOptions.MaxSize.Value < 16 * 1024)
            {
                throw new InvalidOperationException("Max size value of batch options cannot be lower than that 16 KB");
            }

            var commands = database == null
                                ? documentStore.AsyncDatabaseCommands
                                : documentStore.AsyncDatabaseCommands.ForDatabase(database);

            await SendOpenSubscriptionRequest(commands, id, options).ConfigureAwait(false);

            var subscription = new Subscription <T>(id, options, commands, documentStore.Changes(database), documentStore.Conventions, () =>
                                                    SendOpenSubscriptionRequest(commands, id, options)); // to ensure that subscription is open try to call it with the same connection id

            subscriptions.Add(subscription);

            return(subscription);
        }
Пример #3
0
        protected override void OnStart()
        {
            subscription = store.Changes().ForDocumentsStartingWith("ExternalIntegrationDispatchRequests").Where(c => c.Type == DocumentChangeTypes.Put).Subscribe(OnNext);

            tokenSource    = new CancellationTokenSource();
            circuitBreaker = new RepeatedFailuresOverTimeCircuitBreaker("EventDispatcher",
                                                                        TimeSpan.FromMinutes(5),
                                                                        ex => criticalError.Raise("Repeated failures when dispatching external integration events.", ex),
                                                                        TimeSpan.FromSeconds(20));

            StartDispatcher();
        }
Пример #4
0
        internal static void Subscribe(IDocumentStore store, IDictionary <string, TimeSpan> defaults)
        {
            store.Ensure("store").IsNotNull();

            var settings = new AggressiveCachingSettings(defaults);

            settings.store = store;
            store.SetProperty(AggressiveCachingSettings.StorePropertyKey, settings);

            store.Changes()
            .ForDocument(LiveId)
            .Subscribe(new DocumentChangeObserver(_ => settings.LoadFromStore()));
        }
Пример #5
0
        private static async Task <Operation> SendAsync(IDocumentStore store, IMaintenanceOperation <OperationIdResult <StartBackupOperationResult> > operation, CancellationToken token = default)
        {
            var re = store.GetRequestExecutor();

            using (re.ContextPool.AllocateOperationContext(out var context))
            {
                var command = operation.GetCommand(re.Conventions, context);

                await re.ExecuteAsync(command, context, null, token).ConfigureAwait(false);

                var selectedNodeTag = command.SelectedNodeTag ?? command.Result.Result.ResponsibleNode;
                return(new Operation(re, () => store.Changes(store.Database, selectedNodeTag), re.Conventions, command.Result.OperationId, selectedNodeTag));
            }
        }
Пример #6
0
        public ActionResult Changes()
        {
            using (var ravenSession = ravenStore.OpenSession())
            {
                #region article_viewmodels_8
                // Listen for changes to Recipes.
                // When that happens, update the corresponding RecipeViewModel.
                ravenStore
                .Changes()
                .ForDocumentsOfType <Recipe>()
                .Subscribe(docChange => this.UpdateViewModelFromRecipe(docChange.Id));
                #endregion
            }

            return(View());
        }
Пример #7
0
        private static async Task <long> AggressiveCacheOnLazilyLoadAsyncTest(
            IDocumentStore store,
            Func <IAsyncDocumentSession, string, Task> loadFuncAsync,
            AggressiveCacheMode aggressiveCacheMode,
            bool createVersion2 = true)
        {
            const string docId = "doc-1";

            using (var session = store.OpenAsyncSession())
            {
                await session.StoreAsync(new Doc(), docId);

                await session.SaveChangesAsync();
            }

            using (var session = store.OpenAsyncSession())
                using (session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(5), AggressiveCacheMode.TrackChanges))
                {
                    await loadFuncAsync(session, docId);
                }

            if (createVersion2)
            {
                var amre       = new AsyncManualResetEvent();
                var observable = store.Changes().ForDocument(docId);
                await observable.EnsureSubscribedNow();

                observable.Subscribe(_ => amre.Set());

                using var session = store.OpenAsyncSession();
                await session.StoreAsync(new Doc { Version = "2" }, docId);

                await session.SaveChangesAsync();

                await amre.WaitAsync(TimeSpan.FromSeconds(30));
            }

            using (var session = store.OpenAsyncSession())
                using (session.Advanced.DocumentStore.AggressivelyCacheFor(TimeSpan.FromMinutes(5), aggressiveCacheMode))
                {
                    var loadAsync = session.Advanced.Lazily.LoadAsync <Doc>(docId);
                    _ = await loadAsync.Value;
                    return(session.Advanced.NumberOfRequests);
                }
        }
        public TwitterHub(IDocumentStore documentStore)
        {
            _documentStore = documentStore;

            _documentStore.Changes().ForDocumentsStartingWith("tweets/").Subscribe(async change =>
            {
                if (change.Type == DocumentChangeTypes.Put)
                {
                    Tweet tweet;

                    using (var session = _documentStore.OpenAsyncSession())
                    {
                        tweet = await session.LoadAsync <Tweet>(change.Id);
                    }

                    Send(tweet);
                }
            });
        }
Пример #9
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Store = new DocumentStore { DefaultDatabase = "Mono", Url = "http://192.168.1.12:8080" }.Initialize();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            Store.Changes("Mono").ForAllDocuments().Subscribe(obj => RunOnUiThread(() =>
            {
                var local = FindViewById<Button>(Resource.Id.MyButton);
                local.Text = "changed at: " + DateTime.Now.TimeOfDay;
            }));

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
Пример #10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Store = new DocumentStore {
                DefaultDatabase = "Mono", Url = "http://192.168.1.12:8080"
            }.Initialize();


            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.MyButton);

            Store.Changes("Mono").ForAllDocuments().Subscribe(obj => RunOnUiThread(() =>
            {
                var local  = FindViewById <Button>(Resource.Id.MyButton);
                local.Text = "changed at: " + DateTime.Now.TimeOfDay;
            }));

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
Пример #11
0
 protected override void OnStart()
 {
     subscription = store.Changes().ForIndex(new FailedMessageViewIndex().IndexName).Subscribe(notifications);
 }
Пример #12
0
 public IDatabaseChanges Changes(string database = null)
 {
     return(_inner.Changes(database));
 }
Пример #13
0
        public async Task <Subscription <T> > OpenAsync <T>(long id, SubscriptionConnectionOptions options, string database = null) where T : class
        {
            if (options == null)
            {
                throw new InvalidOperationException("Cannot open a subscription if options are null");
            }

            if (options.BatchOptions == null)
            {
                throw new InvalidOperationException("Cannot open a subscription if batch options are null");
            }

            if (options.BatchOptions.MaxSize.HasValue && options.BatchOptions.MaxSize.Value < 16 * 1024)
            {
                throw new InvalidOperationException("Max size value of batch options cannot be lower than that 16 KB");
            }

            var commands = database == null
                ? documentStore.AsyncDatabaseCommands
                : documentStore.AsyncDatabaseCommands.ForDatabase(database);

            var open = true;

            try
            {
                await SendOpenSubscriptionRequest(commands, id, options).ConfigureAwait(false);
            }
            catch (SubscriptionException subscriptionException)
            {
                if (options.Strategy != SubscriptionOpeningStrategy.WaitForFree || (subscriptionException is SubscriptionInUseException) == false)
                {
                    throw;
                }

                open = false;
            }

            var subscription = new Subscription <T>(id, database ?? MultiDatabase.GetDatabaseName(documentStore.Url), options, commands, documentStore.Changes(database),
                                                    documentStore.Conventions, open, () => SendOpenSubscriptionRequest(commands, id, options)); // to ensure that subscription is open try to call it with the same connection id

            subscriptions.Add(subscription);
            subscription.OnDispose += () => subscriptions.TryRemove(subscription);

            return(subscription);
        }
Пример #14
0
 public void Start()
 {
     subscription = store.Changes().ForIndex("FailedMessageViewIndex").SubscribeOn(Scheduler.Default).Subscribe(this);
 }
 public void Start()
 {
     subscription = store.Changes().ForIndex("CustomChecksIndex").SubscribeOn(Scheduler.Default).Subscribe(this);
 }
Пример #16
0
        private static void Main(string[] args)
        {
            using (_store = new DocumentStore {Url = "http://localhost:8080", DefaultDatabase="Messages"}.Initialize())
            {
                Boostrap(args);

                _store
                    .Changes()
                    .ConnectionStatusChanged +=
                        (sender, a) =>
                            Console.WriteLine("Raven Connection Status Changed to {0}", _store.Changes().Connected); ;

                var sleepingSubscription =
                    _store
                        .Changes()
                        .ForDocument("admin/config")
                        .Subscribe(AdjustSleep);

                var routingSubcription =
                    _store
                        .Changes()
                        .ForDocumentsStartingWith("routing/")
                        .Subscribe(
                            _work,
                            exception => Console.WriteLine("Changes Subscription Error! {0}", exception),
                            () => Console.WriteLine("Changes Subscription Completed Unexpectedly!")
                        );

                while (true)
                {
                    var input = Console.ReadLine();
                    if (string.IsNullOrWhiteSpace(input)) break;

                    var sleep = WorkerSleep > 0 ? 0 : 1000;
                    SetSleep(sleep);
                }
                routingSubcription.Dispose();
                sleepingSubscription.Dispose();
            }
        }
Пример #17
0
 public IDatabaseChanges Changes(string database = null)
 {
     return(_docStore.Changes(database));
 }
Пример #18
0
 protected override void OnStart()
 {
     subscription = store.Changes().ForIndex(new CustomChecksIndex().IndexName).Subscribe(notifications);
 }