Exemple #1
0
        public int AddBatch(RLib.DB.DbConn dbconn, List <Model.Dispatch> modelsx)
        {
            if (modelsx == null || modelsx.Count == 0)
            {
                return(0);
            }
            var skp   = 0;
            var psize = 30;

            if (dbconn.GetBaseConnection().DataSource.ToUpper().EndsWith("SQLEXPRESS"))
            {
                psize = 1;
            }
            while (skp < modelsx.Count)
            {
                var models = modelsx.Skip(skp).Take(psize);
                skp += psize;
                string        sql  = @"INSERT INTO [dbo].[dispatch]
            ([groupId],[invokeId],[taskId],[dispatchState],[runKey],[nickName],[runArgs],[createTime],[expireTime],nodeId) VALUES ";
                string        vlt  = "(@groupid_{0},@invokeid_{0},@taskid_{0},0,@runkey_{0},@nickname_{0},@runargs_{0},getdate(),@expiretime_{0},0 )";
                List <string> sqls = new List <string>();
                List <RLib.DB.ProcedureParameter> para = new List <RLib.DB.ProcedureParameter>();
                int i = 0;
                foreach (var a in models)
                {
                    i++;
                    para.Add(new RLib.DB.ProcedureParameter("@groupid_" + i, a.GroupId));
                    para.Add(new RLib.DB.ProcedureParameter("@invokeid_" + i, a.InvokeId));
                    para.Add(new RLib.DB.ProcedureParameter("@taskid_" + i, a.TaskId));
                    para.Add(new RLib.DB.ProcedureParameter("@runkey_" + i, a.RunKey));
                    para.Add(new RLib.DB.ProcedureParameter("@nickname_" + i, a.NickName));
                    para.Add(new RLib.DB.ProcedureParameter("@runargs_" + i, a.RunArgs ?? ""));
                    para.Add(new RLib.DB.ProcedureParameter("@expiretime_" + i, a.ExpireTime));
                    sqls.Add(string.Format(vlt, i));
                }
                sql = sql + string.Join(",", sqls);
                int r = dbconn.ExecuteSql(sql, para);
            }
            return(modelsx.Count);
        }