Пример #1
0
 public static void SaveDictionary(ConcurrentDictionary <string, int> freqeuncyDictionary, string connectionString)
 {
     try
     {
         using (var context = new RecordContext(connectionString))
         {
             var buffer = new List <Stat>();
             foreach (var item in freqeuncyDictionary)
             {
                 buffer.Add(new Stat()
                 {
                     Id = 1, Word = item.Key, Count = item.Value
                 });
             }
             context.Stats.AddRange(buffer);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Log.Write(ex);
     }
 }
Пример #2
0
        public static void OutputResults(int top, string connectionString)
        {
            try
            {
                using (var context = new RecordContext(connectionString))
                {
                    var result = context.Stats.OrderByDescending(n => n.Count).Take(top).AsEnumerable();

                    Console.WriteLine();
                    Console.WriteLine("Top most commonly found words:");
                    foreach (var node in result)
                    {
                        Console.WriteLine("{0} - {1} times", node.Word, node.Count);
                    }

                    Console.WriteLine();
                    Console.WriteLine("{0} words in dictionary", context.Stats.Count());
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
        }