public string ConvertTo(object obj)
        {
            if (obj == null)
            {
                return("");
            }

            UnitDataCollection udc = null;

            if (obj is UnitDataCollection)
            {
                udc = (UnitDataCollection)obj;
            }
            else
            {
                throw new Exception("QueryByPage2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }
            FrameDLRObject rtn = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);

            if (udc.QueryTable != null)
            {
                rtn.SetValue("page", udc.CurrentPage + "");
                rtn.SetValue("total", udc.TotalRow + "");

                rtn.SetValue("rows", udc.QueryTable.Rows);
            }

            return(rtn.ToJSONString());
        }
        /// <summary>
        /// 将对象写入session
        /// </summary>
        /// <param name="session"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetObject(this ISession session, string key, object value)
        {
            if (value == null)
            {
                session.Remove(key);
                return;
            }
            var    t = value.GetType();
            string assemblyQualifiedName = t.AssemblyQualifiedName;
            var    controlType           = t.FullName;
            string assemblyInformation   = assemblyQualifiedName.Substring(assemblyQualifiedName.IndexOf(","));
            var    assemblefullname      = controlType + assemblyInformation;

            if (value is FrameDLRObject)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(((FrameDLRObject)value).ToJSONString()));
            }
            else if (value is IJSONable)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(((IJSONable)value).ToJSONString()));
            }
            else if (value is string)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(ComFunc.nvl(value)));
            }
            else if (value is int)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(ComFunc.nvl(value)));
            }
            else if (value is long)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(ComFunc.nvl(value)));
            }
            else if (value is double)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(ComFunc.nvl(value)));
            }
            else if (value is float)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(ComFunc.nvl(value)));
            }
            else if (value is decimal)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(ComFunc.nvl(value)));
            }
            else if (value is DateTime)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(((DateTime)value).ToString("yyyy/MM/dd HH:mm:ss fff")));
            }
            else if (value is bool)
            {
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(ComFunc.nvl(value)));
            }
            else
            {
                FrameDLRObject dobj = FrameDLRObject.CreateInstance(value);
                session.SetString(key, assemblefullname + ";" + ComFunc.Base64Code(dobj.ToJSONString()));
            }
        }
Example #3
0
        /// <summary>
        /// 設置appSetting的值
        /// </summary>
        /// <param name="key">鍵</param>
        /// <param name="value">值</param>
        public void SetConfiguration(string key, object value)
        {
            FrameDLRObject config = FrameDLRObject.CreateInstance(File.ReadAllText(ConfigFilePath), Constants.FrameDLRFlags.SensitiveCase);

            config.SetValue(key, value);
            File.WriteAllText(ConfigFilePath, config.ToJSONString());
            _config.Reload();
        }
            /// <summary>
            /// 执行接口发送操作
            /// </summary>
            /// <param name="url">目标地址</param>
            /// <param name="data">请求的参数,json格式</param>
            /// <returns></returns>
            public string Send(string url, object data)
            {
                var            rtn = "";
                var            dt  = DateTime.Now;
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

                try
                {
                    FrameDLRObject content = (FrameDLRObject)FrameDLRObject.CreateInstance(data, EFFC.Frame.Net.Base.Constants.FrameDLRFlags.SensitiveCase);
                    Console.WriteLine($"body={content.ToJSONString()}");
                    req.Headers.Add("X-HW-ID", APP_ID);
                    req.Headers.Add("X-HW-APPKEY", Token);

                    byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(content.ToJSONString());
                    req.Method           = "POST";
                    req.ContentType      = "application/json;charset=utf-8";
                    req.ContentLength    = requestBytes.Length;
                    req.Timeout          = 60000;
                    req.ReadWriteTimeout = 60000;
                    Stream requestStream = req.GetRequestStream();
                    requestStream.Write(requestBytes, 0, requestBytes.Length);
                    requestStream.Close();
                    HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                    Console.WriteLine($"send cast time:{(DateTime.Now - dt).TotalMilliseconds}ms");
                    StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.UTF8);
                    rtn           = sr.ReadToEnd();
                    requestStream = null;
                    sr.Close();
                    res.Close();
                }
                catch (WebException ex)
                {
                    var rep = ex.Response;
                    var str = new StreamReader(rep.GetResponseStream(), System.Text.Encoding.UTF8).ReadToEnd();
                    rtn = str;
                }
                finally
                {
                    req = null;
                }

                return(rtn);
            }
Example #5
0
        public string ConvertTo(object obj)
        {
            DataTableStd dtt = null;

            if (obj is DataTableStd)
            {
                dtt = (DataTableStd)obj;
            }
            else
            {
                throw new Exception("DataTable2Json无法转化" + obj.GetType().FullName + "类型数据!");
            }
            FrameDLRObject data = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);

            data.SetValue("rows", dtt.Rows);

            return(data.ToJSONString());
        }
Example #6
0
        /// <summary>
        /// 执行Rest接口发送操作,POST,PATCH,PUT操作,基于json的数据结构
        /// </summary>
        /// <param name="url">目标地址</param>
        /// <param name="data">请求的参数,json格式</param>
        /// <param name="header">请求的header</param>
        /// <param name="method">请求的method,POST,PATCH,PUT</param>
        /// <returns></returns>
        public virtual string Send(string url, object data, object header = null, string method = "POST")
        {
            FrameDLRObject content = (FrameDLRObject)FrameDLRObject.CreateInstance(data, FrameDLRFlags.SensitiveCase);

            return(SendHttpRequest(url, content.ToJSONString(), header, method));
        }
Example #7
0
        protected override void SetResponseContent(WebParameter p, GoData d)
        {
            var dt = DateTime.Now;

            if (!string.IsNullOrEmpty(d.RedirectUri))
            {
                p.CurrentHttpContext.Response.Redirect(d.RedirectUri);
                return;
            }

            var    obj   = CurrentContext.Request.Headers;
            String agent = ComFunc.nvl(obj["USER-AGENT"]);

            if (d.ResponseData == null)
            {
                throw new Exception("ResponseData is null!");
            }
            CurrentContext.Response.StatusCode = 200;

            if (d.ContentType == GoResponseDataType.Pic_Jpg)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.Headers.Add("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/jpeg";
                CurrentContext.Response.Body.Write(b, 0, b.Length);
            }
            else if (d.ContentType == GoResponseDataType.Pic_Gif)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.Headers.Add("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/gif";
                CurrentContext.Response.Body.Write(b, 0, b.Length);
            }
            else if (d.ContentType == GoResponseDataType.Pic_Bmp)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.Headers.Add("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/bmp";
                CurrentContext.Response.Body.Write(b, 0, b.Length);
            }
            else if (d.ContentType == GoResponseDataType.Pic_png)
            {
                byte[] b = null;
                if (d.ResponseData is Stream)
                {
                    b = StreamToBytes((Stream)d.ResponseData);
                }
                else
                {
                    b = ((byte[])d.ResponseData);
                }

                CurrentContext.Response.Headers.Add("Content-Length", b.Length + "");
                CurrentContext.Response.ContentType = "image/png";
                CurrentContext.Response.Body.Write(b, 0, b.Length);
            }
            else if (d.ContentType == GoResponseDataType.Excel)
            {
                CurrentContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + ComFunc.UrlEncode(ComFunc.nvl(d["__download_filename__"])));
                //CurrentContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                CurrentContext.Response.ContentType = ResponseHeader_ContentType.xls;
                if (d.ResponseData is byte[])
                {
                    CurrentContext.Response.Body.Write((byte[])d.ResponseData, 0, ((byte[])d.ResponseData).Length);
                }
                else if (d.ResponseData is Stream)
                {
                    var arr = StreamToBytes((Stream)d.ResponseData);
                    CurrentContext.Response.Body.Write(arr, 0, arr.Length);
                }
                else
                {
                    CurrentContext.Response.WriteAsync(ComFunc.nvl(d.ResponseData)).Wait();
                }
                CurrentContext.Response.Body.Flush();
            }
            else if (d.ContentType == GoResponseDataType.Word)
            {
                CurrentContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + ComFunc.UrlEncode(ComFunc.nvl(d["__download_filename__"])));
                //CurrentContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                CurrentContext.Response.ContentType = ResponseHeader_ContentType.doc;
                if (d.ResponseData is byte[])
                {
                    CurrentContext.Response.Body.Write((byte[])d.ResponseData, 0, ((byte[])d.ResponseData).Length);
                }
                else if (d.ResponseData is Stream)
                {
                    var arr = StreamToBytes((Stream)d.ResponseData);
                    CurrentContext.Response.Body.Write(arr, 0, arr.Length);
                }
                else
                {
                    CurrentContext.Response.WriteAsync(ComFunc.nvl(d.ResponseData)).Wait();
                }
                CurrentContext.Response.Body.Flush();
            }
            else if (d.ContentType == GoResponseDataType.PDF)
            {
                if (agent != null && agent.IndexOf("MSIE") == -1 && agent.IndexOf("Chrome") == -1 && agent.IndexOf("Opera") == -1)
                {
                    //非IE非Chrom
                    CurrentContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + ComFunc.nvl(d["__download_filename__"]));
                }
                else
                {
                    CurrentContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + ComFunc.UrlEncode(ComFunc.nvl(d["__download_filename__"])));
                }

                //CurrentContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
                CurrentContext.Response.ContentType = ResponseHeader_ContentType.pdf;
                if (d.ResponseData is byte[])
                {
                    CurrentContext.Response.Body.Write((byte[])d.ResponseData, 0, ((byte[])d.ResponseData).Length);
                }
                else if (d.ResponseData is Stream)
                {
                    var arr = StreamToBytes((Stream)d.ResponseData);
                    CurrentContext.Response.Body.Write(arr, 0, arr.Length);
                }
                else
                {
                    CurrentContext.Response.WriteAsync(ComFunc.nvl(d.ResponseData)).Wait();
                }
                CurrentContext.Response.Body.Flush();
            }
            else if (d.ContentType == GoResponseDataType.Json)
            {
                //CurrentContext.Response.Charset = "UTF-8";
                CurrentContext.Response.ContentType = ResponseHeader_ContentType.json + ";charset=utf-8";
                if (d.ResponseData is FrameDLRObject)
                {
                    var jsonstr       = ComFunc.FormatJSON((FrameDLRObject)d.ResponseData).ToJSONString();
                    var msgbytelength = Encoding.UTF8.GetByteCount(jsonstr);
                    CurrentContext.Response.Headers.Add("Content-Length", msgbytelength + "");
                    CurrentContext.Response.WriteAsync(jsonstr).Wait();
                }
                else if (d.ResponseData is string)
                {
                    var jsonstr       = ComFunc.FormatJSON(ComFunc.nvl(d.ResponseData)).ToJSONString();
                    var msgbytelength = Encoding.UTF8.GetByteCount(jsonstr);
                    CurrentContext.Response.Headers.Add("Content-Length", msgbytelength + "");
                    CurrentContext.Response.WriteAsync(jsonstr).Wait();
                }
                else
                {
                    FrameDLRObject dobj          = FrameDLRObject.CreateInstance(d.ResponseData);
                    var            jsonstr       = ComFunc.FormatJSON(dobj).ToJSONString();
                    var            msgbytelength = Encoding.UTF8.GetByteCount(jsonstr);
                    CurrentContext.Response.Headers.Add("Content-Length", msgbytelength + "");
                    CurrentContext.Response.WriteAsync(ComFunc.FormatJSON(dobj).ToJSONString()).Wait();
                }
            }
            else if (d.ContentType == GoResponseDataType.HostView)
            {
                //if (d.ResponseData is FrameDLRObject)
                //{
                //    var dobj = (FrameDLRObject)d.ResponseData;
                //    //获取view路径
                //    string vieWebParameterath = ComFunc.nvl(d.ExtentionObj.hostvieWebParameterath);
                //    vieWebParameterath = vieWebParameterath.Replace("~", GlobalCommon.HostCommon.RootPath + HostJsConstants.COMPILED_VIEW_PATH);
                //    if (File.Exists(vieWebParameterath))
                //    {
                //        //调用hostview引擎进行渲染
                //        HostJsView hjv = (HostJsView)p.ExtentionObj.hostviewengine;
                //        hjv.CurrentContext.SetDataModel(dobj.ToDictionary());
                //        var html = hjv.Render(File.ReadAllText(vieWebParameterath, Encoding.UTF8));

                //        //CurrentContext.Response.Charset = "UTF-8";
                //        CurrentContext.Response.ContentType = ResponseHeader_ContentType.html + ";charset=utf-8";
                //        CurrentContext.Response.WriteAsync(html).Wait();
                //    }
                //    else
                //    {
                //        CurrentContext.Response.WriteAsync("File Not Found!").Wait();
                //    }
                //}
            }
            else if (d.ContentType == GoResponseDataType.RazorView)
            {
                //Mvc进行视图展示
                var htmlstr = GlobalCommon.Proxys["razor"].CallModule <string>(new
                {
                    ViewPath    = d.ViewPath,
                    Model       = d.MvcModuleData,
                    ViewList    = d.Domain(DomainKey.VIEW_LIST),
                    HttpContext = p.CurrentHttpContext
                }).GetAwaiter().GetResult();
                //var htmlstr =  _render.RenderViewToString(_excutefilepath, d.ViewPath, p.CurrentHttpContext, d.MvcModuleData, d.Domain(DomainKey.VIEW_LIST)).GetAwaiter().GetResult();
                GlobalCommon.Logger.WriteLog(LoggerLevel.DEBUG, $"Razor render cast time:{(DateTime.Now - dt).TotalMilliseconds}ms "); dt = DateTime.Now;
                var msgbytelength = Encoding.UTF8.GetByteCount(htmlstr);
                CurrentContext.Response.Headers.Add("Content-Length", msgbytelength + "");
                CurrentContext.Response.ContentType = ResponseHeader_ContentType.html + ";charset=utf-8";
                CurrentContext.Response.WriteAsync(htmlstr);
            }
            else
            {
                if (d is IJSONable)
                {
                    CurrentContext.Response.ContentType = ResponseHeader_ContentType.json + ";charset=utf-8";
                    CurrentContext.Response.WriteAsync(((IJSONable)d.ResponseData).ToJSONString());
                }
                else
                {
                    CurrentContext.Response.ContentType = ResponseHeader_ContentType.html + ";charset=utf-8";
                    FrameDLRObject dobj = FrameDLRObject.CreateInstance(d.ResponseData, FrameDLRFlags.SensitiveCase);
                    CurrentContext.Response.WriteAsync(dobj.ToJSONString());
                }
            }
        }
Example #8
0
        public string ToJSONString(Dictionary <string, object> obj)
        {
            FrameDLRObject dobj = FrameDLRObject.CreateInstance(obj, FrameDLRFlags.SensitiveCase);

            return(dobj.ToJSONString());
        }
        public DataCollection DoOperate(ParameterStd p)
        {
            UnitDataCollection rtn  = new UnitDataCollection();
            string             flag = p.GetValue <string>("_unit_action_flag_");
            UnitParameter      up   = (UnitParameter)p;

            if (up.Dao is ADBAccess)
            {
                T   t      = (T)Activator.CreateInstance(typeof(T), true);
                var sqlobj = t.GetSqlFunc(flag)(up);
                if (!(sqlobj is FrameDLRObject))
                {
                    throw new TypeRequiredException("需要指定的动态数据对象:FrameDLRObject");
                }
                string    sql = sqlobj.sql;
                ADBAccess dba = (ADBAccess)up.Dao;
                DBOParameterCollection dbc = new DBOParameterCollection();
                if (!string.IsNullOrEmpty(sql))
                {
                    string regstr = "";
                    regstr = @"(?<=" + (dba.ParameterFlagChar == "$"?"\\$": dba.ParameterFlagChar) + @")[A-Za-z0-9_]+\d*";
                    string regexpress = @"(?isx)
                                (')                                                           #开始标记“<tag...>”
                                (?>                                                                  #分组构造,用来限定量词“*”修饰范围
                                \1  (?<Open>)                                                 #命名捕获组,遇到开始标记,入栈,Open计数加1
                                |\1  (?<-Open>)                                                   #狭义平衡组,遇到结束标记,出栈,Open计数减1
                                |[^']*                                                   #右侧不为开始或结束标记的任意字符
                                )
                                (?(Open)(?!))                                                        #判断是否还有'OPEN',有则说明不配对,什么都不匹配
                                \1                                                                #结束标记“</tag>”
                     ";
                    Regex  re         = new Regex(regstr);
                    string tmpsql     = "";
                    Regex  re2        = new Regex(regexpress);
                    tmpsql = sql.Replace("''", "#sp#");
                    foreach (Match m in re2.Matches(tmpsql))
                    {
                        tmpsql = tmpsql.Replace(m.Value, "#sp#");
                    }
                    foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql))
                    {
                        if (up.GetValue(m.ToString()) is byte[])
                        {
                            dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Binary);
                        }
                        else if (up.GetValue(m.ToString()) is DateTime)
                        {
                            dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.DateTime);
                        }
                        else if (up.GetValue(m.ToString()) is int)
                        {
                            dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Int32);
                        }
                        else if (up.GetValue(m.ToString()) is double)
                        {
                            dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Double);
                        }
                        else
                        {
                            dbc.Add(m.ToString(), up.GetValue(m.ToString()));
                        }
                    }
                }
                try
                {
                    rtn.QueryDatas = dba.Query(sql, dbc);
                }catch (Exception ex)
                {
                    FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase);
                    foreach (var item in dbc)
                    {
                        if (item.Value.ParameterValue is DateTime)
                        {
                            dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss"));
                        }
                        else if (item.Value.ParameterValue is DBNull)
                        {
                            dp.SetValue(item.Key, null);
                        }
                        else
                        {
                            dp.SetValue(item.Key, item.Value.ParameterValue);
                        }
                    }
                    GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QuerySql={sql};\nParameters={dp.ToJSONString()}");

                    throw ex;
                }
                if (rtn.QueryDatas != null && rtn.QueryDatas.Tables.Count > 0)
                {
                    rtn.QueryTable = rtn.QueryDatas[0];
                }
            }
            return(rtn);
        }
Example #10
0
        /// <summary>
        /// 登入时通过Code获取到登入人的UserID
        /// </summary>
        /// <param name="code">传入,Code</param>
        /// <param name="userTicket">传出,ticketId可以让你在7200s之内获取更加详细的用户信息</param>
        /// <param name="deviceId">传出,登入用设备ID</param>
        /// <param name="openId">非企业成员OpenID</param>
        /// <returns></returns>
        public string GetUserIdByCode(string code, ref string userTicket, ref string deviceId, ref string openId)
        {
            /*  企业成员rtn
             *      {
             *         "errcode": 0,
             *         "errmsg": "ok",
             *         "UserId":"USERID",
             *         "DeviceId":"DEVICEID",
             *         "user_ticket": "USER_TICKET",
             *         "expires_in":7200
             *      }
             */
            /*非企业成员Rtn
             *  {
             *    "errcode": 0,
             *    "errmsg": "ok",
             *    "OpenId":"OPENID",
             *    "DeviceId":"DEVICEID"
             *  }
             */
            FrameDLRObject obj = CallWeixinServer(string.Format(GetUserTicketUrl, Access_Token, code));

            GlobalCommon.Logger.WriteLog(LoggerLevel.DEBUG, "***********************" + obj.ToJSONString());
            dynamic dobj   = obj;
            string  userId = ComFunc.nvl(dobj.userid);

            deviceId   = ComFunc.nvl(dobj.DeviceId);
            userTicket = ComFunc.nvl(dobj.user_ticket);
            openId     = ComFunc.nvl(dobj.OpenId);
            return(userId);
        }
        /// <summary>
        /// 用户支付完成后,获取该用户的 UnionId,无需用户授权
        /// </summary>
        /// <param name="openid">传入,支付用户唯一标识</param>
        /// <param name="transaction_id">微信支付订单号</param>
        /// <param name="mch_id">微信支付分配的商户号,和商户订单号配合使用</param>
        /// <param name="out_trade_no">微信支付商户订单号,和商户号配合使用</param>
        /// <returns></returns>
        public FrameDLRObject GetPaidUnionId(string openid, string transaction_id = "", string mch_id = "", string out_trade_no = "")
        {
            /*  成功 rtn
             *      {
             *         unionid	string	用户唯一标识,调用成功后返回
             *          errcode	number	错误码
             *          errmsg	string	错误信息
             *      }
             *  失败{
             *          errcode	number	错误码
             *          errmsg	string	错误信息
             *      }
             */
            var url = string.Format(GetUnionIDByPayUrl, AppSecret, openid);

            if (!string.IsNullOrEmpty(transaction_id))
            {
                url += $"&transaction_id={transaction_id}";
            }
            if (!string.IsNullOrEmpty(mch_id))
            {
                url += $"&mch_id={mch_id}";
            }
            if (!string.IsNullOrEmpty(out_trade_no))
            {
                url += $"&out_trade_no={out_trade_no}";
            }
            FrameDLRObject obj = CallWeixinServer(url, "get");

            GlobalCommon.Logger.WriteLog(LoggerLevel.DEBUG, "***********************GetPaidUnionId result=" + obj.ToJSONString());
            return(obj);
        }
        /// <summary>
        /// 登录凭证校验。通过 wx.login() 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程
        /// </summary>
        /// <param name="code">传入,Code</param>
        /// <returns></returns>
        public FrameDLRObject GetSessionByCode(string code)
        {
            /*  成功 rtn
             *      {
             *         openid	string	用户唯一标识
             *          session_key	string	会话密钥
             *          unionid	string	用户在开放平台的唯一标识符,在满足 UnionID 下发条件的情况下会返回,详见 UnionID 机制说明。
             *          errcode	number	错误码
             *          errmsg	string	错误信息
             *      }
             *  失败{
             *          errcode	number	错误码
             *          errmsg	string	错误信息
             *      }
             */
            FrameDLRObject obj = CallWeixinServer(string.Format(GetCode2SessionUrl, AppID, AppSecret, code), "get");

            GlobalCommon.Logger.WriteLog(LoggerLevel.DEBUG, "***********************GetSessionByCode result=" + obj.ToJSONString());
            return(obj);
        }
Example #13
0
        public DataCollection DoOperate(ParameterStd p)
        {
            string flag = p.GetValue <string>("_unit_action_flag_");
            //预执行
            T                  t   = (T)Activator.CreateInstance(typeof(T), true);
            UnitParameter      up  = (UnitParameter)p;
            UnitDataCollection rtn = new UnitDataCollection();

            if (up.Dao is ADBAccess)
            {
                var       sqlobj     = t.GetSqlFunc(flag)(up);
                ADBAccess dba        = (ADBAccess)up.Dao;
                string    regstr     = "";
                string    regexpress = @"(?isx)
                                (')                                                           #开始标记“<tag...>”
                                (?>                                                                  #分组构造,用来限定量词“*”修饰范围
                                \1  (?<Open>)                                                 #命名捕获组,遇到开始标记,入栈,Open计数加1
                                |\1  (?<-Open>)                                                   #狭义平衡组,遇到结束标记,出栈,Open计数减1
                                |[^']*                                                   #右侧不为开始或结束标记的任意字符
                                )
                                (?(Open)(?!))                                                        #判断是否还有'OPEN',有则说明不配对,什么都不匹配
                                \1                                                                #结束标记“</tag>”
                     ";
                string    tmpsql     = "";
                regstr = @"(?<=" + (dba.ParameterFlagChar == "$" ? "\\$" : dba.ParameterFlagChar) + @")[A-Za-z0-9_]+\d*";

                Regex re  = new Regex(regstr);
                Regex re2 = new Regex(regexpress);
                try
                {
                    if (!(sqlobj is FrameDLRObject))
                    {
                        throw new TypeRequiredException("需要指定的动态数据对象:FrameDLRObject");
                    }

                    string   presql = sqlobj.presql;
                    DBAPageP dbc    = new DBAPageP();
                    //dba.BeginTransaction();
                    if (!string.IsNullOrEmpty(presql))
                    {
                        tmpsql = presql.Replace("''", "#sp#");
                        foreach (Match m in re2.Matches(tmpsql))
                        {
                            tmpsql = tmpsql.Replace(m.Value, "#sp#");
                        }

                        foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql))
                        {
                            dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString()));
                        }
                        try
                        {
                            dba.ExecuteNoQuery(presql, dbc.SQL_Parameters);
                        }
                        catch (Exception ex)
                        {
                            FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase);
                            foreach (var item in dbc.SQL_Parameters)
                            {
                                if (item.Value.ParameterValue is DateTime)
                                {
                                    dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss"));
                                }
                                else if (item.Value.ParameterValue is DBNull)
                                {
                                    dp.SetValue(item.Key, null);
                                }
                                else
                                {
                                    dp.SetValue(item.Key, item.Value.ParameterValue);
                                }
                            }
                            GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QueryByPage PreSql={presql};\nParameters={dp.ToJSONString()}");

                            throw ex;
                        }
                    }
                    //执行翻页查询
                    string sql     = sqlobj.sql;
                    string orderby = sqlobj.orderby;
                    if (!string.IsNullOrEmpty(sql))
                    {
                        tmpsql = sql.Replace("''", "#sp#");
                        foreach (Match m in re2.Matches(tmpsql))
                        {
                            tmpsql = tmpsql.Replace(m.Value, "#sp#");
                        }

                        dbc.SQL_Parameters.Clear();
                        foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql))
                        {
                            if (up.GetValue(m.ToString()) is byte[])
                            {
                                dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Binary);
                            }
                            else
                            {
                                dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString()));
                            }
                        }
                        try
                        {
                            dbc.SQL              = sql;
                            dbc.OrderBy          = orderby;
                            dbc.Count_of_OnePage = up.Count_Of_OnePage;
                            dbc.CurrentPage      = up.CurrentPage;
                            dba.StartPageByCondition(dbc);
                            rtn.QueryTable = dba.GoToPage(up.ToPage);
                            rtn.QueryDatas = new DataSetStd();
                            rtn.QueryDatas.Tables.Add(rtn.QueryTable);
                            rtn.Count_Of_OnePage = up.Count_Of_OnePage;
                            rtn.CurrentPage      = dba.CurrentPage;
                            rtn.TotalPage        = dba.TotalPage;
                            rtn.TotalRow         = dba.TotalRow;
                        }
                        catch (Exception ex)
                        {
                            FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase);
                            foreach (var item in dbc.SQL_Parameters)
                            {
                                if (item.Value.ParameterValue is DateTime)
                                {
                                    dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss"));
                                }
                                else if (item.Value.ParameterValue is DBNull)
                                {
                                    dp.SetValue(item.Key, null);
                                }
                                else
                                {
                                    dp.SetValue(item.Key, item.Value.ParameterValue);
                                }
                            }
                            GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QueryByPage sql={sql};\n order by={orderby};\nParameters={dp.ToJSONString()}");

                            throw ex;
                        }
                    }
                    //收尾处理
                    string aftersql = sqlobj.aftersql;
                    if (!string.IsNullOrEmpty(aftersql))
                    {
                        tmpsql = aftersql.Replace("''", "#sp#");
                        foreach (Match m in re2.Matches(tmpsql))
                        {
                            tmpsql = tmpsql.Replace(m.Value, "#sp#");
                        }

                        dbc.SQL_Parameters.Clear();
                        foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql))
                        {
                            dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString()));
                        }
                        try
                        {
                            dba.ExecuteNoQuery(aftersql, dbc.SQL_Parameters);
                        }catch (Exception ex)
                        {
                            FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase);
                            foreach (var item in dbc.SQL_Parameters)
                            {
                                if (item.Value.ParameterValue is DateTime)
                                {
                                    dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss"));
                                }
                                else if (item.Value.ParameterValue is DBNull)
                                {
                                    dp.SetValue(item.Key, null);
                                }
                                else
                                {
                                    dp.SetValue(item.Key, item.Value.ParameterValue);
                                }
                            }
                            GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QueryByPage AfterSql={aftersql};\nParameters={dp.ToJSONString()}");

                            throw ex;
                        }
                    }

                    //dba.CommitTransaction();
                }
                catch
                {
                    //if (dba != null)
                    //    dba.RollbackTransaction();
                    throw;
                }
            }
            return(rtn);
        }
Example #14
0
        /// <summary>
        /// 獲得postdata的串
        /// </summary>
        /// <returns></returns>
        private object GetPostDataData()
        {
            if (_contenttype.ToLower().IndexOf("/json") > 0)
            {
                return(_postdata.ToJSONString());
            }
            else if (_contenttype == "multipart/form-data")
            {
                /*
                 * multipart/form-data的请求内容格式如下
                 * Content-Type: multipart/form-data; boundary=AaB03x
                 *
                 * --boundary
                 * Content-Disposition: form-data; name="submit-name"
                 *
                 * Larry
                 * --boundary
                 * Content-Disposition: form-data; name="file"; filename="file1.dat"
                 * Content-Type: application/octet-stream
                 *
                 * ... contents of file1.dat ...
                 * --boundary--
                 * */

                var boundary = String.Format("----------{0:N}", Guid.NewGuid());
                _contenttype = _contenttype + ";boundary=" + boundary;

                Stream formDataStream = new System.IO.MemoryStream();

                foreach (var k in _postdata.Keys)
                {
                    var item = _postdata.GetValue(k);
                    if (item is FrameDLRObject)
                    {
                        dynamic dobj = item;
                        if (ComFunc.nvl(dobj.contenttype) == "application/octet-stream")
                        {
                            var name            = ComFunc.nvl(dobj.name);
                            var filename        = ComFunc.nvl(dobj.filename);
                            var filecontenttype = ComFunc.nvl(dobj.filecontenttype);
                            var filecontent     = (byte[])dobj.formitem;

                            // Add just the first part of this param, since we will write the file data directly to the Stream
                            string header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n",
                                                          boundary,
                                                          name,
                                                          filename,
                                                          filecontenttype != "" ? filecontenttype : "application/octet-stream");

                            formDataStream.Write(_encoding.GetBytes(header), 0, _encoding.GetByteCount(header));

                            // Write the file data directly to the Stream, rather than serializing it to a string.
                            formDataStream.Write(filecontent, 0, filecontent.Length);
                        }
                        else
                        {
                            var name     = ComFunc.nvl(dobj.name);
                            var formitem = ComFunc.nvl(dobj.formitem);
                            // Add just the first part of this param, since we will write the file data directly to the Stream
                            string header = string.Format("--{0}\r\nContent-Disposition: form-data; name={1}\r\n\r\n",
                                                          boundary,
                                                          name);

                            formDataStream.Write(_encoding.GetBytes(header), 0, _encoding.GetByteCount(header));
                            var bytes = Encoding.UTF8.GetBytes(formitem);
                            // Write the file data directly to the Stream, rather than serializing it to a string.
                            formDataStream.Write(bytes, 0, bytes.Length);
                        }
                    }
                }
                // Add the end of the request.  Start with a newline
                string footer = "\r\n--" + boundary + "--\r\n";
                formDataStream.Write(_encoding.GetBytes(footer), 0, _encoding.GetByteCount(footer));

                // Dump the Stream into a byte[]
                formDataStream.Position = 0;
                byte[] formData = new byte[formDataStream.Length];
                formDataStream.Read(formData, 0, formData.Length);
                formDataStream.Close();

                return(formData);
            }//以put的方式发送文件内容
            else if (_contenttype.ToLower().StartsWith("put/"))
            {
                if (_postdata.Keys.Count > 0)
                {
                    var item = _postdata.GetValue(_postdata.Keys[0]);
                    if (item is FrameDLRObject)
                    {
                        dynamic dobj = item;
                        //只处理第一笔资料
                        //var name = ComFunc.nvl(dobj.name);
                        //var filename = ComFunc.nvl(dobj.filename);
                        //var filecontenttype = ComFunc.nvl(dobj.filecontenttype);
                        var filecontent = (byte[])dobj.formitem;

                        return(filecontent);
                    }
                    else if (item is byte[])
                    {
                        return((byte[])item);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else if (_contenttype.ToLower().IndexOf("/xml") > 0)
            {
                return(_postdata.ToXml());
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (string s in _postdata.Keys)
                {
                    sb.AppendFormat("&{0}={1}", s, _postdata.GetValue(s));
                }
                return(sb.Length > 0 ? sb.ToString().Substring(1) : "");
            }
        }