public DataFillerImpl() { people = new List <Person>(); items = new Dictionary <string, Item>(); events = new ObservableCollection <Event>(); states = new List <StateDescription>(); Author author1 = new Author("John", "Tolkien", 81, "Orania"); Book book1 = new Book("Lord of the rings - The Fellowship of the Ring", author1, 412, "XYZ"); Book book2 = new Book("Lord of the rings - The Two Towers", author1, 350, "XYZ"); Book book3 = new Book("Lord of the rings - The Return of the King", author1, 507, "XYZ"); BookDescription state1 = new BookDescription(book1, "Story of powerful ring", new DateTime(2000, 1, 12), Purpose.All, Kind.Fantasy); BookDescription state2 = new BookDescription(book2, "Story of powerful ring", new DateTime(2002, 12, 5), Purpose.All, Kind.Fantasy); BookDescription state3 = new BookDescription(book3, "Story of powerful ring", new DateTime(2003, 6, 22), Purpose.All, Kind.Fantasy); Reader person1 = new Reader("Dawid", "Urbaniak", 22, "Brzezna"); Reader person2 = new Reader("Igor", "Orynski", 22, "Manhatan"); people.Add(person1); people.Add(person2); people.Add(author1); items.Add(book1.Id, book1); items.Add(book2.Id, book2); items.Add(book3.Id, book3); states.Add(state1); states.Add(state2); states.Add(state3); events.Add(new Rental(state1, person1, DateTime.Now)); events.Add(new Rental(state2, person1, DateTime.Now)); events.Add(new Rental(state3, person2, DateTime.Now)); }
public LargeDataFillerImpl() { people = new List <Person>(); items = new Dictionary <string, Item>(); states = new List <StateDescription>(); events = new ObservableCollection <Event>(); for (int i = 0; i < 10000; i++) { Author author = new Author(randomString(), randomString(), random.Next(100), randomString()); Reader reader = new Reader(randomString(), randomString(), random.Next(100), randomString()); people.Add(author); people.Add(reader); Book book = new Book(randomString(), author, random.Next(1000), randomString()); items.Add(book.Id, book); BookDescription state = new BookDescription(book, randomString(), new DateTime(random.Next(1500, 2000), random.Next(1, 12), random.Next(1, 27)), Purpose.All, Kind.Criminal); states.Add(state); events.Add(new Rental(state, reader, DateTime.Now)); } }
public static DataContext Deserialize(string filename) { DataContext dataContext = new DataContext(); SerializeHelper helper = new SerializeHelper(); string data = System.IO.File.ReadAllText(filename); var dataList = data.Split('\n'); for (int i = 0; i < dataList.Length; i++) { if (!string.IsNullOrEmpty(dataList[i])) { var splittedLine = dataList[i].Split(','); Type type = Type.GetType(splittedLine[0]); object obj = Activator.CreateInstance(type); switch (splittedLine[0]) { case "Library.Person": Person person = (Person)obj; person.Deserialize(splittedLine, helper); helper.PeopleDictionary.Add(splittedLine[1], person); dataContext.PeopleCatalog.Add(person); break; case "Library.Reader": Reader reader = (Reader)obj; reader.Deserialize(splittedLine, helper); helper.PeopleDictionary.Add(splittedLine[1], reader); dataContext.PeopleCatalog.Add(reader); break; case "Library.Author": Author author = (Author)obj; author.Deserialize(splittedLine, helper); helper.PeopleDictionary.Add(splittedLine[1], author); dataContext.PeopleCatalog.Add(author); break; case "Library.Item": Item item = (Item)obj; item.Deserialize(splittedLine, helper); helper.ItemsDictionary.Add(splittedLine[1], item); dataContext.ItemsCatalog.Add(item.Id, item); break; case "Library.Book": Book book = (Book)obj; book.Deserialize(splittedLine, helper); helper.ItemsDictionary.Add(splittedLine[1], book); dataContext.ItemsCatalog.Add(book.Id, book); break; case "Library.StateDescription": StateDescription stateDescription = (StateDescription)obj; stateDescription.Deserialize(splittedLine, helper); helper.StatesDictionary.Add(splittedLine[1], stateDescription); dataContext.StatesCatalog.Add(stateDescription); break; case "Library.BookDescription": BookDescription bookDescription = (BookDescription)obj; bookDescription.Deserialize(splittedLine, helper); helper.StatesDictionary.Add(splittedLine[1], bookDescription); dataContext.StatesCatalog.Add(bookDescription); break; case "Library.Event": Event ev = (Event)obj; ev.Deserialize(splittedLine, helper); dataContext.EventsCatalog.Add(ev); break; case "Library.Rental": Rental rental = (Rental)obj; rental.Deserialize(splittedLine, helper); dataContext.EventsCatalog.Add(rental); break; } } } return(dataContext); }