Netop.Core主要提供的服务是类工厂服务及AOP服务,当然还其它一些小服务:
一、对话上下文Netop.Core.Context.SessionContext
此对话上下文可用在桌面程序和ASP.NET程序,可用SetData和GetData在上下文中传递数据。方法有:
public static bool IsWeb()
public static string GetAppMapPath (string path)
public static object GetData(string key)
public static object GetData(string key, bool isToSession)
public static void SetData(string key, object value)
public static void SetData(string key, object value, bool isToSession)
public static void Remove(string key)
二、缓冲
定义了缓冲接口ICache和ILocalCache(本地缓冲),Netop.Core.Cache.MicrosoftEnterpriseLibraryCache就是包装Microsoft.Practices.EnterpriseLibrary.Caching实现ILocalCache接口的一个类,当然也可以做一个包装MemCached实现ICache接口的类,以后有时间把它共享出来。
本地缓冲服务的调用是通过Netop.Core.Cache.AppMemoryCache来的,当然配置文件是需要进行配置的:
Microsoft.Practices.EnterpriseLibrary.Caching有关的配置为:
<configSections>
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings,Microsoft.Practices.EnterpriseLibrary.Caching" />
<section name="Netop.Application" type="Netop.Core.Configuration.ConfigurationHandler,Netop.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<cachingConfiguration defaultCacheManager="Default Cache Manager">
<backingStores>
<add name="inMemory" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching" />
</backingStores>
<cacheManagers>
<add name="Default Cache Manager"
type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching"
expirationPollFrequencyInSeconds="60"
maximumElementsInCacheBeforeScavenging="1000"
numberToRemoveWhenScavenging="10"
backingStoreName="inMemory" />
</cacheManagers>
</cachingConfiguration>
在<Netop.Application>节点下的配置:
<Application.Cache>
<Provider>Netop.Core.Cache.MicrosoftEnterpriseLibraryCache,Netop.Core</Provider>
<ApplicationLog>Application.Log</ApplicationLog>
<ExpirationPolicy.IsSet>1</ExpirationPolicy.IsSet>
<ExpirationPolicy.Expiration>60</ExpirationPolicy.Expiration>
<ExpirationPolicy.TypeFullName>Microsoft.Practices.EnterpriseLibrary.Caching.Expirations.SlidingTime,Microsoft.Practices.EnterpriseLibrary.Caching</ExpirationPolicy.TypeFullName>
</Application.Cache>
经过这些配置的设定后,就可以使用AppMemoryCache的方法了:
public static void AddCacheData(string key, object data)
public static void AddCacheData(string key, object data, Priority priority)
public static void AddCacheDataForEver(string key, object data)
public static void AddCacheDataForFileDependency(string key, object data, Priority priority, string fileName)
public static void AddDataForAbsoluteTime(string key, object data, Priority priority, TimeSpan timeFromNow)
public static void AddDataForAbsoluteTime(string key, object data, Priority priority, System.DateTime absoluteTime)
public static void AddDataForSlidingTime(string key, object data, Priority priority, TimeSpan slidingExpiration)
public static void AddDataForSlidingTime(string key, object data, Priority priority, TimeSpan slidingExpiration, System.DateTime originalTimeStamp)
public static object GetCacheData(string key)
public static void RemoveCacheData(string key)
public static bool Contains(string key)
public static int Count
三、日志
Netop.Core.Log.Log4Net是实现了Netop.Core.Log.ILog接口的对Log4Net包装类,ILog接口为:
public interface ILog
{
void Debug(object message);
void Write(object message);
void Write(object message, LogInfoType logInfoType);
void Write(object message, Exception exception);
void Write(object message, Exception exception, LogInfoType logInfoType);
}
Netop.Core.Log.LogManager是使用日志的工厂类,最主要的处理是对如对Log4Net进行数据库配置的日志时如何提取自己加密的ConnectionString给Log4Net,细节可看GetLog4NetLogger方法及相关的配置代码。
使用Log4Net有关的配置为:
<configSections>
<section name="Netop.Application" type="Netop.Core.Configuration.ConfigurationHandler,Netop.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
另外配置<log4net>艽点,如:
<log4net>
<logger name="Log">
<level value="ERROR" />
<appender-ref ref="LogFile" />
</logger>
<appender name="LogFile" type="log4net.Appender.FileAppender" >
<param name="File" value="Log/log-file.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n"/>
</layout>
</appender>
</log4net>
在Netop.Application里的配置呢?如你自己要配置另外的日志,可在Netop.Application里加类似这样的配置(当然请给XXXXXX和YYYYYY取个好名),如 :
<XXXXXX>
<LogCategory>Netop.Core.Log.Log4Net,Netop.Core</LogCategory>
<LogParameter>YYYYYY</LogParameter>
</XXXXXX>
我自己的系统的一种配置为(当然还有多个形表式式的日志的配置):
<Application.Log>
<LogCategory>Netop.Core.Log.Log4Net,Netop.Core</LogCategory>
<LogParameter>Log</LogParameter>
</Application.Log>
当然Log对应的在log4net中的等等配置你要搞好(那个你就参照相关Log4Net的资料吧),上面<LogParameter>Log</LogParameter>中的Log名就是上面的<logger name=" Log">的Log名,要对应关联起来才行。
然后程序就可调用了:
Netop.Core.Log.ILog log = Netop.Core.Log.LogManager.GetLogger("Application.Log");
log. Debug(“......”);
顺便说一下,在
<Application.Cache>
...
<ApplicationLog>Application.Log</ApplicationLog>
...
</Application.Cache>
中的<ApplicationLog>Application.Log</ApplicationLog>就是指着Application.Log的Log配置,在Netop.Core.Cache.MicrosoftEnterpriseLibraryCache,Netop.Core中已可根据配置记录相关日志。
其它的一些小服务,如验证码等等简单易用的就不说了。
轻量级的.NET对象查找服务和AOP开发框架源码Netop.Core3.5下载地址:http://download.csdn.NET/detail/tom_cat_xie_jxdy/9837303
轻量级的.NET对象查找服务和AOP开发框架测试源码 下载地址:http://download.csdn.Net/detail/tom_cat_xie_jxdy/9837278
Netop.Core--轻量级的.NET对象查找服务和AOP开发框架文档下载地址:http://download.csdn.net/detail/tom_cat_xie_jxdy/9838212