示例#1
0
        private void fileSelectButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                InitialDirectory = Environment.CurrentDirectory,
                Filter           = "text documents (*.txt)|*.txt"
            };

            ofd.ShowDialog();
            richTextBox1.Clear();
            computePrimesButton.Enabled = false;
            if (string.IsNullOrWhiteSpace(ofd.FileName) || Path.GetExtension(ofd.FileName) != ".txt")   //only take in .txt files
            {
                MessageBox.Show("Select a valid .txt file");
                label1.Text = "No File Selected";
                return;
            }
            _filePath      = ofd.FileName;
            _numbersString = File.ReadLines(_filePath);
            _numbersString = _numbersString.Where(entry => !string.IsNullOrWhiteSpace(entry));    //remove empty entries caused by empty lines
            if (_numbersString.Any(entry => !FunctionRepository.CheckStringValue(entry)))
            {
                MessageBox.Show("All values in .txt file must be integers.  Please reference your file for non-integer values");
                return;
            }
            computePrimesButton.Enabled = true;
            label1.Text = Path.GetFileName(_filePath);
        }
示例#2
0
        private static void Main(string[] args)
        {
            IEnumerable <string> numbersString;

            if (!args.Any()) //if you run the exe by clicking then you wont have an input
            {
                //args = new string[] {Environment.CurrentDirectory + "\\test1.txt"};
                Console.WriteLine(
                    "Please drag txt file onto icon or use the command line to specify a target file to run program \nPress Enter To Continue");
                Console.ReadLine();
                return;
            }
            if (Path.GetExtension(args[0]) != ".txt") //only work with .txt files
            {
                Console.WriteLine("Please Select a File With the '.txt' Extension");
                return;
            }
            try //try to read the sepecified file
            {
                numbersString = File.ReadLines(args[0]);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File Not Found.  Please Enter a Valid File ");
                //Inform the user their file was not found at the specified locaton
                return;
            }

            numbersString = numbersString.Where(entry => !string.IsNullOrWhiteSpace(entry));
            //remove empty entries caused by empty lines
            if (numbersString.Any(entry => !FunctionRepository.CheckStringValue(entry)))
            {
                Console.WriteLine(
                    "All values in .txt file must be integers.  Please reference your file for non-integer values \nPress Enter To Continue");
                Console.ReadLine();
                return;
            }

            List <int> numbers = numbersString.Select(int.Parse).ToList();

            //create list of ints from list of strings from file

            foreach (int number in numbers)
            {
                string productString;
                Console.WriteLine(FunctionRepository.BuildOutputString(number, out productString));
            }
            Console.WriteLine("\nPress Enter To Continue");
            Console.ReadLine();
        }
示例#3
0
 public void CheckStringValueTestValidInt()
 {
     Assert.IsTrue(FunctionRepository.CheckStringValue("1"));
 }
示例#4
0
 public void CheckStringValueTestNumberLargerThanInt32()
 {
     Assert.IsFalse(FunctionRepository.CheckStringValue("9000000000000000000000000"));
 }
示例#5
0
 public void CheckStringValueTestNonNumericString()
 {
     Assert.IsFalse(FunctionRepository.CheckStringValue("meh"));
 }
示例#6
0
 public void CheckStringValueTestWhiteSpace()
 {
     Assert.IsFalse(FunctionRepository.CheckStringValue("   "));
 }
示例#7
0
 public void CheckStringValueTestInvalidInt()
 {
     Assert.IsFalse(FunctionRepository.CheckStringValue("1.3"));
 }
示例#8
0
 public void CheckStringValueTestNegativeInt()
 {
     Assert.IsTrue(FunctionRepository.CheckStringValue("-1"));
 }