Beispiel #1
0
        public ProjectAdoValidator(IProjectAdoServices projectAdoServices, IAdoProjectRepository adoProjectRepository, ILogger <ProjectAdoValidator> logger)
        {
            _projectAdoServices   = projectAdoServices;
            _adoProjectRepository = adoProjectRepository;
            _logger = logger;

            RuleFor(p => p.Organization)
            .NotEmpty()
            .WithMessage("Organization must be selected");

            RuleFor(p => p.ProcessName)
            .NotEmpty()
            .WithMessage("Process must be selected");

            When(p => string.IsNullOrWhiteSpace(p.Name), () =>
            {
                RuleFor(p => p.Name).NotEmpty()
                .WithMessage("Name must be entered");
            }).Otherwise(() =>
            {
                RuleFor(p => p.Name)
                .MustAsync(ProjectName).WithMessage("Project already exist in ADO, Enter different name")
                .MustAsync(ProjecAlredyRequested).WithMessage("Project already requested, Enter different name")
                ;
            });
        }
Beispiel #2
0
 public AdoProjectController(ILogger <AdoProjectController> logger,
                             IAdoProjectRepository repository,
                             IMapper mapper)
 {
     _logger     = logger;
     _repository = repository;
     _mapper     = mapper;
 }
 public CreateApprovedAdoProjectIdsCommandHandler
 (
     IProjectAdoServices projectAdoServices,
     IAdoProjectRepository adoProjectRepository,
     IAdoProjectHistoryRepository adoProjectHistoryRepository,
     IMapper mapper,
     ILogger <CreateApprovedAdoProjectIdsCommandHandler> logger
 )
 {
     _projectAdoServices          = projectAdoServices;
     _adoProjectRepository        = adoProjectRepository;
     _adoProjectHistoryRepository = adoProjectHistoryRepository;
     _mapper = mapper;
     _logger = logger;
 }
Beispiel #4
0
 public AzServiceBusConsumer(
     IConfiguration configuration,
     IMessageBus messageBus,
     IMediator mediator,
     IProjectAdoServices projectAdoServices,
     IAdoProjectRepository adoProjectRepository,
     IAdoProjectHistoryRepository adoProjectHistoryRepository,
     IMapper mapper,
     ILogger <AzServiceBusConsumer> logger)
 {
     _configuration               = configuration;
     _messageBus                  = messageBus;
     _mediator                    = mediator;
     _projectAdoServices          = projectAdoServices;
     _adoProjectRepository        = adoProjectRepository;
     _adoProjectHistoryRepository = adoProjectHistoryRepository;
     _logger = logger;
 }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
            services.AddMediatR(Assembly.GetExecutingAssembly());

            services.AddApplicationServices(Configuration, _env, _logger);

            string ApiEndpointAuth = Configuration.GetValue <string>(ConstatCsro.EndPoints.ApiEndpointAuth);

            services.AddHttpClient(Core.ConstatCsro.EndPoints.ApiEndpointAuth, (client) =>
            {
                client.Timeout     = TimeSpan.FromMinutes(ConstatCsro.ClientNames.API_TimeOut_Mins);
                client.BaseAddress = new Uri(ApiEndpointAuth);
                client.DefaultRequestHeaders.Add("Accept", "application/json");
            }).ConfigurePrimaryHttpMessageHandler(() =>
            {
                return(new HttpClientHandler()
                {
                    AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.Brotli,
                    UseCookies = false
                });
            })
            .SetHandlerLifetime(TimeSpan.FromMinutes(5))
            .AddPolicyHandler(PollyHelper.GetRetryPolicy())
            .AddPolicyHandler(PollyHelper.GetRetryPolicy());
            ;

            #region Auth

            services.AddAuthorization(options =>
            {
                // By default, all incoming requests will be authorized according to the default policy
                //Will automatical sign in user
                //options.FallbackPolicy = options.DefaultPolicy;

                options.AddPolicy(PoliciesCsro.CanApproveAdoRequestPolicy, policy => policy.RequireClaim(ClaimTypesCsro.CanApproveAdoRequestClaim, true.ToString()));
            });

            //TODO replace with rest or GRPC service
            services.AddScoped <IRestUserService, RestUserService>();
            services.AddScoped <IClaimsTransformation, ClaimsTransformation>();

            #endregion

            services.AddApplicationInsightsTelemetry();
            services.AddControllers();
            services.AddMvc(options =>
            {
                options.Filters.Add(new CsroValidationFilter());
            })
            .AddFluentValidation(options =>
            {
                //options.RegisterValidatorsFromAssemblyContaining<Startup>();
                options.RegisterValidatorsFromAssemblyContaining <Validation.BaseAdoAbstractValidator>();
            });


            services.AddScoped <IApiIdentity, ApiIdentity>();
            services.AddScoped <IEmailService, EmailService>();
            services.AddSingleton <IMessageBus, AzServiceBusMessageBus>();

            services.AddTransient <IProjectAdoServices, ProjectAdoServices>();
            services.AddTransient <IProcessAdoServices, ProcessAdoServices>();
            services.AddSingleton <ICacheProvider, CacheProvider>(); //testing
            services.AddTransient <IPropertyMappingService, AdoPropertyMappingService>();

            //services.AddSingleton<IServiceBusConsumer, AzServiceBusConsumer>();

            services.AddScoped <IAdoProjectApproverService, AdoProjectApproverService>();
            services.AddScoped <IGenerateEmailForApprovalService, GenerateEmailForApprovalService>();
            services.AddScoped <IAdoProjectAccessRepository, AdoProjectAccessRepository>();

            //services.AddControllers(options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()));
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = _namespace, Version = "v1"
                });
            });

            #region DbContext

            DbTypeEnum DbTypeEnum = DbTypeEnum.Unknown;
            try
            {
                DbTypeEnum = Configuration.GetValue <DbTypeEnum>(nameof(DbTypeEnum));
            }
            catch { }

            services.AddDbContext <AdoContext>(options =>
            {
                if (DbTypeEnum == DbTypeEnum.SqlLite)
                {
                    options.UseSqlite(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.AdoDb), x => x.MigrationsAssembly(_namespace));
                }
                else if (DbTypeEnum == DbTypeEnum.InMemory)
                {
                    options.UseInMemoryDatabase(databaseName: KeyVaultConfig.ConnectionStrings.AdoDb);
                }
                else
                {
                    options.UseSqlServer(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.AdoDb), x => x.MigrationsAssembly(_namespace));
                }
            });

            //services.AddDbContext<TokenCacheContext>(options =>
            //{
            //    if (UseSqlLiteDb)
            //        options.UseSqlite(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.TokenCacheDb));
            //    else
            //        options.UseSqlServer(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.TokenCacheDb));

            //});

            #endregion

            #region Repositories

            services.AddScoped(typeof(IRepository <>), typeof(AdoRepository <>));
            services.AddScoped <IAdoProjectHistoryRepository, AdoProjectHistoryRepository>();
            services.AddScoped <IAdoProjectRepository, AdoProjectRepository>();

            #endregion

            var busConfig = Configuration.GetSection(nameof(BusConfig)).Get <BusConfig>();
            if (busConfig == null)
            {
                _logger.LogWarning($"No {nameof(BusConfig)} found.");
            }
            else
            {
                _logger.LogInformation($"{nameof(BusConfig)} is {busConfig} ", busConfig);
                //_logger.LogInformation("BusConfig is {busConfig} ", busConfig);
                if (busConfig.IsBusEnabled && busConfig.BusTypeEnum == BusTypeEnum.AzureServiceBus)
                {
                    //should be last to hav all dependencies
                    services.AddHostedService <ProjectApprovalHostedService>(sp =>
                    {
                        var serviceProvider          = services.BuildServiceProvider();
                        var apiIdentity              = serviceProvider.GetService <IApiIdentity>();
                        var ctx                      = serviceProvider.GetService <AdoContext>();
                        IRepository <AdoProject> obj = new Repository <AdoProject>(ctx, apiIdentity);
                        var logger                   = sp.GetService <ILogger <ProjectApprovalHostedService> >();
                        IGenerateEmailForApprovalService generateEmailForApprovalService = serviceProvider.GetService <IGenerateEmailForApprovalService>();
                        return(new ProjectApprovalHostedService(generateEmailForApprovalService, logger));
                    });

                    services.AddHostedService <AzServiceBusConsumer>(sp =>
                    {
                        var serviceProvider = services.BuildServiceProvider();
                        //var serviceProvider = sp;
                        var apiIdentity = serviceProvider.GetService <IApiIdentity>();
                        var ctx         = serviceProvider.GetService <AdoContext>();
                        IRepository <AdoProject> obj = new Repository <AdoProject>(ctx, apiIdentity);

                        IConfiguration configuration               = serviceProvider.GetService <IConfiguration>();
                        IMessageBus messageBus                     = serviceProvider.GetService <IMessageBus>();
                        IMediator mediator                         = serviceProvider.GetService <IMediator>();
                        IProjectAdoServices projectAdoServices     = serviceProvider.GetService <IProjectAdoServices>();
                        IAdoProjectRepository adoProjectRepository = serviceProvider.GetService <IAdoProjectRepository>();
                        IAdoProjectHistoryRepository adoProjectHistoryRepository = serviceProvider.GetService <IAdoProjectHistoryRepository>();
                        IMapper mapper = serviceProvider.GetService <IMapper>();
                        ILogger <AzServiceBusConsumer> logger = serviceProvider.GetService <ILogger <AzServiceBusConsumer> >();
                        return(new AzServiceBusConsumer(configuration, messageBus, mediator, projectAdoServices, adoProjectRepository, adoProjectHistoryRepository, mapper, logger));
                    });
                }
            }
        }