public bool SetLastEndTime(string fileName, DateTime stopTime) { var fileParam = new LastEndTimeFileParameters(this.traceSource, this.logSourceId) { Fs = null, FileName = fileName, Mode = FileMode.OpenOrCreate, Access = FileAccess.Write, // Convert the timestamp from DateTime to binary LastEndTimeLong = stopTime.ToBinary(), LastEndTime = stopTime }; // Open the file that contains the last ETL read timestamp or create // the file if it doesn't already exist. try { Utility.PerformIOWithRetries( fileParam.OpenLastEndTimeFile, EtlInMemoryProducerConstants.MethodExecutionInitialRetryIntervalMs, EtlInMemoryProducerConstants.MethodExecutionMaxRetryCount, EtlInMemoryProducerConstants.MethodExecutionMaxRetryIntervalMs); } catch (Exception e) { this.traceSource.WriteExceptionAsError( this.logSourceId, e, "Failed to open file {0} for write.", fileName); return(false); } try { // Write the time stamp to the file fileParam.Writer = new StreamWriter(fileParam.Fs); try { try { Utility.PerformIOWithRetries( fileParam.WriteLastEndTime, EtlInMemoryProducerConstants.MethodExecutionInitialRetryIntervalMs, EtlInMemoryProducerConstants.MethodExecutionMaxRetryCount, EtlInMemoryProducerConstants.MethodExecutionMaxRetryIntervalMs); } catch (Exception e) { this.traceSource.WriteExceptionAsError( this.logSourceId, e, "Failed to write last ETL read end time to file {0}.", fileName); return(false); } } finally { fileParam.Writer.Dispose(); } } finally { fileParam.Fs.Dispose(); } return(true); }
public bool GetLastEndTime(string fileName, out DateTime lastEndTime) { lastEndTime = DateTime.MinValue; var fileParam = new LastEndTimeFileParameters(this.traceSource, this.logSourceId) { Fs = null, FileName = fileName, Mode = FileMode.Open, Access = FileAccess.Read }; // Try to open the file that contains the last ETL read timestamp try { Utility.PerformIOWithRetries( fileParam.OpenLastEndTimeFile, EtlInMemoryProducerConstants.MethodExecutionInitialRetryIntervalMs, EtlInMemoryProducerConstants.MethodExecutionMaxRetryCount, EtlInMemoryProducerConstants.MethodExecutionMaxRetryIntervalMs); } catch (Exception e) { this.traceSource.WriteExceptionAsError( this.logSourceId, e, "Failed to open file {0} for read.", fileName); return(false); } if (null == fileParam.Fs) { // File wasn't found. So we'll assume that this is the first // time that we are attempting to read ETL files. return(true); } try { // Read the timestamp from the file fileParam.Reader = new StreamReader(fileParam.Fs); try { try { Utility.PerformIOWithRetries( fileParam.ReadLastEndTime, EtlInMemoryProducerConstants.MethodExecutionInitialRetryIntervalMs, EtlInMemoryProducerConstants.MethodExecutionMaxRetryCount, EtlInMemoryProducerConstants.MethodExecutionMaxRetryIntervalMs); } catch (Exception e) { // Abort this ETL processing pass. We'll try again in the next pass. this.traceSource.WriteExceptionAsError( this.logSourceId, e, "Failed to read last ETL read end time from file {0}.", fileName); return(false); } } finally { fileParam.Reader.Dispose(); } } finally { fileParam.Fs.Dispose(); } // Convert the timestamp from binary to DateTime lastEndTime = DateTime.FromBinary(fileParam.LastEndTimeLong); return(true); }
public bool SetLastEndTime(string lastReadFileName, DateTime stopTime) { var fileFullPath = Path.Combine(this.lastEtlFileReadFileDirectoryPath, lastReadFileName); var fileParam = new LastEndTimeFileParameters(this.traceSource, this.logSourceId) { Fs = null, FileName = fileFullPath, Mode = FileMode.OpenOrCreate, Access = FileAccess.Write, // Convert the timestamp from DateTime to binary LastEndTimeLong = stopTime.ToBinary(), LastEndTime = stopTime }; // Open the file that contains the last ETL read timestamp or create // the file if it doesn't already exist. try { Utility.PerformIOWithRetries( fileParam.OpenLastEndTimeFile); } catch (Exception e) { this.traceSource.WriteExceptionAsError( this.logSourceId, e, "Failed to open file {0} for write.", fileFullPath); return(false); } try { // Write the time stamp to the file fileParam.Writer = new StreamWriter(fileParam.Fs); try { try { Utility.PerformIOWithRetries( fileParam.WriteLastEndTime); } catch (Exception e) { this.traceSource.WriteExceptionAsError( this.logSourceId, e, "Failed to write last ETL read end time to file {0}.", fileFullPath); return(false); } } finally { fileParam.Writer.Dispose(); } } finally { fileParam.Fs.Dispose(); } return(true); }