Beispiel #1
0
 public AppSettingComponent(FalconDbContext dbContext,
                            IUserIdentityGateway identityGateway,
                            IDateTimeGateway dateTimeGateway,
                            IMapper mapper, ConfigurationComponent configuration) : base(dateTimeGateway, mapper, identityGateway, configuration)
 {
     this._dbContext = dbContext;
 }
        public static async Task RemoveFeature(this FalconDbContext context, int id)
        {
            var feature = await context.Features
                          .Include(c => c.IncidentMap)
                          .Include(c => c.JourneyMaps)
                          .Include(c => c.Squads).SingleAsync(c => c.Id == id);

            if (feature != null)
            {
                foreach (var map in feature.IncidentMap)
                {
                    context.IncidentMaps.Remove(map);
                }
                foreach (var map in feature.JourneyMaps)
                {
                    context.JourneyMaps.Remove(map);
                }
                foreach (var squad in feature.Squads)
                {
                    context.SquadFeatures.Remove(squad);
                }

                await context.SaveChangesAsync();

                feature = await context.Features
                          .Include(c => c.JourneyMaps)
                          .Include(c => c.Squads).SingleAsync(c => c.Id == id);

                context.Features.Remove(feature);

                await context.SaveChangesAsync();
            }
        }
Beispiel #3
0
        public static async Task <ICollection <JourneyEntity> > GetJourneyByProduct(this FalconDbContext context, int productId)
        {
            var journeys = await context.Journeys
                           .Include(c => c.FeatureMap)
                           .Where(c => c.ProductId == productId).ToListAsync();

            var featuresIds = journeys.SelectMany(c => c.FeatureMap).Select(c => c.FeatureId).Distinct().ToList();

            var features = await context.Features
                           .Include(c => c.Indicators)
                           .Where(c => featuresIds.Contains(c.Id.Value)).ToListAsync();

            var sourceIds = features.SelectMany(c => c.Indicators).Select(c => c.SourceId).Distinct().ToList();

            var sources = await context.Sources.Where(c => sourceIds.Contains(c.Id.Value)).ToListAsync();

            foreach (var feature in features)
            {
                foreach (var indicator in feature.Indicators)
                {
                    indicator.Source = sources.Single(c => c.Id == indicator.SourceId);
                }
            }

            foreach (var journey in journeys)
            {
                foreach (var map in journey.FeatureMap)
                {
                    map.Feature = features.Single(c => c.Id == map.FeatureId);
                }
            }
            return(journeys);
        }
Beispiel #4
0
        public static async Task <JourneyEntity> GetJourney(this FalconDbContext context, int journeyId)
        {
            var journey = await context.Journeys
                          .Include(c => c.FeatureMap)
                          .Where(c => c.Id == journeyId).SingleOrDefaultAsync();

            if (journey == null)
            {
                return(null);
            }

            var featuresIds = journey.FeatureMap.Select(c => c.FeatureId).Distinct().ToList();

            var features = await context.Features
                           .Include(c => c.Indicators)
                           .Where(c => featuresIds.Contains(c.Id.Value)).ToListAsync();

            var sourceIds = features.SelectMany(c => c.Indicators).Select(c => c.SourceId).Distinct().ToList();

            var sources = await context.Sources.Where(c => sourceIds.Contains(c.Id.Value)).ToListAsync();

            foreach (var feature in features)
            {
                foreach (var indicator in feature.Indicators)
                {
                    indicator.Source = sources.Single(c => c.Id == indicator.SourceId);
                }
            }

            foreach (var map in journey.FeatureMap)
            {
                map.Feature = features.Single(c => c.Id == map.FeatureId);
            }
            return(journey);
        }
Beispiel #5
0
        public static async Task RemoveJourney(this FalconDbContext context, int journeyId)
        {
            var journey = await context.Journeys.SingleAsync(c => c.Id == journeyId);

            context.Journeys.Remove(journey);

            await context.SaveChangesAsync();
        }
 public CustomerQueryComponent(FalconDbContext dbContext, IMapper mapper,
                               IDateTimeGateway dateTimeGateway, IUserIdentityGateway identityGateway,
                               SquadQueryComponent squadQueryComponent,
                               ConfigurationComponent configuration, ProductQueryComponent productQueryComponent) : base(dateTimeGateway, mapper, identityGateway, configuration)
 {
     this._squadQueryComponent   = squadQueryComponent;
     this._productQueryComponent = productQueryComponent;
     this._dbContext             = dbContext;
 }
Beispiel #7
0
        public static async Task <SourceEntity> GetSourceWithItems(this FalconDbContext context,
                                                                   int sourceId, DatePeriodValue period)
        {
            var source = await context.Sources.SingleOrDefaultAsync(c => c.Id == sourceId);

            source.SourceItems = await context.GetSourceItems(sourceId, period.Start, period.End);

            return(source);
        }
Beispiel #8
0
 public ProductComponent(FalconDbContext dbContext,
                         IUserIdentityGateway identityGateway, IDateTimeGateway dateTimeGateway,
                         IMapper mapper, ConfigurationComponent configuration,
                         SourceItemComponent sourceItemComponent,
                         SourceComponent sourceComponent) : base(dateTimeGateway, mapper, identityGateway, configuration)
 {
     this._sourceItemComponent = sourceItemComponent;
     this._dbContext           = dbContext;
     this._sourceComponent     = sourceComponent;
 }
Beispiel #9
0
        public static async Task <IEnumerable <IncidentEntity> > GetIncidentsByJourney(
            this FalconDbContext context, int journeyId)
        {
            var features = await context.JourneyMaps.Where(c => c.JourneyId == journeyId).Select(c => c.FeatureId).ToListAsync();

            var incidents = await context.IncidentMaps
                            .Where(c => features.Contains(c.FeatureId))
                            .Select(c => c.Incident).ToListAsync();

            return(incidents);
        }
Beispiel #10
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
        /// </summary>
        /// <param name="app">App</param>
        /// <param name="env">Env</param>
        /// <param name="loggerFactory">Logger</param>
        /// <param name="swaggerOptions">Swagger Option</param>
        /// <param name="configuration">Configuration</param>
        public override void Configure(IApplicationBuilder app, IHostingEnvironment env,
                                       ILoggerFactory loggerFactory, IOptions <SwaggerAppOptions> swaggerOptions,
                                       IConfiguration configuration, FalconDbContext dbContext, IDateTimeGateway dateTimeGateway)
        {
            app.UseMvc();

            dbContext.Database.OpenConnection();
            dbContext.Database.EnsureCreated();

            // Setup Default Data
            app.UseAuthentication();

            //var user = UserEntity.Factory.Create("test", dateTimeGateway.GetCurrentDateTime(), "*****@*****.**");
            //user.Id = 9999;
            //dbContext.Users.Add(user);
        }
Beispiel #11
0
        public static async Task <JourneyEntity> FullJourneyWithSourceItems(this FalconDbContext context, int journeyId,
                                                                            DateTime start, DateTime end)
        {
            var entity = await GetJourney(context, journeyId);

            var sources     = entity.FeatureMap.SelectMany(c => c.Feature.Indicators).Select(c => c.SourceId).Distinct().ToList();
            var sourceItems = await context.GetSourceItems(sources, start, end);

            foreach (var map in entity.FeatureMap)
            {
                foreach (var indicator in map.Feature.Indicators)
                {
                    indicator.Source.SourceItems = sourceItems.Where(c => c.SourceId == indicator.SourceId).ToList();
                }
            }
            return(entity);
        }
        public static async Task <ProductEntity> FullLoadProductWithSourceItems(this FalconDbContext context, int productId, DateTime start, DateTime end)
        {
            var product = await FullLoadProduct(context, productId);

            var sourceItems = await context.GetSourceItemsByProduct(productId, start, end);

            foreach (var journey in product.Journeys)
            {
                foreach (var map in journey.FeatureMap)
                {
                    foreach (var indicator in map.Feature.Indicators)
                    {
                        indicator.Source.SourceItems = sourceItems.Where(c => c.SourceId == indicator.SourceId).ToList();
                    }
                }
            }
            return(product);
        }
        public static async Task <ProductEntity> FullLoadProduct(this FalconDbContext context,
                                                                 int productId)
        {
            var product = await context.Products.Include(c => c.Customer)
                          .Where(c => c.Id == productId).SingleAsync();

            product.Journeys = await context.Journeys
                               .Include(c => c.FeatureMap)
                               .Where(c => c.ProductId == productId).ToListAsync();

            product.Features = await context.Features
                               .Include(c => c.Indicators)
                               .Include(c => c.Squads)
                               .Where(c => c.ProductId == productId).ToListAsync();

            foreach (var item in product.Journeys)
            {
                foreach (var map in item.FeatureMap)
                {
                    map.Feature = product.Features.Single(c => c.Id == map.FeatureId);
                }
            }

            var sources = await context.Sources
                          .Include(c => c.SecurityRisks)
                          .Include(c => c.ReliabilityRisks)
                          .Where(c => c.ProductId == productId).ToListAsync();

            product.Sources = new SourceCollection(sources);

            foreach (var feature in product.Features)
            {
                foreach (var sli in feature.Indicators)
                {
                    sli.Source = sources.Where(c => c.Id == sli.SourceId).Single();
                }
            }
            return(product);
        }
 public MigrationComponent(FalconDbContext dbContext,
                           CustomerComponent customerComponent,
                           ProductComponent productComponent,
                           JourneyComponent journeyComponent,
                           FeatureComponent featureComponent,
                           SourceComponent sourceComponent,
                           JourneyMapComponent journeyMapComponent,
                           IndicatorComponent indicatorComponent,
                           SourceItemComponent sourceItemComponent,
                           IncidentComponent incidentComponent,
                           UserComponent userComponent,
                           ProductQueryComponent productQueryComponent,
                           IUserIdentityGateway identityGateway,
                           IDateTimeGateway dateTimeGateway, IMapper mapper,
                           FeatureQueryComponent featureQueryComponent,
                           SecurityRiskComponent securityRiskComponent,
                           ReliabilityRiskComponent reliabilityRiskComponent,
                           SquadComponent squadComponent, SquadQueryComponent squadQueryComponent,
                           ConfigurationComponent configuration) : base(dateTimeGateway, mapper, identityGateway, configuration)
 {
     this._customerComponent        = customerComponent;
     this._sourceComponent          = sourceComponent;
     this._dbContext                = dbContext;
     this._squadComponent           = squadComponent;
     this._squadQueryComponent      = squadQueryComponent;
     this._productComponent         = productComponent;
     this._journeyComponent         = journeyComponent;
     this._featureComponent         = featureComponent;
     this._journeyMapComponent      = journeyMapComponent;
     this._indicatorComponent       = indicatorComponent;
     this._sourceComponent          = sourceComponent;
     this._sourceItemComponent      = sourceItemComponent;
     this._incidentComponent        = incidentComponent;
     this._userComponent            = userComponent;
     this._productQueryComponent    = productQueryComponent;
     this._featureQueryComponent    = featureQueryComponent;
     this._securityRiskComponent    = securityRiskComponent;
     this._reliabilityRiskComponent = reliabilityRiskComponent;
 }
        public static Container BuildContainer()
        {
            Container container = new Container();
            var       mapper    = BuildMapper();

            container.RegisterInstance <IMapper>(mapper);
            container.RegisterInstance <IUserIdentityGateway>(BuildIdentityGateway());
            container.Register <IDateTimeGateway, MockDateTimeGateway>();

            var builder       = new DbContextOptionsBuilder <FalconDbContext>();
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                                .Build();

            var connectionString = configuration.GetConnectionString("DefaultConnection");

            builder.UseSqlServer(connectionString).AddInterceptors(new OwlveyCommandInterceptor());
            var context = new  FalconDbContext(builder.Options);

            context.Database.OpenConnection();
            context.Database.EnsureCreated();
            container.RegisterInstance <FalconDbContext>(context);
            return(container);
        }
Beispiel #16
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env,
                                      ILoggerFactory loggerFactory, IOptions <SwaggerAppOptions> swaggerOptions,
                                      IConfiguration configuration, FalconDbContext dbContext, IDateTimeGateway dateTimeGateway)
        {
            LogRequestHeaders(app, app.ApplicationServices.GetService <ILoggerFactory>());

            IDisposable collector = DotNetRuntimeStatsBuilder
                                    .Customize()
                                    .WithContentionStats()
                                    .WithJitStats()
                                    .WithThreadPoolSchedulingStats()
                                    .WithThreadPoolStats()
                                    .WithGcStats()
                                    .StartCollecting();


            app.UseMetricServer();

            app.UseStaticFiles();
            app.UseHttpMetrics();


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //TODO enable use ssl
                //app.UseHsts();
                //app.UseHttpsRedirection();
                app.UseDeveloperExceptionPage();
            }
            app.Use(async(context, next) =>
            {
                try
                {
                    await next.Invoke();
                }
                catch (System.Exception)
                {
                    WebMetrics.ExceptionCounter.Inc(1);
                    throw;
                }
            });



            app.UseAuthentication();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.DocumentTitle = swaggerOptions.Value.Title;
                c.RoutePrefix   = string.Empty;
                c.SwaggerEndpoint($"{swaggerOptions.Value.Endpoint}", swaggerOptions.Value.Title);
            });

            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            app.UseMvc();
        }
        public static async Task <ProductEntity> FullLoadProductWithGroupAndSourceItems(this FalconDbContext context, int productId, string group, DateTime start, DateTime end)
        {
            var product = await FullLoadProduct(context, productId);

            product.Journeys = product.Journeys.Where(c => c.Group == group).ToList();
            var sources     = product.Journeys.SelectMany(c => c.FeatureMap).SelectMany(c => c.Feature.Indicators).Select(c => c.SourceId).Distinct().ToList();
            var sourceItems = await context.GetSourceItems(sources, start, end);

            foreach (var journey in product.Journeys)
            {
                foreach (var map in journey.FeatureMap)
                {
                    foreach (var indicator in map.Feature.Indicators)
                    {
                        indicator.Source.SourceItems = sourceItems.Where(c => c.SourceId == indicator.SourceId).ToList();
                    }
                }
            }
            return(product);
        }
 public static async Task <ProductEntity> GetProduct(this FalconDbContext context,
                                                     int customerId, string name)
 {
     return(await context.Products.SingleOrDefaultAsync(c => c.CustomerId == customerId && c.Name == name));
 }
 public FeatureQueryComponent(FalconDbContext dbContext, IDateTimeGateway dateTimeGateway,
                              IMapper mapper, IUserIdentityGateway userIdentityGateway,
                              ConfigurationComponent configuration) : base(dateTimeGateway, mapper, userIdentityGateway, configuration)
 {
     this._dbContext = dbContext;
 }
 public static async Task <IEnumerable <IncidentEntity> > GetIncidentsByFeature(this FalconDbContext context, int featureId)
 {
     return(await context.IncidentMaps.Where(c => c.FeatureId == featureId).Select(c => c.Incident).ToListAsync());
 }
Beispiel #21
0
 public static async Task <CustomerEntity> GetCustomer(this FalconDbContext context, string name)
 {
     return(await context.Customers.SingleOrDefaultAsync(c => c.Name == name));
 }
        public static async Task <SystemModel> Build(IMapper mapper, FalconDbContext dbContext, bool includeData)
        {
            SystemModel result = new SystemModel();

            var users = await dbContext.Users.ToListAsync();

            var customers = await dbContext.Customers
                            .Include(c => c.Products).ThenInclude(c => c.Anchors)
                            .Include(c => c.Squads).ThenInclude(d => d.Members)
                            .ToListAsync();

            var journeys = await dbContext.Journeys.Include(c => c.FeatureMap).ToListAsync();

            var features = await dbContext.Features
                           .Include(c => c.Indicators)
                           .Include(c => c.Squads)
                           .ToListAsync();

            var sources = await dbContext.Sources.ToListAsync();

            var sourceItems = new List <SourceItemEntity>();

            if (includeData)
            {
                sourceItems = await dbContext.SourcesItems.ToListAsync();
            }

            var securityThreats = await dbContext.SecurityThreats.ToListAsync();

            var securityRisks = await dbContext.SecurityRisks.ToListAsync();

            var reliabilityThreats = await dbContext.ReliabilityThreats.ToListAsync();

            var reliabilityRisks = await dbContext.ReliabilityRisks.ToListAsync();

            SystemModelBuilder.PrepareData(users, customers,
                                           securityRisks, reliabilityRisks,
                                           journeys, features, sources, sourceItems);

            result.AddUsers(users);

            var securityThreatModels = mapper.Map <IEnumerable <SecurityThreatModel> >(securityThreats);

            result.AddSecurityThreats(securityThreatModels);

            var securityRiskModels = mapper.Map <IEnumerable <SecurityRiskModel> >(securityRisks);

            result.AddSecurityRisks(securityRiskModels);

            var reliabilityThreatModels = mapper.Map <IEnumerable <ReliabilityThreatModel> >(reliabilityThreats);

            result.AddReliabilityThreats(reliabilityThreatModels);

            var reliabilityRiskModels = mapper.Map <IEnumerable <ReliabilityRiskModel> >(reliabilityRisks);

            result.AddReliabilityRisks(reliabilityRiskModels);

            foreach (var customer in customers)
            {
                result.AddOrganization(customer);
                result.AddSquads(customer.Name, customer.Squads);
                result.AddProducts(customer.Name, customer.Products);

                foreach (var squad in customer.Squads)
                {
                    result.AddMembers(customer.Name, squad.Name, squad.Members);
                }
                foreach (var product in customer.Products)
                {
                    result.AddAnchors(customer.Name, product.Name, product.Anchors);
                    result.AddJourneys(customer.Name, product.Name, product.Journeys);
                    foreach (var journey in product.Journeys)
                    {
                        result.AddJourneyMaps(customer.Name, product.Name, journey.Name, journey.FeatureMap);
                    }
                    result.AddFeatures(customer.Name, product.Name, product.Features);
                    foreach (var feature in product.Features)
                    {
                        result.AddIndicator(customer.Name, product.Name, feature.Name, feature.Indicators);
                        result.AddSquadFeature(customer.Name, product.Name, feature.Name, feature.Squads);
                    }
                    result.AddSources(customer.Name, product.Name, product.Sources);
                    foreach (var source in product.Sources)
                    {
                        result.AddSourceItem(customer.Name, product.Name, source.Name, source.SourceItems);
                    }
                }
            }

            return(result);
        }
Beispiel #23
0
 public static async Task <SourceEntity> GetSource(this FalconDbContext context,
                                                   int productId, string name)
 {
     return(await context.Sources.SingleOrDefaultAsync(c => c.ProductId == productId && c.Name == name));
 }
Beispiel #24
0
 public SquadFeatureComponent(FalconDbContext dbContext,
                              IUserIdentityGateway identityService, IDateTimeGateway dateTimeGateway, IMapper mapper) : base(dateTimeGateway, mapper, identityService)
 {
     this._dbContext = dbContext;
 }
Beispiel #25
0
 public CacheComponent(FalconDbContext dbContext)
 {
     this.DbContext = dbContext;
 }