public void Save(string path) { reportProgress(String.Format("Saving data of {0} requests.", newKnowledge.Count)); if (newKnowledge.Count > 0) { int notZeroCount = newKnowledge.Count(x => x.Distance != 0); reportProgress(String.Format("Path with distance: {0}%", notZeroCount * 100 / newKnowledge.Count)); knowledge = new Knowledge { Entries = knowledge.Entries.Concat(newKnowledge).ToArray() }; using (var stream = File.OpenWrite(path)) { XmlSerializer ser = new XmlSerializer(typeof(Knowledge)); ser.Serialize(stream, knowledge); } } reportProgress(String.Format("Saving done: {0}", newKnowledge.Count)); }
public void LoadData(string path) { using (var stream = File.OpenRead(path)) { XmlSerializer ser = new XmlSerializer(typeof(Knowledge)); knowledge = (Knowledge)ser.Deserialize(stream); var fromList = knowledge.Entries.Select(x => Tuple.Create(x.From, x)); var toList = knowledge.Entries.Select(x => Tuple.Create(x.To, x)); index = new SortedDictionary <Point, List <WalkPath> >(); foreach (var entry in fromList.Concat(toList)) { if (!index.ContainsKey(entry.Item1)) { index.Add(entry.Item1, new List <WalkPath>()); } index[entry.Item1].Add(entry.Item2); } } reportProgress("Data loaded done. Total requests done: " + knowledge.Entries.Length); }