Ejemplo n.º 1
0
        private static void ProcessEXIF(DirectoryInfo folder, bool replace)
        {
            int    _count = 0;
            string mess   = $"\r\n{DateTime.Now}, INFO - ProcessEXIF: target folder is {folder.FullName}\n\rTruncate CheckSum is: {replace}.";

            Log(mess);
            Console.WriteLine($"{DateTime.Now}, INFO - press any key to start processing.");
            Console.ReadLine();

            if (replace)
            {
                using (IDbConnection db = new SqlConnection(ConnectionString))
                {
                    db.Execute("truncate table dbo.CheckSum");
                }
            }

            // get an array of FileInfo objects from the folder tree
            FileInfo[] _files = folder.GetFiles("*.JPG", SearchOption.AllDirectories);

            foreach (FileInfo fi in _files)
            {
                // get the EXIF date/time
                (DateTime _CreateDateTime, string _sCreateDateTime) = ImageEXIF(fi);


                // instantiate a new CheckSum object for the file
                var checkSum = new CheckSum
                {
                    SHA             = "",
                    Folder          = fi.DirectoryName,
                    TheFileName     = fi.Name,
                    FileExt         = fi.Extension,
                    FileSize        = (int)fi.Length,
                    FileCreateDt    = fi.CreationTime,
                    CreateDateTime  = _CreateDateTime,
                    SCreateDateTime = _sCreateDateTime
                };

                // insert into DB table
                CheckSum_ins2(checkSum);


                _count++;

                if (_count % 1000 == 0)
                {
                    mess = $"{DateTime.Now}, INFO - {_count.ToString("N0")}. Completed: {((_count * 100) / _files.Length)}%. Processing folder: {fi.DirectoryName}";
                    Log(mess);
                }
            }
        }
Ejemplo n.º 2
0
        private static int ProcessFiles(DirectoryInfo folder)
        {
            int _count = 0;

            System.Diagnostics.Stopwatch process100Watch = System.Diagnostics.Stopwatch.StartNew();

            FileInfo[] _files = folder.GetFiles("*", SearchOption.AllDirectories);

            // Process all the files in the source directory tree
            foreach (FileInfo fi in _files)
            {
                // instantiate a new CheckSum object for the file
                var checkSum = new CheckSum
                {
                    SHA          = "",
                    Folder       = fi.DirectoryName,
                    TheFileName  = fi.Name,
                    FileExt      = fi.Extension,
                    FileSize     = (int)fi.Length / 1024,
                    FileCreateDt = fi.CreationTime
                };

                // see if the file name already exists in the Checksums list
                var alreadyExists = _checksums.Find(x => x.TheFileName == fi.Name);

                // if the file name already exists then write the Checksum and the new Checksum to the CheckSum table is the DB
                if (alreadyExists != null)
                {
                    CheckSum_ins(alreadyExists);
                    CheckSum_ins(checkSum);
                }
                else                 // just add the new file to the CheckSum list
                {
                    _checksums.Add(checkSum);
                }

                _count++;

                if (_count % 1000 == 0)
                {
                    process100Watch.Stop();
                    Console.WriteLine($"{DateTime.Now}, INFO - {_count}. Last 100 in {process100Watch.ElapsedMilliseconds / 1000} secs. " +
                                      $"Completed: {(_count * 100) / _files.Length}%. " +
                                      $"Processing folder: {fi.DirectoryName}");
                    process100Watch.Reset();
                    process100Watch.Start();
                }
            }
            return(_count);
        }
Ejemplo n.º 3
0
        private static void CheckSum_ins(CheckSum checkSum)
        {
            // create the SqlParameters for the stored procedure
            var p = new DynamicParameters();

            p.Add("@SHA", checkSum.SHA);
            p.Add("@Folder", checkSum.Folder);
            p.Add("@TheFileName", checkSum.TheFileName);
            p.Add("@FileExt", checkSum.FileExt);
            p.Add("@FileSize", checkSum.FileSize);
            p.Add("@FileCreateDt", checkSum.FileCreateDt);
            p.Add("@TimerMs", checkSum.TimerMs);
            p.Add("@Notes", "");

            // call the stored procedure
            using (IDbConnection db = new SqlConnection(ConnectionString))
            {
                db.Execute("dbo.spCheckSum_ins", p, commandType: CommandType.StoredProcedure);
            }
        }