Beispiel #1
0
        public IObservableWithTask <ConflictNotification> ForConflicts()
        {
            var counter = Counters.GetOrAdd("all-fs-conflicts", s =>
            {
                var conflictsSubscriptionTask = AfterConnection(() =>
                {
                    watchAllConflicts = true;
                    return(Send("watch-conflicts", null));
                });
                return(new FilesConnectionState(
                           () =>
                {
                    watchAllConflicts = false;
                    Send("unwatch-conflicts", null);
                    Counters.Remove("all-fs-conflicts");
                },
                           conflictsSubscriptionTask));
            });
            var taskedObservable = new TaskedObservable <ConflictNotification, FilesConnectionState>(
                counter,
                notification => true);

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

            return(taskedObservable);
        }
Beispiel #2
0
        public IObservableWithTask <KeyChangeNotification> ForKey(string type, string key)
        {
            if (string.IsNullOrWhiteSpace(type))
            {
                throw new ArgumentException("Type cannot be empty!");
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("Key cannot be empty!");
            }

            var keyWithType = type + "/" + key;
            var timeSeries  = GetOrAddConnectionState("time-series-key-change/" + keyWithType, "watch-time-series-key-change", "unwatch-time-series-key-change",
                                                      () => watchedKeysChanges.TryAdd(keyWithType),
                                                      () => watchedKeysChanges.TryRemove(keyWithType),
                                                      keyWithType);

            var taskedObservable = new TaskedObservable <KeyChangeNotification, TimeSeriesConnectionState>(
                timeSeries,
                notification => string.Equals(notification.Type, type, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(notification.Key, key, StringComparison.OrdinalIgnoreCase));

            timeSeries.OnChangeNotification += taskedObservable.Send;
            timeSeries.OnError += taskedObservable.Error;

            return(taskedObservable);
        }
        public IObservableWithTask <SynchronizationUpdateNotification> ForSynchronization()
        {
            var counter = Counters.GetOrAdd("all-fs-sync", s =>
            {
                var conflictsSubscriptionTask = AfterConnection(() =>
                {
                    watchAllSynchronizations = true;
                    return(Send("watch-sync", null));
                });
                return(new FileSystemConnectionState(
                           () =>
                {
                    watchAllSynchronizations = false;
                    Send("unwatch-sync", null);
                    Counters.Remove("all-fs-sync");
                },
                           conflictsSubscriptionTask));
            });
            var taskedObservable = new TaskedObservable <SynchronizationUpdateNotification, FileSystemConnectionState>(
                counter,
                notification => true);

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

            return(taskedObservable);
        }
Beispiel #4
0
        public IObservableWithTask <StartingWithNotification> ForCountersStartingWith(string groupName, string prefixForName)
        {
            if (string.IsNullOrWhiteSpace(groupName))
            {
                throw new ArgumentException("Group name cannot be empty!");
            }

            if (string.IsNullOrWhiteSpace(prefixForName))
            {
                throw new ArgumentException("Prefix for counter name cannot be empty");
            }

            var counterPrefix = CounterUtils.GetFullCounterName(groupName, prefixForName);
            var key           = string.Concat("counters-starting-with/", counterPrefix);
            var counter       = GetOrAddConnectionState(key, "watch-counters-prefix", "unwatch-counters-prefix",
                                                        () => watchedPrefixes.TryAdd(counterPrefix),
                                                        () => watchedPrefixes.TryRemove(counterPrefix),
                                                        counterPrefix);

            var taskedObservable = new TaskedObservable <StartingWithNotification, CountersConnectionState>(
                counter,
                notification =>
            {
                var t = string.Equals(notification.GroupName, groupName, StringComparison.OrdinalIgnoreCase) &&
                        notification.CounterName.StartsWith(prefixForName, StringComparison.OrdinalIgnoreCase);
                return(t);
            });

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

            return(taskedObservable);
        }
Beispiel #5
0
        public IObservableWithTask <ChangeNotification> ForChange(string groupName, string counterName)
        {
            if (string.IsNullOrWhiteSpace(groupName))
            {
                throw new ArgumentException("Group name cannot be empty!");
            }

            if (string.IsNullOrWhiteSpace(counterName))
            {
                throw new ArgumentException("Counter name cannot be empty");
            }

            var fullCounterName = CounterUtils.GetFullCounterName(groupName, counterName);
            var key             = "counter-change/" + fullCounterName;
            var counter         = GetOrAddConnectionState(key, "watch-counter-change", "unwatch-counter-change",
                                                          () => watchedChanges.TryAdd(fullCounterName),
                                                          () => watchedChanges.TryRemove(fullCounterName),
                                                          fullCounterName);

            var taskedObservable = new TaskedObservable <ChangeNotification, CountersConnectionState>(
                counter,
                notification => string.Equals(notification.GroupName, groupName, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(notification.CounterName, counterName, StringComparison.OrdinalIgnoreCase));

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

            return(taskedObservable);
        }
        public IObservableWithTask <FileChangeNotification> ForFolder(string folder)
        {
            if (string.IsNullOrWhiteSpace(folder))
            {
                throw new ArgumentException("folder cannot be empty");
            }

            if (!folder.StartsWith("/"))
            {
                throw new ArgumentException("folder must start with /");
            }

            var canonicalisedFolder = folder.TrimStart('/');
            var key     = "fs-folder/" + canonicalisedFolder;
            var counter = GetOrAddConnectionState(key, "watch-folder", "unwatch-folder",
                                                  () => watchedFolders.TryAdd(folder),
                                                  () => watchedFolders.TryRemove(folder),
                                                  folder);

            var taskedObservable = new TaskedObservable <FileChangeNotification, FilesConnectionState>(
                counter,
                notification => notification.File.StartsWith(folder, StringComparison.OrdinalIgnoreCase));

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

            return(taskedObservable);
        }
Beispiel #7
0
        public IObservableWithTask <BulkOperationNotification> ForBulkOperation(Guid?operationId = null)
        {
            var id = operationId != null?operationId.ToString() : string.Empty;

            var key        = "bulk-operations/" + id;
            var timeSeries = Counters.GetOrAdd(key, s =>
            {
                watchedBulkOperations.TryAdd(id);
                var bulkOperationSubscriptionTask = AfterConnection(() =>
                {
                    if (watchedBulkOperations.Contains(id)) // might have been removed in the meantime
                    {
                        return(Send("watch-bulk-operation", id));
                    }
                    return(ConnectionTask);
                });

                return(new TimeSeriesConnectionState(
                           () =>
                {
                    watchedBulkOperations.TryRemove(id);
                    Counters.Remove(key);
                    return Send("unwatch-bulk-operation", id);
                },
                           existingConnectionState =>
                {
                    TimeSeriesConnectionState _;
                    if (Counters.TryGetValue("bulk-operations/" + id, out _))
                    {
                        return _.Task;
                    }

                    Counters.GetOrAdd("bulk-operations/" + id, x => existingConnectionState);

                    return AfterConnection(() =>
                    {
                        if (watchedBulkOperations.Contains(id))     // might have been removed in the meantime
                        {
                            return Send("watch-bulk-operation", id);
                        }
                        return ConnectionTask;
                    });
                },
                           bulkOperationSubscriptionTask));
            });

            var taskedObservable = new TaskedObservable <BulkOperationNotification, TimeSeriesConnectionState>(
                timeSeries,
                notification => operationId == null || notification.OperationId == operationId);

            timeSeries.OnBulkOperationNotification += taskedObservable.Send;
            timeSeries.OnError += taskedObservable.Error;

            return(taskedObservable);
        }
Beispiel #8
0
        public IObservableWithTask <KeyChangeNotification> ForAllTimeSeries()
        {
            var timeSeries = GetOrAddConnectionState("all-time-series", "watch-time-series-key-change", "unwatch-time-series-key-change",
                                                     () => watchAllTimeSeries = true,
                                                     () => watchAllTimeSeries = false,
                                                     null);

            var taskedObservable = new TaskedObservable <KeyChangeNotification, TimeSeriesConnectionState>(
                timeSeries,
                notification => true);

            timeSeries.OnChangeNotification += taskedObservable.Send;
            timeSeries.OnError += taskedObservable.Error;

            return(taskedObservable);
        }
Beispiel #9
0
        public IObservableWithTask <ChangeNotification> ForAllCounters()
        {
            var counter = GetOrAddConnectionState("all-counters", "watch-counter-change", "unwatch-counter-change",
                                                  () => watchAllCounters = true,
                                                  () => watchAllCounters = false,
                                                  null);

            var taskedObservable = new TaskedObservable <ChangeNotification, CountersConnectionState>(
                counter,
                notification => true);

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

            return(taskedObservable);
        }
        public IObservableWithTask <ConflictNotification> ForConflicts()
        {
            var counter = GetOrAddConnectionState("all-fs-conflicts", "watch-conflicts", "unwatch-conflicts",
                                                  () => watchAllConflicts = true,
                                                  () => watchAllConflicts = false,
                                                  null);

            var taskedObservable = new TaskedObservable <ConflictNotification, FilesConnectionState>(
                counter,
                notification => true);

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

            return(taskedObservable);
        }
        public IObservableWithTask <SynchronizationUpdateNotification> ForSynchronization()
        {
            var counter = GetOrAddConnectionState("all-fs-sync", "watch-sync", "unwatch-sync",
                                                  () => watchAllSynchronizations = true,
                                                  () => watchAllSynchronizations = false,
                                                  null);

            var taskedObservable = new TaskedObservable <SynchronizationUpdateNotification, FilesConnectionState>(
                counter,
                notification => true);

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

            return(taskedObservable);
        }
Beispiel #12
0
        public IObservableWithTask <FileChangeNotification> ForFolder(string folder)
        {
            if (string.IsNullOrWhiteSpace(folder))
            {
                throw new ArgumentException("folder cannot be empty");
            }

            if (!folder.StartsWith("/"))
            {
                throw new ArgumentException("folder must start with /");
            }

            var canonicalisedFolder = folder.TrimStart('/');

            // watch-folder, unwatch-folder

            var counter = Counters.GetOrAdd("fs-folder/" + canonicalisedFolder, s =>
            {
                var fileChangeSubscriptionTask = AfterConnection(() =>
                {
                    watchedFolders.TryAdd(folder);
                    return(Send("watch-folder", folder));
                });

                return(new FilesConnectionState(
                           () =>
                {
                    watchedFolders.TryRemove(folder);
                    Send("unwatch-folder", folder);
                    Counters.Remove("fs-folder/" + canonicalisedFolder);
                },
                           fileChangeSubscriptionTask));
            });

            var taskedObservable = new TaskedObservable <FileChangeNotification, FilesConnectionState>(
                counter,
                notification => notification.File.StartsWith(folder, StringComparison.InvariantCultureIgnoreCase));

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

            return(taskedObservable);
        }
Beispiel #13
0
        public IObservableWithTask <InGroupNotification> ForCountersInGroup(string groupName)
        {
            if (string.IsNullOrWhiteSpace(groupName))
            {
                throw new ArgumentException("Group name cannot be empty!");
            }

            var key     = string.Concat("counters-in-group/", groupName);
            var counter = GetOrAddConnectionState(key, "watch-counters-in-group", "unwatch-counters-in-group",
                                                  () => watchedCountersInGroup.TryAdd(groupName),
                                                  () => watchedCountersInGroup.TryRemove(groupName),
                                                  groupName);

            var taskedObservable = new TaskedObservable <InGroupNotification, CountersConnectionState>(
                counter,
                notification => string.Equals(notification.GroupName, groupName, StringComparison.OrdinalIgnoreCase));

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

            return(taskedObservable);
        }