예제 #1
0
 void PopulateNamedAsyncPolicies()
 {
     _namedAsyncPolicyDefiners.ForEach(_ =>
     {
         ThrowIfMultiplePolicyForNameFound(_.Name);
         _namedAsyncPolicies[_.Name] = new NamedAsyncPolicy(_.Name, _.Define());
     });
 }
예제 #2
0
        void PopulateTypedAsyncPolicies()
        {
            _typedAsyncPolicyDefiners.ForEach(_ =>
            {
                ThrowIfMultiplePolicyForTypeFound(_.Type);
                var policyFor   = typeof(AsyncPolicyFor <>).MakeGenericType(_.Type);
                var constructor = policyFor.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[] { typeof(Polly.IAsyncPolicy) }, new ParameterModifier[] { new ParameterModifier(1) });

                _typedAsyncPolicies[_.Type] = constructor.Invoke(new[] { _.Define() }) as IAsyncPolicy;
            });
        }
 /// <inheritdoc/>
 public void Perform()
 {
     _buildMessages.Information("Perform post build tasks");
     _buildMessages.Indent();
     _runners.ForEach(_ =>
     {
         _buildMessages.Information($"{_.Message} (Post Task: '{_.GetType().AssemblyQualifiedName}')");
         _buildMessages.Indent();
         _.Perform();
         _buildMessages.Unindent();
     });
     _buildMessages.Unindent();
 }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of <see cref="Serializer"/>
        /// </summary>
        /// <param name="converterProviders">Instances of <see cref="ICanProvideConverters"/></param>
        public Serializer(IInstancesOf <ICanProvideConverters> converterProviders)
        {
            _converterProviders        = converterProviders;
            _cacheAutoTypeName         = new ConcurrentDictionary <ISerializationOptions, JsonSerializer>();
            _cacheNoneTypeName         = new ConcurrentDictionary <ISerializationOptions, JsonSerializer>();
            _cacheAutoTypeNameReadOnly = new ConcurrentDictionary <ISerializationOptions, JsonSerializer>();
            _cacheNoneTypeNameReadOnly = new ConcurrentDictionary <ISerializationOptions, JsonSerializer>();

            _converters.Add(new ExceptionConverter());
            _converters.Add(new CamelCaseToPascalCaseExpandoObjectConverter());
            _converterProviders.ForEach(provider => provider.Provide().ForEach(_converters.Add));

            SetSerializerForConvertersRequiringIt(_converters);
        }
예제 #5
0
        static void RegisterClassMapsIfNotRegistered(IInstancesOf <BsonClassMap> classMaps)
        {
            if (registered)
            {
                return;
            }

            classMaps.ForEach(c => {
                if (!BsonClassMap.IsClassMapRegistered(c.ClassType))
                {
                    BsonClassMap.RegisterClassMap(c);
                }
            });
            registered = true;
        }
예제 #6
0
        public void Process(CaseRegistered @event)
        {
            var caseItem = new Case(@event.CaseId)
            {
                CaseReportId      = @event.CaseReportId,
                DataCollectorId   = @event.DataCollectorId,
                OriginPhoneNumber = @event.OriginPhoneNumber,
                AgeGroup          = (AgeGroup)@event.AgeGroup,
                Sex              = (Sex)@event.Sex,
                HealthRiskId     = @event.HealthRiskId,
                HealthRiskNumber = @event.HealthRiskNumber,
                Latitude         = @event.Latitude,
                Longitude        = @event.Longitude,
                Timestamp        = @event.Timestamp
            };

            _repositoryForCase.Insert(caseItem);
            _services.ForEach(s => s.Changed(caseItem));
        }
예제 #7
0
        CommittedEventStream Commit(UncommittedEventStream uncommittedEvents, CommitSequenceNumber commitSequenceNumber)
        {
            lock (lockObject)
            {
                ThrowIfDuplicate(uncommittedEvents.Id);
                ThrowIfConcurrencyConflict(uncommittedEvents.Source);

                var commit = new CommittedEventStream(commitSequenceNumber, uncommittedEvents.Source, uncommittedEvents.Id, uncommittedEvents.CorrelationId, uncommittedEvents.Timestamp, uncommittedEvents.Events);
                _commits.Add(commit);
                _duplicates.Add(commit.Id);
                _versions.AddOrUpdate(commit.Source.Key, commit.Source, (id, ver) => commit.Source);

                var commitsAsJson = _serializer.ToJson(_commits, SerializationOptions.CamelCase);
                _jsRuntime.Invoke($"{_globalObject}.save", commitsAsJson);

                _commitListeners.ForEach(_ => _.Handle(commit));

                return(commit);
            }
        }
 void Discover()
 {
     _processors.ForEach(_ =>
     {
         var methods          = _.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
         var processorMethods = methods.Where(method => method.GetCustomAttributes().Any(attribute => attribute is DataPointProcessorAttribute));
         if (!processorMethods.Any())
         {
             _logger.Warning($"DataPoint processor of type '{_.GetType().AssemblyQualifiedName}' does not seem to have any methods adorned with [DataPointProcessor] - this means it does not have any processors");
         }
         else
         {
             processorMethods.ForEach(method =>
             {
                 var processor = new DataPointProcessor(_, method);
                 _dataProcessors[processor.Id] = processor;
             });
         }
     });
 }
예제 #9
0
        /// <inheritdoc />
        public void GatherEventProcessors()
        {
            var eventProcessorsByArtifact = new Dictionary <Artifact, List <IEventProcessor> >();

            _systemsThatKnowsAboutEventProcessors.ForEach(a => a.ForEach(e =>
            {
                List <IEventProcessor> eventProcessors;
                if (eventProcessorsByArtifact.ContainsKey(e.Event))
                {
                    eventProcessors = eventProcessorsByArtifact[e.Event];
                }
                else
                {
                    eventProcessors = new List <IEventProcessor>();
                    eventProcessorsByArtifact[e.Event] = eventProcessors;
                }
                eventProcessors.Add(e);
            }));

            _eventProcessorsByResourceIdentifier = eventProcessorsByArtifact;
        }
예제 #10
0
        public void Process(TextMessage message)
        {
            var commandContext = _commandContextManager.EstablishForCommand(
                new CommandRequest(
                    TransactionCorrelationId.New(),
                    null,
                    new Dictionary <string, object>())
                );

            _processors.ForEach(processor =>
            {
                try
                {  
                  processor.Process(message); }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Problems processing message");
                }
            });

            commandContext.Commit();
        }
예제 #11
0
        /// <inheritdoc/>
        public void Start()
        {
            _connectors.ForEach(_ =>
            {
                Task.Run(() =>
                {
                    _.DataReceived += (tag, data, timestamp) => DataReceived(_, tag, data, timestamp);

                    var policy = Policy
                                 .Handle <Exception>()
                                 .WaitAndRetryForever(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                                                      (exception, timeSpan, context) =>
                    {
                        _logger.Error(exception, $"Connector '{_.GetType()}' - with name '{_.Name}' threw an exception during connect - retrying");
                    });

                    policy.Execute(() =>
                    {
                        _.Connect();
                    });
                });
            });
        }
예제 #12
0
 /// <inheritdoc/>
 public void Populate(ITenant tenant, dynamic details)
 {
     _populators.ForEach(p => p.Populate(tenant, details));
 }
예제 #13
0
 public void Process(TextMessage message)
 {
     _processors.ForEach(processor => processor.Process(message));
 }
 /// <summary>
 /// Initializes a new instance of <see cref="EventStoragePathTemplates"/>
 /// </summary>
 /// <param name="providers"><see cref="ICanProvideEventStoragePathTemplates">Providers</see> that can provide string versions of the template</param>
 public EventStoragePathTemplates(IInstancesOf <ICanProvideEventStoragePathTemplates> providers)
 {
     providers.ForEach(_ => _.Provide().ForEach(Add));
 }
예제 #15
0
 void PopulateMappingTargetsByType()
 {
     _mappingTargets.ForEach(mt => _mappingTargetsByType[mt.TargetType] = mt);
 }
예제 #16
0
 void PopulateMapsBasedOnKeys()
 {
     _maps.ForEach(map => _mapsByKey[GetKeyFor(map.Source, map.Target)] = map);
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KnownClients"/> class.
 /// </summary>
 /// <param name="clientProviders"><see cref="IInstancesOf{T}"/> <see cref="IKnowAboutClients"/>.</param>
 public KnownClients(IInstancesOf <IKnowAboutClients> clientProviders)
 {
     clientProviders.ForEach(provider => provider.Clients.ForEach(client => _clientsByType.Add(client.Type, client)));
 }