-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.cs
60 lines (53 loc) · 1.87 KB
/
Project.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TicketPrinter
{
public class Project
{
//
// CONNECTION
//
public string PortName = null;
//
// PROJECT
//
public string ProjectName;
public List<Ticket> Tickets = new List<Ticket>();
public int NextTicketNumber = 10001;
public int XOffset = 200;
public int YOffset = 50;
public static Project Deserialize(IDictionary<string, object> dict)
{
Project project = new Project();
project.ProjectName = dict["name"].ToString();
project.PortName = (dict["port"] == null ? null : dict["port"].ToString());
project.NextTicketNumber = int.Parse(dict["nextTicket"].ToString());
List<Ticket> tickets = new List<Ticket>();
var ticketDictList = dict["tickets"];
foreach (object o in (IEnumerable<object>)ticketDictList)
{
IDictionary<string, object> ticketDict = (IDictionary<string, object>)o;
tickets.Add(Ticket.Deserialize(ticketDict));
}
project.Tickets = tickets;
return project;
}
public IDictionary<string, object> Serialize()
{
IDictionary<string, object> dict = new Dictionary<string, object>();
dict["name"] = this.ProjectName;
dict["port"] = this.PortName;
dict["nextTicket"] = this.NextTicketNumber;
List<IDictionary<string, object>> ticketDicts = new List<IDictionary<string, object>>();
foreach (Ticket ticket in this.Tickets)
{
ticketDicts.Add(ticket.Serialize());
}
dict["tickets"] = ticketDicts;
return dict;
}
}
}