public StandardNotificationLogClient(ISettingsService settingsService, IRepository <Settings> settingsRepository, INeuronRepository neuronRepository, ITerminalRepository terminalRepository)
 {
     this.settingsService    = settingsService;
     this.neuronRepository   = neuronRepository;
     this.terminalRepository = terminalRepository;
     this.settingsRepository = settingsRepository;
     this.polling            = false;
 }
Exemplo n.º 2
0
 public NeuronController(
     ILogger <NeuronController> logger,
     INeuronRepository neuronRepository,
     ISetReminderUseCase setReminderUseCase)
 {
     this.logger             = logger ?? throw new ArgumentNullException(nameof(logger));
     this.neuronRepository   = neuronRepository ?? throw new ArgumentNullException(nameof(neuronRepository));
     this.setReminderUseCase = setReminderUseCase ?? throw new ArgumentNullException(nameof(setReminderUseCase));
 }
Exemplo n.º 3
0
        public CortexGraphViewModel(NeuronCollection neurons, INotificationLogClient notificationLogClient, IRepository <works.ei8.Cortex.Graph.Domain.Model.Neuron> neuronRepository, ISpikeTargetListService spikeTargetListService, IResultMarkerService resultMarkerService)
        {
            this.AvatarUri              = Properties.Settings.Default.AvatarUri;
            this.neurons                = neurons;
            this.notificationLogClient  = notificationLogClient;
            this.neuronRepository       = (INeuronRepository)neuronRepository;
            this.spikeTargetListService = spikeTargetListService;
            this.resultMarkerService    = resultMarkerService;

            this.ReloadCommand = ReactiveCommand.Create(this.Reload, this.WhenAnyValue(vm => vm.AvatarUri).Select(s => !string.IsNullOrEmpty(s)));
            this.RenderCommand = ReactiveCommand.Create(this.Render, this.WhenAnyValue(vm => vm.AvatarUri).Select(s => !string.IsNullOrEmpty(s)));
        }
Exemplo n.º 4
0
        public async Task <bool> Process(INeuronRepository neuronRepository, ITerminalRepository terminalRepository, string eventName, string data, string authorId)
        {
            bool result = false;

            JObject        jd = JsonHelper.JObjectParse(data);
            DomainNeuron   n  = null;
            DomainTerminal t  = null;
            var            changeTimestamp = string.Empty;

            switch (eventName)
            {
            case "NeuronCreated":
                changeTimestamp = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Neuron.NeuronCreated.Timestamp));
                n = new DomainNeuron()
                {
                    Id                = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Neuron.NeuronCreated.Id)),
                    Version           = JsonHelper.GetRequiredValue <int>(jd, nameof(EventDataFields.Neuron.NeuronCreated.Version)),
                    CreationTimestamp = changeTimestamp,
                    CreationAuthorId  = authorId,
                    Active            = true
                };
                await neuronRepository.Save(n);

                result = true;
                break;

            case "TagChanged":
                n = await neuronRepository.Get(
                    Guid.Parse(JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Tag.TagChanged.Id)))
                    );

                n.Tag     = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Tag.TagChanged.Tag));
                n.Version = JsonHelper.GetRequiredValue <int>(jd, nameof(EventDataFields.Tag.TagChanged.Version));
                n.LastModificationTimestamp = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Tag.TagChanged.Timestamp));
                n.LastModificationAuthorId  = authorId;
                await neuronRepository.Save(n);

                result = true;
                break;

            case "AggregateChanged":
                n = await neuronRepository.Get(
                    Guid.Parse(JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Aggregate.AggregateChanged.Id)))
                    );

                n.RegionId = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Aggregate.AggregateChanged.Aggregate));
                n.Version  = JsonHelper.GetRequiredValue <int>(jd, nameof(EventDataFields.Aggregate.AggregateChanged.Version));
                n.LastModificationTimestamp = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Aggregate.AggregateChanged.Timestamp));
                n.LastModificationAuthorId  = authorId;
                await neuronRepository.Save(n);

                result = true;
                break;

            case "NeuronDeactivated":
                n = await neuronRepository.Get(
                    Guid.Parse(JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Neuron.NeuronDeactivated.Id)))
                    );

                n.Version = JsonHelper.GetRequiredValue <int>(jd, nameof(EventDataFields.Neuron.NeuronDeactivated.Version));
                n.LastModificationTimestamp = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Neuron.NeuronDeactivated.Timestamp));
                n.LastModificationAuthorId  = authorId;
                n.Active = false;
                await neuronRepository.Save(n);

                result = true;
                break;

            case "TerminalCreated":
                changeTimestamp = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Terminal.TerminalCreated.Timestamp));

                t = new DomainTerminal(
                    JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Terminal.TerminalCreated.Id)),
                    JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Terminal.TerminalCreated.PresynapticNeuronId)),
                    JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Terminal.TerminalCreated.PostsynapticNeuronId)),
                    (NeurotransmitterEffect)Enum.Parse(typeof(NeurotransmitterEffect), JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Terminal.TerminalCreated.Effect))),
                    JsonHelper.GetRequiredValue <float>(jd, nameof(EventDataFields.Terminal.TerminalCreated.Strength))
                    )
                {
                    Version           = JsonHelper.GetRequiredValue <int>(jd, nameof(EventDataFields.Terminal.TerminalCreated.Version)),
                    CreationTimestamp = changeTimestamp,
                    CreationAuthorId  = authorId,
                    Active            = true
                };
                await terminalRepository.Save(t);

                n = await neuronRepository.Get(Guid.Parse(t.PresynapticNeuronIdCore));

                n.UnifiedLastModificationTimestamp = changeTimestamp;
                n.UnifiedLastModificationAuthorId  = authorId;
                await neuronRepository.Save(n);

                result = true;
                break;

            case "TerminalDeactivated":
                changeTimestamp = JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Terminal.TerminalDeactivated.Timestamp));

                t = await terminalRepository.Get(
                    Guid.Parse(JsonHelper.GetRequiredValue <string>(jd, nameof(EventDataFields.Terminal.TerminalDeactivated.Id)))
                    );

                t.Version = JsonHelper.GetRequiredValue <int>(jd, nameof(EventDataFields.Terminal.TerminalDeactivated.Version));
                t.LastModificationTimestamp = changeTimestamp;
                t.LastModificationAuthorId  = authorId;
                t.Active = false;
                await terminalRepository.Save(t);

                n = await neuronRepository.Get(Guid.Parse(t.PresynapticNeuronIdCore));

                n.UnifiedLastModificationTimestamp = changeTimestamp;
                n.UnifiedLastModificationAuthorId  = authorId;
                await neuronRepository.Save(n);

                result = true;
                break;
            }

            return(result);
        }
Exemplo n.º 5
0
 public ReminderController(ILogger <ReminderController> logger, INeuronRepository neuronRepository)
 {
     this.logger           = logger;
     this.neuronRepository = neuronRepository;
 }
Exemplo n.º 6
0
 public GroupController(ILogger <GroupController> logger, INeuronRepository neuronRepository)
 {
     this.logger           = logger;
     this.neuronRepository = neuronRepository;
 }
Exemplo n.º 7
0
 public SetReminderUseCase(INeuronRepository neuronRepository, INotificationScheduler scheduler)
 {
     this.neuronRepository = neuronRepository ?? throw new ArgumentNullException(nameof(neuronRepository));
     this.scheduler        = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
 }
        private async static Task UpdateGraph(string notificationLogBaseUrl, string position, INeuronRepository neuronRepository, ITerminalRepository terminalRepository, IRepository <Settings> settingsRepository)
        {
            AssertionConcern.AssertStateTrue(long.TryParse(position, out long lastPosition), $"Specified position value of '{position}' is not a valid integer (long).");
            AssertionConcern.AssertMinimum(lastPosition, 0, nameof(position));

            var eventSourcingUrl   = notificationLogBaseUrl + "/";
            var notificationClient = new HttpNotificationClient();
            // get current log
            var currentNotificationLog = await notificationClient.GetNotificationLog(eventSourcingUrl, string.Empty);

            NotificationLog processingEventInfoLog = null;

            if (lastPosition == StandardNotificationLogClient.StartPosition)
            {
                // get first log from current
                processingEventInfoLog = await notificationClient.GetNotificationLog(eventSourcingUrl, currentNotificationLog.FirstNotificationLogId);
            }
            else
            {
                processingEventInfoLog = currentNotificationLog;
                while (lastPosition < processingEventInfoLog.DecodedNotificationLogId.Low)
                {
                    processingEventInfoLog = await notificationClient.GetNotificationLog(eventSourcingUrl, processingEventInfoLog.PreviousNotificationLogId);
                }
            }

            // while processing logid is not equal to newly retrieved currenteventinfolog
            while (processingEventInfoLog.DecodedNotificationLogId.Low <= currentNotificationLog.DecodedNotificationLogId.Low)
            {
                foreach (Notification e in processingEventInfoLog.NotificationList)
                {
                    if (e.SequenceId > lastPosition)
                    {
                        var eventName = e.GetEventName();

                        StandardNotificationLogClient.logger.Info($"Processing event '{eventName}' with Sequence Id-{e.SequenceId.ToString()} for Neuron '{e.Id}");

                        if (await new EventDataProcessor().Process(neuronRepository, terminalRepository, eventName, e.Data, e.AuthorId))
                        {
                            // update current position
                            lastPosition = e.SequenceId;

                            if (!processingEventInfoLog.HasNextNotificationLog && processingEventInfoLog.NotificationList.Last() == e)
                            {
                                await settingsRepository.Save(
                                    new Settings()
                                {
                                    Id = Guid.Empty.ToString(), LastPosition = lastPosition.ToString()
                                }
                                    );
                            }
                        }
                        else
                        {
                            StandardNotificationLogClient.logger.Warn($"Processing failed.");
                        }
                    }
                }

                if (processingEventInfoLog.HasNextNotificationLog)
                {
                    processingEventInfoLog = await notificationClient.GetNotificationLog(eventSourcingUrl, processingEventInfoLog.NextNotificationLogId);
                }
                else
                {
                    break;
                }
            }
        }