/// <summary> /// Creates a new tracking file. /// </summary> /// <remarks> /// If the project already contains a <see cref="TrackingFile"/> /// this will throw an <see cref="InvalidOperationException"/>. /// </remarks> /// <param name="projectId">The internal project id.</param> /// <param name="directoryInfo">The directory of the project.</param> /// <returns>The created <see cref="TrackingFile"/>.</returns> public TrackingFile CreateTrackingFile(Guid projectId, DirectoryInfo directoryInfo) { if (projectId == null || projectId == Guid.Empty) { throw new ArgumentNullException(nameof(projectId)); } if (directoryInfo == null) { throw new ArgumentNullException(nameof(directoryInfo)); } if (HasTrackingFile(directoryInfo)) { throw new InvalidOperationException("Project already has a tracking file"); } // TODO Pass required properties to this file. var trackingFile = new TrackingFile { ProjectId = projectId, TrackingFileDateCreated = DateTimeOffset.Now, ProjectDateScraped = DateTimeOffset.Now, TrackingFileStatus = TrackingFileStatus.UpToDate }; WriteToFile(directoryInfo, trackingFile); return(trackingFile); }
// TODO Move to helper /// <summary> /// Actually writes a <see cref="TrackingFile"/> to file. /// </summary> /// <param name="directoryInfo">The directory.</param> /// <param name="trackingFile">The tracking file to write.</param> private static void WriteToFile(DirectoryInfo directoryInfo, TrackingFile trackingFile) { var path = $"{directoryInfo.FullPathFormatted()}/{trackingFile.ProjectId}{Constants.TrackingFileExtension}"; using var stream = new FileStream(path, FileMode.Create); var formatter = new BinaryFormatter(); formatter.Serialize(stream, trackingFile); }
/// <summary> /// Deletes and creates a tracking file. /// </summary> /// <param name="directoryInfo">The file directory.</param> /// <param name="trackingFile">The new tracking file.</param> private void OverwriteFile(DirectoryInfo directoryInfo, TrackingFile trackingFile) { DeleteTrackingFile(directoryInfo); WriteToFile(directoryInfo, trackingFile); }
private void ProcessFile() { TrackingFile trackingFile = new TrackingFile(_sender.FileClosed); trackingFile(_filePath); }