Exemplo n.º 1
0
        private Dictionary <string, List <string> > FindDuplicateFilesIterative(string rootDirectory)
        {
            Dictionary <string, List <string> > duplicatesFiles = new Dictionary <string, List <string> >();

            Console.WriteLine($"Start iterative operation for finding duplicate files from {rootDirectory}");

            Queue <string> directoriesToSearch = new Queue <string>();

            directoriesToSearch.Enqueue(rootDirectory);

            while (directoriesToSearch.Count > 0)
            {
                string currentSearchDirectory = directoriesToSearch.Dequeue();
                Console.WriteLine($"Collecting from {currentSearchDirectory}");

                // Adding subdirectories to search.
                foreach (string directory in Directory.EnumerateDirectories(currentSearchDirectory))
                {
                    directoriesToSearch.Enqueue(directory);
                }

                // Search files.
                foreach (string filePath in Directory.EnumerateFiles(currentSearchDirectory))
                {
                    AddFileHashToGivenDict(duplicatesFiles, HashCalculator.CalculateHash(filePath), filePath);
                }
            }

            Console.WriteLine($"Finished iterative operation for finding duplicate files from {rootDirectory}");
            return(duplicatesFiles);
        }
Exemplo n.º 2
0
        public async Task Return_unprocessableEntityObjectResult_when_credentials_are_null()
        {
            var request = PrepareRequestWithCredentials(null);

            var result = await HashCalculator.CalculateHash(request) as UnprocessableEntityObjectResult;

            result.ShouldNotBeNull();
        }
Exemplo n.º 3
0
        public async Task Return_hash_for_correct_credentials(
            Credentials credentials)
        {
            var request = PrepareRequestWithCredentials(credentials);

            var result = await HashCalculator.CalculateHash(request) as OkObjectResult;

            // We could check hash length and things like that but I don't know the exact requirements
            result.ShouldNotBeNull();
            result.Value.ShouldNotBeNull();
        }
Exemplo n.º 4
0
        public async Task Return_unprocessableEntityObjectResult_when_login_or_password_is_null_or_whitespace(
            string login,
            string password)
        {
            var credentials = new Credentials {
                Login = login, Password = password
            };
            var request = PrepareRequestWithCredentials(credentials);

            var result = await HashCalculator.CalculateHash(request) as UnprocessableEntityObjectResult;

            result.ShouldNotBeNull();
        }
Exemplo n.º 5
0
        //TODO: переместить в BLL
        public static bool IsBlockValid(Block currentBlock)
        {
            //compare registered hash and calculated hash:
            //TODO: nonce надо достать из последного блока из БД
            if (!currentBlock.Hash.Equals(HashCalculator.CalculateHash(currentBlock, 0)))
            {
                return(false);
            }

            //check if hash is solved - перевод на русский
            var hashTarget = new string(new char[Difficulty]).Replace('\0', '0');

            return(currentBlock.Hash.Substring(0, Difficulty).Equals(hashTarget));
        }
Exemplo n.º 6
0
        private static (string hash, long proof) GetHashAndProof(DateTime timestamp)
        {
            long proof = -1;
            var  hash  = string.Empty;

            do
            {
                proof++;
                hash = HashCalculator.CalculateHash(Hash, timestamp, proof);
            }while (!Validators.IsProofValid(hash));

            Hash  = hash;
            Proof = proof;
            return(hash, proof);
        }
Exemplo n.º 7
0
        public async Task Return_the_same_hash_for_the_same_credentials(
            Credentials credentials)
        {
            var request1 = PrepareRequestWithCredentials(credentials);
            var request2 = PrepareRequestWithCredentials(credentials);

            var result1 = await HashCalculator.CalculateHash(request1) as OkObjectResult;

            var result2 = await HashCalculator.CalculateHash(request2) as OkObjectResult;

            result1.ShouldNotBeNull();
            result2.ShouldNotBeNull();

            result1.Value.ShouldNotBeNull();
            result2.Value.ShouldNotBeNull();

            result1.Value.ShouldBe(result2.Value);
        }
Exemplo n.º 8
0
        private Dictionary <string, List <string> > RegisterFiles(Dictionary <string, List <string> > hashToFilePathDict,
                                                                  List <string> unregisteredFiles)
        {
            foreach (string unregisteredFile in unregisteredFiles)
            {
                string unregisteredFileFullPath = mConfiguration.Value.DriveRootDirectory + '/' + unregisteredFile;

                string fileHash = HashCalculator.CalculateHash(unregisteredFileFullPath);
                if (hashToFilePathDict.TryGetValue(fileHash, out List <string> filePaths))
                {
                    filePaths.Add(unregisteredFile);
                }
                else
                {
                    hashToFilePathDict[fileHash] = new List <string> {
                        unregisteredFile
                    };
                }
            }

            return(hashToFilePathDict);
        }
 public override int GetHashCode()
 {
     return(HashCalculator.CalculateHash(Protocol, (int)LocalPort, PLength, LocalAddress.Address, (int)RemotePort, (PID + (int)State)));
 }
 public override int GetHashCode()
 {
     return(HashCalculator.CalculateHash(Protocol, (int)LocalPort, PLength, LocalAddress.Address, 0, PID));
 }