diff --git a/src/MicroStationTagExplorer/MainWindow.xaml b/src/MicroStationTagExplorer/MainWindow.xaml index c715ae2..da5a606 100644 --- a/src/MicroStationTagExplorer/MainWindow.xaml +++ b/src/MicroStationTagExplorer/MainWindow.xaml @@ -39,7 +39,7 @@ diff --git a/src/MicroStationTagExplorer/MainWindow.xaml.cs b/src/MicroStationTagExplorer/MainWindow.xaml.cs index 4761ed1..b5dfd78 100644 --- a/src/MicroStationTagExplorer/MainWindow.xaml.cs +++ b/src/MicroStationTagExplorer/MainWindow.xaml.cs @@ -23,26 +23,29 @@ namespace MicroStationTagExplorer InitializeComponent(); } - private ObservableCollection GetFiles() + private Project GetProject() { - ObservableCollection files = null; + Project project = null; if (DataGridFiles.DataContext != null) { - files = DataGridFiles.DataContext as ObservableCollection; + project = DataGridFiles.DataContext as Project; } else { - files = new ObservableCollection(); - DataGridFiles.DataContext = files; + project = new Project() + { + Files = new ObservableCollection() + }; + DataGridFiles.DataContext = project; } - return files; + return project; } - private void SetFiles(ObservableCollection files) + private void SetProject(Project project) { - DataGridFiles.DataContext = files; + DataGridFiles.DataContext = project; } private void AddFiles() @@ -55,7 +58,7 @@ namespace MicroStationTagExplorer var result = dlg.ShowDialog(this); if (result == true) { - ObservableCollection files = GetFiles(); + Project project = GetProject(); foreach (var fileName in dlg.FileNames) { @@ -63,14 +66,14 @@ namespace MicroStationTagExplorer { Path = fileName }; - files.Add(file); + project.Files.Add(file); } } } private void AddPaths(string[] paths) { - ObservableCollection files = GetFiles(); + Project project = GetProject(); foreach (var path in paths) { @@ -85,7 +88,7 @@ namespace MicroStationTagExplorer { Path = fileName }; - files.Add(file); + project.Files.Add(file); } } else @@ -96,7 +99,7 @@ namespace MicroStationTagExplorer { Path = path }; - files.Add(file); + project.Files.Add(file); } } } @@ -104,7 +107,10 @@ namespace MicroStationTagExplorer private void NewProject() { - SetFiles(new ObservableCollection()); + SetProject(new Project() + { + Files = new ObservableCollection() + }); } private void OpenProject() @@ -119,9 +125,9 @@ namespace MicroStationTagExplorer { using (var reader = new System.IO.StreamReader(dlg.FileName)) { - var serializer = new XmlSerializer(typeof(ObservableCollection)); - ObservableCollection files = (ObservableCollection)serializer.Deserialize(reader); - SetFiles(files); + var serializer = new XmlSerializer(typeof(Project)); + Project project = (Project)serializer.Deserialize(reader); + SetProject(project); } } } @@ -131,17 +137,17 @@ namespace MicroStationTagExplorer var dlg = new SaveFileDialog { Filter = "Supported Files (*.xml)|*.xml|All Files (*.*)|*.*", - FileName = "tags" + FileName = "project" }; var result = dlg.ShowDialog(this); if (result == true) { - ObservableCollection files = GetFiles(); + Project project = GetProject(); using (var writer = new System.IO.StreamWriter(dlg.FileName)) { - var serializer = new XmlSerializer(typeof(ObservableCollection)); - serializer.Serialize(writer, files); + var serializer = new XmlSerializer(typeof(Project)); + serializer.Serialize(writer, project); } } } @@ -163,7 +169,7 @@ namespace MicroStationTagExplorer TokenSource = new CancellationTokenSource(); Token = TokenSource.Token; - ObservableCollection files = GetFiles(); + Project project = GetProject(); Task.Factory.StartNew(() => { @@ -171,10 +177,10 @@ namespace MicroStationTagExplorer { Token.ThrowIfCancellationRequested(); - int count = files.Count; - for (int i = 0; i < files.Count; i++) + int count = project.Files.Count; + for (int i = 0; i < project.Files.Count; i++) { - var file = files[i]; + var file = project.Files[i]; if (Token.IsCancellationRequested) { Token.ThrowIfCancellationRequested(); @@ -269,12 +275,12 @@ namespace MicroStationTagExplorer { if (IsRunning == false) { - ObservableCollection files = GetFiles(); + Project project = GetProject(); try { object[,] values; - Tag[] tags = files.SelectMany(f => f.Tags).ToArray(); + Tag[] tags = project.Files.SelectMany(f => f.Tags).ToArray(); ToValues(tags, out values); using (var excel = new Excelnterop()) { diff --git a/src/MicroStationTagExplorer/MicroStationTagExplorer.csproj b/src/MicroStationTagExplorer/MicroStationTagExplorer.csproj index 7786aa4..70db07e 100644 --- a/src/MicroStationTagExplorer/MicroStationTagExplorer.csproj +++ b/src/MicroStationTagExplorer/MicroStationTagExplorer.csproj @@ -93,6 +93,7 @@ + diff --git a/src/MicroStationTagExplorer/Model/File.cs b/src/MicroStationTagExplorer/Model/File.cs index 8755a68..05e2102 100644 --- a/src/MicroStationTagExplorer/Model/File.cs +++ b/src/MicroStationTagExplorer/Model/File.cs @@ -1,12 +1,19 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Xml.Serialization; namespace MicroStationTagExplorer { + [XmlRoot("File")] public class File { + [XmlAttribute("Path")] public string Path { get; set; } + + [XmlArray("TagSets")] public ObservableCollection TagSets { get; set; } + + [XmlArray("Tags")] public ObservableCollection Tags { get; set; } } } diff --git a/src/MicroStationTagExplorer/Model/Project.cs b/src/MicroStationTagExplorer/Model/Project.cs new file mode 100644 index 0000000..558d0dd --- /dev/null +++ b/src/MicroStationTagExplorer/Model/Project.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Xml.Serialization; + +namespace MicroStationTagExplorer +{ + [XmlRoot("Project")] + public class Project + { + [XmlArray("Files")] + public ObservableCollection Files { get; set; } + } +} diff --git a/src/MicroStationTagExplorer/Model/Tag.cs b/src/MicroStationTagExplorer/Model/Tag.cs index 318129e..ac71ff8 100644 --- a/src/MicroStationTagExplorer/Model/Tag.cs +++ b/src/MicroStationTagExplorer/Model/Tag.cs @@ -1,14 +1,27 @@ using System; +using System.Xml.Serialization; namespace MicroStationTagExplorer { + [XmlRoot("Tag")] public class Tag { + [XmlAttribute("TagSetName")] public string TagSetName { get; set; } + + [XmlAttribute("TagDefinitionName")] public string TagDefinitionName { get; set; } + + [XmlElement] public object Value { get; set; } + + [XmlAttribute("ID")] public Int64 ID { get; set; } + + [XmlAttribute("HostID")] public Int64 HostID { get; set; } + + [XmlAttribute("Path")] public string Path { get; set; } } } diff --git a/src/MicroStationTagExplorer/Model/TagDefinition.cs b/src/MicroStationTagExplorer/Model/TagDefinition.cs index 2b0435f..d5f8a20 100644 --- a/src/MicroStationTagExplorer/Model/TagDefinition.cs +++ b/src/MicroStationTagExplorer/Model/TagDefinition.cs @@ -1,8 +1,12 @@  +using System.Xml.Serialization; + namespace MicroStationTagExplorer { + [XmlRoot("TagDefinition")] public class TagDefinition { + [XmlAttribute("Name")] public string Name { get; set; } } } diff --git a/src/MicroStationTagExplorer/Model/TagSet.cs b/src/MicroStationTagExplorer/Model/TagSet.cs index a45719b..627faa6 100644 --- a/src/MicroStationTagExplorer/Model/TagSet.cs +++ b/src/MicroStationTagExplorer/Model/TagSet.cs @@ -1,11 +1,16 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Xml.Serialization; namespace MicroStationTagExplorer { + [XmlRoot("TagSet")] public class TagSet { + [XmlAttribute("Path")] public string Name { get; set; } + + [XmlArray("TagDefinitions")] public ObservableCollection TagDefinitions { get; set; } } }