Exemplo n.º 1
0
        public static void Map(this EntityTypeBuilder <AuditLog> entityBuilder)
        {
            // Key
            entityBuilder.HasKey(t => t.LogId)
            .IsClustered(false);

            // Indexes
            entityBuilder.HasIndex(t => t.Time)
            .IsClustered();

            // Properties
            entityBuilder.Property(t => t.LogId)
            .HasColumnType("uniqueidentifier")
            .IsRequired();

            entityBuilder.Property(t => t.Entity)
            .HasColumnType("nvarchar(50)")
            .HasMaxLength(50)
            .IsRequired();

            entityBuilder.Property(t => t.EntityId)
            .HasColumnType("nvarchar(50)")
            .HasMaxLength(50)
            .IsRequired();

            entityBuilder.Property(t => t.Action)
            .HasColumnType("nvarchar(50)")
            .HasMaxLength(50)
            .IsRequired();

            entityBuilder.Property(t => t.Json)
            .HasColumnType("nvarchar(max)")
            .IsRequired();

            entityBuilder.Property(t => t.Time)
            .HasColumnType("datetime2")
            .IsRequired();

            // Seed data
            var time                   = DateTime.Now;
            var user1                  = new User("master", time);
            var indicator1             = new Indicator("price", IndicatorType.CurrencyIndicator, "master", "Price", "", "", null, 0, time);
            var indicator2             = new Indicator("price-change-24hrs", IndicatorType.CurrencyIndicator, "master", "Price change 24Hrs", "", "", null, 1, time);
            var indicator3             = new Indicator("hype", IndicatorType.CurrencyIndicator, "master", "Hype", "", "", null, 1, time);
            var indicatorDependencies1 = new IndicatorDependency("hype", "price-change-24hrs", time);

            entityBuilder.HasData(
                new AuditLog("Add", user1, user1.Id, time),
                new AuditLog("Add", indicator1, indicator1.Id, time),
                new AuditLog("Add", indicator2, indicator2.Id, time),
                new AuditLog("Add", indicator3, indicator3.Id, time),
                new AuditLog("Add", indicatorDependencies1, indicatorDependencies1.Id, time)
                );
        }
Exemplo n.º 2
0
        public static List <IndicatorDependency> BuildIndicatorDependencies(string indicatorId, List <Indicator> dependencies)
        {
            // Now
            var now = DateTime.UtcNow.StripSeconds();

            // Prepare list
            var indicatorDependencies = new List <IndicatorDependency>();

            // Build
            foreach (var dependency in dependencies)
            {
                // Create
                var indicatorDependency = new IndicatorDependency(indicatorId, dependency.IndicatorId, now);

                // Add
                indicatorDependencies.Add(indicatorDependency);
            }

            // Return
            return(indicatorDependencies);
        }
Exemplo n.º 3
0
        private async Task <List <IndicatorDependency> > BuildDependencies(string indicatorId, string[] dependencies)
        {
            var indicatorDependencies = new List <IndicatorDependency>();

            foreach (var dependencyId in dependencies)
            {
                // Get indicator
                var dependency = await _indicatorRepository.GetSingle(IndicatorExpression.Indicator(dependencyId));

                // Throw ValidationException if it does not exist
                if (dependency == null)
                {
                    throw new ValidationException(string.Format(IndicatorMessage.DepenedencyNotFound, dependencyId));
                }

                // Add
                var indicatorDependency = new IndicatorDependency(indicatorId, dependency.IndicatorId, dependency.DependencyLevel);
                indicatorDependencies.Add(indicatorDependency);
            }

            // Return
            return(indicatorDependencies);
        }