Example #1
0
        public GameService()
        {
            _sessions
            .Connect()
            .SubscribeMany(x => x.Players
                           .ToObservableChangeSet()
                           .Count()
                           .Do(count => {
                if (count == 0)
                {
                    _sessions.Remove(x);
                }
            })
                           .Finally(() => _sessions.Remove(x))
                           .Subscribe()
                           )
            .DisposeMany()
            .Subscribe();

            var gcInterval = TimeSpan.FromHours(1);

            Observable.Timer(gcInterval, gcInterval)
            .Do(_ => {
                var currentTime = DateTimeOffset.Now;
                _sessions.Remove(_sessions.Items
                                 .Where(x => currentTime - x.LastRunTime > gcInterval)
                                 .ToList()
                                 );
            })
            .Subscribe();
        }
        private async Task OnDeleteClicked(SourceCache <Neuron, int> cache, object parameter)
        {
            await Helper.SetStatusOnComplete(async() =>
            {
                bool stat      = false;
                string message = string.Empty;
                if (this.Neuron.Type == RelativeType.NotSet)
                {
                    message = $"Are you sure you wish to delete Neuron '{this.Tag}'?";
                }
                else
                {
                    message = $"Are you sure you wish to delete relative '{this.Tag}' of '{this.Parent.Value.Neuron.Tag}'?";
                }

                if ((await this.dialogService.ShowDialogYesNo(message, parameter, out DialogResult result)).GetValueOrDefault() &&
                    result == DialogResult.Yes)
                {
                    switch (this.Neuron.Type)
                    {
                    case RelativeType.NotSet:
                        await this.neuronApplicationService.DeactivateNeuron(
                            this.host.AvatarUrl,
                            this.NeuronId,
                            this.Neuron.Version
                            );
                        cache.Remove(this.Neuron);
                        break;

                    case RelativeType.Postsynaptic:
                        await this.terminalApplicationService.DeactivateTerminal(
                            this.host.AvatarUrl,
                            this.Neuron.Terminal.Id,
                            this.Neuron.Terminal.Version
                            );
                        cache.Remove(this.Neuron);
                        break;

                    case RelativeType.Presynaptic:
                        await this.terminalApplicationService.DeactivateTerminal(
                            this.host.AvatarUrl,
                            this.Neuron.Terminal.Id,
                            this.Neuron.Terminal.Version
                            );
                        cache.Remove(this.Neuron);
                        break;
                    }
                    stat = true;
                }
                return(stat);
            },
                                             "Deletion successful.",
                                             this.statusService,
                                             "Deletion cancelled."
                                             );
        }
Example #3
0
        public Task Delete(Folder folder)
        {
            StorageApplicationPermissions.FutureAccessList.Remove(folder.Token);
            source.Remove(folder.Token);

            return(Task.CompletedTask);
        }
        public void DoNotThrowAWobblyWhenRemovingaMutatedValue()
        {

            var pageController = new PageController();
            var sortController = new SortController<TestVm>(SortExpressionComparer<TestVm>.Ascending(t => t.DateFavorited ?? DateTime.MinValue));
            var filterController = new FilterController<TestVm>(myVm => myVm.Id != 0);
            var items = new ObservableCollectionExtended<TestVm>();
            var itemCache = new SourceCache<TestVm, int>(myVm => myVm.Id);

            var item1 = new TestVm(1) { DateFavorited = DateTime.Now };
            var item2 = new TestVm(2) { DateFavorited = DateTime.Now };

            itemCache.AddOrUpdate(item1);
            itemCache.AddOrUpdate(item2);

            bool error = false;
            itemCache.Connect()
                .Filter(filterController)
                .Sort(sortController)
                .Page(pageController)//error doesnt occur with paging disabled
                .Bind(items)
                .Subscribe(changes => { }, ex => error = true);

            pageController.Change(new PageRequest(1, 100));

            //NB: never errored if it was the first item which was removed
            item2.DateFavorited = null;
            itemCache.Remove(item2); //ERROR!

            Assert.IsFalse(error, "Error has been thrown");
        }
Example #5
0
 public Task Remove(Guid id) => Task.Run(() =>
 {
     var persistentId = id.ToString();
     _blobCache.InvalidateObject <ProviderModel>(persistentId).Subscribe();
     var provider = _connectable.Items.First(x => x.Id == id);
     _connectable.Remove(provider);
 });
Example #6
0
 /// <inheritdoc />
 public IObservable <Unit> Delete(T dto) =>
 _client
 .Delete(dto)
 .ToObservable()
 .WhereNotNull()
 .Do(_ => SourceCache.Remove(dto))
 .ToSignal();
        private async Task OnReload(SourceCache <Neuron, int> cache, int millisecondsDelay = 0)
        {
            this.host.Loading = true;

            if (millisecondsDelay > 0)
            {
                await Task.Delay(millisecondsDelay);
            }

            await Helper.SetStatusOnComplete(async() =>
            {
                // reload self
                var reloadedNeuron = (await this.neuronQueryService.GetNeuronById(
                                          this.host.AvatarUrl,
                                          this.Neuron.Id,
                                          this.Parent.ConvertOr(n => n.Neuron.Id, () => null),
                                          this.Neuron.Type
                                          )).First();
                NeuronViewModelBase.CopyNeuronData(this.Neuron, reloadedNeuron);
                this.SetNeuron(this.Neuron);

                // reload relatives
                cache.Remove(NeuronViewModelBase.GetAllChildren(cache, this.Neuron.UIId));
                var relatives = await this.neuronQueryService.GetNeurons(this.host.AvatarUrl, this.Neuron.Id);
                relatives.FillUIIds(this.Neuron);
                cache.AddOrUpdate(relatives);
                return(true);
            },
                                             "Neuron reloaded successfully.",
                                             this.statusService
                                             );

            this.host.Loading = false;
        }
Example #8
0
 public void Delete(SourceCache <NeuronDto, int> cache, NeuronDto dto)
 {
     // TODO: update data source
     // TODO: warn user
     // TODO: if dto has a parent then user is deleting a relationship only, otherwise a neuron is being deleted
     cache.Remove(dto);
 }
        public void AutoRefreshFromObservable()
        {
            var items = Enumerable.Range(1, 100).Select(i => new Person("Person" + i, 1)).ToArray();

            //result should only be true when all items are set to true
            using var cache   = new SourceCache <Person, string>(m => m.Name);
            using var results = cache.Connect().AutoRefreshOnObservable(p => p.WhenAnyPropertyChanged()).AsAggregator();
            cache.AddOrUpdate(items);

            results.Data.Count.Should().Be(100);
            results.Messages.Count.Should().Be(1);

            items[0].Age = 10;
            results.Data.Count.Should().Be(100);
            results.Messages.Count.Should().Be(2);

            results.Messages[1].First().Reason.Should().Be(ChangeReason.Refresh);

            //remove an item and check no change is fired
            var toRemove = items[1];

            cache.Remove(toRemove);
            results.Data.Count.Should().Be(99);
            results.Messages.Count.Should().Be(3);
            toRemove.Age = 100;
            results.Messages.Count.Should().Be(3);

            //add it back in and check it updates
            cache.AddOrUpdate(toRemove);
            results.Messages.Count.Should().Be(4);
            toRemove.Age = 101;
            results.Messages.Count.Should().Be(5);

            results.Messages.Last().First().Reason.Should().Be(ChangeReason.Refresh);
        }
        public void Merge(string source, IEnumerable <Connection> sourceConnections)
        {
            if (sourceConnections == null)
            {
                throw new ArgumentNullException(nameof(sourceConnections));
            }
            if (string.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException(nameof(source));
            }

            var existingConnections = _connectionSoureCache
                                      .Items
                                      .Where(ic => ic.Source.Equals(source))
                                      .Select(ic => (Connection)ic)
                                      .ToList();

            var connections       = sourceConnections.ToList();
            var removeConnections = existingConnections.Except(connections).Select(cn => (ImplicitConnection)cn).ToList();
            var addConnections    = connections.Except(existingConnections).ToList();

            _connectionSoureCache.Remove(removeConnections);
            _connectionSoureCache.AddOrUpdate(
                addConnections.Select(
                    cn => new ImplicitConnection(source, cn.Host, cn.AuthorisationKey, cn.DatabaseId, cn.CollectionId)));
        }
Example #11
0
        private ApplicationManager()
        {
            RootPaths = new ObservableCollection <string>();

            MatchedAppInfos   = new SourceList <MatchedApplication>();
            ApplicationModels = new ObservableCollection <ApplicationModel>();
            Menus             = new SourceCache <INotifyMenu, string>(x => x.Label);
            Menus.AddOrUpdate(new ConfigMenu());
            Menus.AddOrUpdate(new ExitM());

            ExternalPrograms = new SourceCache <IExternalProgram, string>(x => x.Label);
            ExternalPrograms.Connect()
            .OnItemAdded(x =>
            {
                if (File.Exists(x.File))
                {
                    try
                    {
                        x.IconImage = new Image
                        {
                            Source = FileToImageIconConverter.Icon(x.File)
                        };
                        Menus.AddOrUpdate(x);
                    }
                    catch
                    {
                    }
                }
            })
            .OnItemRemoved(x =>
            {
                Menus.Remove(x);
            })
            .Subscribe();
        }
        public void CanRemoveFromGroup()
        {
            var person = new Person("A", 10);

            _source.AddOrUpdate(person);
            _source.Remove(person);

            Assert.AreEqual(0, _results.Data.Count);
        }
Example #13
0
        public void Remove(SearchInfo searchResult)
        {
            if (searchResult is null)
            {
                throw new ArgumentNullException(nameof(searchResult));
            }

            _cache.Remove(searchResult);
        }
Example #14
0
        public void CanRemoveFromGroup()
        {
            var person = new Person("A", 10);

            _source.AddOrUpdate(person);
            _source.Remove(person);

            _results.Data.Count.Should().Be(0);
        }
Example #15
0
        private void AddSomethingNew()
        {
            Source.AddOrUpdate(new ProjectDto(1, 3, "3rd"));
            Source.AddOrUpdate(new ProjectDto(2, 4, "4th"));
            Source.AddOrUpdate(new ProjectDto(1, 5, "5th"));
            Source.AddOrUpdate(new ProjectDto(2, 6, "6th"));
            Source.AddOrUpdate(new ProjectDto(3, 7, "7th"));
            Source.AddOrUpdate(new ProjectDto(4, 8, "8th"));
            Source.AddOrUpdate(new ProjectDto(5, 9, "9th"));
            Source.AddOrUpdate(new ProjectDto(1, 1, "New Name!"));

            Source.AddOrUpdate(new QuotationDto(2, 5));
            Source.AddOrUpdate(new QuotationDto(1, 6));
            Source.AddOrUpdate(new QuotationDto(2, 7));

            var toRemove = MainItems.Where(i => !(i.Item is AddressDto)).ToList();

            toRemove.ForEach(i => Source.Remove(i.Item));
        }
Example #16
0
        public async Task Remove(long id)
        {
            if (id == default)
            {
                return;
            }

            _data.Remove(FlattenThisAndChildren(id));

            await SaveLocalStorage();
        }
Example #17
0
        public void OnItemRemovedCalled()
        {
            var called = false;
            var source = new SourceCache <Person, int>(x => x.Age);

            source.Connect().OnItemRemoved(_ => called = true).Subscribe();

            var person = new Person("A", 1);

            source.AddOrUpdate(person);
            source.Remove(person);
            Assert.True(called);
        }
Example #18
0
        public void RemoveProduceCorrectResult()
        {
            int sum = 0;

            var accumulator = _source.Connect().Sum(p => p.Age).Subscribe(x => sum = x);

            _source.AddOrUpdate(new Person("A", 10));
            _source.AddOrUpdate(new Person("B", 20));
            _source.AddOrUpdate(new Person("C", 30));

            _source.Remove("A");
            sum.Should().Be(50, "Accumulated value should be 50 after remove");
            accumulator.Dispose();
        }
Example #19
0
        public void RemoveProduceCorrectResult()
        {
            double avg = 0;

            var accumulator = _source.Connect().Avg(p => p.Age).Subscribe(x => avg = x);

            _source.AddOrUpdate(new Person("A", 10));
            _source.AddOrUpdate(new Person("B", 20));
            _source.AddOrUpdate(new Person("C", 30));

            _source.Remove("A");
            avg.Should().Be(25, "Average value should be 25 after remove");
            accumulator.Dispose();
        }
Example #20
0
        public void RemoveItems()
        {
            var result = 0;

            var accumulator = _source.Connect().Maximum(p => p.Age).Subscribe(x => result = x);

            _source.AddOrUpdate(new Person("A", 10));
            _source.AddOrUpdate(new Person("B", 20));
            _source.AddOrUpdate(new Person("C", 30));

            _source.Remove("C");
            result.Should().Be(20, "Max value should be 20 after remove");
            accumulator.Dispose();
        }
Example #21
0
        public void SetBuffer(string key, decimal?value)
        {
            if (value == null)
            {
                sourceCache.Remove(key);
            }
            else
            {
                var newBuffer = new BufferInfo();
                newBuffer.key   = key;
                newBuffer.value = value.Value;

                sourceCache.AddOrUpdate(newBuffer);
            }
        }
Example #22
0
        public void RemoveProduceCorrectResult()
        {
            var result = 0;

            var accumulator = _source.Connect()
                              .Minimum(p => p.Age)
                              .Subscribe(x => result = x);

            _source.AddOrUpdate(new Person("A", 10));
            _source.AddOrUpdate(new Person("B", 20));
            _source.AddOrUpdate(new Person("C", 30));

            _source.Remove("A");
            Assert.AreEqual(20, result, "Min value should be 20 after remove");
            accumulator.Dispose();
        }
Example #23
0
        public void RemovedItemWillNotCauseInvocation()
        {
            bool invoked = false;
            var  stream  = _source.Connect()
                           .MergeMany(o => o.Observable)
                           .Subscribe(o => { invoked = true; });

            var item = new ObjectWithObservable(1);

            _source.AddOrUpdate(item);
            _source.Remove(item);
            Assert.IsFalse(invoked, "Error. The operator should not have been invoked");

            item.InvokeObservable(true);
            Assert.IsFalse(invoked, "The observable should not have notified as it is no longer in  the stream");
            stream.Dispose();
        }
        public void RemovedItemWillNotCauseInvocation()
        {
            bool invoked = false;
            var  stream  = _source.Connect()
                           .MergeMany(o => o.Observable)
                           .Subscribe(o => { invoked = true; });

            var item = new ObjectWithObservable(1);

            _source.AddOrUpdate(item);
            _source.Remove(item);
            invoked.Should().BeFalse();

            item.InvokeObservable(true);
            invoked.Should().BeFalse();
            stream.Dispose();
        }
Example #25
0
        public void Reload(SourceCache <NeuronDto, int> cache, NeuronDto neuronDto = null)
        {
            IEnumerable <NeuronDto> children = null;

            if (neuronDto == null || !cache.Items.Any(i => i.ParentId == neuronDto.Id))
            {
                children = NeuronService.CreateChildren(neuronDto);
            }
            else
            {
                children = cache.Items.Where(i => i.ParentId == neuronDto.Id);
                cache.Remove(children);
                // TODO: set children to data from cortex graph
            }

            cache.AddOrUpdate(children);
        }
Example #26
0
        public async void DeleteUserButton_Click(SteamUser user)
        {
            var result = await MessageBox.ShowAsync(AppResources.UserChange_DeleteUserTip, button : MessageBox.Button.OKCancel);

            if (result == MessageBox.Result.OK)
            {
                result = await MessageBox.ShowAsync(AppResources.UserChange_DeleteUserDataTip, button : MessageBox.Button.OKCancel);

                if (result == MessageBox.Result.OK)
                {
                    steamService.DeleteLocalUserData(user, true);
                }
                else
                {
                    steamService.DeleteLocalUserData(user, false);
                }
                _SteamUsersSourceList.Remove(user);
            }
        }
Example #27
0
        public void RemoveChild()
        {
            var people = Enumerable.Range(1, 10).Select(
                i =>
            {
                string parent = "Person" + CalculateParent(i, 10);
                return(new Person("Person" + i, i, parentName: parent));
            }).ToArray();

            _people.AddOrUpdate(people);

            var last = people.Last();

            _people.Remove(last);

            var updatedPeople = people.Where(p => p.Name != last.Name).ToArray();

            AssertDataIsCorrectlyFormed(updatedPeople, last.Name);
        }
Example #28
0
        public void RemoveSymbol(SymbolObservationViewModel symbol)
        {
            symbolCache.Remove(symbol.Name);

            var seriesToRemove = PlotModel.Series.FirstOrDefault(series => series.Title == symbol.Name);

            if (seriesToRemove != null)
            {
                PlotModel.Series.Remove(seriesToRemove);
            }

            var axisToRemove = PlotModel.Axes.FirstOrDefault(axis => axis.Key == symbol.Name);

            if (axisToRemove != null)
            {
                PlotModel.Axes.Remove(axisToRemove);
            }

            RescaleAxisDistances();
        }
Example #29
0
        public static async Task RemoveDatabaseRoutine(IDialogCoordinator dialogCoordinator, object dialogContext, SourceCache <Database, string> databasesSourceCache, Database database)
        {
            var serviceOperationHelper = new ServiceOperationHelper(typeof(Database), Plurality.Single, ServiceOperation.Remove, "databases source cache", database.Name);
            var dialogSettings         = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Yes",
                NegativeButtonText    = "No",
                DefaultButtonFocus    = MessageDialogResult.Negative,
            };
            var dialogResult = await dialogCoordinator.ShowMessageAsync(dialogContext, "Remove Database", $"Are you sure that you would like to remove database \"{database.Name}\"?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings);

            if (dialogResult == MessageDialogResult.Affirmative)
            {
                serviceOperationHelper.ServiceOperationResult = await SettingsService.RemoveDatabaseByName(database.Name, true);

                if (serviceOperationHelper.ServiceOperationResult.OperationSuceeded)
                {
                    await Task.Run(() =>
                    {
                        try
                        {
                            serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting);

                            databasesSourceCache.Remove(database);

                            serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded);
                        }
                        catch (Exception ex)
                        {
                            serviceOperationHelper.LogServiceOperation(ex.Message);
                        }
                    });
                }
            }

            if (serviceOperationHelper.ServiceOperationResult.OperationFailed)
            {
                await serviceOperationHelper.ServiceOperationResult.ShowUserErrorMessage(dialogCoordinator, dialogContext);
            }
        }
Example #30
0
        public static async Task DeleteLogViewRoutine(IDialogCoordinator dialogCoordinator, object dialogContext, SourceCache <LogView, string> logViewsSourceCache, LogView logView)
        {
            var serviceOperationHelper = new ServiceOperationHelper(typeof(LogView), Plurality.Single, ServiceOperation.Remove, "log views source cache", logView.Name);
            var dialogSettings         = new MetroDialogSettings()
            {
                AffirmativeButtonText = "Yes",
                NegativeButtonText    = "No",
                DefaultButtonFocus    = MessageDialogResult.Negative,
            };

            var dialogResult = await dialogCoordinator.ShowMessageAsync(dialogContext, "Permanently Delete Log View", $"Are you sure that you would like to permanently delete log view \"{logView.Name}\"?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings);

            if (dialogResult == MessageDialogResult.Affirmative)
            {
                await Task.Run(() =>
                {
                    try
                    {
                        serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Attempting);
                        logViewsSourceCache.Remove(logView);
                        serviceOperationHelper.LogServiceOperation(ServiceOperationStatus.Succeeded);
                    }
                    catch (Exception ex)
                    {
                        serviceOperationHelper.LogServiceOperation(ex.Message);
                    }
                });

                if (serviceOperationHelper.ServiceOperationResult.OperationSuceeded)
                {
                    serviceOperationHelper.ServiceOperationResult = await SettingsService.RemoveLogViewByName(logView.Name, true);
                }
            }

            if (serviceOperationHelper.ServiceOperationResult.OperationFailed)
            {
                await serviceOperationHelper.ServiceOperationResult.ShowUserErrorMessage(dialogCoordinator, dialogContext);
            }
        }
Example #31
0
        public void DuplicateKeysRefreshAfterRemove()
        {
            var source1 = new SourceCache <Person, string>(p => p.Name);
            var source2 = new SourceCache <Person, string>(p => p.Name);

            var person = new Person("Person2", 12);

            var results = source1.Connect().Merge(source2.Connect()).DistinctValues(p => p.Age).AsAggregator();

            source1.AddOrUpdate(person);
            source2.AddOrUpdate(person);
            source2.Remove(person);
            source1.Refresh(person); // would previously throw KeyNotFoundException here

            results.Messages.Should().HaveCount(1);
            results.Data.Items.ShouldAllBeEquivalentTo(new[] { 12 });

            source1.Remove(person);

            results.Messages.Should().HaveCount(2);
            results.Data.Items.Should().BeEmpty();
        }