Exemple #1
0
        public void Export(object data)
        {
            var stream = new MemoryStream();
            var exportWriter = new StreamWriter(stream);
            var exporter = new XmlExporter();

            exporter.Export(exportWriter, data);

            var exportReader = new StreamReader(stream);

            stream.Position = 0;
            var xmlData = exportReader.ReadToEnd();

            xmlData = xmlData.Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", "");

            var fileStream = new StreamWriter(ExportPath, false);
            fileStream.Write(xmlData);

            fileStream.Close();

            PostExportAction();
        }
Exemple #2
0
        public void SaveMainRegionDataToXml()
        {
            var views = _RegionManager.Regions[CoreRegionNames.MainRegion].Views.ToList();
            string data = string.Empty;

            while (true)
            {
                if (!views.Any())
                {
                    break;
                }

                var view = views.First() as UserControl;

                if (view == null)
                {
                    break;
                }

                if (view.DataContext == null)
                {
                    break;
                }

                if (view.DataContext == null)
                {
                    break;
                }

                var viewModel = view.DataContext;

                if (viewModel == null)
                {
                    break;
                }

                var stream = new MemoryStream();
                var exportWriter = new StreamWriter(stream);
                var exporter = new XmlExporter();

                exporter.Export(exportWriter, viewModel);

                var exportReader = new StreamReader(stream);

                stream.Position = 0;
                data = exportReader.ReadToEnd();

                break;
            }

            if (data == string.Empty)
            {
                Dialogs.ShowModalMessage("Cannot save data to Xml");
                return;
            }

            var fileDialog = new Microsoft.Win32.SaveFileDialog();
            fileDialog.DefaultExt = "xml";

            if (!fileDialog.ShowDialog().Value)
            {
                return;
            }

            data = data.Replace(@"<?xml version=""1.0"" encoding=""utf-16""?>", "");

            var fileStream = new StreamWriter(fileDialog.FileName);
            fileStream.Write(data);

            fileStream.Close();
        }