Skip to content

Commit

Permalink
Merge pull request aspnetboilerplate#2 from aspnetboilerplate/master
Browse files Browse the repository at this point in the history
合并
  • Loading branch information
yuzukwok committed Sep 30, 2015
2 parents 5b286d1 + 98324b1 commit 58e313d
Show file tree
Hide file tree
Showing 42 changed files with 475 additions and 291 deletions.
18 changes: 13 additions & 5 deletions doc/WebSiteContents/caching.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ <h3>ICacheManager</h3>

<pre lang="cs">public class TestAppService : ApplicationService
{
private readonly ICache _myCache;
private readonly ICacheManager _cacheManager;

public TestAppService(ICacheManager cacheManager)
{
_myCache = cacheManager.GetCache(&quot;MyCache&quot;);
_cacheManager = cacheManager;
}

public Item GetItem(int id)
{
//Try to get from cache
return _myCache.Get(id.ToString(), () =&gt; GetFromDatabase(id)) as Item;
return _cacheManager
.GetCache(&quot;MyCache&quot;)
.Get(id.ToString(), () =&gt; GetFromDatabase(id)) as Item;
}

public Item GetFromDatabase(int id)
Expand All @@ -47,13 +49,19 @@ <h3>ICacheManager</h3>
<p>In this sample, we're injecting <strong>ICacheManager</strong> and getting a
cache named <strong>MyCache</strong>.</p>

<div class="bs-callout bs-callout-warning">
<h4><strong>WARNING: </strong>GetCache Method</h4>
<p>Do not use GetCache method in your constructor. This may dispose the
Cache if your class is transient.</p>
</div>

<h3>ICache</h3>

<p>ICacheManager.<strong>GetCache</strong> method returns an <strong>ICache</strong>.
A cache is singleton (per cache name). It is created first time it's
requested, then returns always the same cache object. So, we can share same
cache with same name in different classes (clients).</p>
<p>In the sample code, we see simple usage of ICache.<strong>Get</strong>
<p>In the sample code, we see simple usage of ICache.<strong>Get</strong>
method. It has two arguments:</p>
<ul>
<li><strong>key</strong>: A string unique key of an item in the cache.</li>
Expand All @@ -72,7 +80,7 @@ <h3>ITypedCache</h3>
wrapper to ICache to provide <strong>type safe</strong>, generic cache. To
convert ICache to ITypedCache, we can use <strong>AsTyped</strong> extension method as shown
below:</p>
<pre lang="cs">ITypedCache&lt;int, Item&gt; myCache = cacheManager.GetCache(&quot;MyCache&quot;)<strong>.AsTyped&lt;int, Item&gt;()</strong>;</pre>
<pre lang="cs">ITypedCache&lt;int, Item&gt; myCache = _cacheManager.GetCache(&quot;MyCache&quot;)<strong>.AsTyped&lt;int, Item&gt;()</strong>;</pre>
<p>Then we can use Get method without converting and casting code.</p>

<h3>Configuration</h3>
Expand Down
1 change: 1 addition & 0 deletions nupkg/pack_abp.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.MemoryDb\Abp.MemoryDb.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.MongoDB\Abp.MongoDB.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.NHibernate\Abp.NHibernate.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.RedisCache\Abp.RedisCache.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.Web\Abp.Web.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.Web.Api\Abp.Web.Api.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
"..\src\.nuget\NuGet.exe" "pack" "..\src\Abp.Web.Mvc\Abp.Web.Mvc.csproj" -Properties Configuration=Release -IncludeReferencedProjects -Symbols
Expand Down
1 change: 1 addition & 0 deletions src/Abp.RedisCache/Abp.RedisCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AbpRedisCacheConfig.cs" />
<Compile Include="RedisCache\AbpRedisCacheModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RedisCache\AbpRedisCache.cs" />
Expand Down
33 changes: 33 additions & 0 deletions src/Abp.RedisCache/AbpRedisCacheConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Abp.Configuration.Startup;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Abp
{
public class AbpRedisCacheConfig
{
private string connectionStringKey = "Abp.Redis.Cache";

public string ConnectionStringKey
{
get { return connectionStringKey; }
set { connectionStringKey = value; }
}


}

public static class AbpRedisCacheConfigEctensions
{
public static AbpRedisCacheConfig AbpRedisCacheModule(this IModuleConfigurations moduleConfigurations)
{
return moduleConfigurations.AbpConfiguration
.GetOrCreate("AbpRedisCacheModule",
() => moduleConfigurations.AbpConfiguration.IocManager.Resolve<AbpRedisCacheConfig>()
);
}
}
}
7 changes: 4 additions & 3 deletions src/Abp.RedisCache/RedisCache/AbpRedisCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Abp.RedisCache
{
public class AbpRedisCache : CacheBase
{
public const string ConnectionStringKey = "Abp.Redis.Cache";

private readonly ConnectionMultiplexer _connectionMultiplexer;
private readonly AbpRedisCacheConfig _config;

public IDatabase Database
{
Expand All @@ -23,10 +23,11 @@ public IDatabase Database
/// <summary>
/// Constructor.
/// </summary>
public AbpRedisCache(string name, IAbpRedisConnectionProvider redisConnectionProvider)
public AbpRedisCache(string name, IAbpRedisConnectionProvider redisConnectionProvider, AbpRedisCacheConfig config)
: base(name)
{
var connectionString = redisConnectionProvider.GetConnectionString(ConnectionStringKey);
_config = config;
var connectionString = redisConnectionProvider.GetConnectionString(_config.ConnectionStringKey);
_connectionMultiplexer = redisConnectionProvider.GetConnection(connectionString);
}
public override object GetOrDefault(string key)
Expand Down
2 changes: 2 additions & 0 deletions src/Abp.Web.Mvc/Web/Mvc/Controllers/AbpController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ private void HandleAuditingBeforeAction(ActionExecutingContext filterContext)
{
TenantId = AbpSession.TenantId,
UserId = AbpSession.UserId,
ImpersonatorUserId = AbpSession.ImpersonatorUserId,
ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
ServiceName = methodInfo.DeclaringType != null
? methodInfo.DeclaringType.FullName
: filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
Expand Down
3 changes: 2 additions & 1 deletion src/Abp.Web/Web/AbpWebModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Reflection;
using System.Web;
using Abp.Localization.Sources;
using Abp.Localization.Dictionaries;
using Abp.Localization.Dictionaries.Xml;
using Abp.Localization.Sources.Xml;
using Abp.Modules;
using Abp.Web.Configuration;
Expand Down
25 changes: 10 additions & 15 deletions src/Abp.Web/Web/Localization/LocalizationScriptManager.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
using System;
using System.Globalization;
using System.Linq;
using System.Runtime.Caching;
using System.Text;
using System.Threading;
using Abp.Dependency;
using Abp.Localization;
using Abp.Runtime.Caching.Memory;
using Abp.Runtime.Caching;

namespace Abp.Web.Localization
{
internal class LocalizationScriptManager : ILocalizationScriptManager, ISingletonDependency
{
private readonly ILocalizationManager _localizationManager;
private readonly ICacheManager _cacheManager;

private readonly ThreadSafeObjectCache<string> _cache;

/// <summary>
/// Initializes a new instance of the <see cref="Abp.Web.Localization.LocalizationScriptManager"/> class.
/// </summary>
/// <param name="localizationManager">Localization manager.</param>
public LocalizationScriptManager(ILocalizationManager localizationManager)
public LocalizationScriptManager(ILocalizationManager localizationManager, ICacheManager cacheManager)
{
_localizationManager = localizationManager;
_cache = new ThreadSafeObjectCache<string>(new MemoryCache("__LocalizationScriptManager"), TimeSpan.FromDays(1));
_cacheManager = cacheManager;
}

/// <inheritdoc/>
Expand All @@ -35,21 +29,22 @@ public string GetScript()
/// <inheritdoc/>
public string GetScript(CultureInfo cultureInfo)
{
return _cache.Get(cultureInfo.Name, BuildAll);
return _cacheManager
.GetCache<string, string>("AbpLocalizationScripts")
.Get(cultureInfo.Name, () => BuildAll(cultureInfo));
}

private string BuildAll()
private string BuildAll(CultureInfo cultureInfo)
{
var script = new StringBuilder();
var currentCulture = Thread.CurrentThread.CurrentUICulture;

script.AppendLine("(function(){");
script.AppendLine();
script.AppendLine(" abp.localization = abp.localization || {};");
script.AppendLine();
script.AppendLine(" abp.localization.currentCulture = {");
script.AppendLine(" name: '" + currentCulture.Name + "',");
script.AppendLine(" displayName: '" + currentCulture.DisplayName + "'");
script.AppendLine(" name: '" + cultureInfo.Name + "',");
script.AppendLine(" displayName: '" + cultureInfo.DisplayName + "'");
script.AppendLine(" };");
script.AppendLine();
script.Append(" abp.localization.languages = [");
Expand Down
20 changes: 13 additions & 7 deletions src/Abp/Abp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
<Compile Include="Auditing\IMvcControllersAuditingConfiguration.cs" />
<Compile Include="Auditing\MvcControllersAuditingConfiguration.cs" />
<Compile Include="Configuration\CacheManagerSettingExtensions.cs" />
<Compile Include="Localization\DefaultLanguageProvider.cs" />
<Compile Include="Localization\Dictionaries\Xml\LocalizationDictionaryProviderBase.cs" />
<Compile Include="Localization\ILanguageManager.cs" />
<Compile Include="Localization\ILanguageProvider.cs" />
<Compile Include="Localization\LanguageManager.cs" />
<Compile Include="Runtime\Caching\CacheManagerExtensions.cs" />
<Compile Include="Runtime\Caching\Configuration\CacheConfigurator.cs" />
<Compile Include="Runtime\Caching\Configuration\CachingConfiguration.cs" />
Expand Down Expand Up @@ -159,7 +164,7 @@
<Compile Include="Domain\Uow\AbpDataFilters.cs" />
<Compile Include="Domain\Uow\DataFilterConfiguration.cs" />
<Compile Include="Extensions\ExceptionExtensions.cs" />
<Compile Include="Localization\Sources\IDictionaryBasedLocalizationSource.cs" />
<Compile Include="Localization\Dictionaries\IDictionaryBasedLocalizationSource.cs" />
<Compile Include="Timing\Clock.cs" />
<Compile Include="Timing\IClockProvider.cs" />
<Compile Include="MultiTenancy\MultiTenancyExtensions.cs" />
Expand Down Expand Up @@ -251,11 +256,10 @@
<Compile Include="Events\Bus\Entities\NullEntityChangedEventHelper.cs" />
<Compile Include="Events\Bus\IEventDataWithInheritableGenericArgument.cs" />
<Compile Include="IShouldInitialize.cs" />
<Compile Include="Localization\Sources\LocalizationDictionaryInfo.cs" />
<Compile Include="Localization\Sources\LocalizationSourceExtensions.cs" />
<Compile Include="Localization\Sources\ILocalizationDictionaryProvider.cs" />
<Compile Include="Localization\Sources\Xml\XmlEmbeddedFileLocalizationDictionaryProvider.cs" />
<Compile Include="Localization\Sources\Xml\XmlFileLocalizationDictionaryProvider.cs" />
<Compile Include="Localization\Dictionaries\ILocalizationDictionaryProvider.cs" />
<Compile Include="Localization\Dictionaries\Xml\XmlEmbeddedFileLocalizationDictionaryProvider.cs" />
<Compile Include="Localization\Dictionaries\Xml\XmlFileLocalizationDictionaryProvider.cs" />
<Compile Include="Net\Mail\EmailSettingNames.cs" />
<Compile Include="Net\Mail\EmailSettingProvider.cs" />
<Compile Include="Net\Mail\EmailSenderConfiguration.cs" />
Expand Down Expand Up @@ -414,7 +418,7 @@
<Compile Include="Localization\LocalizationHelper.cs" />
<Compile Include="Localization\LocalizationManager.cs" />
<Compile Include="Localization\Dictionaries\ILocalizationDictionary.cs" />
<Compile Include="Localization\Sources\DictionaryBasedLocalizationSource.cs" />
<Compile Include="Localization\Dictionaries\DictionaryBasedLocalizationSource.cs" />
<Compile Include="Localization\Sources\Xml\XmlLocalizationSource.cs" />
<Compile Include="Modules\AbpModule.cs" />
<Compile Include="Modules\AbpModuleManager.cs" />
Expand Down Expand Up @@ -442,7 +446,9 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Localization\Sources\AbpXmlSource\Abp-tr.xml" />
<EmbeddedResource Include="Localization\Sources\AbpXmlSource\Abp.xml" />
<EmbeddedResource Include="Localization\Sources\AbpXmlSource\Abp.xml">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Localization\Sources\AbpXmlSource\Abp-zh-CN.xml" />
Expand Down
2 changes: 1 addition & 1 deletion src/Abp/AbpConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class AbpConsts
/// <summary>
/// Current version of the ABP.
/// </summary>
public const string CurrentVersion = "0.7.0.5";
public const string CurrentVersion = "0.7.1.0";

/// <summary>
/// Localization source name of ASP.NET Boilerplate framework.
Expand Down
4 changes: 2 additions & 2 deletions src/Abp/AbpKernelModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using Abp.Domain.Uow;
using Abp.Events.Bus;
using Abp.Localization;
using Abp.Localization.Sources;
using Abp.Localization.Sources.Xml;
using Abp.Localization.Dictionaries;
using Abp.Localization.Dictionaries.Xml;
using Abp.Modules;
using Abp.Net.Mail;
using Abp.Runtime.Validation.Interception;
Expand Down
10 changes: 9 additions & 1 deletion src/Abp/Application/Navigation/MenuItemDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ public bool IsLeaf
/// <summary>
/// Creates a new <see cref="MenuItemDefinition"/> object.
/// </summary>
public MenuItemDefinition(string name, ILocalizableString displayName, string icon = null, string url = null, bool requiresAuthentication = false, string requiredPermissionName = null, int order = 0, object customData = null)
public MenuItemDefinition(
string name,
ILocalizableString displayName,
string icon = null,
string url = null,
bool requiresAuthentication = false,
string requiredPermissionName = null,
int order = 0,
object customData = null)
{
if (string.IsNullOrEmpty(name))
{
Expand Down
15 changes: 15 additions & 0 deletions src/Abp/Auditing/AuditInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ public class AuditInfo
/// </summary>
public long? UserId { get; set; }

/// <summary>
/// ImpersonatorUserId.
/// </summary>
public long? ImpersonatorUserId { get; set; }

/// <summary>
/// ImpersonatorTenantId.
/// </summary>
public int? ImpersonatorTenantId { get; set; }

/// <summary>
/// Service (class/interface) name.
/// </summary>
Expand Down Expand Up @@ -56,6 +66,11 @@ public class AuditInfo
/// Browser information if this method is called in a web request.
/// </summary>
public string BrowserInfo { get; set; }

/// <summary>
/// Optional custom data that can be filled and used.
/// </summary>
public string CustomData { get; set; }

/// <summary>
/// Exception object, if an exception occured during execution of the method.
Expand Down
2 changes: 2 additions & 0 deletions src/Abp/Auditing/AuditingInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private AuditInfo CreateAuditInfo(IInvocation invocation)
{
TenantId = AbpSession.TenantId,
UserId = AbpSession.UserId,
ImpersonatorUserId = AbpSession.ImpersonatorUserId,
ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
ServiceName = invocation.MethodInvocationTarget.DeclaringType != null
? invocation.MethodInvocationTarget.DeclaringType.FullName
: "",
Expand Down
18 changes: 17 additions & 1 deletion src/Abp/Configuration/SettingDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public class SettingDefinition
/// </summary>
public bool IsVisibleToClients { get; private set; }

/// <summary>
/// Can be used to store a custom object related to this setting.
/// </summary>
public object CustomData { get; set; }

/// <summary>
/// Creates a new <see cref="SettingDefinition"/> object.
/// </summary>
Expand All @@ -65,7 +70,17 @@ public class SettingDefinition
/// <param name="scopes">Scopes of this setting. Default value: <see cref="SettingScopes.Application"/>.</param>
/// <param name="isVisibleToClients">Can clients see this setting and it's value. Default: false</param>
/// <param name="isInherited">Is this setting inherited from parent scopes. Default: True.</param>
public SettingDefinition(string name, string defaultValue, ILocalizableString displayName = null, SettingDefinitionGroup group = null, ILocalizableString description = null, SettingScopes scopes = SettingScopes.Application, bool isVisibleToClients = false, bool isInherited = true)
/// <param name="customData">Can be used to store a custom object related to this setting</param>
public SettingDefinition(
string name,
string defaultValue,
ILocalizableString displayName = null,
SettingDefinitionGroup group = null,
ILocalizableString description = null,
SettingScopes scopes = SettingScopes.Application,
bool isVisibleToClients = false,
bool isInherited = true,
object customData = null)
{
if (string.IsNullOrEmpty(name))
{
Expand All @@ -80,6 +95,7 @@ public SettingDefinition(string name, string defaultValue, ILocalizableString di
Scopes = scopes;
IsVisibleToClients = isVisibleToClients;
IsInherited = isInherited;
CustomData = customData;
}
}
}
Loading

0 comments on commit 58e313d

Please sign in to comment.