Exemplo n.º 1
0
        public HeaderRecordValidationResult ValidateHeaderRecord(HeaderRecordValidationRequest request)
        {
            if (Logger.IsInfoEnabled)
            {
                Logger.Info("Validating Schedule Header Record.");
            }

            if (request?.RecordToCheck == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var headerRecord = request.RecordToCheck;

            var response = new HeaderRecordValidationResult();

            using (var unitOfWork = _unitOfWorkFactory.Create())
            {
                var previousUpdate = unitOfWork.HeaderRecords.GetRecentUpdates().FirstOrDefault();

                if (previousUpdate != null)
                {
                    if (headerRecord.DateOfExtract <= previousUpdate.DateOfExtract)
                    {
                        throw new InvalidOperationException(
                                  $"The schedule file is out of order. Previous update date: {previousUpdate.DateOfExtract}. Attempted update date: {headerRecord.DateOfExtract}");
                    }

                    if (previousUpdate.ExtractUpdateType != ExtractUpdateType.U)
                    {
                        return(response);
                    }

                    if (previousUpdate.CurrentFileRef != headerRecord.LastFileRef)
                    {
                        throw new InvalidOperationException($"The schedule file is out of order. Last file reference: {previousUpdate.CurrentFileRef}. Expected Last file reference: {headerRecord.LastFileRef}");
                    }
                }
            }

            if (Logger.IsInfoEnabled)
            {
                Logger.Info("Finished validating Schedule Header Record. Header is valid.");
            }

            response.IsValid = true;

            return(response);
        }
Exemplo n.º 2
0
        public void StoreRecord(IScheduleRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            using (var unitOfWork = _unitOfWorkFactory.Create())
            {
                unitOfWork.AssociationRecords.InsertRecord(record as AssociationRecord);

                unitOfWork.Complete();
            }

            if (Logger.IsTraceEnabled)
            {
                Logger.Trace("Processed an Association Insert Record.");
            }
        }
Exemplo n.º 3
0
        public void StoreRecord(IScheduleRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            using (var unitOfWork = _unitOfWorkFactory.Create())
            {
                var recordToDelete = record as ScheduleRecord;

                unitOfWork.ScheduleRecords.DeleteRecord(recordToDelete);

                unitOfWork.Complete();
            }

            if (Logger.IsTraceEnabled)
            {
                Logger.Trace("Processed a Schedule Delete Record.");
            }
        }