Exemplo n.º 1
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbFilePath.Text))
            {
                MessageBox.Show("Please select a file");
            }
            else
            {
                var lines = "";
                try
                {
                    lines = File.ReadAllText(tbFilePath.Text).ToString();
                }
                catch (System.IO.FileNotFoundException exception)
                {
                    try
                    {
                        using (StreamWriter w = File.AppendText(@"ErrorLog\ErrorLog.log"))
                        {
                            Log(exception.Message, w);
                        }
                    }
                    catch (Exception e2)
                    {
                        Console.WriteLine("Exception: " + e2.Message);
                    }

                    MessageBox.Show(exception.Message);
                    goto Error;
                }

                TextReaderClasses.Utilities.TextReader reader = new TextReaderClasses.Utilities.TextReader(new ScrabbleScore());

                var words = reader.GetWords(lines);

                var output = reader.CalculateOutput(words);

                tbMostFrequentWord.Text = "Word: " + output.MostFrequentWord.Text + "," +
                                          "Length: " + output.MostFrequentWord.Length + "," +
                                          "Occurances: " + output.MostFrequentWord.Count + "," +
                                          "Score: " + output.MostFrequentWord.Score
                ;

                tbMostFrequent7LetterWord.Text = "Word: " + output.MostFrequent7LetterWord.Text + "," +
                                                 "Length: " + output.MostFrequent7LetterWord.Length + "," +
                                                 "Occurances: " + output.MostFrequent7LetterWord.Count + "," +
                                                 "Score: " + output.MostFrequent7LetterWord.Score
                ;

                tbHighestScoredWord.Text = "Word: " + output.HighestScoredWord.Text + "," +
                                           "Length: " + output.HighestScoredWord.Length + "," +
                                           "Occurances: " + output.HighestScoredWord.Count + "," +
                                           "Score: " + output.HighestScoredWord.Score
                ;

                Error :;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            if (args.Length == 0)
            {
                Console.WriteLine("Please enter file path");
            }
            else
            {
                var lines = "";
                try
                {
                    lines = File.ReadAllText(args[0]).ToString();
                }
                catch (System.IO.FileNotFoundException e)
                {
                    try
                    {
                        using (StreamWriter w = File.AppendText(@"ErrorLog\ErrorLog.log"))
                        {
                            Log(e.Message, w);
                        }
                    }
                    catch (Exception e2)
                    {
                        Console.WriteLine("Exception: " + e2.Message);
                    }

                    Console.WriteLine(e.Message);
#if DEBUG
                    Console.WriteLine("Press enter to close...");
                    Console.ReadLine();
#endif
                    Environment.Exit(0);
                }

                stopwatch.Start();
                TextReaderClasses.Utilities.TextReader reader = new TextReaderClasses.Utilities.TextReader(new ScrabbleScore());

                var words = reader.GetWords(lines);

                var output = reader.CalculateOutput(words);

                stopwatch.Stop();

                Console.WriteLine(
                    "Most Frequent Word: " +
                    output.MostFrequentWord.Text +
                    "\n\t occured: " + output.MostFrequentWord.Count +
                    "\n\t length: " + output.MostFrequentWord.Length +
                    "\n\t score: " + output.MostFrequentWord.Score
                    );

                Console.WriteLine(
                    "Most Frequent 7 letter Word: " +
                    output.MostFrequent7LetterWord.Text +
                    "\n\t occured: " + output.MostFrequent7LetterWord.Count +
                    "\n\t length: " + output.MostFrequent7LetterWord.Length +
                    "\n\t score: " + output.MostFrequent7LetterWord.Score
                    );

                Console.WriteLine(
                    "Highest scoring word: " +
                    output.HighestScoredWord.Text +
                    "\n\t occured: " + output.HighestScoredWord.Count +
                    "\n\t length: " + output.HighestScoredWord.Length +
                    "\n\t score: " + output.HighestScoredWord.Score
                    );

#if DEBUG
                Console.WriteLine("Press enter to close...");
                Console.ReadLine();
#endif
            }
        }