Browse Source

Merge pull request #21058 from abpframework/auto-merge/prerel-9-0/3075

Merge branch dev with prerel-9.0
pull/21067/head
maliming 2 years ago
committed by GitHub
parent
commit
12c74a3573
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs
  2. 33
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs
  3. 28
      framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

@ -193,7 +193,7 @@ public class PackagePreviewSwitcher : ITransientDependency
var folder = Path.GetDirectoryName(project);
_packageSourceManager.Add(FindSolutionFolder(project) ?? folder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json");
"https://www.myget.org/F/abp-nightly/api/v3/index.json", "Volo.*");
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(
project,
@ -213,7 +213,8 @@ public class PackagePreviewSwitcher : ITransientDependency
var solutionAngularFolder = GetSolutionAngularFolder(solutionFolder);
_packageSourceManager.Add(solutionFolder, "ABP Nightly",
"https://www.myget.org/F/abp-nightly/api/v3/index.json");
"https://www.myget.org/F/abp-nightly/api/v3/index.json",
"Volo.*");
if (solutionPath != null)
{

33
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackageSourceManager.cs

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
@ -16,7 +17,7 @@ public class PackageSourceManager : ITransientDependency
Logger = NullLogger<PackageSourceManager>.Instance;
}
public void Add(string solutionFolder, string sourceKey, string sourceValue)
public void Add(string solutionFolder, string sourceKey, string sourceValue, params string[] packageMappingPatterns)
{
var nugetConfigPath = GetNugetConfigPath(solutionFolder);
@ -61,6 +62,11 @@ public class PackageSourceManager : ITransientDependency
sourceNodes?[0]?.AppendChild(newNode);
if (packageMappingPatterns.Any())
{
ConfigurePackageSourceMappings(doc, sourceKey, packageMappingPatterns);
}
File.WriteAllText(nugetConfigPath, doc.OuterXml);
}
catch
@ -69,6 +75,31 @@ public class PackageSourceManager : ITransientDependency
}
}
protected virtual void ConfigurePackageSourceMappings(XmlDocument doc, string sourceKey, string[] packageMappingPatterns)
{
var packageMappingNodes = doc.SelectNodes("/configuration/packageSourceMapping");
if (packageMappingNodes == null)
{
// If there is no packageSourceMapping node, leave it as it is.
Logger.LogWarning($"<packageSourceMapping> node not found in 'NuGet.Config' file. Skipping adding patterns for '{sourceKey}' source.");
return;
}
var packageSourceNode = doc.CreateElement("packageSource");
var sourceAttr = doc.CreateAttribute("key");
sourceAttr.Value = sourceKey;
packageSourceNode.Attributes.Append(sourceAttr);
packageMappingNodes[0]?.AppendChild(packageSourceNode);
foreach (var pattern in packageMappingPatterns)
{
var packageNode = doc.CreateElement("package");
var patternAttr = doc.CreateAttribute("pattern");
patternAttr.Value = pattern;
packageNode.Attributes.Append(patternAttr);
packageSourceNode.AppendChild(packageNode);
}
}
public void Remove(string solutionFolder, string sourceKey)
{
var nugetConfigPath = GetNugetConfigPath(solutionFolder);

28
framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs

@ -118,27 +118,25 @@ public class MultiTenantConnectionStringResolver : DefaultConnectionStringResolv
return connString!;
}
//Fallback to tenant's default connection string if available
if (!tenantDefaultConnectionString.IsNullOrWhiteSpace())
{
return tenantDefaultConnectionString!;
}
//Try to find the specific connection string for given name
var connStringInOptions = Options.ConnectionStrings.GetOrDefault(connectionStringName);
if (!connStringInOptions.IsNullOrWhiteSpace())
//Fallback to the mapped database for the specific connection string
var database = Options.Databases.GetMappedDatabaseOrNull(connectionStringName);
if (database != null && database.IsUsedByTenants)
{
return connStringInOptions!;
connString = tenant.ConnectionStrings?.GetOrDefault(database.DatabaseName);
if (!connString.IsNullOrWhiteSpace())
{
//Found for the tenant
return connString!;
}
}
//Fallback to the global default connection string
var defaultConnectionString = Options.ConnectionStrings.Default;
if (!defaultConnectionString.IsNullOrWhiteSpace())
//Fallback to tenant's default connection string if available
if (!tenantDefaultConnectionString.IsNullOrWhiteSpace())
{
return defaultConnectionString!;
return tenantDefaultConnectionString!;
}
throw new AbpException("No connection string defined!");
return base.Resolve(connectionStringName);
}
protected virtual async Task<TenantConfiguration?> FindTenantConfigurationAsync(Guid tenantId)

Loading…
Cancel
Save