Exemplo n.º 1
0
 private void InitializePublicInfo(CrozzleGenerateFile boot)
 {
     PublicInfo.SetRows(boot.GetRows());
     PublicInfo.SetColumns(boot.GetColumns());
     PublicInfo.SetFullColumns(boot.GetColumns() * 2);
     PublicInfo.SetFullRows(boot.GetRows() + 3);
     PublicInfo.SetConfig(boot.GetConfigurationFile());
     PublicInfo.SetWordlist(boot.GetWordListFile());
 }
Exemplo n.º 2
0
        private void openURLButton_Click(object sender, EventArgs e)
        {
            string newUrl     = historyComboBox.Text;
            string anotherurl = GetAnotherURL(newUrl);

            // initializing data
            WordInfo.intersectingPointsPerLetter    = new Dictionary <char, int>();
            WordInfo.nonIntersectingPointsPerLetter = new Dictionary <char, int>();
            CreateCrozzle.InitializingData();

            WebClient webClient = new WebClient();

            // Download IIS file.
            try
            {
                string crozzleTxt = newUrl;
                webClient.DownloadFile(crozzleTxt, @"crozzle.txt");
            }
            catch (WebException)// wrong web connection
            {
                try
                {
                    if (anotherurl != "")// try to change another url
                    {
                        webClient.DownloadFile(anotherurl, @"crozzle.txt");
                    }
                    else
                    {
                        MessageBox.Show("Internet connection fail");
                        return;
                    }
                }
                catch (WebException)// wrong web connection
                {
                    MessageBox.Show("Internet connection fail");
                    return;
                }
                catch (ArgumentNullException)// url is null
                {
                    MessageBox.Show("url is null");
                    return;
                }
                catch (NotSupportedException)// write file error
                {
                    MessageBox.Show("fail to write file");
                    return;
                }
            }
            catch (ArgumentNullException)// url is null
            {
                MessageBox.Show("url is null");
                return;
            }
            catch (NotSupportedException)// write file error
            {
                MessageBox.Show("fail to write file");
                return;
            }


            CrozzleGenerateFile boot = new CrozzleGenerateFile();

            boot.SetBoot("crozzle.txt");
            boot.SetColumns("crozzle.txt");
            boot.SetRows("crozzle.txt");

            if (!boot.GetPathHaveSet("CONFIGURATION_FILE"))
            {
                MessageBox.Show("Can't find path of configuration file in the crozzle file", "ERROR");
                return;
            }
            if (!boot.GetPathHaveSet("WORDLIST_FILE"))
            {
                MessageBox.Show("Can't find path of word list file in the crozzle file", "ERROR");
                return;
            }
            // Download Azure file. As the file referenced by the following URL has
            // an SAS (Shared Access Signature) end date of Oct 31, 23:59,
            // you cannot access this file after this end date.
            string configurationTxt = boot.GetConfigurationFile();

            try
            {
                webClient.DownloadFile(configurationTxt, @"configuration.txt");
            }
            catch (WebException)// wrong web connection
            {
                MessageBox.Show("net connection false");
                return;
            }
            catch (ArgumentNullException)// url is null
            {
                MessageBox.Show("url is null");
                return;
            }
            catch (NotSupportedException)// write file error
            {
                MessageBox.Show("fail to write file");
                return;
            }


            try
            {
                string wordListTxt = boot.GetWordListFile();
                webClient.DownloadFile(wordListTxt, @"wordList.txt");
            }
            catch (WebException)// wrong web connection
            {
                MessageBox.Show("net connection false");
                return;
            }
            catch (ArgumentNullException)// url is null
            {
                MessageBox.Show("url is null");
                return;
            }
            catch (NotSupportedException)// write file error
            {
                MessageBox.Show("fail to write file");
                return;
            }
            InitializePublicInfo(boot);
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 3
0
        private void loadCrozzleczlToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Title            = "Load Crozzle";
            dialog.Filter           = "czl file(*.czl)|*.czl";
            dialog.FilterIndex      = 2;
            dialog.RestoreDirectory = true;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string path = dialog.FileName;
                Error.InitializeErrorList();

                CrozzleGenerateFile boot = new CrozzleGenerateFile();
                boot.SetBoot(path);
                boot.SetColumns(path);
                boot.SetRows(path);
                if (!boot.GetPathHaveSet("CONFIGURATION_FILE"))
                {
                    MessageBox.Show("Can't find path of configuration file in the crozzle file", "ERROR");
                    return;
                }
                if (!boot.GetPathHaveSet("WORDLIST_FILE"))
                {
                    MessageBox.Show("Can't find path of word list file in the crozzle file", "ERROR");
                    return;
                }
                WebClient webClient = new WebClient();
                // Download Azure file. As the file referenced by the following URL has
                // an SAS (Shared Access Signature) end date of Oct 31, 23:59,
                // you cannot access this file after this end date.
                try
                {
                    string configurationTxt = boot.GetConfigurationFile();
                    webClient.DownloadFile(configurationTxt, "configuration.txt");
                    string wordListTxt = boot.GetWordListFile();
                    webClient.DownloadFile(wordListTxt, "wordList.txt");
                }
                catch (WebException)// wrong web connection
                {
                    MessageBox.Show("Internet connection fail");
                    return;
                }
                catch (ArgumentNullException)// url is null
                {
                    MessageBox.Show("url is null");
                    return;
                }
                catch (NotSupportedException)// write file error
                {
                    MessageBox.Show("fail to write file");
                    return;
                }

                Config configuration = new Config();
                configuration.SetConfig("configuration.txt");
                string intersectionsPerPoints    = configuration.GetIntersectingPointsPerLetter();
                string nonIntersectionsPerPoints = configuration.GetNonIntersectingPointsPerLetter();

                WordInfo wordlist = new WordInfo();
                wordlist.SetWordList("wordList.txt");
                wordlist.SetIntersectingPointsPerLetter(intersectionsPerPoints);
                wordlist.SetNonIntersectingPointsPerLetter(nonIntersectionsPerPoints);

                WordResult result = new WordResult();
                result.InitializeSetValue();
                result.SetRows(path);
                result.SetColumns(path);
                result.SetUsedWord(path);
                result.ValidateRowsColumns(configuration);

                CrozzleValidation crozzle = new CrozzleValidation();
                Log.AddLogInformation("crozzle validation : begin");
                crozzle.ValidateCrozzle(configuration, wordlist, result);
                crozzle.CheckGroup(configuration, result);
                Log.AddLogInformation("crozzle validation : end");
                List <string> crozzleError       = Error.GetCrozzleError();
                List <string> configurationError = Error.GetConfigurationError();
                List <string> crozzleFileError   = Error.GetCrozzleFileError();
                List <string> wordListError      = Error.GetWordListError();
                bool          error = false;
                // Set default value of uppercase: false
                bool uppercase = false;
                if (configuration.GetSetInformation("UPPERCASE"))
                {
                    uppercase = configuration.GetUppercase();
                }

                // Set default value for style
                string style = @"<style>table, td {border: 1px solid black;border - collapse: collapse;}td {width: 24px; text - align: center;}</ style > ";//default style value
                if (configuration.GetSetInformation("STYLE"))
                {
                    style = configuration.GetStyle();
                }

                // Display error information and stored in log file
                string errorHTML = @"<!DOCTYPE html>
                                <html>
                                <head></head><body><h3>file validation</h3>";
                if (configurationError.Count() != 0)
                {
                    error      = true;
                    errorHTML += "<p>configuration.txt</p>";
                    if (configurationError.Count() == 0)
                    {
                        errorHTML += "<p>configuration.txt: valid</p>";
                    }
                    else
                    {
                        errorHTML += "<p>configuration.txt: invalid</p>";
                    }
                    for (int i = 0; i < configurationError.Count(); i++)
                    {
                        errorHTML += @"<p>error";
                        errorHTML += (i + 1);
                        errorHTML += @": ";
                        errorHTML += configurationError[i];
                        errorHTML += @"</p>";
                    }
                }

                if (wordListError.Count() != 0)
                {
                    error      = true;
                    errorHTML += "<p>word list.txt</p>";
                    if (wordListError.Count() == 0)
                    {
                        errorHTML += "<p>wordlist.txt: valid</p>";
                    }
                    else
                    {
                        errorHTML += "<p>wordlist.txt: invalid</p>";
                    }
                    for (int i = 0; i < wordListError.Count(); i++)
                    {
                        errorHTML += @"<p>error";
                        errorHTML += (i + 1);
                        errorHTML += @": ";
                        errorHTML += wordListError[i];
                        errorHTML += @"</p>";
                    }
                }

                if (crozzleFileError.Count() != 0)
                {
                    error      = true;
                    errorHTML += "<p>crozzle.txt</p>";
                    if (crozzleFileError.Count() == 0)
                    {
                        errorHTML += "<p>crozzle.txt: valid</p>";
                    }
                    else
                    {
                        errorHTML += "<p>crozzle.txt: invalid</p>";
                    }
                    for (int i = 0; i < crozzleFileError.Count(); i++)
                    {
                        errorHTML += @"<p>error";
                        errorHTML += (i + 1);
                        errorHTML += @": ";
                        errorHTML += crozzleFileError[i];
                        errorHTML += @"</p>";
                    }
                }

                if (error == false)
                {
                    errorHTML += "<p>configuration.txt: valid</p><p>wordlist.txt: valid</p><p>crozzle.txt: valid</p>";
                }

                if (crozzleError.Count > 0)
                {
                    error      = true;
                    errorHTML += "<h3>crozzle validation</h3>";
                    if (crozzleError.Count() == 0)
                    {
                        errorHTML += "<p>crozzle: valid</p>";
                    }
                    else
                    {
                        errorHTML += "<p>crozzle: invalid</p>";
                    }
                    for (int i = 0; i < crozzleError.Count(); i++)
                    {
                        errorHTML += @"<p>error";
                        errorHTML += (i + 1);
                        errorHTML += @": ";
                        errorHTML += crozzleError[i];
                        errorHTML += @"</p>";
                    }
                }


                if (error == true)
                {
                    errorHTML += @"</body></html>";
                    ErrorBrowser.DocumentText = errorHTML;
                    FileStream   stream = new FileStream(configuration.GetLogfileName(), FileMode.Append);
                    StreamWriter writer = new StreamWriter(stream);
                    writer.WriteLine("\r\n\r\n==================begin test " + path + " " + DateTime.Now.ToString() + "==================");
                    List <string> logInfo = Log.GetLogInformation();
                    for (int i = 0; i < logInfo.Count; i++)
                    {
                        writer.WriteLine(logInfo[i]);
                    }
                    if (configurationError.Count() == 0)
                    {
                        writer.WriteLine("configuration.txt: valid");
                    }
                    else
                    {
                        writer.WriteLine("configuration.txt: invalid");
                    }
                    if (wordListError.Count() == 0)
                    {
                        writer.WriteLine("wordlist.txt: valid");
                    }
                    else
                    {
                        writer.WriteLine("wordlist.txt: invalid");
                    }
                    if (crozzleFileError.Count() == 0)
                    {
                        writer.WriteLine("crozzle.txt: valid");
                    }
                    else
                    {
                        writer.WriteLine("crozzle.txt: invalid");
                    }
                    if (crozzleError.Count() == 0)
                    {
                        writer.WriteLine("crozzle: valid");
                    }
                    else
                    {
                        writer.WriteLine("crozzle: invalid");
                    }
                    writer.WriteLine("errors:");
                    writer.WriteLine("files validation");
                    writer.WriteLine("configuration.txt");
                    for (int i = 0; i < configurationError.Count(); i++)
                    {
                        writer.WriteLine(configurationError[i]);
                    }
                    writer.WriteLine("wordlist.txt");
                    for (int i = 0; i < wordListError.Count(); i++)
                    {
                        writer.WriteLine(wordListError[i]);
                    }
                    writer.WriteLine("crozzle.txt");
                    for (int i = 0; i < crozzleFileError.Count(); i++)
                    {
                        writer.WriteLine(crozzleFileError[i]);
                    }
                    writer.WriteLine("crozzle validation");
                    for (int i = 0; i < crozzleError.Count(); i++)
                    {
                        writer.WriteLine(crozzleError[i]);
                    }

                    writer.WriteLine("==================end test " + path + "==================");
                    writer.Close();
                    stream.Close();
                }
                else
                {
                    ErrorBrowser.DocumentText = @"<p>All files valid</p><p>Crozzle valid</p><p>No error</p>";
                    FileStream   stream = new FileStream(configuration.GetLogfileName(), FileMode.Append);
                    StreamWriter writer = new StreamWriter(stream);
                    writer.WriteLine("\r\n\r\n==================begin test " + path + " " + DateTime.Now.ToString() + "==================");
                    List <string> logInfo = Log.GetLogInformation();
                    for (int i = 0; i < logInfo.Count; i++)
                    {
                        writer.WriteLine(logInfo[i]);
                    }
                    writer.WriteLine("configuration.txt: valid");
                    writer.WriteLine("wordlist.txt: valid");
                    writer.WriteLine("crozzle.txt: valid");
                    writer.WriteLine("crozzle: valid");
                    writer.WriteLine("NO ERROR");
                    writer.WriteLine("==================end test " + path + "==================");
                    writer.Close();
                    stream.Close();
                }

                // Display Crozzle
                int  rows        = result.GetRows();
                int  columns     = result.GetColumns();
                Grid crozzleGrid = new Grid(rows, columns, result.GetUsedWord());
                char[,] grid = crozzleGrid.GetGrid();
                String crozzleHTML = @"<!DOCTYPE html>
                                <html>
                                <head>" + style + @"</head><body><table>";

                for (int row = 0; row < rows; row++)
                {
                    String tr = "<tr>";
                    for (int column = 0; column < columns; column++)
                    {
                        if (grid[row, column].CompareTo('\0') != 0)
                        {
                            tr += @"<td style='background:" + configuration.GetBgcolourNonEmptyTD();
                            if (uppercase == true)
                            {
                                tr += "'>" + grid[row, column].ToString().ToUpper() + @"</td>";
                            }
                            if (uppercase == false)
                            {
                                tr += "'>" + grid[row, column].ToString().ToLower() + @"</td>";
                            }
                        }
                        else
                        {
                            tr += @"<td style='background:" + configuration.GetBgcolourEmptyTD();
                            if (uppercase == true)
                            {
                                tr += "'>" + grid[row, column].ToString().ToUpper() + @"</td>";
                            }
                            if (uppercase == false)
                            {
                                tr += "'>" + grid[row, column].ToString().ToLower() + @"</td>";
                            }
                        }
                    }
                    tr += "</tr>";

                    crozzleHTML += tr;
                }
                crozzleHTML += @"</table>";
                crozzleHTML += @"<br><p>score: ";

                if (error == true)
                {
                    crozzleHTML += configuration.GetInvalidCrozzleScore();
                }
                else
                {
                    result.CalculateScore(configuration.GetPointsPerWord());
                    crozzleHTML += result.GetScore();
                }
                crozzleHTML += "</p></body></html>";

                CrozzleBrowser.DocumentText = crozzleHTML;
            }
        }