private void PurgeStaleEventData(AdoDataConnection connection, DataRescueOperation operation) { string baseCriteria = $"FileGroupID IN " + $"( " + $" SELECT FileGroupID " + $" FROM DataRescueFileGroup " + $" WHERE DataRescueOperationID = {operation.ID} " + $")"; CascadeDelete(connection, "Event", baseCriteria); XDANodeClient.NotifyNodes("openXDA.Nodes.dll", "openXDA.Nodes.Types.FilePruning.FilePrunerNode", "PurgeOrphanData"); }
public async Task DeleteOperationAsync(int dataRescueOperationID, CancellationToken cancellationToken = default) { using (AdoDataConnection connection = CreateDbConnection()) { DataRescueOperation ToOperation(DataRow row) => new DataRescueOperation() { ID = row.ConvertField <int>("ID"), MeterID = row.ConvertField <int>("MeterID"), StartTime = row.ConvertField <DateTime>("StartTime"), EndTime = row.ConvertField <DateTime>("EndTime") }; DataRescueOperation operation = new Func <DataRescueOperation>(() => { const string QueryFormat = "SELECT " + " ID, " + " MeterID, " + " StartTime, " + " EndTime " + "FROM DataRescueOperation " + "WHERE ID = {0}"; using (DataTable table = connection.RetrieveData(QueryFormat, dataRescueOperationID)) { return(table .AsEnumerable() .Select(ToOperation) .FirstOrDefault()); } })(); const string DeleteFormat = "DELETE FROM DataRescueTimeShift " + "WHERE DataRescueOperationID = {0} " + "" + "DELETE FROM DataRescueChannelAdjustment " + "WHERE DataRescueOperationID = {0}"; connection.ExecuteNonQuery(DeleteFormat, operation.ID); PurgeStaleEventData(connection, operation); await PurgeStaleTrendingDataAsync(operation, cancellationToken); ReprocessAffectedFiles(connection, operation); string baseCriteria = $"ID = {dataRescueOperationID}"; CascadeDelete(connection, "DataRescueOperation", baseCriteria); XDANodeClient.NotifyNodes("openXDA.Nodes.dll", "openXDA.Nodes.Types.Analysis.AnalysisNode", "PollTaskQueue"); } }
private void ReprocessAffectedFiles(AdoDataConnection connection, DataRescueOperation operation) { const string QueryFormat = "INSERT INTO AnalysisTask(FileGroupID, MeterID, Priority) " + "SELECT " + " DataRescueFileGroup.FileGroupID, " + " {1} MeterID, " + " 1 Priority " + "FROM DataRescueFileGroup " + "WHERE DataRescueFileGroup.DataRescueOperationID = {0}"; int operationID = operation.ID; int meterID = operation.MeterID; connection.ExecuteNonQuery(QueryFormat, operationID, meterID); XDANodeClient.NotifyNodes("openXDA.Nodes.dll", "openXDA.Nodes.Types.Analysis.AnalysisNode", "PollTaskQueue"); }
private void DeleteEventData(AdoDataConnection connection, int meterID, DateTime startTime, DateTime endTime) { const string TimestampFormat = "yyyy-MM-dd HH:mm:ss.fffffff"; string Format(DateTime dateTime) => dateTime.ToString(TimestampFormat); string start = Format(startTime); string end = Format(endTime); string baseCriteria = $"FileGroupID IN " + $"( " + $" SELECT ID " + $" FROM FileGroup " + $" WHERE " + $" MeterID = {meterID} AND " + $" DataEndTime >= '{start}' AND " + $" DataStartTime <= '{end}' " + $")"; CascadeDelete(connection, "Event", baseCriteria); XDANodeClient.NotifyNodes("openXDA.Nodes.dll", "openXDA.Nodes.Types.FilePruning.FilePrunerNode", "PurgeOrphanData"); }