Esempio n. 1
0
        public static string IdToTenantPartitionId(this string id)
        {
            var idList = id.Split(':');

            if (id.StartsWith("tenant:"))
            {
                return(Tenant.PartitionIdFormat());
            }
            else if (id.StartsWith("track:"))
            {
                return(Track.PartitionIdFormat(new Track.IdKey {
                    TenantName = idList[1], TrackName = idList[2]
                }));
            }
            else if (id.StartsWith("party:"))
            {
                return(DataDocument.PartitionIdFormat(new Track.IdKey {
                    TenantName = idList[2], TrackName = idList[3]
                }));
            }
            else
            {
                return(DataDocument.PartitionIdFormat(new Track.IdKey {
                    TenantName = idList[1], TrackName = idList[2]
                }));
            }
        }
Esempio n. 2
0
        public async Task <UpParty> GetUpPartyByNameAsync(Party.IdKey idKey, bool required = true)
        {
            if (idKey == null)
            {
                new ArgumentNullException(nameof(idKey));
            }

            return(await ReadItemAsync <UpParty>(await UpParty.IdFormatAsync(idKey), DataDocument.PartitionIdFormat(idKey), required));
        }
Esempio n. 3
0
        public async Task <Track> GetTrackByNameAsync(Track.IdKey idKey, bool requered = true)
        {
            if (idKey == null)
            {
                new ArgumentNullException(nameof(idKey));
            }

            return(await ReadDocumentAsync <Track>(await Track.IdFormat(idKey), DataDocument.PartitionIdFormat(idKey), requered));
        }
Esempio n. 4
0
        public async Task <T> DeleteAsync <T>(Track.IdKey idKey, Expression <Func <T, bool> > whereQuery) where T : IDataDocument
        {
            if (idKey == null)
            {
                new ArgumentNullException(nameof(idKey));
            }
            await idKey.ValidateObjectAsync();

            var partitionId = DataDocument.PartitionIdFormat(idKey);
            var query       = GetQueryAsync <T>(partitionId).Where(whereQuery).AsDocumentQuery();

            double totalRU = 0;

            try
            {
                var response = await query.ExecuteNextAsync <T>();

                totalRU += response.RequestCharge;
                var item = response.FirstOrDefault();
                if (item != null)
                {
                    var requestOptions = new RequestOptions {
                        PartitionKey = new PartitionKey(partitionId)
                    };
                    var deleteResponse = await client.DeleteDocumentAsync(GetDocumentLink <T>(item.Id), requestOptions);

                    totalRU += deleteResponse.RequestCharge;
                }
                await item.ValidateObjectAsync();

                return(item);
            }
            catch (Exception ex)
            {
                throw new CosmosDataException(partitionId, ex);
            }
            finally
            {
                var scopedLogger = httpContextAccessor.HttpContext.RequestServices.GetService <TelemetryScopedLogger>();
                scopedLogger.ScopeMetric($"CosmosDB RU, tenant - delete type '{typeof(T)}'.", totalRU);
            }
        }
Esempio n. 5
0
 private string PartitionIdFormat <T>(Track.IdKey idKey) where T : IDataDocument
 {
     if (typeof(T).Equals(typeof(Tenant)))
     {
         return(Tenant.PartitionIdFormat());
     }
     else if (typeof(T).Equals(typeof(Track)))
     {
         if (idKey == null)
         {
             new ArgumentNullException(nameof(idKey));
         }
         return(Track.PartitionIdFormat(idKey));
     }
     else
     {
         if (idKey == null)
         {
             new ArgumentNullException(nameof(idKey));
         }
         return(DataDocument.PartitionIdFormat(idKey));
     }
 }