private void FillLocomotives(IRepository repository) { foreach (var locomotive in repository.Locomotives) { Locomotives.Add(new LocomotiveViewModel(locomotive)); } // Связываем модель представления локомотивов с локомотивами из модели данных. _locomotivesLinker = new ObservableCollectionsConnector <ILocomotive, ILocomotiveViewModel> (repository.Locomotives, Locomotives, OnNewLocomotiveAdded, locomotive => Locomotives.FirstOrDefault(e => e.Locomotive == locomotive)); }
public static void Init() { try { Reset(); foreach (string str in System.IO.Directory.GetDirectories(Application.StartupPath + "\\data\\trains\\resources")) { string[] l = System.IO.File.ReadAllLines(str + @"\data.xml", System.Text.Encoding.Default); if (l[0] == @"<locomotive>") { Locomotive loc = new Locomotive(); loc.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1)); Locomotives.Add(loc); continue; } else if (l[0] == @"<coach>") { Coach car = new Coach(); car.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1)); Coachs.Add(car); continue; } else if (l[0] == @"<enginecoach>") { EngineCoach lc = new EngineCoach(); lc.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1)); EngineCoachs.Add(lc); continue; } } foreach (string str in System.IO.Directory.GetDirectories(".\\data\\trains\\datas")) { TrainData train = new TrainData(); train.Load(str.Substring(str.LastIndexOf('\\') + 1, str.Length - str.LastIndexOf('\\') - 1)); TrainDatas.Add(train); } } catch (Exception e) { Environment.ReportError(e, AccessManager.AccessKey); } }