Пример #1
0
        static void Main(string[] args)
        {
            var fileProcessor = new FileProcessor();
            var filePath = args[0];
            var config = new Config();
            var sortedDict = fileProcessor.GetHashesForFile(filePath, config);
               foreach (var entry in sortedDict)
            {
                Console.WriteLine("{0}:{1}:{2}:{3}", entry.Value.Offset, entry.Key, Convert.ToBase64String(entry.Value.StrongHash) , entry.Value.Length);
            }
            Console.Clear();

            //var comparisonFile = fileProcessor.GetDiffBlocksForFile(sortedDict, args[1], config);

            Console.WriteLine("Returned: {0} hashes", sortedDict.Count());

            //Console.WriteLine(comparisonFile.Count);
            Console.ReadKey();
        }
Пример #2
0
        public Guid CalculateHashesForFile(Config config, Guid sessionId)
        {
            var fileProcessor = new FileProcessor();
            var filePath = @"D:\\Downloads\\en_windows_7_ultimate_rc_x64_dvd_347803.iso";
            var fileId = Guid.NewGuid();
            fileProcessor.GetHashesForFileBockComplete += delegate(Guid currentFileId)
                                                                  {

                                                                      using (var ds = new DataStoreEntities())
                                                                      {
                                                                          var statusEntry =
                                                                              ds.FileStatuses.Where(
                                                                                  x => x.FileId == fileId)
                                                                          _.FirstOrDefault;

                                                                          if(statusEntry != null)
                                                                          {

                                                                          }

                                                                          else
                                                                          {

                                                                          }
                                                                      }
                                                                  };
            using (var ds = new DataStoreEntities())
            {

                var fileSignature = ds.FileSignatures.Where(x => x.FilePath == filePath).FirstOrDefault();

                if (fileSignature != null)
                {
                    return fileSignature.FileId;

                }

                var progressReporter = new ProgressReporter();

                Task.Factory.StartNew(() =>
                                          {

                                              var fileHashes = fileProcessor.GetHashesForFile(filePath, progressReporter,
                                                                                              config);
                                              using (var ms = new MemoryStream())
                                              {
                                                  var binaryFormatter = new BinaryFormatter();
                                                  binaryFormatter.Serialize(ms, fileHashes);

                                                  ds.FileSignatures.AddObject(new FileSignature()
                                                                                  {
                                                                                      FileId = fileId,
                                                                                      FilePath = filePath,
                                                                                      Signature = ms.ToArray()
                                                                                  });
                                              }
                                              ds.SaveChanges();
                                          });

                return fileId;

            }
        }