Ejemplo n.º 1
0
        internal static void deletionOccured(FileSystemEventArgs e)
        {
            string[] filesInDirectory = null;

            filesInDirectory = Directory.GetFiles(returnFilePath(e.FullPath));

            Boolean newSimilarFileIsCreated = false;

            ShannonEntropy entropyCreator = new ShannonEntropy();

            string fileName = returnFileName(e.FullPath);

            double oldEntropy = ShannonEntropy.getSavedEntropies()[e.FullPath];

            foreach (string s in filesInDirectory)
            {
                if (s.Contains(fileName))
                {
                    newSimilarFileIsCreated = true;
                    FileInfo newFileInfo = new FileInfo(s);
                    double   newEntropy  = entropyCreator.CalculateEntropy(newFileInfo);

                    //TODO  react if needed
                    entropyHandler(e, oldEntropy, newEntropy);
                }
            }

            ShannonEntropy.removeKeyFromSavedEntropies(e.FullPath);
        }
Ejemplo n.º 2
0
        internal static void changeOccured(FileSystemEventArgs e)
        {
            //Kig på entropien før og efter
            Dictionary <string, double> savedEntropies = ShannonEntropy.getSavedEntropies();
            FileInfo       changedFile         = new FileInfo(e.FullPath);
            ShannonEntropy entropyCalculator   = new ShannonEntropy();
            Double         changedFileEntropy  = entropyCalculator.CalculateEntropy(changedFile);
            Double         originalFileEntropy = 0.0;

            Console.WriteLine("File " + e.FullPath + " has been changed to and has now an entropy of " + changedFileEntropy);
            if (changedFileEntropy == -1)
            {
                return;
            }

            try
            {
                originalFileEntropy = savedEntropies[e.FullPath];
            }
            catch (Exception)
            {
            }

            entropyHandler(e, originalFileEntropy, changedFileEntropy);
        }
Ejemplo n.º 3
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);
                }
            }
        }