Example #1
0
        public static void add(SearchedFile file)
        {
            lock (RankingProp)
            {
                LinkedListNode<SearchedFile> node = ranking.First;
                if (ranking.Count == 0)
                {
                    ranking.AddFirst(file);
                }
                else
                {
                    while (node != null)
                    {
                        if (node.Value.AmountFound < file.AmountFound)
                        {
                            ranking.AddBefore(node, file);

                            if (ranking.Count > MAXSIZE)
                            {
                                ranking.RemoveLast();
                            }
                            break;
                        }
                    }
                }
                showRanking();
            }
        }
Example #2
0
        public static void add(SearchedFile file)
        {
            lock (RankingProp)
            {
                LinkedListNode <SearchedFile> node = ranking.First;
                if (ranking.Count == 0)
                {
                    ranking.AddFirst(file);
                }
                else
                {
                    while (node != null)
                    {
                        if (node.Value.AmountFound < file.AmountFound)
                        {
                            ranking.AddBefore(node, file);

                            if (ranking.Count > MAXSIZE)
                            {
                                ranking.RemoveLast();
                            }
                            break;
                        }
                    }
                }
                showRanking();
            }
        }
Example #3
0
        static void exe(object argsObject)
        {
            string[]       args     = (string[])argsObject;
            String         fullPath = Path.GetFullPath(args[0]);
            FileAttributes attr     = File.GetAttributes(fullPath);

            //detect whether its a directory or file
            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                String[] files = Directory.GetFiles(fullPath, "*", SearchOption.AllDirectories);
                foreach (String file in files)
                {
                    args[0] = file;
                    startNewThread(args);
                }
            }
            else
            {
                //if (!amountPerFile.ContainsKey(fullPath))
                //{
                //    amountPerFile.Add(fullPath, 0);
                //}
                //string[] lines = System.IO.File.ReadAllLines(fullPath);

                //foreach (String line in lines)
                //{
                //    string[] words = line.Split(' ');
                //    foreach (String word in words)
                //    {
                //        if (word.Contains("42"))
                //        {
                //            int amount = 0;
                //            amountPerFile.TryGetValue(fullPath, out amount);

                //            amountPerFile[fullPath] = amount + 1;
                //        }

                //    }
                //}

                int    count = 0;
                byte[] bytes = File.ReadAllBytes(fullPath);
                foreach (byte b in bytes)
                {
                    //Console.Write(b + " ");
                    if (b == 42)
                    {
                        count++;
                    }
                }
                SearchedFile file = new SearchedFile(fullPath, count);
                if (Ranking.canAdd(file))
                {
                    Ranking.add(file);
                }
            }
        }
Example #4
0
        static void exe(object argsObject)
        {
            string[] args = (string[])argsObject;
            String fullPath = Path.GetFullPath(args[0]);
            FileAttributes attr = File.GetAttributes(fullPath);

            //detect whether its a directory or file
            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
            {
                String[] files = Directory.GetFiles(fullPath, "*", SearchOption.AllDirectories);
                foreach (String file in files)
                {
                    args[0] = file;
                    startNewThread(args);
                }
            }
            else
            {
                //if (!amountPerFile.ContainsKey(fullPath))
                //{
                //    amountPerFile.Add(fullPath, 0);
                //}
                //string[] lines = System.IO.File.ReadAllLines(fullPath);

                //foreach (String line in lines)
                //{
                //    string[] words = line.Split(' ');
                //    foreach (String word in words)
                //    {
                //        if (word.Contains("42"))
                //        {
                //            int amount = 0;
                //            amountPerFile.TryGetValue(fullPath, out amount);

                //            amountPerFile[fullPath] = amount + 1;
                //        }

                //    }
                //}

                int count = 0;
                byte[] bytes = File.ReadAllBytes(fullPath);
                foreach (byte b in bytes)
                {
                    //Console.Write(b + " ");
                    if (b == 42)
                        count++;
                }
                SearchedFile file = new SearchedFile(fullPath, count);
                if(Ranking.canAdd(file))
                {
                    Ranking.add(file);
                }

            }
        }
Example #5
0
 public static bool canAdd(SearchedFile file)
 {
     lock (RankingProp)
     {
         if (ranking.Count < MAXSIZE)
         {
             return true;
         }
         return ranking.Last.Value.AmountFound < file.AmountFound;
     }
 }
Example #6
0
 public static bool canAdd(SearchedFile file)
 {
     lock (RankingProp)
     {
         if (ranking.Count < MAXSIZE)
         {
             return(true);
         }
         return(ranking.Last.Value.AmountFound < file.AmountFound);
     }
 }