Update to dotnet core

This commit is contained in:
Arti Zirk 2017-02-07 01:02:19 +02:00
parent d1f4e69191
commit 33aeeb4382
5 changed files with 110 additions and 1452 deletions

View File

@ -1,3 +1,8 @@
# Praktikum 1 # Praktikum 1
https://wiki.itcollege.ee/index.php/Praktikum:_XML_failide_loomine(VR2.1) https://wiki.itcollege.ee/index.php/Praktikum:_XML_failide_loomine(VR2.1)
# Run
dotnet restore
dotnet run

View File

@ -3,17 +3,19 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.Serialization; using System.Xml.Serialization;
using System.IO;
using System.Xml;
namespace vr21 namespace vr21
{ {
public class Receipe public class Recipe
{ {
public string Name; public string Name;
public string Description; public string Description;
public List<Ingredient> Ingredients; public List<Ingredient> Ingredients;
public List<string> Steps; public List<string> Steps;
public Receipe() public Recipe()
{ {
Ingredients = new List<Ingredient>(); Ingredients = new List<Ingredient>();
Steps = new List<string>(); Steps = new List<string>();
@ -23,31 +25,40 @@ namespace vr21
public class Ingredient public class Ingredient
{ {
public string Name; public string Name;
public int Count; public int Amount;
public string Unit; public string Unit;
} }
class Program class Program
{ {
private static string _xmllocation = @"..\..\..\XMLRecipe.xml"; // private static string _xmllocation = @"..\..\..\XMLRecipe.xml";
private static string _xmllocation = @"XMLRecipe.xml";
public static List<Recipe> Recipes = new List<Recipe>();
static void Main(string[] args) static void Main(string[] args)
{ {
Ingredient kartul = new Ingredient() {Name = "Kartul", Count = 500, Unit = "g"}; Ingredient kartul = new Ingredient() {Name = "Kartul", Amount = 500, Unit = "g"};
Receipe r = new Receipe() {Name="Supp"}; Recipe r = new Recipe() {Name="Supp"};
r.Ingredients.Add(kartul); r.Ingredients.Add(kartul);
r.Ingredients.Add(kartul); r.Ingredients.Add(kartul);
r.Steps.Add("Koori"); r.Steps.Add("Koori");
r.Steps.Add("Keeda"); r.Steps.Add("Keeda");
List<Receipe> l = new List<Receipe>(); var l = Recipes;
l.Add(r); l.Add(r);
l.Add(r); l.Add(r);
XmlSerializer x = new XmlSerializer(l.GetType()); r = new Recipe() {Name="kala"};
// x.Serialize(Console.Out, l); l.Add(r);
//writeReceipesInformation();
XmlSerializer x = new XmlSerializer(l.GetType());
using (var fs = new FileStream(_xmllocation, FileMode.Create)) {
x.Serialize(fs, l);
}
//writeReceipesInformation();
readRecipesInformation();
System.Environment.Exit(1);
LineEditor le = new LineEditor("foo") {HeuristicsMode = "csharp"};
string s; string s;
while ((s = le.Edit("shell> ", "")) != null) while ((s = Console.ReadLine()) != null)
{ {
var arguments = s.Split(' '); var arguments = s.Split(' ');
var command = arguments[0].Trim(); var command = arguments[0].Trim();
@ -63,10 +74,22 @@ namespace vr21
} }
} }
static void readRecipesInformation() {
var x = new XmlSerializer(typeof(List<Recipe>));
FileStream fs = new FileStream(_xmllocation, FileMode.Open);
XmlReader reader = XmlReader.Create(fs);
var l = (List<Recipe>)x.Deserialize(reader);
foreach (var r in l) {
Console.WriteLine(r.Name);
}
}
static void writeReceipesInformation() static void writeReceipesInformation()
{ {
XDocument xdoc = XDocument.Load(_xmllocation); XDocument xdoc = XDocument.Load(_xmllocation);
var allReceipes = xdoc.Descendants("Recipe"); var allReceipes = xdoc.Descendants("Recipe");
Console.WriteLine(allReceipes.Count());
foreach (var receipe in allReceipes) foreach (var receipe in allReceipes)
{ {
Console.WriteLine(receipe.Element("Name").Value); Console.WriteLine(receipe.Element("Name").Value);

46
vr21/XMLRecipe.xml Normal file
View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfRecipe xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Recipe>
<Name>Supp</Name>
<Ingredients>
<Ingredient>
<Name>Kartul</Name>
<Amount>500</Amount>
<Unit>g</Unit>
</Ingredient>
<Ingredient>
<Name>Kartul</Name>
<Amount>500</Amount>
<Unit>g</Unit>
</Ingredient>
</Ingredients>
<Steps>
<string>Koori</string>
<string>Keeda</string>
</Steps>
</Recipe>
<Recipe>
<Name>Supp</Name>
<Ingredients>
<Ingredient>
<Name>Kartul</Name>
<Amount>500</Amount>
<Unit>g</Unit>
</Ingredient>
<Ingredient>
<Name>Kartul</Name>
<Amount>500</Amount>
<Unit>g</Unit>
</Ingredient>
</Ingredients>
<Steps>
<string>Koori</string>
<string>Keeda</string>
</Steps>
</Recipe>
<Recipe>
<Name>kala</Name>
<Ingredients />
<Steps />
</Recipe>
</ArrayOfRecipe>

File diff suppressed because it is too large Load Diff

23
vr21/project.json Executable file
View File

@ -0,0 +1,23 @@
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0-preview1-001100-00"
},
"System.Xml.XmlSerializer":{
"version":"*"
},
"System.IO.FileSystem": {"version":"*"}
},
"imports": "dnxcore50"
}
}
}