diff --git a/OS.Common/Modules/AsynModule/AsynUtil.cs b/OS.Common/Modules/AsynModule/AsynUtil.cs index 112da7d..b6cdbda 100644 --- a/OS.Common/Modules/AsynModule/AsynUtil.cs +++ b/OS.Common/Modules/AsynModule/AsynUtil.cs @@ -1,5 +1,5 @@ using System; -using System.Collections.Generic; +using System.Collections.Concurrent; namespace OS.Common.Modules.AsynModule { @@ -8,7 +8,7 @@ namespace OS.Common.Modules.AsynModule /// public static class AsynUtil { - private static IDictionary _asynDirs = new Dictionary(); + private static readonly ConcurrentDictionary _asynDirs = new ConcurrentDictionary();//Dictionary(); /// /// 通过模块名称获取异步处理模块实例 /// @@ -21,11 +21,10 @@ namespace OS.Common.Modules.AsynModule if (_asynDirs.ContainsKey(asynModule)) return _asynDirs[asynModule]; - var asyn = OsConfig.Provider.GetAsynBlock(asynModule) ?? new AsynBlock(); - _asynDirs.Add(asynModule, asyn); - + _asynDirs.TryAdd(asynModule,asyn); + return asyn; } diff --git a/OS.Common/Modules/CacheModule/CacheUtil.cs b/OS.Common/Modules/CacheModule/CacheUtil.cs index 6fa33fd..4291388 100644 --- a/OS.Common/Modules/CacheModule/CacheUtil.cs +++ b/OS.Common/Modules/CacheModule/CacheUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; namespace OS.Common.Modules.CacheModule @@ -8,7 +9,7 @@ namespace OS.Common.Modules.CacheModule /// public static class CacheUtil { - private static IDictionary _cacheDirs=new Dictionary(); + private static readonly ConcurrentDictionary _cacheDirs = new ConcurrentDictionary(); /// /// 通过模块名称获取 @@ -24,7 +25,7 @@ namespace OS.Common.Modules.CacheModule return _cacheDirs[cacheModule]; var cache = OsConfig.Provider.GetCache(cacheModule) ?? new Cache(); - _cacheDirs.Add(cacheModule, cache); + _cacheDirs.TryAdd(cacheModule, cache); return cache; } diff --git a/OS.Common/Modules/DirConfigModule/DirConfigUtil.cs b/OS.Common/Modules/DirConfigModule/DirConfigUtil.cs index 6008582..2b016b3 100644 --- a/OS.Common/Modules/DirConfigModule/DirConfigUtil.cs +++ b/OS.Common/Modules/DirConfigModule/DirConfigUtil.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Concurrent; using OS.Common.ComModels; namespace OS.Common.Modules.DirConfigModule @@ -8,7 +8,7 @@ namespace OS.Common.Modules.DirConfigModule /// public static class DirConfigUtil { - private static IDictionary _dirConfigDirs = new Dictionary(); + private static readonly ConcurrentDictionary _dirConfigDirs = new ConcurrentDictionary(); /// /// 通过模块名称获取 @@ -24,7 +24,7 @@ namespace OS.Common.Modules.DirConfigModule return _dirConfigDirs[dirConfigModule]; var dirConfig = OsConfig.Provider.GetDirConfig(dirConfigModule) ?? new DirConfig(); - _dirConfigDirs.Add(dirConfigModule, dirConfig); + _dirConfigDirs.TryAdd(dirConfigModule, dirConfig); return dirConfig; } diff --git a/OS.Common/Modules/LogModule/LogUtil.cs b/OS.Common/Modules/LogModule/LogUtil.cs index 15611b8..43f8485 100644 --- a/OS.Common/Modules/LogModule/LogUtil.cs +++ b/OS.Common/Modules/LogModule/LogUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using OS.Common.Modules.AsynModule; @@ -98,12 +99,10 @@ namespace OS.Common.Modules.LogModule get; set; } - - - private static Dictionary _logDirs= - new Dictionary(); - + private static readonly ConcurrentDictionary _logDirs = + new ConcurrentDictionary(); + /// /// 通过模块名称获取日志模块实例 /// @@ -118,7 +117,7 @@ namespace OS.Common.Modules.LogModule return _logDirs[logModule]; var log = OsConfig.Provider.GetLogWrite(logModule) ?? new LogWriter(); - _logDirs.Add(logModule, log); + _logDirs.TryAdd(logModule, log); return log; } diff --git a/OS.Common/Modules/LogModule/LogWriter.cs b/OS.Common/Modules/LogModule/LogWriter.cs index 920029f..3997bbd 100644 --- a/OS.Common/Modules/LogModule/LogWriter.cs +++ b/OS.Common/Modules/LogModule/LogWriter.cs @@ -7,7 +7,7 @@ namespace OS.Common.Modules.LogModule internal class LogWriter : ILogWriter { private readonly string _logBaseDirPath = null; - private const string logFormat = "{0:T} Key:{1} Detail:{2}"; + private const string _logFormat = "{0:T} Key:{1} Detail:{2}"; public LogWriter() { @@ -39,7 +39,8 @@ namespace OS.Common.Modules.LogModule using (StreamWriter sw = new StreamWriter(filePath, true, Encoding.Default)) { - sw.WriteLine(format: logFormat, arg0: DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), arg1: info.MsgKey, arg2: info.Msg); + // ReSharper disable once FormatStringProblem + sw.WriteLine(format: _logFormat, arg0: DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), arg1: info.MsgKey, arg2: info.Msg); sw.Close(); } } diff --git a/OS.Common/OS.Common.csproj b/OS.Common/OS.Common.csproj index d2bc5a8..6ba995f 100644 --- a/OS.Common/OS.Common.csproj +++ b/OS.Common/OS.Common.csproj @@ -9,7 +9,7 @@ Properties OS.Common OS.Common - v4.5 + v4.0 512 diff --git a/OS.Common/OSConfig.cs b/OS.Common/OSConfig.cs index 1a92cb3..4ce3c81 100644 --- a/OS.Common/OSConfig.cs +++ b/OS.Common/OSConfig.cs @@ -15,7 +15,7 @@ namespace OS.Common /// internal static ModuleBaseProvider Provider { - get { return _provider ?? new ModuleBaseProvider(); } + get { return _provider ?? (_provider = new ModuleBaseProvider()); } } diff --git a/OS.Common/Properties/AssemblyInfo.cs b/OS.Common/Properties/AssemblyInfo.cs index f0c62d2..d28dbe3 100644 --- a/OS.Common/Properties/AssemblyInfo.cs +++ b/OS.Common/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -32,5 +31,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.17.0")] -[assembly: AssemblyFileVersion("1.1.17.0")] +[assembly: AssemblyVersion("1.2.35.0")] +[assembly: AssemblyFileVersion("1.2.35.0")]