Beispiel #1
0
        /// <summary>
        /// 获得事件实体String,根据编号或者流程标记
        /// </summary>
        /// <param name="flowMark">流程标记</param>
        /// <param name="flowNo">流程编号</param>
        /// <returns>null, 或者流程实体.</returns>
        public static string GetBuessUnitEntityStringByFlowMark(string flowMark, string flowNo)
        {
            BuessUnitBase en = GetBuessUnitEntityByFlowMark(flowMark, flowNo);

            if (en == null)
            {
                return("");
            }
            return(en.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// 获得节点事件实体
        /// </summary>
        /// <param name="enName">实例名称</param>
        /// <returns>获得节点事件实体,如果没有就返回为空.</returns>
        public static BuessUnitBase GetBuessUnitEntityByEnName(string enName)
        {
            if (Htable_BuessUnit == null || Htable_BuessUnit.Count == 0)
            {
                Htable_BuessUnit = new Hashtable();
                ArrayList al = BP.En.ClassFactory.GetObjects("BP.Sys.BuessUnitBase");
                foreach (BuessUnitBase en in al)
                {
                    Htable_BuessUnit.Add(en.ToString(), en);
                }
            }

            BuessUnitBase myen = Htable_BuessUnit[enName] as BuessUnitBase;

            if (myen == null)
            {
                //throw new Exception("@根据类名称获取业务单元实例出现错误:" + enName + ",没有找到该类的实体.");
                BP.DA.Log.DefaultLogWriteLineError("@根据类名称获取业务单元实例出现错误:" + enName + ",没有找到该类的实体.");
                return(null);
            }
            return(myen);
        }
Beispiel #3
0
        /// <summary>
        /// 获得业务单元.
        /// </summary>
        /// <param name="flowMark">流程标记</param>
        /// <param name="flowNo">流程编号</param>
        /// <returns>null, 或者流程实体.</returns>
        public static BuessUnitBase GetBuessUnitEntityByFlowMark(string flowMark, string flowNo)
        {
            if (Htable_BuessUnit == null || Htable_BuessUnit.Count == 0)
            {
                Htable_BuessUnit = new Hashtable();
                ArrayList al = BP.En.ClassFactory.GetObjects("BP.Sys.BuessUnitBase");
                Htable_BuessUnit.Clear();
                foreach (BuessUnitBase en in al)
                {
                    Htable_BuessUnit.Add(en.ToString(), en);
                }
            }

            foreach (string key in Htable_BuessUnit.Keys)
            {
                BuessUnitBase fee = Htable_BuessUnit[key] as BuessUnitBase;
                if (fee.ToString() == flowMark || fee.ToString().Contains("," + flowNo + ",") == true)
                {
                    return(fee);
                }
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// 执行事件,事件标记是 EventList.
        /// </summary>
        /// <param name="dotype">执行类型</param>
        /// <param name="en">数据实体</param>
        /// <param name="atPara">特殊的参数格式@key=value 方式.</param>
        /// <returns></returns>
        private string _DoEventNode(string dotype, Entity en, string atPara)
        {
            if (this.Count == 0)
            {
                return(null);
            }

            FrmEvent nev = this.GetEntityByKey(FrmEventAttr.FK_Event, dotype) as FrmEvent;

            if (nev == null || nev.HisDoType == EventDoType.Disable)
            {
                return(null);
            }

            #region 执行的是业务单元.
            if (nev.HisDoType == EventDoType.BuessUnit)
            {
                /* 获得业务单元,开始执行他 */
                BuessUnitBase enBuesss = BP.Sys.Glo.GetBuessUnitEntityByEnName(nev.DoDoc);
                enBuesss.WorkID = Int64.Parse(en.PKVal.ToString());
                return(enBuesss.DoIt());
            }
            #endregion 执行的是业务单元.


            string doc = nev.DoDoc.Trim();
            if ((doc == null || doc == "") && nev.HisDoType != EventDoType.SpecClass)   //edited by liuxc,2016-01-16,执行DLL文件不需要判断doc为空
            {
                return(null);
            }

            #region 处理执行内容
            Attrs  attrs  = en.EnMap.Attrs;
            string MsgOK  = "";
            string MsgErr = "";
            foreach (Attr attr in attrs)
            {
                if (doc.Contains("@" + attr.Key) == false)
                {
                    break;
                }
                if (attr.MyDataType == DataType.AppString ||
                    attr.MyDataType == DataType.AppDateTime ||
                    attr.MyDataType == DataType.AppDate)
                {
                    doc = doc.Replace("@" + attr.Key, "'" + en.GetValStrByKey(attr.Key) + "'");
                }
                else
                {
                    doc = doc.Replace("@" + attr.Key, en.GetValStrByKey(attr.Key));
                }
            }

            doc = doc.Replace("~", "'");
            doc = doc.Replace("@WebUser.No", BP.Web.WebUser.No);
            doc = doc.Replace("@WebUser.Name", BP.Web.WebUser.Name);
            doc = doc.Replace("@WebUser.FK_Dept", BP.Web.WebUser.FK_Dept);
            doc = doc.Replace("@FK_Node", nev.FK_MapData.Replace("ND", ""));
            doc = doc.Replace("@FK_MapData", nev.FK_MapData);
            doc = doc.Replace("@WorkID", en.GetValStrByKey("OID", "@WorkID"));

            //SDK表单上服务器地址,应用到使用ccflow的时候使用的是sdk表单,该表单会存储在其他的服务器上.
            doc = doc.Replace("@SDKFromServHost", SystemConfig.AppSettings["SDKFromServHost"]);

            if (doc.Contains("@") == true)
            {
                if (System.Web.HttpContext.Current != null)
                {
                    /*如果是 bs 系统, 有可能参数来自于url ,就用url的参数替换它们 .*/
                    string url = BP.Sys.Glo.Request.RawUrl;
                    if (url.IndexOf('?') != -1)
                    {
                        url = url.Substring(url.IndexOf('?')).TrimStart('?');
                    }

                    string[] paras = url.Split('&');
                    foreach (string s in paras)
                    {
                        string[] mys = s.Split('=');

                        if (doc.Contains("@" + mys[0]) == false)
                        {
                            continue;
                        }

                        doc = doc.Replace("@" + mys[0], mys[1]);
                    }
                }
            }

            if (nev.HisDoType == EventDoType.URLOfSelf)
            {
                if (doc.Contains("?") == false)
                {
                    doc += "?1=2";
                }

                doc += "&UserNo=" + WebUser.No;
                doc += "&SID=" + WebUser.SID;
                doc += "&FK_Dept=" + WebUser.FK_Dept;
                // doc += "&FK_Unit=" + WebUser.FK_Unit;
                doc += "&OID=" + en.PKVal;

                if (SystemConfig.IsBSsystem)
                {
                    /*是bs系统,并且是url参数执行类型.*/
                    string url = BP.Sys.Glo.Request.RawUrl;

                    if (url.IndexOf('?') != -1)
                    {
                        url = url.Substring(url.IndexOf('?')).TrimStart('?');
                    }

                    string[] paras = url.Split('&');
                    foreach (string s in paras)
                    {
                        string[] mys = s.Split('=');

                        if (doc.Contains(mys[0] + "="))
                        {
                            continue;
                        }

                        doc += "&" + s;
                    }

                    doc = doc.Replace("&?", "&");
                }

                if (SystemConfig.IsBSsystem == false)
                {
                    /*非bs模式下调用,比如在cs模式下调用它,它就取不到参数. */
                }

                if (doc.StartsWith("http") == false)
                {
                    /*如果没有绝对路径 */
                    if (SystemConfig.IsBSsystem)
                    {
                        /*在cs模式下自动获取*/
                        string host = BP.Sys.Glo.Request.Url.Host;
                        if (doc.Contains("@AppPath"))
                        {
                            doc = doc.Replace("@AppPath", "http://" + host + BP.Sys.Glo.Request.ApplicationPath);
                        }
                        else
                        {
                            doc = "http://" + BP.Sys.Glo.Request.Url.Authority + doc;
                        }
                    }

                    if (SystemConfig.IsBSsystem == false)
                    {
                        /*在cs模式下它的baseurl 从web.config中获取.*/
                        string cfgBaseUrl = SystemConfig.HostURL;
                        if (DataType.IsNullOrEmpty(cfgBaseUrl))
                        {
                            string err = "调用url失败:没有在web.config中配置BaseUrl,导致url事件不能被执行.";
                            Log.DefaultLogWriteLineError(err);
                            throw new Exception(err);
                        }
                        doc = cfgBaseUrl + doc;
                    }
                }

                //增加上系统约定的参数.
                doc += "&EntityName=" + en.ToString() + "&EntityPK=" + en.PK + "&EntityPKVal=" + en.PKVal + "&FK_Event=" + nev.MyPK;
            }
            #endregion 处理执行内容

            if (atPara != null && doc.Contains("@") == true)
            {
                AtPara ap = new AtPara(atPara);
                foreach (string s in ap.HisHT.Keys)
                {
                    doc = doc.Replace("@" + s, ap.GetValStrByKey(s));
                }
            }

            if (dotype == FrmEventList.FrmLoadBefore)
            {
                en.Retrieve(); /*如果不执行,就会造成实体的数据与查询的数据不一致.*/
            }
            switch (nev.HisDoType)
            {
            case EventDoType.SP:
            case EventDoType.SQL:
                try
                {
                    // 允许执行带有GO的sql.
                    DBAccess.RunSQLs(doc);
                    return(nev.MsgOK(en));
                }
                catch (Exception ex)
                {
                    throw new Exception(nev.MsgError(en) + " Error:" + ex.Message);
                }
                break;

            case EventDoType.URLOfSelf:
                string myURL = doc.Clone() as string;
                if (myURL.Contains("http") == false)
                {
                    if (SystemConfig.IsBSsystem)
                    {
                        string host = BP.Sys.Glo.Request.Url.Host;
                        if (myURL.Contains("@AppPath"))
                        {
                            myURL = myURL.Replace("@AppPath", "http://" + host + BP.Sys.Glo.Request.ApplicationPath);
                        }
                        else
                        {
                            myURL = "http://" + BP.Sys.Glo.Request.Url.Authority + myURL;
                        }
                    }
                    else
                    {
                        string cfgBaseUrl = SystemConfig.HostURL;
                        if (DataType.IsNullOrEmpty(cfgBaseUrl))
                        {
                            string err = "调用url失败:没有在web.config中配置BaseUrl,导致url事件不能被执行.";
                            Log.DefaultLogWriteLineError(err);
                            throw new Exception(err);
                        }
                        myURL = cfgBaseUrl + myURL;
                    }
                }
                myURL = myURL.Replace("@SDKFromServHost", SystemConfig.AppSettings["SDKFromServHost"]);

                if (myURL.Contains("&FID=") == false && en.Row.ContainsKey("FID") == true)
                {
                    string str = en.Row["FID"].ToString();
                    myURL = myURL + "&FID=" + str;
                }

                if (myURL.Contains("&FK_Flow=") == false && en.Row.ContainsKey("FK_Flow") == true)
                {
                    string str = en.Row["FK_Flow"].ToString();
                    myURL = myURL + "&FK_Flow=" + str;
                }

                if (myURL.Contains("&WorkID=") == false && en.Row.ContainsKey("WorkID") == true)
                {
                    string str = en.Row["WorkID"].ToString();
                    myURL = myURL + "&WorkID=" + str;
                }

                try
                {
                    Encoding encode = System.Text.Encoding.GetEncoding("gb2312");
                    string   text   = DataType.ReadURLContext(myURL, 600000, encode);
                    if (text == null)
                    {
                        throw new Exception("@流程设计错误,执行的url错误:" + myURL + ", 返回为null, 请检查url设置是否正确。提示:您可以copy出来此url放到浏览器里看看是否被正确执行。");
                    }

                    if (text != null &&
                        text.Length > 7 &&
                        text.Substring(0, 7).ToLower().Contains("err"))
                    {
                        throw new Exception(text);
                    }

                    if (text == null || text.Trim() == "")
                    {
                        return(null);
                    }
                    return(text);
                }
                catch (Exception ex)
                {
                    throw new Exception("@" + nev.MsgError(en) + " Error:" + ex.Message);
                }
                break;

            case EventDoType.EventBase:     //执行事件类.
                // 获取事件类.
                string           evName = doc.Clone() as string;
                BP.Sys.EventBase ev     = null;
                try
                {
                    ev = BP.En.ClassFactory.GetEventBase(evName);
                }
                catch (Exception ex)
                {
                    throw new Exception("@事件名称:" + evName + "拼写错误,或者系统不存在。说明:事件所在的类库必须是以BP.开头,并且类库的BP.xxx.dll。");
                }

                //开始执行.
                try
                {
                    #region 处理整理参数.
                    Row r = en.Row;
                    try
                    {
                        //系统参数.
                        r.Add("FK_MapData", en.ClassID);
                    }
                    catch
                    {
                        r["FK_MapData"] = en.ClassID;
                    }

                    try
                    {
                        r.Add("EventType", nev.FK_Event);
                    }
                    catch
                    {
                        r["EventType"] = nev.FK_Event;
                    }

                    if (atPara != null)
                    {
                        AtPara ap = new AtPara(atPara);
                        foreach (string s in ap.HisHT.Keys)
                        {
                            try
                            {
                                r.Add(s, ap.GetValStrByKey(s));
                            }
                            catch
                            {
                                r[s] = ap.GetValStrByKey(s);
                            }
                        }
                    }

                    if (SystemConfig.IsBSsystem == true)
                    {
                        /*如果是bs系统, 就加入外部url的变量.*/
                        foreach (string key in BP.Sys.Glo.Request.QueryString)
                        {
                            string val = BP.Sys.Glo.Request.QueryString[key];
                            try
                            {
                                r.Add(key, val);
                            }
                            catch
                            {
                                r[key] = val;
                            }
                        }
                    }
                    #endregion 处理整理参数.

                    ev.SysPara = r;
                    ev.HisEn   = en;
                    ev.Do();
                    return(ev.SucessInfo);
                }
                catch (Exception ex)
                {
                    throw new Exception("@执行事件(" + ev.Title + ")期间出现错误:" + ex.Message);
                }
                break;

            case EventDoType.WSOfSelf:     //执行webservices.. 为石油修改.
                string[]  strs   = doc.Split('@');
                string    url    = "";
                string    method = "";
                Hashtable paras  = new Hashtable();
                foreach (string str in strs)
                {
                    if (str.Contains("=") && str.Contains("Url"))
                    {
                        url = str.Split('=')[2];
                        continue;
                    }

                    if (str.Contains("=") && str.Contains("Method"))
                    {
                        method = str.Split('=')[2];
                        continue;
                    }

                    //处理参数.
                    string[] paraKeys = str.Split(',');

                    if (paraKeys[3] == "Int")
                    {
                        paras.Add(paraKeys[0], int.Parse(paraKeys[1]));
                    }

                    if (paraKeys[3] == "String")
                    {
                        paras.Add(paraKeys[0], paraKeys[1]);
                    }

                    if (paraKeys[3] == "Float")
                    {
                        paras.Add(paraKeys[0], float.Parse(paraKeys[1]));
                    }

                    if (paraKeys[3] == "Double")
                    {
                        paras.Add(paraKeys[0], double.Parse(paraKeys[1]));
                    }
                }
                return(null);

                //开始执行webserives.
                break;

            case EventDoType.SpecClass:
                #region     //执行dll文件中指定类的指定方法,added by liuxc,2016-01-16
                string evdll    = nev.MonthedDLL;
                string evclass  = nev.MonthedClass;
                string evmethod = nev.MonthedName;
                string evparams = nev.MonthedParas;

                if (string.IsNullOrWhiteSpace(evdll) || !System.IO.File.Exists(evdll))
                {
                    throw new Exception("@DLL文件【MonthedDLL】“" + (evdll ?? string.Empty) + "”设置不正确,请重新设置!");
                }

                Assembly abl = Assembly.LoadFrom(evdll);

                //判断类是否是静态类
                Type type = abl.GetType(evclass, false);

                if (type == null)
                {
                    throw new Exception(@"@DLL文件【MonthedDLL】“" + evdll + "”中的类名【MonthedClass】“" +
                                        (evclass ?? string.Empty) + "”设置不正确,未检索到此类,请重新设置!");
                }

                //方法
                if (string.IsNullOrWhiteSpace(evmethod))
                {
                    throw new Exception(@"@DLL文件【MonthedDLL】“" + evdll + "”中类【MonthedClass】“" +
                                        evclass + "”的方法名【MonthedName】不能为空,请重新设置!");
                }

                MethodInfo                  md  = null;                              //当前方法
                ParameterInfo[]             pis = null;                              //方法的参数集合
                Dictionary <string, string> pss = new Dictionary <string, string>(); //参数名,参数值类型名称字典,如:Name,String
                string mdName = evmethod.Split('(')[0];                              //方法名称

                //获取method对象
                if (mdName.Length == evmethod.Length - 2)
                {
                    md = type.GetMethod(mdName);
                }
                else
                {
                    string[] pssArr = null;

                    //获取设置里的参数信息
                    foreach (string pstr in evmethod.Substring(mdName.Length + 1, evmethod.Length - mdName.Length - 2).Split(','))
                    {
                        pssArr = pstr.Split(' ');
                        pss.Add(pssArr[1], pssArr[0]);
                    }

                    //与设置里的参数信息对比,取得MethodInfo对象
                    foreach (MethodInfo m in type.GetMethods())
                    {
                        if (m.Name != mdName)
                        {
                            continue;
                        }

                        pis = m.GetParameters();
                        bool isOK = true;
                        int  idx  = 0;

                        foreach (KeyValuePair <string, string> ps in pss)
                        {
                            if (pis[idx].Name != ps.Key || pis[idx].ParameterType.ToString()
                                .Replace("System.IO.", "")
                                .Replace("System.", "")
                                .Replace("System.Collections.Generic.", "")
                                .Replace("System.Collections.", "") != ps.Value)
                            {
                                isOK = false;
                                break;
                            }

                            idx++;
                        }

                        if (isOK)
                        {
                            md = m;
                            break;
                        }
                    }
                }

                if (md == null)
                {
                    throw new Exception(@"@DLL文件【MonthedDLL】“" + evdll + "”中类【MonthedClass】“" +
                                        evclass + "”的方法名【MonthedName】“" + evmethod + "”设置不正确,未检索到此方法,请重新设置!");
                }

                //处理参数
                object[] pvs = new object[pss.Count];       //invoke,传递的paramaters参数,数组中的项顺序与方法参数顺序一致

                if (pss.Count > 0)
                {
                    if (string.IsNullOrWhiteSpace(evparams))
                    {
                        throw new Exception(@"@DLL文件【MonthedDLL】“" + evdll + "”中类【MonthedClass】“" +
                                            evclass + "”的方法【MonthedName】“" + evmethod + "”的参数【MonthedParas】不能为空,请重新设置!");
                    }

                    Dictionary <string, string> pds = new Dictionary <string, string>();    //MonthedParas中保存的参数信息集合,格式如:title,@Title
                    int      idx    = 0;
                    int      pidx   = -1;
                    string[] pdsArr = evparams.Split(';');
                    string   val;

                    //将参数中的名称与值分开
                    foreach (string p in pdsArr)
                    {
                        pidx = p.IndexOf('=');
                        if (pidx == -1)
                        {
                            continue;
                        }

                        pds.Add(p.Substring(0, pidx), p.Substring(pidx + 1));
                    }

                    foreach (KeyValuePair <string, string> ps in pss)
                    {
                        if (!pds.ContainsKey(ps.Key))
                        {
                            //设置中没有此参数的值信息,则将值赋为null
                            pvs[idx] = null;
                        }
                        else
                        {
                            val = pds[ps.Key];

                            foreach (BP.En.Attr attr in en.EnMap.Attrs)
                            {
                                if (pds[ps.Key] == "`" + attr.Key + "`")
                                {
                                    //表示此参数与该attr的值一致,类型也一致
                                    pvs[idx] = en.Row[attr.Key];
                                    break;
                                }

                                //替换@属性
                                val = val.Replace("`" + attr.Key + "`", (en.Row[attr.Key] ?? string.Empty).ToString());
                            }

                            //转换参数类型,从字符串转换到参数的实际类型,NOTE:此处只列出了简单类型的转换,其他类型暂未考虑
                            switch (ps.Value)
                            {
                            case "String":
                                pvs[idx] = val;
                                break;

                            case "Int32":
                                pvs[idx] = int.Parse(val);
                                break;

                            case "Int64":
                                pvs[idx] = long.Parse(val);
                                break;

                            case "Double":
                                pvs[idx] = double.Parse(val);
                                break;

                            case "Single":
                                pvs[idx] = float.Parse(val);
                                break;

                            case "Decimal":
                                pvs[idx] = decimal.Parse(val);
                                break;

                            case "DateTime":
                                pvs[idx] = DateTime.Parse(val);
                                break;

                            default:
                                pvs[idx] = val;
                                break;
                            }
                        }

                        idx++;
                    }
                }

                if (type.IsSealed && type.IsAbstract)
                {
                    //静态类
                    return((md.Invoke(null, pvs) ?? string.Empty).ToString());
                }

                //非静态类
                //虚类必须被重写,不能直接使用
                if (type.IsAbstract)
                {
                    return(null);
                }

                //静态方法
                if (md.IsStatic)
                {
                    return((md.Invoke(null, pvs) ?? string.Empty).ToString());
                }

                //非静态方法
                return((md.Invoke(abl.CreateInstance(evclass), pvs) ?? string.Empty).ToString());

                #endregion
            default:
                throw new Exception("@no such way." + nev.HisDoType.ToString());
            }
        }