Exemple #1
0
        public string Promise(string name, string key, string value)
        {
            //为了兼容之前的系统,对sendMonitorMsg 做特殊处理
            if (name != null && name == "sendMonitorMsg")
            {
                return(PromisePost(name, key, value));
            }
            WebClient wc  = new WebClient();
            string    url = string.Empty;

            if (string.IsNullOrEmpty(CommonConfig.WebStateCenterUrl))
            {
                throw new Exception("未配置节点:WebStateCenterUrl");
            }
            try
            {
                string ekey = string.IsNullOrEmpty(key) ? "" : EncodeHelper.UrlEncode(key);
                string eVal = string.IsNullOrEmpty(value) ? "" :   EncodeHelper.UrlEncode(value);
                url = CommonConfig.WebStateCenterUrl + "?op=" + name + "&key=" + ekey + "&val=" + eVal;
                if (CommonConfig.IsEncrypt)
                {
                    url = url + "&en=" + EncodeHelper.UrlEncode(EncryptAESHelper.Encrypt((name + DateTime.Now.ToString("dd")), CommonConfig.EncryptKey));
                }
                Byte[] pageData = wc.DownloadData(url);
                string result   = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句
                return(result);
            }
            catch (Exception ex)
            {
                CommonLog.InnerErrorLog.Error("访问站点出错:" + url + "  |" + ex.ToString());
                return(string.Empty);
            }
            finally
            {
                wc.Dispose();
            }
        }
Exemple #2
0
        public string PromisePost(string name, string key, string value)
        {
            WebClient wc = new WebClient();

            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            string postString = string.Empty;

            if (string.IsNullOrEmpty(CommonConfig.WebStateCenterUrl))
            {
                throw new Exception("未配置节点:WebStateCenterUrl");
            }
            try
            {
                string ekey = string.IsNullOrEmpty(key) ? "" : EncodeHelper.UrlEncode(key);
                string eVal = string.IsNullOrEmpty(value) ? "" : EncodeHelper.UrlEncode(value);
                postString = "op=" + name + "&key=" + ekey + "&val=" + eVal;
                if (CommonConfig.IsEncrypt)
                {
                    postString = postString + "&en=" + EncodeHelper.UrlEncode(EncryptAESHelper.Encrypt((name + DateTime.Now.ToString("dd")), CommonConfig.EncryptKey));
                }
                byte[] postData = Encoding.UTF8.GetBytes(postString);

                Byte[] pageData = wc.UploadData(CommonConfig.WebStateCenterUrl, "POST", postData); //得到返回字符流
                string result   = Encoding.Default.GetString(pageData);                            //如果获取网站页面采用的是GB2312,则使用这句
                return(result);
            }
            catch (Exception ex)
            {
                CommonLog.InnerErrorLog.Error("访问站点出错:" + CommonConfig.WebStateCenterUrl + "  |" + ex.ToString());
                return(string.Empty);
            }
            finally
            {
                wc.Dispose();
            }
        }
Exemple #3
0
        public void ProcessRequest(HttpContext context)
        {
            string strOp  = context.Request.QueryString["op"];
            string strKey = context.Request.QueryString["key"];
            string strVal = context.Request.QueryString["val"];
            string strEn  = context.Request.QueryString["en"];

            if (string.IsNullOrEmpty(context.Request.Form["op"]) == false)
            {
                strOp = context.Request.Form["op"];
            }
            if (string.IsNullOrEmpty(context.Request.Form["key"]) == false)
            {
                strKey = context.Request.Form["key"];
            }
            if (string.IsNullOrEmpty(context.Request.Form["val"]) == false)
            {
                strVal = context.Request.Form["val"];
            }
            if (string.IsNullOrEmpty(context.Request.Form["en"]) == false)
            {
                strEn = context.Request.Form["en"];
            }

            if (string.IsNullOrEmpty(strEn) && CommonConfig.IsEncrypt)
            {
                Return(context, "数据必须进行加密");
                return;
            }
            else if (string.IsNullOrEmpty(strEn))
            {
                //直接继续
            }
            else
            {
                try
                {
                    //存在加密信息时,进行解密处理
                    string strRaw = EncryptAESHelper.Decrypt(strEn, CommonConfig.EncryptKey);
                    if (strRaw != (strOp + DateTime.Now.ToString("dd")))
                    {
                        Return(context, "密钥无法验证通过");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Return(context, "解密出错:" + ex.ToString());
                    return;
                }
            }


            if (string.IsNullOrEmpty(strOp))
            {
                Return(context, "Hello, here is main");
            }
            else
            {
                if (string.IsNullOrEmpty(strOp) == false)
                {
                    strOp = HttpUtility.UrlDecode(strOp);
                }
                if (string.IsNullOrEmpty(strKey) == false)
                {
                    strKey = HttpUtility.UrlDecode(strKey);
                }
                if (string.IsNullOrEmpty(strVal) == false)
                {
                    strVal = HttpUtility.UrlDecode(strVal);
                }
                switch (strOp)
                {
                case "isAlive":
                    Return(context, "1");
                    break;

                case "getBeatTime":
                    Return(context, MainExe.GetBeatTime(strKey));
                    break;

                case "beat":
                    Return(context, MainExe.Beat(strKey, strVal) ? "1" : "0");
                    break;

                case "isKeyAlived":
                    Return(context, MainExe.IsAlved(strKey) ? "1" : "0");
                    break;

                case "sendMsg":
                    MainExe.SendMsg(strKey, strVal);
                    Return(context, "1");
                    break;

                case "getMSMQConfig":
                    Return(context, MonitorExe.getMSMQConfig());
                    break;

                case "getLastConfigTime":
                    Return(context, MonitorExe.getLastConfigTime());
                    break;

                case "sendMonitorMsg":
                    MonitorExe.addMsg(strVal);
                    Return(context, "1");
                    break;
                }
            }
        }