Exemplo n.º 1
0
        public NotificationsPaneViewModel(INotificationApplicationService neuronApplicationService = null, INeuronQueryClient neuronGraphQueryClient = null, IExtendedSelectionService selectionService = null, IStatusService statusService = null, IDialogService dialogService = null)
        {
            this.notificationApplicationService = neuronApplicationService ?? Locator.Current.GetService <INotificationApplicationService>();
            this.neuronGraphQueryClient         = neuronGraphQueryClient ?? Locator.Current.GetService <INeuronQueryClient>();
            this.selectionService = selectionService ?? Locator.Current.GetService <IExtendedSelectionService>(SelectionContract.Select.ToString());
            this.statusService    = statusService ?? Locator.Current.GetService <IStatusService>();
            this.dialogService    = dialogService ?? Locator.Current.GetService <IDialogService>();

            var selector = this.WhenPropertyChanged(p => p.SelectedNotification)
                           .Where(p => p != null)
                           .Subscribe(x =>
            {
                this.selectionService.SetSelectedComponents(new object[] { x.Value });
                if (x.Value != null && Array.IndexOf(new string[] { EventTypeNames.NeuronCreated.ToString(), EventTypeNames.NeuronTagChanged.ToString() }, x.Value.Type) > -1)
                {
                    this.Target = NotificationsPaneViewModel.ConvertNotificationViewModelToEditorNeuron(x.Value);
                }
            });

            this.statusService.WhenPropertyChanged(s => s.Message)
            .Subscribe(s => this.StatusMessage = s.Sender.Message);

            this.LoadCommand = ReactiveCommand.Create(async() => await this.OnLoadClicked());
            var canMore = this.WhenAnyValue <NotificationsPaneViewModel, bool, NotificationLog>(x => x.NotificationLog, nl => nl != null && nl.PreviousNotificationLogId != null);

            this.MoreCommand      = ReactiveCommand.Create(async() => await this.OnMoreClicked(), canMore);
            this.SetRegionCommand = ReactiveCommand.Create <object>(async(parameter) => await this.OnSetRegionIdClicked(parameter));

            this.Loading        = false;
            this.IconSourcePath = @"pack://application:,,,/d23-wpf;component/images/notification.ico";
        }
Exemplo n.º 2
0
        public static async Task <IEnumerable <NotificationData> > UpdateCacheGetNotifications(NotificationLog notificationLog, INeuronQueryClient neuronGraphQueryClient, string avatarUrl, IDictionary <string, Neuron> cache)
        {
            var ids = new List <string>();
            var ns  = notificationLog.NotificationList.ToList();

            ns.ForEach(n =>
            {
                ids.Add(n.AuthorId);
                ids.Add(n.Id);
                dynamic d = JsonConvert.DeserializeObject(n.Data);
                // NeuronCreated
                if (n.TypeName.Contains(EventTypeNames.NeuronCreated.ToString()))
                {
                    // RegionId
                    if (d.RegionId != null)
                    {
                        ids.Add(d.RegionId.ToString());
                    }
                }
                // TerminalCreated
                else if (n.TypeName.Contains(EventTypeNames.TerminalCreated.ToString()))
                {
                    // PresynapticNeuronId
                    ids.Add(d.PresynapticNeuronId.ToString());
                    // PostsynapticNeuronId
                    ids.Add(d.PostsynapticNeuronId.ToString());
                }
            }
                       );
            ids.RemoveAll(i => cache.ContainsKey(i));
            ids = new List <string>(ids.Distinct());

            if (ids.Count() > 0)
            {
                (await neuronGraphQueryClient.GetNeurons(avatarUrl, neuronQuery: new NeuronQuery()
                {
                    Id = ids.ToArray()
                }))
                .ToList()
                .ForEach(n => cache.Add(n.Id, n));
            }

            return(notificationLog.NotificationList.ToArray().Select(n => Common.Helper.CreateNotificationData(n, cache)));
        }
Exemplo n.º 3
0
 public NeuronQueryService(INeuronQueryClient neuronQueryClient = null)
 {
     this.neuronQueryClient = neuronQueryClient ?? Locator.Current.GetService<INeuronQueryClient>();
 }