Пример #1
0
        internal static void creationOccured(FileSystemEventArgs e)
        {
            //Er der en fil i directoriet der har samme entropi som denne er den blot rykket
            //Løb listen af keys igennem, se value, nogen ens? Godt
            //add til databasen den nye fil, slet den gamle

            Dictionary <string, double> savedEntropies = new Dictionary <string, double>();

            savedEntropies = ShannonEntropy.getSavedEntropies();

            FileInfo createdFileInfo = new FileInfo(e.FullPath);

            ShannonEntropy entropyCreator     = new ShannonEntropy();
            double         createdFileEntropy = entropyCreator.CalculateEntropy(createdFileInfo);


            Console.WriteLine("File " + e.FullPath + " has been created and entropy is now " + createdFileEntropy);
            if (createdFileEntropy == -1)
            {
                return;
            }

            Boolean fileHasBeenMoved = false;
            string  oldFilePath      = "";

            foreach (var item in savedEntropies)
            {
                if (item.Value == createdFileEntropy)
                {
                    //File has been moved
                    fileHasBeenMoved = true;
                    oldFilePath      = item.Key;
                }
            }

            if (fileHasBeenMoved)
            {
                ShannonEntropy.removeKeyFromSavedEntropies(oldFilePath);
                ShannonEntropy.addKeyAndDoubleToSavedEntropies(e.FullPath, createdFileEntropy);
            }
            else
            {
                //TODO find threshold på nye filer og om entropien er for høj
                ShannonEntropy.removeKeyFromSavedEntropies(oldFilePath);
                ShannonEntropy.addKeyAndDoubleToSavedEntropies(e.FullPath, createdFileEntropy);
                if (createdFileEntropy > entropyThreshold)
                {
                    react(e);
                }
            }
        }
Пример #2
0
 //Event handeler if an object is renamed
 private static void OnRenamed(object source, RenamedEventArgs e)
 {
     Console.WriteLine(e.OldFullPath + " is renamed to " + e.FullPath);
     if (e.OldFullPath.Contains(@"C:\Users\PoC\Desktop") ||
         e.OldFullPath.Contains(@"C:\Users\PoC\Documents") ||
         e.OldFullPath.Contains(@"C:\Users\PoC\Downloads") ||
         e.OldFullPath.Contains(@"C:\Users\PoC\Videos"))
     {
         if (ShannonEntropy.getSavedEntropies().ContainsKey(e.OldFullPath))
         {
             Double tempEntropy = ShannonEntropy.getSavedEntropies()[e.OldFullPath];
             ShannonEntropy.removeKeyFromSavedEntropies(e.OldFullPath);
             ShannonEntropy.addKeyAndDoubleToSavedEntropies(e.FullPath, tempEntropy);
         }
     }
 }