Beispiel #1
0
        private static int add(JObject job, ScriptExecuteResut model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ScriptExecuteResut(");
            strSql.Append("AccomPlishNum,succeed,fail,SatrtDate,EndDate,ter_id,ScriptName,LogFilePath,ExecuteTrimLenght,isDel)");
            strSql.Append(" values (");
            strSql.Append("@AccomPlishNum,@succeed,@fail,@SatrtDate,@EndDate,@ter_id,@ScriptName,@LogFilePath,@ExecuteTrimLenght,@isDel)");
            strSql.Append(";select LAST_INSERT_ROWID()");
            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@AccomPlishNum",     DbType.Int32,   8),
                new SQLiteParameter("@succeed",           DbType.Int32,   8),
                new SQLiteParameter("@fail",              DbType.Int32,   8),
                new SQLiteParameter("@SatrtDate",         DbType.String),
                new SQLiteParameter("@EndDate",           DbType.String),
                new SQLiteParameter("@ter_id",            DbType.Int32,   8),
                new SQLiteParameter("@ScriptName",        DbType.String),
                new SQLiteParameter("@LogFilePath",       DbType.String),
                new SQLiteParameter("@ExecuteTrimLenght", DbType.Int32,   8),
                new SQLiteParameter("@isDel",             DbType.Int32, 4)
            };
            parameters[0].Value = model.AccomPlishNum;
            parameters[1].Value = model.succeed;
            parameters[2].Value = model.fail;
            parameters[3].Value = model.SatrtDate;
            parameters[4].Value = model.EndDate;
            parameters[5].Value = model.ter_id;
            parameters[6].Value = model.ScriptName;
            parameters[7].Value = model.LogFilePath;
            parameters[8].Value = model.ExecuteTrimLenght;
            parameters[9].Value = model.IsDel;

            object obj = SqliteHelpDao.ExecuteScalar(ConnectionString, CommandType.Text, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #2
0
        private static void Result(IAsyncResult ar)
        {
            listener.BeginGetContext(Result, null);
            Console.WriteLine($"接到新的请求");
            var context  = listener.EndGetContext(ar);
            var request  = context.Request;
            var response = context.Response;

            context.Response.ContentType = "text/plain;charset=UTF-8";//告诉客户端返回的ContentType类型为纯文本格式,编码为UTF-8
            //context.Response.AddHeader("Content-type", "text/plain");//添加响应头信息
            context.Response.ContentEncoding = Encoding.UTF8;
            string returnObj = null;//定义返回客户端的信息

            if (request.HttpMethod == "POST" && request.InputStream != null)
            {
                try
                {
                    Stream       stream    = request.InputStream;
                    StreamReader strStream = new StreamReader(stream, Encoding.UTF8);
                    string       retString = strStream.ReadToEnd();

                    stream.Close();
                    strStream.Close();
                    //var ret = JObject.Parse(retString).ToObject<Dictionary<String, object>>();
                    //Dictionary<String,object> ret = JsonConvert.DeserializeObject<Dictionary<String, object>>(retString);
                    //Dictionary<String,List<Message>> me = JsonConvert.DeserializeObject<Dictionary<String, List<Message>>>(ret["Table"].ToString());
                    //JArray jarray = JArray.Parse(ret["Table"].ToString());
                    JArray jarray = JArray.Parse(retString);
                    foreach (var jsonitem in jarray)
                    {
                        JObject job    = (JObject)jsonitem;
                        int     ser_id = AddScriptResult(job);
                        ScriptExecuteDetailResult model  = addRe(ser_id, job);
                        StringBuilder             strSql = new StringBuilder();
                        strSql.Append("insert into ScriptExecuteDetailResult(");
                        strSql.Append("ScriptName,ser_id,IsSucceed,StartDate,EndDate,LogFilePath,terminal,isDel,DeviceName,ExecuteTrimLenght,remark,TaskNum,IsUnLoad)");
                        strSql.Append(" values (");
                        strSql.Append("@ScriptName,@ser_id,@IsSucceed,@StartDate,@EndDate,@LogFilePath,@terminal,@isDel,@DeviceName,@ExecuteTrimLenght,@remark,@TaskNum,0)");
                        strSql.Append(";select LAST_INSERT_ROWID()");
                        SQLiteParameter[] parameters =
                        {
                            new SQLiteParameter("@ScriptName",        DbType.String),
                            new SQLiteParameter("@ser_id",            DbType.Int32,      8),
                            new SQLiteParameter("@IsSucceed",         DbType.String),
                            new SQLiteParameter("@StartDate",         DbType.String),
                            new SQLiteParameter("@EndDate",           DbType.String),
                            new SQLiteParameter("@LogFilePath",       DbType.String),
                            new SQLiteParameter("@terminal",          DbType.String),
                            new SQLiteParameter("@isDel",             DbType.Int16,      4),
                            new SQLiteParameter("@DeviceName",        DbType.String,    50),
                            new SQLiteParameter("@ExecuteTrimLenght", DbType.Int16,      4),
                            new SQLiteParameter("@remark",            DbType.String,  1000),
                            new SQLiteParameter("@TaskNum",           DbType.Int32, 8)
                        };
                        parameters[0].Value  = model.ScriptName;
                        parameters[1].Value  = model.ser_id;
                        parameters[2].Value  = model.IsSucceed;
                        parameters[3].Value  = model.StartDate;
                        parameters[4].Value  = model.EndDate;
                        parameters[5].Value  = model.LogFilePath;
                        parameters[6].Value  = model.Terminal;
                        parameters[7].Value  = model.IsDel;
                        parameters[8].Value  = model.DeviceName;
                        parameters[9].Value  = model.ExecuteTrimLenght;
                        parameters[10].Value = model.Remark;
                        parameters[11].Value = model.TaskNum;

                        object obj = SqliteHelpDao.ExecuteScalar(ConnectionString, CommandType.Text, strSql.ToString(), parameters);
                        int    a;
                        if (obj == null)
                        {
                            a = 0;
                        }
                        else
                        {
                            a = Convert.ToInt32(obj);
                        }
                    }
                    response.StatusDescription = "200"; //获取或设置返回给客户端的 HTTP 状态代码的文本说明。
                    response.StatusCode        = 200;   // 获取或设置返回给客户端的 HTTP 状态代码。
                    returnObj = "已收到,接收成功";
                }
                catch (Exception ex)
                {
                    response.StatusDescription = "404";
                    response.StatusCode        = 404;
                    returnObj = ex.Message;
                }

                Stream outstream = response.OutputStream;
                byte[] buffer    = Encoding.UTF8.GetBytes(returnObj);
                outstream.Write(buffer, 0, buffer.Length);
                outstream.Close();
            }
        }