コード例 #1
0
ファイル: RemoteDatabaseChanges.cs プロジェクト: SHSE/ravendb
        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.InvariantCultureIgnoreCase));

            counter.OnIndexChangeNotification += taskedObservable.Send;
            counter.OnError = taskedObservable.Error;


            return(taskedObservable);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: FilesStore.cs プロジェクト: lahma/ravendb
        protected virtual IFilesChanges CreateFileSystemChanges(string filesystem)
        {
            if (string.IsNullOrEmpty(Url))
            {
                throw new InvalidOperationException("Changes API requires usage of server/client");
            }

            var tenantUrl = Url + "/fs/" + filesystem;

            var commands = fileSystemCommands.GetOrAdd(filesystem, x => (IAsyncFilesCommandsImpl)this.AsyncFilesCommands.ForFileSystem(x));

            using (NoSynchronizationContext.Scope())
            {
                var client = new FilesChangesClient(tenantUrl,
                                                    ApiKey,
                                                    Credentials,
                                                    jsonRequestFactory,
                                                    Conventions,
                                                    commands.ReplicationInformer,
                                                    ((AsyncFilesServerClient)this.AsyncFilesCommands).TryResolveConflictByUsingRegisteredListenersAsync,
                                                    () =>
                {
                    fileSystemChanges.Remove(filesystem);
                    fileSystemCommands.Remove(filesystem);
                });

                return(client);
            }
        }
コード例 #4
0
        protected virtual IDatabaseChanges CreateDatabaseChanges(string database)
        {
            if (string.IsNullOrEmpty(Url))
            {
                throw new InvalidOperationException("Changes API requires usage of server/client");
            }

            database = database ?? DefaultDatabase ?? MultiDatabase.GetDatabaseName(Url);

            var dbUrl = MultiDatabase.GetRootDatabaseUrl(Url);

            if (string.IsNullOrEmpty(database) == false &&
                string.Equals(database, Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase) == false)
            {
                dbUrl = dbUrl + "/databases/" + database;
            }

            using (NoSynchronizationContext.Scope())
            {
                return(new RemoteDatabaseChanges(dbUrl,
                                                 ApiKey,
                                                 Credentials,
                                                 jsonRequestFactory,
                                                 Conventions,
                                                 () => databaseChanges.Remove(database),
                                                 (key, etag, conflictIds, metadata) => ((AsyncServerClient)AsyncDatabaseCommands).TryResolveConflictByUsingRegisteredListenersAsync(key, etag, conflictIds, metadata)));
            }
        }
コード例 #5
0
ファイル: DocumentStore.cs プロジェクト: ravendb/silverlight
        protected virtual IDatabaseChanges CreateDatabaseChanges(string database)
        {
            if (string.IsNullOrEmpty(Url))
            {
                throw new InvalidOperationException("Changes API requires usage of server/client");
            }

            database = database ?? DefaultDatabase;

            var dbUrl = MultiDatabase.GetRootDatabaseUrl(Url);

            if (string.IsNullOrEmpty(database) == false)
            {
                dbUrl = dbUrl + "/databases/" + database;
            }

            using (NoSynchronizationContext.Scope())
            {
                return(new RemoteDatabaseChanges(dbUrl,
                                                 ApiKey,
                                                 Credentials,
                                                 jsonRequestFactory,
                                                 Conventions,
                                                 GetReplicationInformerForDatabase(database),
                                                 () => databaseChanges.Remove(database),
                                                 ((AsyncServerClient)AsyncDatabaseCommands).TryResolveConflictByUsingRegisteredListenersAsync));
            }
        }
コード例 #6
0
        public void SecondPass()
        {
            KeyValuePair <C, B> firstItem;

            _di4.TryGetFirst(out firstItem);

            var lambdaCarrier = new AtomicDictionary <uint, Lambda>();
            KeyValueUpdate <C, B> updateFunction = delegate(C k, B i) { return(i.Update(lambdaCarrier.Values)); };
            List <uint> keysToRemove             = new List <uint>();
            List <uint> keys;

            foreach (var bookmark in _di4.EnumerateFrom(firstItem.Key))
            {
                foreach (var lambda in bookmark.Value.lambda)
                {
                    lambdaCarrier.AddOrUpdate(lambda.atI, lambda);
                    if (lambda.phi == Phi.RightEnd)
                    {
                        keysToRemove.Add(lambda.atI);
                    }
                }

                if (UpdateRequired(bookmark.Value.lambda, lambdaCarrier))
                {
                    _di4.TryUpdate(bookmark.Key, updateFunction);
                }

                foreach (uint item in keysToRemove)
                {
                    lambdaCarrier.Remove(item);
                }
                keysToRemove.Clear();

                keys = new List <uint>(lambdaCarrier.Keys);
                foreach (var key in keys)
                {
                    lambdaCarrier[key] = new Lambda(Phi.Middle, lambdaCarrier[key].atI, _collectionID);
                }
            }
        }
コード例 #7
0
        protected TConnectionState GetOrAddConnectionState(string name, string watchCommand, string unwatchCommand, Action afterConnection, Action beforeDisconnect, string value)
        {
            var counter = Counters.GetOrAdd(name, s =>
            {
                Func <Task> onZero = () =>
                {
                    beforeDisconnect();

                    Counters.Remove(name);
                    return(Send(unwatchCommand, value));
                };

                Func <TConnectionState, Task> ensureConnection = existingConnectionState =>
                {
                    TConnectionState _;
                    if (Counters.TryGetValue(name, out _))
                    {
                        return(_.Task);
                    }

                    Counters.GetOrAdd(name, x => existingConnectionState);

                    return(AfterConnection(() =>
                    {
                        afterConnection();
                        return Send(watchCommand, value);
                    }));
                };

                var counterSubscriptionTask = AfterConnection(() =>
                {
                    afterConnection();
                    return(Send(watchCommand, value));
                });

                return(CreateTConnectionState(onZero, ensureConnection, counterSubscriptionTask));
            });

            return(counter);
        }
コード例 #8
0
ファイル: CounterStore.cs プロジェクト: Danielle9897/ravendb
        private ICountersChanges CreateCounterStorageChanges(string counterStorage)
        {
            if (string.IsNullOrEmpty(Url))
            {
                throw new InvalidOperationException("Changes API requires usage of server/client");
            }

            AssertInitialized();

            var tenantUrl = $"{Url}/cs/{counterStorage}";

            using (NoSynchronizationContext.Scope())
            {
                var client = new CountersChangesClient(tenantUrl,
                                                       Credentials.ApiKey,
                                                       Credentials.Credentials,
                                                       CountersConvention,
                                                       () => counterStorageChanges.Remove(counterStorage));

                return(client);
            }
        }
コード例 #9
0
        private ITimeSeriesChanges CreateTimeSeriesChanges(string timeSeries)
        {
            if (string.IsNullOrEmpty(Url))
            {
                throw new InvalidOperationException("Changes API requires usage of server/client");
            }

            AssertInitialized();

            var tenantUrl = Url + "/ts/" + timeSeries;

            using (NoSynchronizationContext.Scope())
            {
                var client = new TimeSeriesChangesClient(tenantUrl,
                                                         Credentials.ApiKey,
                                                         Credentials.Credentials,
                                                         TimeSeriesConvention,
                                                         () => timeSeriesChanges.Remove(timeSeries));

                return(client);
            }
        }
コード例 #10
0
        protected virtual IDatabaseChanges CreateDatabaseChanges(string database)
        {
            if (string.IsNullOrEmpty(Url))
            {
                throw new InvalidOperationException("Changes API requires usage of server/client");
            }

            database = database ?? DefaultDatabase;

            var dbUrl = MultiDatabase.GetRootDatabaseUrl(Url);

            if (string.IsNullOrEmpty(database) == false)
            {
                dbUrl = dbUrl + "/databases/" + database;
            }

            return(new RemoteDatabaseChanges(dbUrl,
                                             Credentials,
                                             jsonRequestFactory,
                                             Conventions,
                                             GetReplicationInformerForDatabase(database),
                                             () => databaseChanges.Remove(database)));
        }