public static bool TryParseFromPath(string path, out TemporaryFileHash val) { val = Empty; var fileName = Path.GetFileNameWithoutExtension(path); var splitedStrings = fileName.Split('_'); if (splitedStrings.Length < 3) { return(false); } Array.Reverse(splitedStrings); if (!long.TryParse(splitedStrings[0], out var startTimeTick)) { return(false); } if (!int.TryParse(splitedStrings[1], out var processId)) { return(false); } val = new TemporaryFileHash(processId, startTimeTick); return(true); }
private static string AddTempFileHash(string originPath) { var process = LocalEnvironmental.CurrentProcess; var hash = $"_{TemporaryFileHash.CreateFrom(process).ToHashString()}"; return(PathChnager.AddFileName(originPath, hash)); }
private static bool TryGetHash(string filePath, out TemporaryFileHash val) { if (Path.GetExtension(filePath) != _temporaryFileExtension) { val = TemporaryFileHash.Empty; return(false); } else { return(TemporaryFileHash.TryParseFromPath(filePath, out val)); } }
public static bool IsInProcess(string filePath, Process process) { if (filePath is null) { throw new ArgumentNullException(nameof(filePath)); } if (process is null) { throw new ArgumentNullException(nameof(process)); } if (!TryGetHash(filePath, out var hash)) { return(false); } return(TemporaryFileHash.CreateFrom(process).Equals(hash)); }