/// <summary> /// 初始化 需要处理数据的信息 /// </summary> /// <param name="alarmService"></param> /// <param name="meterageService"></param> public OaAlarmModule(IAlarmService alarmService, IMeterageService meterageService) { _clientInfo = CallContext.GetData <ClientInfo>("clientInfo"); _dataOaQueue = RedisHelper.Get <DataOaQueue>(_clientInfo.Database); if (_dataOaQueue == null) { _dataOaQueue = new DataOaQueue(); } _alarmCount = Convert.ToInt32(AppsettingsHelper.GetConfigString("AlarmCount")); _alarmService = alarmService; _meterageService = meterageService; }
/// <summary> /// 构造函数 /// </summary> protected BaseRepository() { ClientInfo clientInfo = CallContext.GetData <ClientInfo>("clientInfo"); string ip = AppsettingsHelper.GetConfigString("DataBase", "Ip"); string account = AppsettingsHelper.GetConfigString("DataBase", "Account"); string password = AppsettingsHelper.GetConfigString("DataBase", "Password"); string connectionStr = $"Database='{clientInfo.Database}';Data Source='{ip}';User Id='{account}';Password='******';"; //string connectionStr = AppsettingsHelper.GetConfigString("DataBase", "ConnectionString"); DbContext.Init(connectionStr); Db = DbContext.GetContext().Db; DbEntity = new SimpleClient <TEntity>(Db); }
static void Main(string[] args) { var basePath = Environment.CurrentDirectory; string redisIP = AppsettingsHelper.GetConfigString("RedisConfig", "IP"); string redisPassword = AppsettingsHelper.GetConfigString("RedisConfig", "Password"); LoggerRepository = LogManager.CreateRepository("BPDM.Logger"); XmlConfigurator.Configure(LoggerRepository, new FileInfo("Log4net.config")); RedisHelper.Initialization(new CSRedis.CSRedisClient($"{redisIP},password={redisPassword},defaultDatabase=13,poolsize=50,ssl=false,writeBuffer=10240,prefix=key前辍")); IServiceCollection services = new ServiceCollection(); services.AddAutoMapper(); services.AddTransient <IHandshakeModule, HandshakeModule>(); services.AddTransient <ISiteModule, SiteModule>(); services.AddTransient <IDataOaModule, DataOaModule>(); services.AddTransient <IDataTwModule, DataTwModule>(); services.AddTransient <IExtractModule, ExtractModule>(); services.AddTransient <IConfigModule, ConfigModule>(); services.AddTransient <IOaAlarmModule, OaAlarmModule>(); services.AddSingleton <ILoggerHelper, LogHelper>(); services.AddTransient <IStopModule, StopModule>(); ContainerBuilder builder = new ContainerBuilder(); var servicesDllFile = Path.Combine(basePath, "Vs.Service.dll"); var assemblysServices = Assembly.LoadFile(servicesDllFile); builder.RegisterAssemblyTypes(assemblysServices) .AsImplementedInterfaces() .InstancePerDependency(); var repositoryDllFile = Path.Combine(basePath, "Vs.Repository.dll"); var assemblysRepository = Assembly.LoadFile(repositoryDllFile); builder.RegisterAssemblyTypes(assemblysRepository).AsImplementedInterfaces().InstancePerDependency(); builder.Populate(services); container = builder.Build(); LoggerHelper = container.Resolve <ILoggerHelper>(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); using (StreamReader sr = new StreamReader(Path.Combine(basePath, "clientInfo.json"), Encoding.GetEncoding("gb2312"))) { string json = sr.ReadToEnd(); ClientInfoList = JsonConvert.DeserializeObject <List <ClientInfo> >(json); } string address = AppsettingsHelper.GetConfigString("SocketServer", "Address"); int port = Convert.ToInt32(AppsettingsHelper.GetConfigString("SocketServer", "port")); IPAddress ip = IPAddress.Parse(address); Socket serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //绑定IP地址:端口 serverSocket.Bind(new IPEndPoint(ip, port)); //设定最多10个排队连接请求 serverSocket.Listen(10); //线程池的容量过去设置 int workerThreads_max = 0; int completionPortThreads_max = 0; int workerThreads_min = 0; int completionPortThreads_min = 0; //获取当前系统最大、最小线程池容量 ThreadPool.GetMaxThreads(out workerThreads_max, out completionPortThreads_max); ThreadPool.GetMinThreads(out workerThreads_min, out completionPortThreads_min); //自定义线程池容量 workerThreads_max = 12; // 12; completionPortThreads_max = 12; //12; workerThreads_min = 5; // 5; completionPortThreads_min = 5; // 5; ThreadPool.SetMinThreads(workerThreads_min, completionPortThreads_min); // set min thread to 5 ThreadPool.SetMaxThreads(workerThreads_max, completionPortThreads_max); // set max thread to 12 ThreadPool.QueueUserWorkItem(SendEmail); //启动发送邮件 while (true) { try { Socket clientSocket = serverSocket.Accept(); Console.WriteLine($"{clientSocket.RemoteEndPoint}连接成功!时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); SocketMiddleware socket = new SocketMiddleware(clientSocket); ThreadPool.QueueUserWorkItem(ExcuteAnalyse, socket); } catch (Exception e) { LoggerHelper.Error(typeof(Program), e.Message, e); Console.WriteLine(e); } } }