Пример #1
0
        // DEL: create dummy data
        private static IEnumerable <NeuronDto> CreateChildren(NeuronDto parentDto = null)
        {
            var random = new Random();

            return(Enumerable.Range(1, random.Next(1, 10))
                   .Select(i =>
            {
                return NeuronService.CreateNeuron($"Neuron {i}", i % 2 == 0 ? ChildType.Postsynaptic : ChildType.Presynaptic, parentDto);
            }));
        }
Пример #2
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);
        }
Пример #3
0
        public NeuronGraphPaneViewModel(INeuronService neuronService = null)
        {
            this.neuronService = neuronService ?? Locator.Current.GetService <INeuronService>();

            bool DefaultPredicate(Node <NeuronDto, int> node) => node.IsRoot;

            var cache = new SourceCache <NeuronDto, int>(x => x.Id);

            this.AddCommand = ReactiveCommand.Create(() =>
                                                     this.neuronService.Add(cache, NeuronService.CreateNeuron("Root Neuron", ChildType.NotSet)));
            this.ReloadCommand = ReactiveCommand.Create(() => {
                cache.Clear();
                this.neuronService.Reload(cache);
            });
            this.cleanUp = cache.AsObservableCache().Connect()
                           .TransformToTree(child => child.ParentId, Observable.Return((Func <Node <NeuronDto, int>, bool>)DefaultPredicate))
                           .Transform(e =>
                                      e.Item.Type == ChildType.Postsynaptic ?
                                      (NeuronViewModelBase)(new PostsynapticViewModel(e.Item.Data, e, cache)) :
                                      (NeuronViewModelBase)(new PresynapticViewModel(e.Item.Data, e, cache)))
                           .Bind(out this.children)
                           .DisposeMany()
                           .Subscribe();
        }