Merge pull request #2972 from abpframework/maliming/BundleContributorCollection

Allow replace & delete BundleContributor.
pull/3173/head
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit 4db091397f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,6 +39,43 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
AddWithDependencies(contributorType);
}
public void Replace<TSourceContributor, TDestContributorType>(bool includeDependencies = false)
where TSourceContributor : IBundleContributor, new()
where TDestContributorType : IBundleContributor, new()
{
Replace(typeof(TSourceContributor), typeof(TDestContributorType), includeDependencies);
}
public void Replace([NotNull] Type sourceContributorType, [NotNull] Type destContributorType, bool includeDependencies = false)
{
Check.NotNull(sourceContributorType, nameof(sourceContributorType));
Check.NotNull(destContributorType, nameof(destContributorType));
if (!includeDependencies)
{
_contributors.ReplaceOne(x => x.GetType() == sourceContributorType,
contributor => (IBundleContributor) Activator.CreateInstance(destContributorType));
}
else
{
RemoveWithDependencies(sourceContributorType);
Add(destContributorType);
}
}
public void Remove<TContributor>(bool includeDependencies = false)
where TContributor : IBundleContributor, new()
{
if (!includeDependencies)
{
_contributors.RemoveAll(x => x.GetType() == typeof(TContributor));
}
else
{
RemoveWithDependencies(typeof(TContributor));
}
}
public IReadOnlyList<IBundleContributor> GetAll()
{
return _contributors.ToImmutableList();
@ -58,6 +95,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
AddInstanceToContributors(contributorType);
}
private void RemoveWithDependencies(Type contributorType)
{
foreach (var dependedType in GetDirectDependencies(contributorType))
{
RemoveWithDependencies(dependedType); //Recursive call
}
_contributors.RemoveAll(x => x.GetType() == contributorType);
}
private IEnumerable<Type> GetDirectDependencies(Type contributorType)
{

@ -21,7 +21,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago
? "en"
: CultureInfo.CurrentUICulture.Name;
if (TryAddCultureFile(context, cultureName))
if (TryAddCultureFile(context, MapCultureName(cultureName)))
{
return;
}
@ -39,5 +39,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.Timeago
context.Files.AddIfNotContains(filePath);
return true;
}
protected virtual string MapCultureName(string cultureName)
{
return cultureName;
}
}
}

@ -25,7 +25,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation
var cultureName = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Replace('-', '_');
if (TryAddCultureFile(context, cultureName))
if (TryAddCultureFile(context, MapCultureName(cultureName)))
{
return;
}
@ -35,7 +35,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation
return;
}
TryAddCultureFile(context, cultureName.Substring(0, cultureName.IndexOf('_')));
TryAddCultureFile(context, MapCultureName(cultureName.Substring(0, cultureName.IndexOf('_'))));
}
protected virtual bool TryAddCultureFile(BundleConfigurationContext context, string cultureName)
@ -51,5 +51,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Packages.JQueryValidation
context.Files.AddIfNotContains(filePath);
return true;
}
protected virtual string MapCultureName(string cultureName)
{
return cultureName;
}
}
}

Loading…
Cancel
Save