public EarningEventKey(IPaymentsEvent earningEvent)
 {
     if (earningEvent == null)
     {
         throw new ArgumentNullException(nameof(earningEvent));
     }
     JobId            = earningEvent.JobId;
     Ukprn            = earningEvent.Ukprn;
     CollectionPeriod = earningEvent.CollectionPeriod;
     Learner          = new Learner
     {
         Uln             = earningEvent.Learner.Uln,
         ReferenceNumber = earningEvent.Learner.ReferenceNumber
     };
     LearningAim = new LearningAim
     {
         StartDate       = earningEvent.LearningAim.StartDate,
         FrameworkCode   = earningEvent.LearningAim.FrameworkCode,
         FundingLineType = earningEvent.LearningAim.FundingLineType,
         Reference       = earningEvent.LearningAim.Reference,
         SequenceNumber  = earningEvent.LearningAim.SequenceNumber,
         PathwayCode     = earningEvent.LearningAim.PathwayCode,
         StandardCode    = earningEvent.LearningAim.StandardCode,
         ProgrammeType   = earningEvent.LearningAim.ProgrammeType
     };
     EventType = earningEvent.GetType().Name;
 }
        private List <FunctionalSkillDataLockEvent> CreateDataLockEvents(IPaymentsEvent earningEvent, DataLockErrorCode dataLockErrorCode)
        {
            var dataLockEvents    = new List <FunctionalSkillDataLockEvent>();
            var nonPayableEarning = mapper.Map <FunctionalSkillEarningFailedDataLockMatching>(earningEvent);

            foreach (var onProgrammeEarning in nonPayableEarning.Earnings)
            {
                foreach (var period in onProgrammeEarning.Periods)
                {
                    period.DataLockFailures = new List <DataLockFailure>
                    {
                        new DataLockFailure
                        {
                            DataLockError = dataLockErrorCode
                        }
                    };
                }
            }

            if (nonPayableEarning.Earnings.Any())
            {
                dataLockEvents.Add(nonPayableEarning);
            }

            return(dataLockEvents);
        }
        public async Task <bool> IsDuplicate(IPaymentsEvent earningEvent, CancellationToken cancellationToken)
        {
            logger.LogDebug($"Checking if earning event of type {earningEvent.GetType().Name} with guid: {earningEvent.EventId} has already been received.");
            var earningEventKey = new EarningEventKey(earningEvent);

            logger.LogDebug($"Earning event key: {earningEventKey.LogSafeKey}");
            if (await cache.Contains(earningEventKey.Key, cancellationToken).ConfigureAwait(false))
            {
                logger.LogWarning($"Key: {earningEventKey.LogSafeKey} found in the cache and is probably a duplicate.");
                return(true);
            }
            logger.LogDebug($"New earnings event. Event key: {earningEventKey.LogSafeKey}, event id: {earningEvent.EventId}");
            await cache.Add(earningEventKey.Key, earningEventKey, cancellationToken);

            logger.LogInfo($"Added new earnings event to cache. Key: {earningEventKey.LogSafeKey}");
            return(false);
        }
Ejemplo n.º 4
0
 public static string ToDebug(this IPaymentsEvent paymentsEvent)
 {
     return($"Type: {paymentsEvent.GetType().Name}, Id: {paymentsEvent.EventId}, Event Time: {paymentsEvent.EventTime:G}, Ukrpn: {paymentsEvent.Ukprn}, Job Id: {paymentsEvent.JobId}, Collection Period: {paymentsEvent.CollectionPeriod.AcademicYear}-{paymentsEvent.CollectionPeriod.Period}, Learner: {paymentsEvent.Learner.ReferenceNumber}");
 }
        public static void TrackDuration(this ITelemetry telemetry, string eventName, TimeSpan duration, IPaymentsEvent paymentEvent, long?employerAccountId = null)
        {
            var props = new Dictionary <string, string>
            {
                { TelemetryKeys.LearnerRef, paymentEvent.Learner?.ReferenceNumber },
                { TelemetryKeys.CollectionPeriod, paymentEvent.CollectionPeriod.Period.ToString() },
                { TelemetryKeys.AcademicYear, paymentEvent.CollectionPeriod.AcademicYear.ToString() },
                { "JobId", paymentEvent.JobId.ToString() },
                { TelemetryKeys.Ukprn, paymentEvent.Ukprn.ToString() },
            };

            if (employerAccountId.HasValue)
            {
                props.Add("Employer", employerAccountId.ToString());
            }

            telemetry.TrackEvent(eventName,
                                 props,
                                 new Dictionary <string, double>
            {
                { TelemetryKeys.Duration, duration.TotalMilliseconds }
            });
        }
 public static void TrackDuration(this ITelemetry telemetry, string eventName, Stopwatch stopwatch, IPaymentsEvent paymentEvent, long?employerAccountId = null)
 {
     stopwatch.Stop();
     TrackDuration(telemetry, eventName, stopwatch.Elapsed, paymentEvent, employerAccountId);
 }
        public static void TrackDuration(this ITelemetry telemetry, string eventName, TimeSpan duration, IPaymentsEvent paymentEvent, long?employerAccountId = null)
        {
            var props = new Dictionary <string, string>
            {
                { TelemetryKeys.LearnerRef, paymentEvent.Learner?.ReferenceNumber },
                { TelemetryKeys.CollectionPeriod, paymentEvent.CollectionPeriod.Period.ToString() },
                { TelemetryKeys.AcademicYear, paymentEvent.CollectionPeriod.AcademicYear.ToString() },
                { "JobId", paymentEvent.JobId.ToString() },
            };

            TrackDuration(telemetry, eventName, duration, props, employerAccountId, null);
        }