G
Guest
I've been working on a project for the last week and I can't seem to get it working. It's supposed to be finished within the next few days so a speedy reply would be appriciated. Anyways, it seems that my program goes into some sort of endless loop that I can't find, as when I click a link to get to the page I'm working on, the page never loads, and the aspnet_wp process consumes 98% of cpu time (the other 2% is used by task manager). I'm using visual studio 2005 express beta 1 with ASP.NET 2.0.40607.0.
Here is the code:
public partial class Testaspx
{
private StreamReader questions;
private XmlTextReader questionReader;
string number;
private string prefix;
void Page_Load(object sender, EventArgs e)
{
this.btnNext.Click += new EventHandler(this.getAnswer);
if (!openFile()) {
lbldisplay.Text = "Error opening";
return;
}
if (!prepare())
{
lbldisplay.Text += "Error preparing";
}
getQuestion();
}
private bool prepare()
{
//do
//{
while (!questionReader.LocalName.Equals("benchmark") && !questionReader.EOF)
{
questionReader.Read();
}
if (questionReader.EOF)
{
return false;
//Server.Transfer("grade.aspx");
}
//} while (!questionReader.IsStartElement("benchmark"));
if (questionReader.ReadToDescendant("preface"))
{
prefix = questionReader.ReadString();
}
else
{
lbldisplay.Text = "Error getting preface";
return false;
}
return true;
}
public void getQuestion()
{
string passage = "";
do
{
//do
//{
while (!questionReader.LocalName.Equals("question") && !questionReader.LocalName.Equals("benchmark"))
{
questionReader.Read();
}
if (questionReader.LocalName.Equals("benchmark"))
{
if (!prepare())
{
lbldisplay.Text += "Error preparing in getQuestion";
return;
}
continue;
}
// } while (!questionReader.IsStartElement("question"));
if (questionReader.ReadToDescendant("number"))
{
number = questionReader.ReadString();
}
else
{
lbldisplay.Text = "error getting passage number";
}
} while (number != Session["next"]);
if (questionReader.ReadToNextSibling("passage"))
{
passage = questionReader.ReadString();
}
else
{
lbldisplay.Text = "Error getting passage";
}
while (questionReader.ReadToNextSibling("option"))
{
options.Items.Add(questionReader.ReadString());
}
lblNumber.Text = number;
lbldisplay.Text = prefix + passage;
return;
}
/// <summary>
/// Finds and stores which answer was selected
/// </summary>
private void getAnswer(object sender, EventArgs e)
{
string selected = "";
selected = options.SelectedItem.Text.Substring(0, 1);
if (selected != "")
{
string number = (string)(Session["next"]);
Session.Add(number, selected);
Session["next"] = getNextNumber();
Server.Transfer("Test.aspx");
}
//return true;
}
/// <summary>
/// Gets the number of the next passage
/// </summary>
/// <returns>Number of next passage as string</returns>
private string getNextNumber()
{
while (!questionReader.LocalName.Equals("number") && !questionReader.EOF)
{
questionReader.Read();
}
if (questionReader.EOF)
{
//replace with redirect to grade page
Server.Transfer("grade.aspx");
//return "none";
}
string next = questionReader.ReadString();
return next;
}
/// <summary>
/// Opens the next questions file
/// </summary>
private bool openFile()
{
questions = new StreamReader(Session["location"] + "\\tests\\" + (string)(Session["file"]) + ".xml");
questionReader = new XmlTextReader(questions);
if (questions == null || questionReader == null)
{
return false;
}
return true;
}
}
Here is the code:
public partial class Testaspx
{
private StreamReader questions;
private XmlTextReader questionReader;
string number;
private string prefix;
void Page_Load(object sender, EventArgs e)
{
this.btnNext.Click += new EventHandler(this.getAnswer);
if (!openFile()) {
lbldisplay.Text = "Error opening";
return;
}
if (!prepare())
{
lbldisplay.Text += "Error preparing";
}
getQuestion();
}
private bool prepare()
{
//do
//{
while (!questionReader.LocalName.Equals("benchmark") && !questionReader.EOF)
{
questionReader.Read();
}
if (questionReader.EOF)
{
return false;
//Server.Transfer("grade.aspx");
}
//} while (!questionReader.IsStartElement("benchmark"));
if (questionReader.ReadToDescendant("preface"))
{
prefix = questionReader.ReadString();
}
else
{
lbldisplay.Text = "Error getting preface";
return false;
}
return true;
}
public void getQuestion()
{
string passage = "";
do
{
//do
//{
while (!questionReader.LocalName.Equals("question") && !questionReader.LocalName.Equals("benchmark"))
{
questionReader.Read();
}
if (questionReader.LocalName.Equals("benchmark"))
{
if (!prepare())
{
lbldisplay.Text += "Error preparing in getQuestion";
return;
}
continue;
}
// } while (!questionReader.IsStartElement("question"));
if (questionReader.ReadToDescendant("number"))
{
number = questionReader.ReadString();
}
else
{
lbldisplay.Text = "error getting passage number";
}
} while (number != Session["next"]);
if (questionReader.ReadToNextSibling("passage"))
{
passage = questionReader.ReadString();
}
else
{
lbldisplay.Text = "Error getting passage";
}
while (questionReader.ReadToNextSibling("option"))
{
options.Items.Add(questionReader.ReadString());
}
lblNumber.Text = number;
lbldisplay.Text = prefix + passage;
return;
}
/// <summary>
/// Finds and stores which answer was selected
/// </summary>
private void getAnswer(object sender, EventArgs e)
{
string selected = "";
selected = options.SelectedItem.Text.Substring(0, 1);
if (selected != "")
{
string number = (string)(Session["next"]);
Session.Add(number, selected);
Session["next"] = getNextNumber();
Server.Transfer("Test.aspx");
}
//return true;
}
/// <summary>
/// Gets the number of the next passage
/// </summary>
/// <returns>Number of next passage as string</returns>
private string getNextNumber()
{
while (!questionReader.LocalName.Equals("number") && !questionReader.EOF)
{
questionReader.Read();
}
if (questionReader.EOF)
{
//replace with redirect to grade page
Server.Transfer("grade.aspx");
//return "none";
}
string next = questionReader.ReadString();
return next;
}
/// <summary>
/// Opens the next questions file
/// </summary>
private bool openFile()
{
questions = new StreamReader(Session["location"] + "\\tests\\" + (string)(Session["file"]) + ".xml");
questionReader = new XmlTextReader(questions);
if (questions == null || questionReader == null)
{
return false;
}
return true;
}
}