/// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="appSettings">The app settings.</param>
        public SevisUnityContainer(AppSettings appSettings)
        {
            Contract.Requires(appSettings != null, "The app settings must not be null.");
            this.RegisterInstance <AppSettings>(appSettings);

            var connectionString = GetConnectionString(appSettings);

            this.RegisterType <ISevisBatchProcessingNotificationService, TextWriterSevisBatchProcessingNotificationService>();
            this.RegisterType <IBlobStorageSettings, BlobStorageSettings>();
            this.RegisterType <IFileStorageService, FileStorageService>();
            this.RegisterType <IEcaHttpMessageHandlerService, EcaHttpMessageHandlerService>();
            //Register ECA Context
            this.RegisterType <EcaContext>(new InjectionConstructor(connectionString));
            this.RegisterType <DbContext, EcaContext>(new InjectionConstructor(connectionString));
            this.RegisterType <ISevisApiResponseHandler, ZipArchiveSevisApiResponseHandler>(new InjectionFactory((c) =>
            {
                return(new ZipArchiveSevisApiResponseHandler(c.Resolve <ISevisBatchProcessingService>()));
            }));
            this.RegisterType <IParticipantPersonsSevisService>(new InjectionFactory((c) =>
            {
                var service = new ParticipantPersonsSevisService(
                    context: c.Resolve <EcaContext>(),
                    saveActions: null);
                return(service);
            }));
            this.RegisterType <IExchangeVisitorService>(new InjectionFactory((c) =>
            {
                var service = new ExchangeVisitorService(
                    context: c.Resolve <EcaContext>(),
                    appSettings: c.Resolve <AppSettings>(),
                    saveActions: null);
                return(service);
            }));

            this.RegisterType <IExchangeVisitorValidationService>(new InjectionFactory((c) =>
            {
                var context = c.Resolve <EcaContext>();
                var service = new ExchangeVisitorValidationService(
                    context: c.Resolve <EcaContext>(),
                    exchangeVisitorService: c.Resolve <IExchangeVisitorService>(),
                    participantPersonSevisService: c.Resolve <IParticipantPersonsSevisService>(),
                    exchangeVisitorValidator: null,
                    saveActions: null
                    );
                return(service);
            }));

            //Register the SEVIS Batch Processing service
            this.RegisterType <ISevisBatchProcessingService>(new InjectionFactory((c) =>
            {
                var context = c.Resolve <EcaContext>();
                var service = new SevisBatchProcessingService(
                    context: c.Resolve <EcaContext>(),
                    appSettings: c.Resolve <AppSettings>(),
                    cloudStorageService: c.Resolve <IFileStorageService>(),
                    exchangeVisitorService: c.Resolve <IExchangeVisitorService>(),
                    notificationService: c.Resolve <ISevisBatchProcessingNotificationService>(),
                    exchangeVisitorValidationService: c.Resolve <IExchangeVisitorValidationService>(),
                    maxCreateExchangeVisitorRecordsPerBatch: Int32.Parse(appSettings.MaxCreateExchangeVisitorRecordsPerBatch),
                    maxUpdateExchangeVisitorRecordsPerBatch: Int32.Parse(appSettings.MaxUpdateExchangeVisitorRecordsPerBatch),
                    saveActions: null
                    );
                return(service);
            }));
        }
Exemple #2
0
        /// <summary>
        /// Creates a new default instance.
        /// <param name="isExchangeVisitorValidated">True, if the exchange visitor has been validated in the sevis api.</param>
        /// <param name="sevisId">The sevis id of the exchange visitor.</param>
        /// <param name="participantStartDate">The particiant/exchange visitor start date.</param>
        /// <param name="sevisOrgId">The sevis org id.</param>
        /// </summary>
        public PersonValidator(string sevisId, string sevisOrgId, bool isExchangeVisitorValidated, DateTime participantStartDate)
            : base()
        {
            this.SevisId = sevisId;
            this.ParticipantStartDate = participantStartDate;
            this.IsValidated          = isExchangeVisitorValidated;
            this.SevisOrgId           = sevisOrgId;
            Func <Person, object> homeAddressTypeDelelgate = (p) => AddressType.Home.Value;
            Func <Person, object> hostAddressTypeDelegate  = (p) => AddressType.Host.Value;

            RuleFor(x => x.ProgramCategoryCode)
            .NotNull()
            .WithMessage(CATEGORY_CODE_REQUIRED_ERROR_MESSAGE)
            .WithState(x => new ProgramCategoryCodeErrorPath())
            .Length(CATEGORY_CODE_LENGTH)
            .WithMessage(PROGRAM_CATEGORY_CODE_ERROR_MESSAGE)
            .WithState(x => new ProgramCategoryCodeErrorPath());

            RuleFor(x => x.PositionCode)
            .NotNull()
            .WithMessage(POSITION_CODE_REQUIRED_ERROR_MESSAGE)
            .WithState(x => new PositionCodeErrorPath())
            .Matches(POSITION_CODE_REGEX)
            .WithMessage(POSITION_CODE_MUST_BE_DIGITS_ERROR_MESSAGE)
            .WithState(x => new PositionCodeErrorPath());

            RuleFor(x => x.SubjectField)
            .NotNull()
            .WithMessage(SUBJECT_FIELD_REQUIRED_ERROR_MESSAGE)
            .WithState(x => new FieldOfStudyErrorPath())
            .SetValidator(new SubjectFieldValidator());

            When(x => !String.IsNullOrWhiteSpace(this.SevisId) &&
                 !this.IsValidated &&
                 this.ParticipantStartDate < ParticipantPersonsSevisService.GetEarliestNeedsValidationInfoParticipantDate(),
                 () =>
            {
                When(x => this.SevisOrgId == null || !this.SevisOrgId.ToUpper().StartsWith(G_PROGRAM_PREFIX), () =>
                {
                    RuleFor(x => x.EmailAddress)
                    .NotNull()
                    .WithMessage(EMAIL_ADDRESS_REQUIRED_FORMAT_MESSAGE, EmailAddressType.Personal.Value)
                    .WithState(x => new EmailErrorPath());

                    RuleFor(x => x.PhoneNumber)
                    .NotNull()
                    .WithMessage(VISITING_PHONE_REQUIRED_ERROR_MESSAGE, (p) => Data.PhoneNumberType.Visiting.Value, GetPersonTypeDelegate(), GetNameDelegate())
                    .WithState(x => new PhoneNumberErrorPath());
                });

                RuleFor(visitor => visitor.MailAddress)
                .NotNull()
                .WithMessage(MAILING_ADDRESS_REQUIRED_FORMAT_MESSAGE, hostAddressTypeDelegate, p => LocationServiceAddressValidator.UNITED_STATES_COUNTRY_NAME)
                .WithState(x => new AddressErrorPath())
                .SetValidator(new AddressDTOValidator(a => AddressType.Host.Value));
            });

            RuleFor(x => x.PermanentResidenceCountryCode)
            .NotNull()
            .WithMessage(PERMANENT_RESIDENCE_COUNTRY_CODE_ERROR_MESSAGE, GetPersonTypeDelegate(), GetNameDelegate(), homeAddressTypeDelelgate, (p) => LocationServiceAddressValidator.UNITED_STATES_COUNTRY_NAME)
            .WithState(x => GetPermanentResidenceCountryCodeErrorPath(x));

            When(x => x.PermanentResidenceCountryCode != null, () =>
            {
                RuleFor(x => x.PermanentResidenceCountryCode)
                .Must((code) =>
                {
                    try
                    {
                        var codeType = code.GetCountryCodeWithType();
                        return(true);
                    }
                    catch (CodeTypeConversionException)
                    {
                        return(false);
                    }
                })
                .WithMessage(PERMANENT_RESIDENCE_COUNTRY_NOT_SUPPORTED, (p) => p.PermanentResidenceCountryCode, GetPersonTypeDelegate(), GetNameDelegate(), homeAddressTypeDelelgate)
                .WithState(x => GetPermanentResidenceCountryCodeErrorPath(x));
            });
        }