Beispiel #1
0
        public async Task <Metric> CreateAsync(CreateMetricRequest request)
        {
            Ensure.NotNull(request, nameof(request));

            var id = await db.Metrics.Sequence.NextAsync();

            var metric = new Metric(
                id: id,
                ownerId: request.OwnerId,
                name: request.Name,
                type: request.Type,
                unit: request.Unit
                );

            await db.Metrics.InsertAsync(metric);

            if (request.Dimensions != null)
            {
                var dimensions = new MetricDimension[request.Dimensions.Length];

                for (var i = 0; i < dimensions.Length; i++)
                {
                    dimensions[i] = new MetricDimension(
                        id: ScopedId.Create(metric.Id, i + 1),
                        name: request.Name
                        );
                }

                await db.MetricDimensions.InsertAsync(dimensions);
            }

            return(metric);
        }
Beispiel #2
0
        public static async Task <long> NextAsync(IDbContext context, long programId)
        {
            using (var connection = await context.GetConnectionAsync())
            {
                var currentReleaseCount = await connection.ExecuteScalarAsync <int>(sql, new { id = programId });

                return(ScopedId.Create(programId, currentReleaseCount + 1));
            }
        }
        public static async Task <long> NextAsync(IDbContext context, long domainId)
        {
            using (var connection = await context.GetConnectionAsync())
            {
                var currentValue = await connection.ExecuteScalarAsync <int>(sql, new { id = domainId });

                return(ScopedId.Create(domainId, currentValue + 1));
            }
        }
Beispiel #4
0
        public static async Task <long> GetNextScopedIdAsync <T>(this Dataset <T, long> dataset, long scopeId)
        {
            var range = ScopedId.GetRange(scopeId);

            // should be max id in range...
            var count = await dataset.CountAsync(
                Expression.Between("id", range.Start, range.End)
                );

            return(ScopedId.Create(scopeId, count));
        }
        public void B()
        {
            var name = DomainName.Parse("www.processor.ai");

            var record = new DomainRecord(
                id: ScopedId.Create(456, 1),
                name: "www",
                path: name.Path,
                type: DnsRecordType.A,
                value: "192.168.1.1",
                ttl: 600,
                flags: DomainRecordFlags.None
                );

            Assert.Equal(1912602625, record.Id);
            Assert.Equal("www", record.Name);
            Assert.Equal("ai/processor/www", record.Path);
            Assert.Equal(456, record.DomainId);
            Assert.Equal(1, (int)record.Type);
            Assert.Equal("192.168.1.1", record.Value);
            Assert.Equal(600, record.Ttl);
        }
Beispiel #6
0
        public static Uid Create(long accountId, DateTimeOffset timestamp, long sequenceNumber)
        {
            #region Preconditions

            if (accountId < 0)
            {
                throw new ArgumentException("Must be >= 0", nameof(accountId));
            }

            if (sequenceNumber < 0)
            {
                throw new ArgumentException("Must be >= 0", nameof(sequenceNumber));
            }

            #endregion

            var(hours, milliseconds) = Timestamp.Split(timestamp.ToUnixTimeMilliseconds());

            return(new Uid(
                       upper: (ulong)ScopedId.Create(accountId, (int)hours),
                       lower: RequestIdLower.Create((ulong)milliseconds, (ulong)sequenceNumber)
                       ));
        }