WPFQuiz.QuestionCollection.LoadQuestions C# (CSharp) Метод

LoadQuestions() публичный Метод

public LoadQuestions ( string strDirectory, System.Windows.Controls.RichTextBox richMain ) : bool
strDirectory string
richMain System.Windows.Controls.RichTextBox
Результат bool
        public bool LoadQuestions(string strDirectory, RichTextBox richMain)
        {
            if (Directory.Exists(strDirectory) == false)
            {
                System.Windows.MessageBox.Show("Couldn't find the directory containing questions: " + strDirectory, "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                return false;
            }

            int intCount = 0;
            foreach(string strFile in Directory.EnumerateFiles(strDirectory,"*.xml")){

                XDocument thisXML = XDocument.Load(strFile);
                Question thisQuestion = new Question(strFile,richMain);
                lstQuestions.Add(thisQuestion);
                intCount++;
            }

            richMain.AppendText("Loaded a total of " + lstQuestions.Count() + " files" + Environment.NewLine);
            Count = lstQuestions.Count();

            return true;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Init the main window
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            try
            {
                masterPRNG = new Random(Convert.ToInt32(System.DateTime.Now));
            }
            catch
            {
                masterPRNG = new Random();
            }

            qCollection = new QuestionCollection(masterPRNG);
            richTextBox1.AppendText("Loading questions..." + Environment.NewLine);
            if (qCollection.LoadQuestions(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\NCCQuestions", richTextBox1) == false)
            {
                MessageBox.Show("Having to exit due to not being able to find the questions directory!", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            richTextBox1.AppendText("Loaded questions." + Environment.NewLine);

            button1.IsEnabled = false;
            button2.IsEnabled = false;
            button3.IsEnabled = false;
            button4.IsEnabled = false;
            button5.IsEnabled = true;
            button6.IsEnabled = false;
            button7.IsEnabled = false;
        }
All Usage Examples Of WPFQuiz.QuestionCollection::LoadQuestions