Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 private void tbStart_Click(object sender, EventArgs e)
 {
     tbStart.Enabled = false;
     MonitorCache.GetInstance().PushMessage(new CacheMessage {
         Message = "服务正在启动中..."
     }, CacheEnum.FormMonitor);
     worker.RunWorkerAsync();
 }
Ejemplo n.º 4
0
 protected override void OnStart(string[] args)
 {
     MonitorCache.GetInstance().PushMessage(new CacheMessage {
         Message = "服务正在启动中..."
     }, CacheEnum.LogMonitor);
     _worker.RunWorkerAsync();
     _logthread.Start();
 }
Ejemplo n.º 5
0
 protected override void OnStop()
 {
     if (host != null && host.State == CommunicationState.Opened && !_isError)
     {
         host.Close();
         MonitorCache.GetInstance().PushMessage(new CacheMessage {
             Message = "服务器已停止"
         }, CacheEnum.LogMonitor);
     }
 }
Ejemplo n.º 6
0
        public void StartAllMonitors_WithNoMonitorsAdded_DoesNothing()
        {
            // Arrange
            var monitorCache = new MonitorCache();

            // Act
            TestDelegate test = () => monitorCache.StartAllMonitors();

            // Assert
            Assert.That(test, Throws.Nothing);
        }
Ejemplo n.º 7
0
        public void AddMonitor_BeforeStarted_DoesNothing()
        {
            // Arrange
            var monitorCache = new MonitorCache();

            // Act
            monitorCache.AddMonitor(monitor);

            // Assert
            mockMonitor.Verify(m => m.StartMonitoring(), Times.Never);
        }
Ejemplo n.º 8
0
        public void AddMonitor_AfterStarted_StartsSenderMonitor()
        {
            // Arrange
            var monitorCache = new MonitorCache();

            monitorCache.StartAllMonitors();

            // Act
            monitorCache.AddMonitor(monitor);

            // Assert
            mockMonitor.Verify(m => m.StartMonitoring(), Times.Once);
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        public void StartAllMonitors_WithMonitorsAdded_StartsTheMonitors()
        {
            // Arrange
            var monitorCache = new MonitorCache();

            monitorCache.AddMonitor(monitor);
            monitorCache.AddMonitor(monitor2);

            // Act
            monitorCache.StartAllMonitors();

            // Assert
            mockMonitor.Verify(m => m.StartMonitoring(), Times.Once);
            mockMonitor2.Verify(m => m.StartMonitoring(), Times.Once);
        }
Ejemplo n.º 11
0
        public void StartAllMonitors_WhenAlreadyStarted_DoesNothing()
        {
            // Arrange
            var monitorCache = new MonitorCache();

            monitorCache.AddMonitor(monitor);
            monitorCache.StartAllMonitors();
            mockMonitor.Invocations.Clear();

            // Act
            monitorCache.StartAllMonitors();

            // Assert
            mockMonitor.Verify(m => m.StartMonitoring(), Times.Never);
        }
Ejemplo n.º 12
0
 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);
     //}
 }
Ejemplo n.º 13
0
 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;
     }
 }
Ejemplo n.º 14
0
        public Builder(string name)
        {
            this.name          = name;
            TopicRouter        = new TopicRouter();
            MonitorCache       = new MonitorCache();
            RequestRouter      = new RequestRouter();
            PackageFactory     = new PackageFactory();
            TopicDispatcher    = new TopicDispatcher();
            RequestDispatcher  = new RequestDispatcher();
            SubscriptionsCache = new SubscriptionsCache();
            SerializerCache    = new SerializerCache();

            SenderCache     = new SenderCache(RequestRouter, MonitorCache);
            ReceiverCache   = new ReceiverCache(MonitorCache);
            PublisherCache  = new PublisherCache(MonitorCache);
            SubscriberCache = new SubscriberCache(TopicRouter, MonitorCache, SubscriptionsCache);
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
        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;
            }
        }
Ejemplo n.º 17
0
 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;
     }
 }
Ejemplo n.º 18
0
        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");
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        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());
            }
        }
Ejemplo n.º 22
0
 public void Clear()
 {
     MonitorCache.GetInstance().Clear(CacheEnum.FormMonitor);
 }
Ejemplo n.º 23
0
 public void Add(CacheMessage message)
 {
     MonitorCache.GetInstance().PushMessage(message, CacheEnum.FormMonitor);
 }
Ejemplo n.º 24
0
 private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     MonitorCache.GetInstance().PushMessage(new CacheMessage {
         Message = "服务器已启动"
     }, CacheEnum.LogMonitor);
 }