Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Applications » Downloads
 
Add your own
alternative version

CooksMate

, 21 Jan 2008
A simple program to help get the timing of a roast dinner
cooksmate-bin-mono.zip
cooksmate-bin-mono
CooksMate
mono
cooksmate.exe
cooksmate.exe.mdb
cooksmate.sh
log4net.dll
uk.org.aspellclark.common.dll
uk.org.aspellclark.common.gui.dll
cooksmate-bin-net.zip
cooksmate-bin-net
CooksMate
bin
Debug
cooksmate.exe
cooksmate.log
log4net.dll
uk.org.aspellclark.common.dll
uk.org.aspellclark.common.gui.dll
cooksmate-src.zip
cooksmate-src
Common
common.build
Properties
src
main
csharp
NotImplementedDlg.resources
CommonFile
common.file.build
CommonGui
common.gui.build
CooksMate
cooksmate.build
cooksmate.sh
cooksmate_norm.png
DlgAction.resources
DlgEditRecipe.resources
MainForm.resources
libs
mono
log4net.dll
Mono.GetOptions.dll
sqlite-3.5.4.so
net
log4net.dll
Mono.GetOptions.dll
sqlite3.def
sqlite3.dll
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.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Andy Aspell-Clark
Software Developer (Senior) Airbus Defense and Space
United Kingdom United Kingdom
No Biography provided
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 21 Jan 2008
Article Copyright 2007 by Andy Aspell-Clark
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid