Exemplo n.º 1
0
            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);
            }
Exemplo n.º 2
0
        private static string AddTempFileHash(string originPath)
        {
            var process = LocalEnvironmental.CurrentProcess;
            var hash    = $"_{TemporaryFileHash.CreateFrom(process).ToHashString()}";

            return(PathChnager.AddFileName(originPath, hash));
        }
Exemplo n.º 3
0
 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));
     }
 }
Exemplo n.º 4
0
        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));
        }