/// <summary> /// 保存日志附加的字符串值。 /// </summary> /// <param name="code">属性类型,通常使用搜索筛选器的类名。</param> /// <param name="ordinalNumber">序号,用于存储同一属性的多个值。</param> /// <param name="dataValue">数据值,长度在 250 个字符之内。</param> protected void Save(string code, int ordinalNumber, string dataValue) { AC.Base.Database.DbConnection dbConn = this.Application.GetDbConnection(); if (dbConn != null) { string strTableName = Tables.LogString.GetTableName(this.LogTime); if (dbConn.TableIsExist(strTableName) == false) { dbConn.CreateTable(typeof(Tables.LogString), strTableName); } try { string strSql = this.LogId + "," + Function.SqlStr(code, 250) + "," + ordinalNumber + "," + Function.SqlStr(dataValue, 250); strSql = "INSERT INTO " + strTableName + " (" + Tables.LogString.LogId + "," + Tables.LogString.Code + "," + Tables.LogString.OrdinalNumber + "," + Tables.LogString.DataValue + ") VALUES (" + strSql + ")"; dbConn.ExecuteNonQuery(strSql); } catch (Exception ex) { throw ex; } finally { dbConn.Close(); } } }
//任务运行完成后必须调用该方法 private void Save() { this.StopTime = DateTime.Now; AC.Base.Database.DbConnection dbConn = this.Config.Application.GetDbConnection(); if (dbConn != null) { try { string strTableName = Tables.TaskRunLog.GetTableName(this.Log.LogTime); if (dbConn.TableIsExist(strTableName) == false) { dbConn.CreateTable(typeof(Tables.TaskRunLog), strTableName); } string strConfig = null; System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); System.Xml.XmlNode xnConfig = this.GetTaskRunConfig(xmlDoc); if (xnConfig != null) { xmlDoc.AppendChild(xnConfig); strConfig = xmlDoc.OuterXml; } this.TimeStr = this.Log.LogId.ToString() + "_" + this.RetryTimes; string strSql = Function.SqlStr(this.Log.LogId.ToString()) + "," + this.RetryTimes + "," + this.StartTime.Ticks + "," + this.StopTime.Ticks + "," + (this.StopTime - this.StartTime).TotalMilliseconds + "," + ((int)this.State) + "," + this.Progress + "," + Function.SqlStr(this.taskName) + "," + Function.SqlStr(this.TimeStr) + "," + Function.SqlStr(strConfig); strSql = "INSERT INTO " + strTableName + " (" + Tables.TaskRunLog.TaskLogId + "," + Tables.TaskRunLog.RetryTimes + "," + Tables.TaskRunLog.StartTime + "," + Tables.TaskRunLog.StopTime + "," + Tables.TaskRunLog.TimeSpan + "," + Tables.TaskRunLog.TaskState + "," + Tables.TaskRunLog.TaskProgress + "," + Tables.TaskRunLog.DeviceName + "," + Tables.TaskRunLog.TimeStr + "," + Tables.TaskRunLog.XMLConfig + ") VALUES (" + strSql + ")"; dbConn.ExecuteNonQuery(strSql); strTableName = Tables.TaskLog.GetTableName(this.Log.LogTime); strSql = "UPDATE " + strTableName + " Set " + Tables.TaskLog.RetryTimes + "=" + this.RetryTimes + "," + Tables.TaskLog.LastProgress + "=" + this.Progress + " Where " + Tables.TaskLog.TaskLogId + "=" + Function.SqlStr(this.Log.LogId.ToString()); dbConn.ExecuteNonQuery(strSql); if (this.ExceptionInfos.Count > 0) { strTableName = Tables.TaskExceptionLog.GetTableName(this.Log.LogTime); if (dbConn.TableIsExist(strTableName) == false) { dbConn.CreateTable(typeof(Tables.TaskExceptionLog), strTableName); } for (int intIndex = 0; intIndex < this.ExceptionInfos.Count; intIndex++) { strSql = this.Log.LogId + "," + this.RetryTimes + "," + (intIndex + 1) + "," + this.ExceptionInfos[intIndex].ExceptionTime.Ticks + "," + Function.SqlStr(this.ExceptionInfos[intIndex].ExceptionInfo); strSql = "INSERT INTO " + strTableName + " (" + Tables.TaskExceptionLog.TaskLogId + "," + Tables.TaskExceptionLog.RetryTimes + "," + Tables.TaskExceptionLog.ExceptionId + "," + Tables.TaskExceptionLog.ExceptionTime + "," + Tables.TaskExceptionLog.XMLConfig + ") VALUES (" + strSql + ")"; dbConn.ExecuteNonQuery(strSql); } } } catch (Exception ex) { this.OnException(ex); } finally { dbConn.Close(); } } this.Log.Tasks.Add(this); if (this.Stopped != null) { try { this.Stopped(this); } catch (Exception ex) { this.OnException(ex.Message); } } }