/// <summary> /// Initialises the ImageFileHeader class and populates it with /// the specific data from the file contents /// </summary> /// <param name="fileContents">The contents of the file being read as an array</param> /// <param name="offset">The offset for the image file header</param> public FileHeader(byte[] fileContents, Offset offset) { _machine = (MachineTypes)BitConverter.ToUInt16(fileContents, offset.Shift(2)); _numberOfSections = BitConverter.ToUInt16(fileContents, offset.Shift(2)); _timeDateStamp = BitConverter.ToUInt32(fileContents, offset.Shift(4)); _pointerToSymbolTable = BitConverter.ToUInt32(fileContents, offset.Shift(4)); _numberOfSymbols = BitConverter.ToUInt32(fileContents, offset.Shift(4)); _sizeOfOptionalHeader = BitConverter.ToUInt16(fileContents, offset.Shift(2)); _characteristics = (FileCharacteristics)BitConverter.ToUInt16(fileContents, offset.Shift(2)); }
/// <summary> /// Returns the length of a specified file and the last time it has been written. File appender is queried before the file system. /// </summary> /// <param name="filePath">File which the information are requested.</param> /// <returns>The file characteristics, if the file information was retrieved successfully, otherwise null.</returns> private FileCharacteristics GetFileCharacteristics(string filePath) { var fileCharacteristics = this.fileAppenderCache.GetFileCharacteristics(filePath); if (fileCharacteristics != null) return fileCharacteristics; var fileInfo = new FileInfo(filePath); if (fileInfo.Exists) { #if !SILVERLIGHT fileCharacteristics = new FileCharacteristics(fileInfo.CreationTimeUtc, fileInfo.LastWriteTimeUtc, fileInfo.Length); #else fileCharacteristics = new FileCharacteristics(fileInfo.CreationTime, fileInfo.LastWriteTime, fileInfo.Length); #endif return fileCharacteristics; } return null; }
private bool PreviousLogOverlappedPeriod(FileCharacteristics fileCharacteristics, LogEventInfo logEvent) { if (!previousLogEventTimestamp.HasValue) return false; string formatString = GetArchiveDateFormatString(string.Empty); string lastWriteTimeString = TimeSource.Current.FromSystemTime(fileCharacteristics.LastWriteTimeUtc).ToString(formatString, CultureInfo.InvariantCulture); string logEventTimeString = logEvent.TimeStamp.ToString(formatString, CultureInfo.InvariantCulture); if (lastWriteTimeString != logEventTimeString) return false; DateTime periodAfterPreviousLogEventTime; switch (this.ArchiveEvery) { case FileArchivePeriod.Year: periodAfterPreviousLogEventTime = previousLogEventTimestamp.Value.AddYears(1); break; case FileArchivePeriod.Month: periodAfterPreviousLogEventTime = previousLogEventTimestamp.Value.AddMonths(1); break; case FileArchivePeriod.Day: periodAfterPreviousLogEventTime = previousLogEventTimestamp.Value.AddDays(1); break; case FileArchivePeriod.Hour: periodAfterPreviousLogEventTime = previousLogEventTimestamp.Value.AddHours(1); break; case FileArchivePeriod.Minute: periodAfterPreviousLogEventTime = previousLogEventTimestamp.Value.AddMinutes(1); break; default: return false; } string periodAfterPreviousLogEventTimeString = periodAfterPreviousLogEventTime.ToString(formatString, CultureInfo.InvariantCulture); return lastWriteTimeString == periodAfterPreviousLogEventTimeString; }