|
@@ -100,7 +100,6 @@ namespace TEAMModelOS.SDK.DI
|
|
|
/// <returns></returns>
|
|
|
public async Task InitializeDatabase()
|
|
|
{
|
|
|
- // int CollectionThroughput = 400;
|
|
|
string[] DatabaseIds = BaseConfigModel.Configuration.GetSection("Azure:Cosmos:Database").Get<string[]>();
|
|
|
bool isMonitor = false;
|
|
|
string leases = "leases";
|
|
@@ -122,7 +121,6 @@ namespace TEAMModelOS.SDK.DI
|
|
|
{
|
|
|
string PartitionKey = AzureCosmosUtil.GetPartitionKey(type);
|
|
|
string CollectionName = "";
|
|
|
- // int RU = 0;
|
|
|
bool cache = false;
|
|
|
bool monitor = false;
|
|
|
IEnumerable<CosmosDBAttribute> attributes = type.GetCustomAttributes<CosmosDBAttribute>(true);
|
|
@@ -146,25 +144,13 @@ namespace TEAMModelOS.SDK.DI
|
|
|
isMonitor = true;
|
|
|
}
|
|
|
}
|
|
|
- //if (attributes.First<CosmosDBAttribute>().RU > 400)
|
|
|
- //{
|
|
|
- // RU = attributes.First<CosmosDBAttribute>().RU;
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // RU = CollectionThroughput;
|
|
|
- //}
|
|
|
+
|
|
|
//如果表存在于数据则检查RU是否变动,如果不存在则执行创建DocumentCollection
|
|
|
if (CosmosDict.nameCosmos.TryGetValue(CollectionName, out AzureCosmosModel AzureCosmosModel))
|
|
|
{ //更新RU
|
|
|
|
|
|
AzureCosmosModel.cache = cache;
|
|
|
CosmosContainer container = GetCosmosClient().GetDatabase(attributes.First().Database).GetContainer(AzureCosmosModel.container.Id);
|
|
|
- //int? throughputResponse = await container.ReadThroughputAsync();
|
|
|
- //if (throughputResponse < RU)
|
|
|
- //{
|
|
|
- // await GetCosmosClient().GetDatabase(attributes.First().Database).GetContainer(AzureCosmosModel.container.Id).ReplaceThroughputAsync(RU);
|
|
|
- //}
|
|
|
AzureCosmosModel cosmos = new AzureCosmosModel { container = container, cache = cache, monitor = monitor, type = type, partitionKey = PartitionKey };
|
|
|
CosmosDict.nameCosmos[CollectionName] = cosmos;
|
|
|
CosmosDict.typeCosmos.Add(type.Name, cosmos);
|
|
@@ -176,12 +162,8 @@ namespace TEAMModelOS.SDK.DI
|
|
|
{
|
|
|
containerProperties.PartitionKeyPath = "/" + PartitionKey;
|
|
|
}
|
|
|
- //if (RU > CollectionThroughput)
|
|
|
- //{
|
|
|
- // CollectionThroughput = RU;
|
|
|
- //}
|
|
|
CosmosDatabase database = GetCosmosClient().GetDatabase(attributes.First().Database);
|
|
|
- CosmosContainer containerWithConsistentIndexing =await database.CreateContainerIfNotExistsAsync(containerProperties);
|
|
|
+ CosmosContainer containerWithConsistentIndexing = database.GetContainer(CollectionName);
|
|
|
AzureCosmosModel cosmos = new AzureCosmosModel { container = containerWithConsistentIndexing, cache = cache, monitor = monitor, type = type, partitionKey = PartitionKey,database=database };
|
|
|
CosmosDict.nameCosmos[CollectionName] = cosmos;
|
|
|
CosmosDict.typeCosmos.Add(type.Name, cosmos);
|
|
@@ -194,14 +176,11 @@ namespace TEAMModelOS.SDK.DI
|
|
|
foreach (string DatabaseId in DatabaseIds)
|
|
|
{
|
|
|
CosmosDatabase database = GetCosmosClient().GetDatabase(DatabaseId);
|
|
|
- ContainerProperties leaseProperties = new ContainerProperties { Id = leases, PartitionKeyPath = "/id", DefaultTimeToLive = -1 };
|
|
|
- CosmosContainer leaseContainer = await database.CreateContainerIfNotExistsAsync(leaseProperties);
|
|
|
+ CosmosContainer leaseContainer = database.GetContainer(leases);
|
|
|
CosmosDict.nameCosmos.TryAdd(leases, new AzureCosmosModel { container = leaseContainer, cache = false, monitor = false, partitionKey = "/id", database = database });
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|