private void worker_DoWork(object sender, DoWorkEventArgs e) { host = null; try { host = new ServiceHost(typeof(JsonHost)); host.Open(); started = true; _isError = false; var endpoint = host.Description.Endpoints.FirstOrDefault(t => t.Contract.Name == typeof(JsonHost).Name); if (endpoint != null) { tssHostIp.Text = "服务地址:" + endpoint.Address.Uri.AbsoluteUri; } if (!host.Ping()) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "服务器启动超时" }, CacheEnum.FormMonitor); } } catch (Exception ex) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = ex.Message }, CacheEnum.FormMonitor); _isError = true; } }
public override void OnExceptionOccurs(ActionContext context) { try { if (!context.Parameters.ContainsKey(Common.MapperKey)) { base.OnExceptionOccurs(context); return; } ISqlMapper mapper = context.Parameters[Common.MapperKey] as ISqlMapper; try { if (mapper.IsSessionStarted) { mapper.RollBackTransaction(); } } catch (NullReferenceException ex) { } base.OnExceptionOccurs(context); } catch (Exception ex) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "在OnExceptionOccurs中报错--Message:" + ex.Message }, SOAFramework.Library.CacheEnum.FormMonitor); } }
private void tbStart_Click(object sender, EventArgs e) { tbStart.Enabled = false; MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "服务正在启动中..." }, CacheEnum.FormMonitor); worker.RunWorkerAsync(); }
protected override void OnStart(string[] args) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "服务正在启动中..." }, CacheEnum.LogMonitor); _worker.RunWorkerAsync(); _logthread.Start(); }
protected override void OnStop() { if (host != null && host.State == CommunicationState.Opened && !_isError) { host.Close(); MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "服务器已停止" }, CacheEnum.LogMonitor); } }
private void Timer_Run(object state) { //处理日志信息 List <CacheMessage> list = MonitorCache.GetInstance().PopMessages(CacheEnum.LogMonitor); while (list.Count > 0) { CacheMessage message = list[0]; string text = string.Format("{0} -- Message:{1} -- Stack Trace:{2}", message.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss"), message.Message, message.StackTrace); //_logger.Write(text, false); list.Remove(message); } }
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (host.State == CommunicationState.Opened) { tbStart.Enabled = false; tbStop.Enabled = true; MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "服务器已启动" }, CacheEnum.FormMonitor); } else { tbStart.Enabled = true; tbStop.Enabled = false; } }
private void tbStop_Click(object sender, EventArgs e) { if (host != null && host.State == CommunicationState.Opened && !_isError) { host.Close(); tbStart.Enabled = true; tbStop.Enabled = false; MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "服务器已停止" }, CacheEnum.FormMonitor); } //if (domain != null) //{ // AppDomain.Unload(domain); //} }
private static void Loging() { SimpleLogger _logger = new SimpleLogger(_logPath); while (1 == 1) { //处理日志信息 List <CacheMessage> list = MonitorCache.GetInstance().PopMessages(CacheEnum.LogMonitor); while (list.Count > 0) { CacheMessage message = list[0]; string text = string.Format("{0} -- Message:{1} -- Stack Trace:{2}", message.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss"), message.Message, message.StackTrace); _logger.Write(text, false); list.Remove(message); } Thread.Sleep(100); } }
private void worker_DoWork(object sender, DoWorkEventArgs e) { host = null; try { host = new ServiceHost(typeof(JsonHost)); host.Open(); _isError = false; var endpoint = host.Description.Endpoints.FirstOrDefault(t => t.Contract.Name == typeof(JsonHost).Name); } catch (Exception ex) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = ex.Message }, CacheEnum.LogMonitor); _isError = true; } }
public override bool OnActionExecuting(ActionContext context) { try { ISqlMapper mapper = Mapper.Instance(); if (!mapper.IsSessionStarted) { mapper.BeginTransaction(); } context.Parameters[Common.MapperKey] = mapper; return(base.OnActionExecuting(context)); } catch (Exception ex) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "在OnActionExecuting中报错--Message:" + ex.Message }, SOAFramework.Library.CacheEnum.FormMonitor); throw ex; } }
private void timer1_Tick(object sender, EventArgs e) { //处理日志信息 List <CacheMessage> list = MonitorCache.GetInstance().PopMessages(CacheEnum.FormMonitor); while (list.Count > 0) { if (lbMessage.Items.Count > 100000) { lbMessage.Items.Clear(); } else { CacheMessage message = list[0]; string text = string.Format("{0} -- {1}\r\n", message.TimeStamp.ToString("yyyy-MM-dd HH:mm:ss"), message.Message); lbMessage.Items.Insert(0, text); list.Remove(message); } } tssTimer.Text = "时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); }
public UserEntireInfo GetCurrentUser(string token = null) { ISqlMapper mapper = Common.GetMapperFromSession(); if (string.IsNullOrEmpty(token)) { token = ServiceSession.Current.Context.Parameters["token"].ToString(); } var u = GetUserEntireInfoFromCache(token); if (u == null) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "user is null" }, SOAFramework.Library.CacheEnum.FormMonitor); UserDao userdao = new UserDao(mapper); RoleDao roledao = new RoleDao(mapper); UserInfoDao uidao = new UserInfoDao(mapper); LogonHistoryDao lhdao = new LogonHistoryDao(mapper); var logonhistory = lhdao.Query(new LogonHistoryQueryForm { Token = token }).FirstOrDefault(); string userid = logonhistory.UserID; var user = userdao.Query(new UserQueryForm { ID = userid }).FirstOrDefault(); var userinfo = uidao.Query(new UserInfoQueryForm { ID = userid }).FirstOrDefault(); var roles = roledao.QueryRoleByUserID(userid); u = new UserEntireInfo { User = user, Role = roles, UserInfo = userinfo, }; } return(u); }
public T Execute <T>(IWeiXinRequest <T> request) where T : WeiXinBaseResponse { //如果没有token,先去获得token if (string.IsNullOrEmpty(request.AccessToken)) { SignIn signin = new SignIn(); string token = signin.Do(); request.AccessToken = token; ApiHelper.SetTokenIntoCache(token); } string fullurl = UrlConfig.Url + request.GetApi(); T t = default(T); var type = request.GetType(); var querystringproperty = type.GetProperty("QueryString", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); object querystring = null; if (querystringproperty != null) { querystring = querystringproperty.GetValue(request, null); } string response = ""; switch (request.RequestType) { case RequestType.Get: response = ApiHelper.Get <T>(request.AccessToken, fullurl, querystring); break; case RequestType.Post: object postdata = null; var postdataproperty = type.GetProperty("PostData", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); if (postdataproperty != null) { postdata = postdataproperty.GetValue(request, null); } fullurl = HttpHelper.CombineUrl(fullurl, querystring); response = ApiHelper.Post <T>(request.AccessToken, fullurl, postdata); break; } t = JsonHelper.Deserialize <T>(response); if (t != null) { t.Request = fullurl; t.Response = response; } switch (t.errcode) { //token过期 case "40001": SignIn signin = new SignIn(); string token = signin.Do(); request.AccessToken = token; ApiHelper.SetTokenIntoCache(token); t = this.Execute(request); break; default: if (t.errcode != "0" && !string.IsNullOrEmpty(t.errcode)) { string msg = "code=" + t.errcode + ";msg=" + t.errmsg + ";request=" + t.Request + ";response=" + t.Response; MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = msg }, CacheEnum.FormMonitor); throw new WeiXinException(t.errcode, t.errmsg); } break; } return(t); }
Stream IDispatcher.Execute(string typeName, string functionName, Dictionary <string, object> args, List <BaseFilter> filterList, bool enableConsoleMonitor) { try { string interfaceName = ServicePool.Instance.GetIntefaceName(typeName, functionName); bool callSuccess = false; Stream stream = null; while (!callSuccess) { string url = ServicePool.Instance.GetMinCpuDispatcher(); //分配到自己 if (string.IsNullOrEmpty(url) || url == "Server") { stream = ServicePool.Instance.Execute(typeName, functionName, args); callSuccess = true; } else//分配到别的服务器 { #region 分发到其他服务器 IDispatcherExecuter exec = DispatcherExecuterFactory.CreateExecuter(DispatcherExecuterType.Http); string result = null; try { MonitorCache.GetInstance().PushMessage( new CacheMessage { Message = string.Format("接口:{0}开始分发到服务:{1}!", interfaceName, url), MessageType = enumMessageType.Info, TimeStamp = DateTime.Now }, CacheEnum.LogMonitor); result = exec.Execute(url, typeName, functionName, args); MonitorCache.GetInstance().PushMessage( new CacheMessage { Message = string.Format("接口:{0}已经分发到服务:{1}并执行成功!", interfaceName, url), MessageType = enumMessageType.Info, TimeStamp = DateTime.Now }, CacheEnum.LogMonitor); stream = new MemoryStream(Encoding.UTF8.GetBytes(result)); callSuccess = true; } catch (TimeoutException ex) { ServicePool.Instance.RemoveDispatcher(url); MonitorCache.GetInstance().PushMessage( new CacheMessage { Message = string.Format("接口:{0}已经分发到服务:{1},连接服务器失败!", interfaceName, url), MessageType = enumMessageType.Info, TimeStamp = DateTime.Now }, CacheEnum.LogMonitor); } #endregion } } return(stream); } catch (Exception ex) { ServerResponse response = new ServerResponse(); response.IsError = true; response.ErrorMessage = ex.Message; return(response.ToStream()); } }
public void Clear() { MonitorCache.GetInstance().Clear(CacheEnum.FormMonitor); }
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "服务器已启动" }, CacheEnum.LogMonitor); }
public void Add(CacheMessage message) { MonitorCache.GetInstance().PushMessage(message, CacheEnum.FormMonitor); }