Example #1
0
        /// <summary>
        /// 添加一个脚本流实例
        /// </summary>
        /// <param name="script">脚本流对象</param>
        /// <param name="statusModel">启动模式</param>
        /// <param name="db">DBEntities</param>
        /// <param name="err">ErrorInfo</param>
        /// <returns></returns>
        public static EM_SCRIPT_CASE AddScriptCase(EM_SCRIPT script, PubEnum.StatusModel statusModel, DBEntities db, ref ErrorInfo err)
        {
            EM_SCRIPT_CASE _scriptCase = new EM_SCRIPT_CASE
            {
                ID          = Fun.GetSeqID <EM_SCRIPT_CASE>(),
                NAME        = script.NAME,
                SCRIPT_ID   = script.ID,
                START_TIME  = DateTime.Now,
                START_MODEL = (short)statusModel,
                RUN_STATUS  = (short)PubEnum.RunStatus.Wait,
                RETRY_TIME  = script.RETRY_TIME
            };

            db.EM_SCRIPT_CASE.Add(_scriptCase);

            return(_scriptCase);

            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (Exception e)
            //{
            //    err.IsError = true;
            //    err.Message = e.Message;
            //    err.Excep = e;
            //    return _scriptCase.ID;
            //}

            //return null;
        }
Example #2
0
        /// <summary>
        /// 根据脚本ID获取脚本对象
        /// </summary>
        /// <param name="scriptID"></param>
        /// <param name="db"></param>
        /// <param name="err"></param>
        /// <returns></returns>
        public static EM_SCRIPT GetScripByID(long?scriptID, DBEntities db, ref ErrorInfo err)
        {
            //验证scriptID是否为空
            if (scriptID == null)
            {
                err.IsError = true;
                err.Message = "传入的ScriptID值不能为空";
                return(null);
            }

            EM_SCRIPT _script = db.EM_SCRIPT.Find(scriptID);

            if (_script == null)
            {
                err.IsError = true;
                err.Message = "未找到主键值[" + scriptID.ToString() + "]的脚本流";
                return(null);
            }
            return(_script);
        }
Example #3
0
        /// <summary>
        /// 启动一个脚本流实例
        /// </summary>
        /// <param name="scriptID"></param>
        /// <param name="statusModel"></param>
        /// <param name="err"></param>
        public static EM_SCRIPT_CASE StartScriptCase(long?scriptID, PubEnum.StatusModel statusModel, ref ErrorInfo err)
        {
            string msg = "";

            using (DBEntities db = new DBEntities())
            {
                if (scriptID == null)
                {
                    err.IsError = true;
                    err.Message = "传入的scriptID值不能为空";
                    return(null);
                }

                //根据scriptID获取脚本流对象
                EM_SCRIPT _script = GetScripByID(scriptID, db, ref err);
                if (err.IsError)
                {
                    return(null);
                }

                //验证当前脚本流能否启动一个脚本流实例
                //状态不为‘等待’或‘执行中’时,允许添加实例
                EM_SCRIPT_CASE _scriptCase = GetEffectScriptCase(scriptID, db);
                if (_scriptCase == null)
                {
                    #region 添加脚本流实例
                    var  _scriptCa     = AddScriptCase(_script, statusModel, db, ref err);
                    long?_scriptCaseID = _scriptCa.ID;
                    //写入脚本流实例日志
                    msg = "添加脚本流【" + _script.NAME + "】实例,实例ID为【" + _scriptCaseID.ToString() + "】";
                    //写入日志
                    LogForScriptCase(msg, "", _scriptCaseID, ref err);
                    #endregion

                    #region 添加脚本流实例的第一组脚本节点实例
                    //获取脚本流的首组脚本节点
                    List <EM_SCRIPT_REF_NODE> _scRefNodeList = db.EM_SCRIPT.Find(scriptID).EM_SCRIPT_REF_NODE.Where(p => p.PARENT_NODE_ID == null).ToList();
                    //为首组脚本添加节点实例
                    foreach (var _scNode in _scRefNodeList)
                    {
                        //添加一个节点实例
                        var snc       = AddScriptNodeCase(_scNode.CURR_NODE_ID, _scriptCaseID, db, ref err, 1);
                        var _snCaseID = snc.ID;
                        //写入脚本节点实例日志信息
                        if (!err.IsError)
                        {
                            msg = string.Format("添加实例为【{1}】脚本流【{0}】的首组脚本节点【{2}】实例,实例编号为【{3}】",
                                                _script.NAME, _scriptCaseID.ToString(),
                                                db.EM_SCRIPT_NODE.Find(_scNode.CURR_NODE_ID).NAME, _snCaseID);
                            //msg += "\r\n等待调度服务启动!";
                            //写入日志
                            LogForNodeCase(msg, "", _snCaseID, ref err);
                            LogForScriptCase(msg, "", _scriptCaseID, ref err);
                        }
                    }
                    //为当前脚本流【复制】节点配置及内容
                    LogForScriptCase("开始为脚本流【" + _script.NAME + "】实例【" + _scriptCaseID.ToString() + "】复制脚本节点及配置信息", "", _scriptCaseID, ref err);
                    CopyScriptNodeForCase(_scriptCaseID, scriptID, _script.NAME, db, ref err);
                    if (err.IsError)
                    {
                        LogForScriptCase("复制脚本流【" + _script.NAME + "】实例【" + _scriptCaseID.ToString() + "】脚本节点及配置信息【失败】:" + err.Message, "", _scriptCaseID, ref err);
                    }
                    else
                    {
                        LogForScriptCase("复制脚本流【" + _script.NAME + "】实例【" + _scriptCaseID.ToString() + "】脚本节点及配置信息【成功】!", "", _scriptCaseID, ref err);
                    }
                    #endregion

                    try
                    {
                        db.SaveChanges();
                        LogForScriptCase("启动脚本流【" + _script.NAME + "】实例【" + _scriptCaseID.ToString() + "】【成功】!", "", _scriptCaseID, ref err);
                        return(_scriptCa);
                    }
                    catch (Exception e)
                    {
                        err.IsError = true;
                        err.Message = "启动脚本流【" + _script.NAME + "】实例【" + _scriptCaseID.ToString() + "】【失败】:" + e.Message;
                        //写日志
                        LogForScriptCase(err.Message, err.Message, _scriptCaseID, ref err);
                        return(null);
                    }
                }
                else
                {
                    err.IsError = true;
                    err.Message = "添加脚本流实例【失败】!脚本流【" + _script.NAME + "】已存在正运行的实例!";
                    return(null);
                }
            }
        }