praktikum1/vr21/Program.cs

81 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace vr21
{
public class Receipe
{
public string Name;
public string Description;
public List<Ingredient> Ingredients;
public List<string> Steps;
public Receipe()
{
Ingredients = new List<Ingredient>();
Steps = new List<string>();
}
}
public class Ingredient
{
public string Name;
public int Count;
public string Unit;
}
class Program
{
private static string _xmllocation = @"..\..\..\XMLRecipe.xml";
static void Main(string[] args)
{
Ingredient kartul = new Ingredient() {Name = "Kartul", Count = 500, Unit = "g"};
Receipe r = new Receipe() {Name="Supp"};
r.Ingredients.Add(kartul);
r.Ingredients.Add(kartul);
r.Steps.Add("Koori");
r.Steps.Add("Keeda");
List<Receipe> l = new List<Receipe>();
l.Add(r);
l.Add(r);
XmlSerializer x = new XmlSerializer(l.GetType());
// x.Serialize(Console.Out, l);
//writeReceipesInformation();
LineEditor le = new LineEditor("foo") {HeuristicsMode = "csharp"};
string s;
while ((s = le.Edit("shell> ", "")) != null)
{
var arguments = s.Split(' ');
var command = arguments[0].Trim();
switch (command.ToLower())
{
case "list":
Console.WriteLine("Tere");
break;
default:
Console.WriteLine("No command");
break;
}
}
}
static void writeReceipesInformation()
{
XDocument xdoc = XDocument.Load(_xmllocation);
var allReceipes = xdoc.Descendants("Recipe");
foreach (var receipe in allReceipes)
{
Console.WriteLine(receipe.Element("Name").Value);
foreach (var ingredient in receipe.Element("Ingredients").Elements())
{
Console.WriteLine($" {ingredient.Element("Name").Value}: {ingredient.Element("Amount").Value}{ingredient.Element("Unit").Value}");
}
}
}
}
}