Ejemplo n.º 1
0
 public virtual void Unlock(CacheLockType mode)
 {
     outputCache.ReleaseMutex();
 }
Ejemplo n.º 2
0
        DataHash DigestFile(MD5 provider, string filepath, Regex findDateTime)
        {
            var rv = new DataHash()
            {
                Result    = DataHashResult.FileNotFound,
                InputName = filepath,
            };

            if (!FileUtils.Exists(filepath))
            {
                return(rv);
            }
            provider.Initialize();
            var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read, 2048, FileOptions.SequentialScan);

            using (var bs = new BufferedStream(fs))
            {
                Logging.Emit("digest {0}", filepath);
                rv.Hash   = new SoapHexBinary(provider.ComputeHash(bs)).ToString();
                rv.Result = DataHashResult.Ok;


                if (findDateTime != null)
                {
                    bool mark_with_datetime = false;
                    if (Settings.HonorCPPTimes)
                    {
                        // check include cache for this file
                        if (includeCache.ContainsEntry(rv.Hash, F_NotDateTime))
                        {
                            return(rv);
                        }
                        if (includeCache.ContainsEntry(rv.Hash, F_HasDateTime))
                        {
                            rv.Result = DataHashResult.ContainsTimeOrDate;
                            return(rv);
                        }


                        bs.Seek(0, SeekOrigin.Begin);
                        using (var ts = new StreamReader(bs))
                        {
                            string line = null;
                            do
                            {
                                line = ts.ReadLine();
                                if (line != null)
                                {
                                    if (findDateTime.IsMatch(line))
                                    {
                                        mark_with_datetime = true;
                                        break;
                                    }
                                }
                            } while (line != null);
                        }
                    }

                    includeCache.WaitOne();
                    if (!mark_with_datetime)
                    {
                        includeCache.AddTextFileContent(rv.Hash, F_NotDateTime, "");
                    }
                    else
                    {
                        includeCache.AddTextFileContent(rv.Hash, F_HasDateTime, "");
                    }
                    includeCache.ReleaseMutex();
                }
            }
            rv.Result = DataHashResult.Ok;

            return(rv);
        }