protected override bool Initialize(LatLongDataSourceEntity lastEntity) { if (!lastEntity.Enable) return false; string[] parameters = lastEntity.Parameters.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); if (parameters.Length != 2) { Logger.Error("HistoryGPSDataSource初始化参数错误!", "DataSourceID", lastEntity.ID); return false; } string dbConnectionKey = parameters[0]; LatLongConnectionEntity conn = GetDbConnection(dbConnectionKey); if (conn == null || string.IsNullOrEmpty(conn.ConnectionString)) { Logger.Error("HistoryGPSDataSource初始化参数错误: 无法获取连接字符串!", "DataSourceID", lastEntity.ID); return false; } DateTime start; if (string.IsNullOrEmpty(lastEntity.ProgressFlag) || !DateTime.TryParse(lastEntity.ProgressFlag, out start)) { start = new DateTime(2000, 1, 1); } this.dbConnectionString = conn.ConnectionString; this.tableName = parameters[1]; this.progressStart = start; this.progressEnd = null; this.processStatus = LatLongDataSourceStatus.Idle; return base.Initialize(lastEntity); }
public override IEnumerable<LatLong> RetrieveData(int retrieveCount) { string sqlText = string.Format(@"Select * From {0} Where ReportTime > '{1:yyyy-MM-dd hh:mm:ss}' Order By ReportTime Limit {2}", this.tableName, this.progressStart.Value, retrieveCount); int total = 0; using (MySqlDataReader dr = MySqlHelper.ExecuteReader(this.dbConnectionString, sqlText)) { while (dr.Read()) { var modle = new LatLong() { Latitude = Convert.ToDecimal(dr["Latitude"]), Longitude = Convert.ToDecimal(dr["Longitude"]), }; yield return modle; this.progressEnd = Convert.ToDateTime(dr["ReportTime"]); total++; } } this.processStatus = (total < retrieveCount) ? LatLongDataSourceStatus.Over : LatLongDataSourceStatus.Idle; Logger.Trace("处理当前数据源结束", "DataSource ID", this.DataSourceID, "DataSource Name", this.DataSourceName, "已处理数量", total, "希望处理数量", retrieveCount, "处理后状态", this.processStatus); }