Ejemplo n.º 1
0
        private void btnFromFile_Click(object sender, EventArgs e)
        {
            // Prompt for where to save file
            if (this.openDiag.ShowDialog() == DialogResult.OK)
            {
                // Open stream and serializer
                StreamReader stream = new StreamReader(new FileStream(this.openDiag.FileName, FileMode.OpenOrCreate, FileAccess.Read));
                FENSerializer s = new FENSerializer();

                string result = String.Empty;

                try
                {
                    // Generate string and write to file
                    result = stream.ReadLine();

                    if (s.IsValidSerialization(result))
                        this.Result = result;
                }
                catch (Exception ex) // May be FEN Exception
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        private void TestInvalidFen(string fen, string expectedErrMsg, int expectedIndex)
        {
            //Setup
            FENSerializer ser = new FENSerializer();
            bool exceptionThrown = false;
            string actualErrMsg = String.Empty;
            int actualIndex = Int32.MinValue;

            try
            {
                // Act
                ser.Deserialize(fen);
            }
            catch (FENException e)
            {
                exceptionThrown = true;
                actualErrMsg = e.Message;
                actualIndex = e.ErrorIndex;
            }

            // Test
            Assert.IsTrue(exceptionThrown);
            Assert.AreEqual(expectedErrMsg, actualErrMsg);
            Assert.AreEqual(expectedIndex, actualIndex);
            Assert.AreEqual(exceptionThrown, !ser.IsValidSerialization(fen));
        }
Ejemplo n.º 3
0
        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            // Check if valid FEN string
            FENSerializer serializer = new FENSerializer();
            validEntry = serializer.IsValidSerialization(txtInput.Text) || String.IsNullOrEmpty(txtInput.Text);
            //GameSerializer serializer = new GameSerializer();
            //validEntry = String.IsNullOrEmpty(serializer.IsValidFEN(txtInput.Text));
            e.Cancel = !validEntry;

            if (!validEntry)
                errorProvider1.SetError(txtInput, "Not a valid FEN string");
            else
                errorProvider1.SetError(txtInput, "");
        }