public void Save(Book book, string path) { var serializer = new XmlSerializer(typeof (Book)); using (TextWriter writer = new StreamWriter(path)) { serializer.Serialize(writer, this); } }
private static void PrintWay(Book book) { var searchResults = book.GetWay(new SearchParameters(new PersonState(1), SearchAlgorithm.Bfs)); using (TextWriter writer = File.CreateText("output.txt")) { foreach (var result in searchResults) { writer.WriteLine("{0} Distance: {1}", result.State, result.Distance); } } }
private void UseBook(Book newBook) { m_Book = newBook; m_Items = new ObservableCollection<ItemTypeModel>(m_Book.AvailableItems.Select(item => new ItemTypeModel(item))); NotifyPropertyChanged("Items"); m_Paragraphs = new ObservableCollection<ParagraphModel>(m_Book.Paragraphs.Select(p => new ParagraphModel(p))); NotifyPropertyChanged("Paragraphs"); if (m_Book.LastSearchParameters != null) { StartId = m_Book.LastSearchParameters.StartState.ParagraphNo; StartItems = new ObservableCollection<ItemUnit>(m_Book.LastSearchParameters.StartState.Items); SearchAlgorithm = m_Book.LastSearchParameters.Algorithm; } else { StartItems = new ObservableCollection<ItemUnit>(); } NotifyPropertyChanged("StartItems"); SaveCommand.RaiseCanExecuteChanged(); GetFurthestWayCommand.RaiseCanExecuteChanged(); UpdateCommand.RaiseCanExecuteChanged(); FoundWay = ConvertWay(m_Book.LastGeneratedWay); UpdateEdgeList(); }