Exemplo n.º 1
0
        /// <summary>
        /// Update or insert a new
        /// </summary>
        /// <param name="updatedEntry"></param>
        public void UpdateListEntry(FileScan updatedEntry)
        {
            int index = FindInList(updatedEntry.FileName);

            if (index >= 0)
            {
                FileList.RemoveAt(index);
                FileList.Insert(index, updatedEntry);
            }
            else
            {
                FileList.Add(updatedEntry);
            }
        }
Exemplo n.º 2
0
        public bool LoadFileListFile()
        {
            // Make the file if it doesn't exist
            if (!File.Exists(FileListFile))
            {
                File.WriteAllLines(FileListFile, new string[] { HEADER });
            }

            // Read the file from disk
            string[] lines;
            try
            {
                lines = File.ReadAllLines(FileListFile);
            }
            catch
            {
                return(false);
            }
            FileList.Clear();
            if (lines.Length < 2)
            {
                return(true);
            }

            FileScan entry;

            string[] tokens;
            for (int i = 1; i < lines.Length; i++)
            {
                tokens                   = lines[i].Split(',');
                entry                    = new FileScan();
                entry.FileName           = tokens[0];
                entry.TimeOfLastAccess   = DateTime.Parse(tokens[1]);
                entry.Hash               = tokens[2];
                entry.Bytes              = long.Parse(tokens[3]);
                entry.ProcessedBytes     = long.Parse(tokens[4]);
                entry.TimeOfModification = DateTime.Parse(tokens[5]);
                entry.DataStartTime      = DateTime.Parse(tokens[6]);
                entry.DataEndTime        = DateTime.Parse(tokens[7]);
                FileList.Add(entry);
            }
            return(true);
        }
Exemplo n.º 3
0
        public FileScan ScanFile(string fileName)
        {
            FileInfo info  = new FileInfo(fileName);
            FileScan entry = new FileScan
            {
                FileName         = fileName,
                TimeOfLastAccess = DateTime.Now,
                Bytes            = info.Length,
                ProcessedBytes   = 0,
            };

            if (LazyMode)
            {
                entry.Hash = "";
            }
            else
            {
                entry.Hash = HashFile(fileName);
            }
            long ticks = info.LastWriteTime.Ticks / OneSecond.Ticks;

            entry.TimeOfModification = new DateTime(ticks * OneSecond.Ticks);
            return(entry);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns FileScans that are not consistent with the FileList
        /// </summary>
        /// <returns></returns>
        public List <FileScan> Scan()
        {
            int             listCount        = FileList.Count;
            List <FileScan> scanResults      = ScanDirectory(DirectoryToMonitor);
            List <FileScan> outOfDateResults = new List <FileScan>(scanResults.Count);

            bool[] accountedFor = new bool[listCount];
            for (int i = 0; i < listCount; i++)
            {
                accountedFor[i] = false;
            }

            // Find all out of date and deleted files
            int index;

            for (int i = 0; i < scanResults.Count; i++)
            {
                FileScan scanResult = scanResults[i];
                index = FindInList(scanResult.FileName);
                if (index < 0)
                {
                    outOfDateResults.Add(scanResult);
                }
                else
                if (LazyMode)
                {
                    if (FileList[index].ProcessedBytes < scanResult.Bytes ||
                        FileList[index].Bytes != scanResult.Bytes ||
                        FileList[index].TimeOfModification != scanResult.TimeOfModification)
                    {
                        scanResult.ProcessedBytes = FileList[index].ProcessedBytes;
                        outOfDateResults.Add(scanResult);
                        accountedFor[index] = true;
                    }
                    else
                    {
                        accountedFor[index] = true;
                    }
                }
                else
                {
                    if (FileList[index].ProcessedBytes < scanResult.Bytes ||
                        FileList[index].Hash != scanResult.Hash)
                    {
                        scanResult.ProcessedBytes = FileList[index].ProcessedBytes;
                        outOfDateResults.Add(scanResult);
                        accountedFor[index] = true;
                    }
                    else
                    {
                        accountedFor[index] = true;
                    }
                }
            }

            MissingFiles.Clear();
            for (int i = 0; i < listCount; i++)
            {
                if (!accountedFor[i])
                {
                    MissingFiles.Add(FileList[i]);
                }
            }
            return(outOfDateResults);
        }
Exemplo n.º 5
0
 public GenerateFileCache(CacheManager manager, InstrumentCache instrumentCache, FileScan scan) : base(manager)
 {
     ICache = instrumentCache;
     Scan   = scan;
 }