Пример #1
0
        public async Task <IdReservationResult> ReserveIdAsync(string dataType, string id, string submitter)
        {
            var isNewCollection = await IsNewCollectionAsync(dataType);

            if (isNewCollection)
            {
                await CreateTable(dataType);
            }
            else if (await ExistsAsync(dataType, id))
            {
                return(IdReservationResult.Failed());
            }
            var utcNow = DateTime.UtcNow;
            var query  = $"INSERT INTO {dataType} (Id,OriginalSubmitter,CreatedTimeUtc,Submitter,SubmissionTimeUtc) "
                         + $"VALUES ('{id}','{submitter}','{utcNow:yyyy-MM-dd HH:mm:ss}','{submitter}','{utcNow:yyyy-MM-dd HH:mm:ss}')";

            try
            {
                await sqlQueryExecutor.ExecuteQueryAsync(query);

                return(IdReservationResult.Success(id, isNewCollection));
            }
            catch
            {
                return(IdReservationResult.Failed());
            }
        }
Пример #2
0
        public async Task <IdReservationResult> ReserveIdAsync(string dataType, string id, string submitter)
        {
            if (await ExistsAsync(dataType, id))
            {
                return(IdReservationResult.Failed());
            }
            try
            {
                var isNewCollection = await IsNewCollection(dataType);

                var utcNow = DateTime.UtcNow;
                await metadataStorage.StoreAsync(
                    dataType,
                    new GenericDataContainer(id, submitter, utcNow, submitter, utcNow, ApiVersion.Current, new BsonDocument()),
                    false);

                var container = binaryDataStorage.GetContainer(dataType);
                await container.CreateIfNotExistsAsync();

                var blob = binaryDataStorage.GetBlob(dataType, id);
                await blob.WriteAsync(new MemoryStream(Encoding.ASCII.GetBytes("Reserved")));

                return(IdReservationResult.Success(id, isNewCollection));
            }
            catch (DocumentAlreadyExistsException)
            {
                return(IdReservationResult.Failed());
            }
        }
Пример #3
0
        public async Task <IdReservationResult> ReserveIdAsync(string dataType, string id, string submitter)
        {
            var isNewCollection = await IsNewCollectionAsync(dataType);

            var collection = rdDataClient.DataDatabase.GetCollection <GenericDataContainer>(dataType);

            try
            {
                var utcNow = DateTime.UtcNow;
                await collection.InsertOneAsync(new GenericDataContainer(id, submitter, utcNow, submitter, utcNow, ApiVersion.Current, new BsonDocument()));

                return(IdReservationResult.Success(id, isNewCollection));
            }
            catch (MongoWriteException writeException)
            {
                if (writeException.WriteError.Category == ServerErrorCategory.DuplicateKey)
                {
                    return(IdReservationResult.Failed());
                }
                throw;
            }
        }
        public async Task <List <IdReservationResult> > GetIdsAsync(string dataType, string submitter, int count)
        {
            var tableSetup           = tableSetups[dataType];
            var reservationContainer = tableSetup.BuildReservationContainer(submitter);
            var reservationResults   = new List <IdReservationResult>();

            for (int i = 0; i < count; i++)
            {
                IdReservationResult reservationResult;
                try
                {
                    var storeResult = await StoreAsync(dataType, reservationContainer, false);

                    reservationResult = IdReservationResult.Success(storeResult.Id, storeResult.IsNewCollection);
                }
                catch (DocumentAlreadyExistsException)
                {
                    reservationResult = IdReservationResult.Failed();
                }
                reservationResults.Add(reservationResult);
            }
            return(reservationResults);
        }