Ejemplo n.º 1
0
 public DocumentDbBatchDataOperation(IServerTimestampService timestamps, IOptions <DocumentDbOptions> options,
                                     IOptions <DocumentDbBatchOptions> batchOptions)
 {
     _timestamps   = timestamps;
     _options      = options;
     _batchOptions = batchOptions;
 }
Ejemplo n.º 2
0
 public PersonRepository(IDataConnection db, ISqlDialect dialect, IDataBatchOperation <TOptions> batching, IServerTimestampService timestamps)
 {
     _db         = db;
     _dialect    = dialect;
     _copy       = batching;
     _timestamps = timestamps;
 }
Ejemplo n.º 3
0
 public SqlObjectSaveRepository(IDataConnection <RuntimeBuilder> db, IDataBatchOperation <TBatchOptions> batching,
                                IServerTimestampService timestamps)
 {
     _db         = db;
     _copy       = batching;
     _timestamps = timestamps;
 }
Ejemplo n.º 4
0
 public SqlObjectDeleteRepository(IDataConnection <RuntimeBuilder> db, IObjectGetRepository <TObject, long> gets,
                                  IObjectSaveRepository <TObject, long> saves, IServerTimestampService timestamps)
 {
     _db         = db;
     _gets       = gets;
     _saves      = saves;
     _timestamps = timestamps;
 }
Ejemplo n.º 5
0
 public TokenController(
     UserManager <TUser> userManager,
     IServerTimestampService timestamps,
     IOptions <SecurityOptions> securityOptions,
     IOptions <PublicApiOptions> apiOptions,
     ILogger <TokenController <TUser, TTenant, TKey> > logger)
 {
     _userManager     = userManager;
     _timestamps      = timestamps;
     _securityOptions = securityOptions;
     _apiOptions      = apiOptions;
     _logger          = logger;
 }
Ejemplo n.º 6
0
        public static async Task ExecuteAsync <TData>(IDataDescriptor descriptor, IServerTimestampService timestamps,
                                                      BatchSaveStrategy saveStrategy, IEnumerable <TData> objects,
                                                      long startingAt, int?count, DocumentClient client, string databaseId, Resource collection)
        {
            var offer = client.CreateOfferQuery().Where(o => o.ResourceLink == collection.SelfLink)
                        .AsEnumerable().FirstOrDefault();
            var throughput = ((OfferV2)offer)?.Content.OfferThroughput ?? 1000;

            // ReSharper disable once PossibleMultipleEnumeration
            count ??= objects.Count();

            var batchSize = count.GetValueOrDefault();

            switch (saveStrategy)
            {
            case BatchSaveStrategy.Insert:
            {
                // ReSharper disable once PossibleMultipleEnumeration
                var data = objects.Skip((int)startingAt).Take(batchSize);
                if (descriptor.Id != null && descriptor.Id.IsIdentity)
                {
                    var nextValues = await client.GetNextValuesForSequenceAsync(typeof(TData).Name,
                                                                                databaseId, collection.Id, batchSize);

                    // ReSharper disable once PossibleMultipleEnumeration
                    data = data.Select((x, i) =>
                        {
                            descriptor.Id.Property.Set(x, nextValues.Item1 + i);
                            return(x);
                        });
                }

                if (descriptor.Timestamp != null)
                {
                    var timestamp = timestamps.GetCurrentTime();
                    data = data.Select(x =>
                        {
                            descriptor.Timestamp?.Property?.Set(x, timestamp);
                            return(x);
                        });
                }

                var batch = data.Select(x =>
                    {
                        var @object  = new ExpandoObject();
                        var document = (IDictionary <string, object>)@object;
                        foreach (var property in descriptor.Inserted)
                        {
                            document.Add(property.ColumnName, property.Property.Get(x));
                        }
                        if (!document.ContainsKey("DocumentType"))
                        {
                            document.Add("DocumentType", typeof(TData).Name);
                        }

                        document["id"] = Guid.NewGuid().ToString();
                        return(@object);
                    });

                // set TaskCount = 10 for each 10k RUs, minimum 1, maximum 250
                var taskCount = Math.Min(Math.Max(throughput / 1000, 1), 250);
                var tasks     = new List <Task>();
                var pageSize  = batchSize / taskCount;
                for (var i = 0; i < taskCount; i++)
                {
                    // ReSharper disable once PossibleMultipleEnumeration
                    var page = batch.Skip(i * pageSize).Take(pageSize);
                    tasks.Add(InsertDocumentAsync(client, databaseId, collection, page));
                }

                await Task.WhenAll(tasks);

                break;
            }

            case BatchSaveStrategy.Upsert:
            {
                throw new NotImplementedException();
            }

            case BatchSaveStrategy.Update:
            {
                throw new NotImplementedException();
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(saveStrategy), saveStrategy, null);
            }
        }
Ejemplo n.º 7
0
 protected BackgroundTaskStoreTests(IServiceProvider serviceProvider) : base(serviceProvider)
 {
     Store       = ServiceProvider.GetRequiredService(typeof(IBackgroundTaskStore)) as IBackgroundTaskStore;
     _timestamps = ServiceProvider.GetRequiredService(typeof(IServerTimestampService)) as IServerTimestampService;
 }