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();
            }
        }
        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);
                }
            }
        }