|
using System;
using System.Collections;
using System.Xml;
namespace uk.org.aspellclark.cooksmate.engine
{
/// <summary>
/// Summary description for Recipe.
/// </summary>
public class Recipe
{
#region members
// Create a logger for use in this class
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private bool deleted = false;
private string title;
private DateTime serveTime;
private ArrayList steps;
private string notes;
#endregion
public DateTime ServeTime
{
get{return serveTime;}
set{serveTime = value;}
}
public string Title
{
get{return title;}
set{title = value;}
}
public ArrayList Steps
{
get{return steps;}
set{steps = value;}
}
public string Notes
{
get{return notes;}
set{notes = value;}
}
public bool Deleted
{
get{return deleted;}
set{deleted = value;}
}
public ActionStep GetAction(string name)
{
foreach (ActionStep stp in this.Steps)
{
if (stp.Name.ToLower().Equals(name.ToLower()))
{
return stp;
}
}
return null;
}
public void ActionDone(ActionStep step)
{
step.Done = true;
this.steps.Remove(step);
this.steps.Add(step);
}
public Recipe()
{
steps = new ArrayList();
}
public Recipe(string name)
{
this.Title = name;
steps = new ArrayList();
}
#region XMLCode
public Recipe(XmlReader reader)
{
steps = new ArrayList();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.XmlDeclaration:
break;
case XmlNodeType.ProcessingInstruction:
break;
case XmlNodeType.DocumentType:
break;
case XmlNodeType.Comment:
break;
case XmlNodeType.EndElement:
if (reader.Name.Equals(Constants.XML_TAG_RECIPE))
{
return;
}
break;
case XmlNodeType.Element:
if (reader.Name.Equals(Constants.XML_TAG_NAME))
{
reader.Read();
this.Title = reader.Value;
}
else if (reader.Name.Equals(Constants.XML_TAG_SERVE_TIME))
{
reader.Read();
this.ServeTime = Convert.ToDateTime(reader.Value);
}
else if (reader.Name.Equals(Constants.XML_TAG_NOTES))
{
reader.Read();
this.notes = reader.Value;
}
else if (reader.Name.Equals(Constants.XML_TAG_ACTIONS))
{
ReadActionsFromXml(reader);
}
break;
case XmlNodeType.Text:
break;
case XmlNodeType.Whitespace:
break;
}
}
}
private void ReadActionsFromXml(XmlReader reader)
{
while (reader.Read())
{
//log.Info(String.Format("xml tag [{0}], [{1}], ({2})",
// reader.NodeType,
// reader.Name,
// reader.Value));
switch (reader.NodeType)
{
case XmlNodeType.EndElement:
if (reader.Name.Equals(Constants.XML_TAG_ACTIONS))
{
return;
}
break;
case XmlNodeType.Element:
if (reader.Name.Equals(Constants.XML_TAG_ACTION))
{
ActionStep tmpStep = new ActionStep(reader);
this.steps.Add(tmpStep);
log.Info(String.Format("read in step {0} [{1}]", steps.Count, tmpStep.ToString()));
}
break;
}
}
}
public void WriteToXml(XmlWriter xmlWriter)
{
xmlWriter.WriteStartElement(Constants.XML_TAG_RECIPE);
xmlWriter.WriteElementString(Constants.XML_TAG_NAME, this.Title);
xmlWriter.WriteElementString(Constants.XML_TAG_SERVE_TIME, this.ServeTime.ToString());
xmlWriter.WriteStartElement(Constants.XML_TAG_NOTES);
xmlWriter.WriteString(this.Notes);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement(Constants.XML_TAG_ACTIONS);
foreach (ActionStep action in steps)
{
action.WriteToXml(xmlWriter);
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
}
#endregion
public string ToString(DateTime srveTime)
{
return String.Format("{0}, {1:d}",
this.Title,
this.ServeTime);
}
}//class
}//namespace
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.