public void WriteDataTest() { DataCenterRepository repo = new DataCenterRepository(string.Empty); DataCenterModel dc = new DataCenterModel(); dc.Id = "0"; dc.Name = "datacenter_ams"; dc.ContactPeople = new List<Person>() { new Person(){ FirstName = "John", LastName = "Smith", Email = "*****@*****.**", Phone = "01-234-5678" } }; dc.Racks = new List<RackModel>() { new RackModel(){ Id = "1", Name = "rack_ams0", Floor = "3", Position = "b", Devices = new List<DeviceModel>(){ new DeviceModel(){ Id = "1000", Name = "computer1000", Status = "active", IPAddress = "10.0.0.1"}, new DeviceModel(){ Id = "2000", Name = "computer2000", Status = "active", IPAddress = "10.0.0.2"} } }, new RackModel(){ Id = "2", Name = "rack_ams1", Floor = "3", Position = "d", Devices = new List<DeviceModel>(){ new DeviceModel(){ Id = "1001", Name = "computer1001", Status = "active", IPAddress = "10.0.3.1"}, new DeviceModel(){ Id = "2001", Name = "computer2001", Status = "active", IPAddress = "10.0.3.2"} } } }; dc.Phone = "01-234-5678"; dc.Address = "First street 12, Amsterdam, 1101AH"; repo.AddDataCenter(dc); repo.Save(); }
public void LoadDataTest() { var dialog = new FileDialogView(null){ Mode = Mode.Open, DefaultExt = "*.xml" }; if (dialog.ShowDialog() == true && dialog.FileNames != null && dialog.FileNames.Length > 0) { DataCenterRepository repo = new DataCenterRepository(dialog.FileNames[0]); var dcs = repo.GetDataCenters(); dcs.ToArray(); } }
public MainViewModel(DataCenterRepository dataCenterRepository) { _mainController = new MainController(dataCenterRepository); LoadCommand = _mainController.LoadCommand; SaveCommand = _mainController.SaveCommand; _mainController.OnDataCentersLoaded += delegate { DataCenters = new DataCenterListViewModel(_mainController.LoadDataCenter()); WindowTitle = _mainController.Title; }; WindowTitle = _mainController.Title; }
public void OnLoad() { if (_fileDialog == null) _fileDialog = new FileDialogView(null); try { _fileDialog.Mode = Mode.Open; _fileDialog.DefaultExt = "xml"; if (_fileDialog.ShowDialog() == true && _fileDialog.FileNames != null && _fileDialog.FileNames.Length > 0) { this._dataCenterRepository = new DataCenterRepository(_fileDialog.FileNames[0]); _loadedFileName = _fileDialog.FileNames[0]; if (OnDataCentersLoaded != null) OnDataCentersLoaded(this, EventArgs.Empty); } } finally { _fileDialog.Mode = Mode.None; } }
public MainController(DataCenterRepository dataCenterRepository) : this() { this._dataCenterRepository = dataCenterRepository; }
private static void WriteTo(DataCenterRepository repository, string filename) { if (repository == null) throw new ArgumentNullException("repository"); if (filename == null) throw new ArgumentNullException("filename"); if (repository._datacenters == null || repository._datacenters.Count == 0) return; if (!File.Exists(filename)) { using (File.Create(filename)) { } } using (Stream stream = new MemoryStream() ) { using (XmlWriter xmlWriter = new XmlTextWriter(stream, Encoding.UTF8)) { var datacenters = repository.GetDataCenters(); XDocument doc = new XDocument(datacenters == null ? new XElement("") : new XElement("datacenters", from datacenter in datacenters orderby datacenter.Id select datacenter == null ? new XElement("") : new XElement("datacenter", new XAttribute("id", datacenter.Id ?? ""), new XAttribute("name", datacenter.Name ?? ""), new XAttribute("phone", datacenter.Phone ?? ""), new XAttribute("address", datacenter.Address ?? ""), new XElement("contactpeople", from person in datacenter.ContactPeople orderby person.LastName select person == null ? new XElement("") : new XElement("person", new XAttribute("firstname", person.FirstName ?? ""), new XAttribute("lastname", person.LastName ?? ""), new XAttribute("phone", person.Phone ?? ""), new XAttribute("email", person.Email ?? ""))), datacenter.Racks == null ? new XElement("") : new XElement("racks", from rack in datacenter.Racks orderby rack.Id select rack == null ? new XElement("") : new XElement("rack", new XAttribute("id", rack.Id ?? ""), new XAttribute("name", rack.Name ?? ""), new XAttribute("floor", rack.Floor ?? ""), new XAttribute("position", rack.Position ?? ""), rack.Devices == null ? new XElement("devices") : new XElement("devices", from device in rack.Devices orderby device.Id select device == null ? new XElement("") : new XElement("device", new XAttribute("id", device.Id ?? ""), new XAttribute("name", device.Name ?? ""), new XAttribute("ipaddress", device.IPAddress ?? ""), new XAttribute("status", device.Status ?? "")))))))); doc.Save(filename); } } }