Netop.Core主要提供的服務是類工廠服務及AOP服務,當然還其它一些小服務: 一、對話上下文Netop.Core.Context.SessionContext 此對話上下文可用在桌面程式和ASP.NET程式,可用SetData和GetData在上下文中傳遞數據。方法有: public stat ...
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