Datei: NDOEnhancer/NDOEnhancer/Enhancer/ProjectDescription.cs
Last Commit (4bf6f30)
| 1 | |
| 2 | // Copyright (c) 2002-2024 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | using System; |
| 23 | using System.Xml; |
| 24 | using System.Collections.Generic; |
| 25 | using System.IO; |
| 26 | |
| 27 | namespace NDOEnhancer |
| 28 | { |
| 29 | ····internal class NDOReference |
| 30 | ····{ |
| 31 | ········public string Name; |
| 32 | ········public string Path; |
| 33 | ········public bool CheckThisDLL; |
| 34 | |
| 35 | ········public NDOReference(string name, string path, bool checkThisDLL) |
| 36 | ········{ |
| 37 | ············this.Name = name; |
| 38 | ············this.Path = path; |
| 39 | ············this.CheckThisDLL = checkThisDLL; |
| 40 | ········} |
| 41 | |
| 42 | ····} |
| 43 | |
| 44 | ····/// <summary> |
| 45 | ····/// Zusammenfassung für ProjectDescription. |
| 46 | ····/// </summary> |
| 47 | ····internal class ProjectDescription |
| 48 | ····{ |
| 49 | ········Dictionary<string, NDOReference> references = null; |
| 50 | ········bool debug; |
| 51 | ········string binFile; |
| 52 | ········string objPath; |
| 53 | ········string projPath; |
| 54 | ········string assemblyName; |
| 55 | ········ConfigurationOptions options; |
| 56 | ········string keyFile = string.Empty; |
| 57 | ········public string FileName { get; set; } |
| 58 | |
| 59 | ········public string KeyFile |
| 60 | ········{ |
| 61 | ············get { return keyFile; } |
| 62 | ············set { keyFile = value; } |
| 63 | ········} |
| 64 | |
| 65 | ········public ConfigurationOptions ConfigurationOptions |
| 66 | ········{ |
| 67 | ············get { return options; } |
| 68 | ········} |
| 69 | |
| 70 | ········public string AssemblyName |
| 71 | ········{ |
| 72 | ············get { return assemblyName; } |
| 73 | ············set { assemblyName = value; } |
| 74 | ········} |
| 75 | |
| 76 | ········public ProjectDescription(string fileName, string targetFramework) |
| 77 | ········{ |
| 78 | ············this.FileName = fileName; |
| 79 | ············// GetFullPath: a file name without directory would result in the root directory "/" |
| 80 | ············this.projPath = Path.GetDirectoryName(Path.GetFullPath(fileName)) + Path.DirectorySeparatorChar; |
| 81 | ············XmlDocument doc = new XmlDocument(); |
| 82 | ············try |
| 83 | ············{ |
| 84 | ················doc.Load(fileName); |
| 85 | ············} |
| 86 | ············catch(XmlException ex) |
| 87 | ············{ |
| 88 | ················throw new Exception("Parameter file '" + fileName + "' is not a valid Xml file. Line: " + ex.LineNumber.ToString() + " Position: " + ex.LinePosition.ToString()); |
| 89 | ············} |
| 90 | ············XmlHelper.AddNamespace(doc); |
| 91 | ············Load(doc, targetFramework); |
| 92 | ············options = new ConfigurationOptions(this, doc); |
| 93 | ········} |
| 94 | |
| 95 | ········string AbsolutePath(string path) |
| 96 | ········{ |
| 97 | ············// .ndoproj files contain Windows paths |
| 98 | ············path = path.Replace( '\\', Path.DirectorySeparatorChar ); |
| 99 | ············if (Path.IsPathRooted(path)) |
| 100 | ················return Path.GetFullPath(path); |
| 101 | ············else |
| 102 | ················return Path.GetFullPath(Path.Combine(projPath, path)); |
| 103 | ········} |
| 104 | |
| 105 | ········void Load(XmlDocument doc, string targetFramework) |
| 106 | ········{ |
| 107 | ············string pns = XmlHelper.Pns(doc); |
| 108 | |
| 109 | ············XmlNode node = doc.SelectSingleNode("//" + pns + "Enhancer/" + pns + "ProjectDescription", XmlHelper.Nsmgr); |
| 110 | ············if (node == null) |
| 111 | ················throw new Exception("Parameters must have at least one //Enhancer/ProjectDescription entry."); |
| 112 | ············ |
| 113 | ············this.binFile = AbsolutePath((string) XmlHelper.GetNode(node, pns + "BinPath")) |
| 114 | ················.Replace( "$(TargetFramework)", targetFramework ); |
| 115 | ············this.objPath = AbsolutePath((string) XmlHelper.GetNode(node, pns + "ObjPath")) |
| 116 | ················.Replace( "$(TargetFramework)", targetFramework ); |
| 117 | |
| 118 | ············this.keyFile = (string)XmlHelper.GetNode(node, pns + "KeyFile", string.Empty); |
| 119 | ············if (this.keyFile != string.Empty) |
| 120 | ················this.keyFile = AbsolutePath(keyFile); |
| 121 | |
| 122 | ············this.assemblyName = (string)XmlHelper.GetNode(node, pns + "AssemblyName"); |
| 123 | ············this.debug = (bool) XmlHelper.GetNode(node, pns + "Debug", false); |
| 124 | ············XmlNodeList refList = doc.SelectNodes("//" + pns + "Enhancer/" + pns + "ProjectDescription/" + pns + "References/" + pns + "Reference", XmlHelper.Nsmgr); |
| 125 | ············this.references = new Dictionary<string, NDOReference>(); |
| 126 | ············foreach(XmlNode rnode in refList) |
| 127 | ············{ |
| 128 | ················string assName = (string) XmlHelper.GetAttribute(rnode, "AssemblyName"); |
| 129 | ················string assPath = AbsolutePath((string) XmlHelper.GetAttribute(rnode, "AssemblyPath")); |
| 130 | ················bool processDLL = true; |
| 131 | ················XmlAttribute attr = rnode.Attributes["CheckThisDLL"]; |
| 132 | ················if ( attr != null && string.Compare( attr.Value, "True", true ) != 0 ) |
| 133 | ····················processDLL = false; |
| 134 | |
| 135 | ················AddReference(assName, assPath, processDLL); |
| 136 | ············} |
| 137 | ········} |
| 138 | |
| 139 | ········public string ObjPath |
| 140 | ········{ |
| 141 | ············get { return objPath; } |
| 142 | ············set { objPath = value; } |
| 143 | ········} |
| 144 | |
| 145 | ········public string BinFile |
| 146 | ········{ |
| 147 | ············get { return binFile; } |
| 148 | ············set { binFile = value; } |
| 149 | ········} |
| 150 | |
| 151 | ········public bool Debug |
| 152 | ········{ |
| 153 | ············get { return debug; } |
| 154 | ············set { debug = value; } |
| 155 | ········} |
| 156 | |
| 157 | ········public string ProjPath |
| 158 | ········{ |
| 159 | ············get { return projPath; } |
| 160 | ············set { projPath = value; } |
| 161 | ········} |
| 162 | |
| 163 | ········private void AddReference( string name, string path, bool checkThisDLL ) |
| 164 | ········{ |
| 165 | ············if ( path.IndexOf( @"Microsoft.NET\Framework" ) > -1 ) |
| 166 | ················return; |
| 167 | ············if ( name.ToUpper() == "NDO" ) |
| 168 | ················return; |
| 169 | if ( name. ToUpper( ) == "NDOInterfaces" ) |
| 170 | ················return; |
| 171 | |
| 172 | ············if ( !references.ContainsKey( name ) ) |
| 173 | ················references.Add( name, new NDOReference( name, path, checkThisDLL ) ); |
| 174 | ········} |
| 175 | |
| 176 | ········public string DefaultMappingFileName |
| 177 | ········{ |
| 178 | ············get |
| 179 | ············{ |
| 180 | ················return Path.Combine(this.projPath, "NDOMapping.xml"); |
| 181 | ············} |
| 182 | ········} |
| 183 | |
| 184 | ········public bool MappingFileExists |
| 185 | ········{ |
| 186 | ············get |
| 187 | ············{ |
| 188 | ················return CheckedMappingFileName != null; |
| 189 | ············} |
| 190 | ········} |
| 191 | |
| 192 | ········/// <summary> |
| 193 | ········/// Returns the mapping file, if the file exists, or null otherwise |
| 194 | ········/// </summary> |
| 195 | ········public string CheckedMappingFileName |
| 196 | ········{ |
| 197 | ············get |
| 198 | ············{ |
| 199 | ················if (File.Exists(DefaultMappingFileName)) |
| 200 | ····················return DefaultMappingFileName; |
| 201 | ················if (assemblyName == null) |
| 202 | ····················return null; |
| 203 | ················string mappingFile = Path.Combine(projPath, this.assemblyName + "ndo.xml"); |
| 204 | ················if (File.Exists(mappingFile)) |
| 205 | ····················return mappingFile; |
| 206 | ················return null; |
| 207 | ············} |
| 208 | ········} |
| 209 | |
| 210 | ········public Dictionary<string, NDOReference> References |
| 211 | ········{ |
| 212 | ············get |
| 213 | ············{ |
| 214 | ················if (references == null) |
| 215 | ····················references = new Dictionary<string,NDOReference>(); |
| 216 | ················return references; |
| 217 | ············} |
| 218 | ········} |
| 219 | |
| 220 | ····} |
| 221 | } |
| 222 |
New Commit (70a7a80)
| 1 | |
| 2 | // Copyright (c) 2002-2024 Mirko Matytschak |
| 3 | // (www.netdataobjects.de) |
| 4 | // |
| 5 | // Author: Mirko Matytschak |
| 6 | // |
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation |
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 11 | // conditions: |
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 14 | // of the Software. |
| 15 | // |
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 | // DEALINGS IN THE SOFTWARE. |
| 21 | |
| 22 | using System; |
| 23 | using System.Xml; |
| 24 | using System.Collections.Generic; |
| 25 | using System.IO; |
| 26 | |
| 27 | namespace NDOEnhancer |
| 28 | { |
| 29 | ····internal class NDOReference |
| 30 | ····{ |
| 31 | ········public string Name; |
| 32 | ········public string Path; |
| 33 | ········public bool CheckThisDLL; |
| 34 | |
| 35 | ········public NDOReference(string name, string path, bool checkThisDLL) |
| 36 | ········{ |
| 37 | ············this.Name = name; |
| 38 | ············this.Path = path; |
| 39 | ············this.CheckThisDLL = checkThisDLL; |
| 40 | ········} |
| 41 | |
| 42 | ····} |
| 43 | |
| 44 | ····/// <summary> |
| 45 | ····/// Zusammenfassung für ProjectDescription. |
| 46 | ····/// </summary> |
| 47 | ····internal class ProjectDescription |
| 48 | ····{ |
| 49 | ········Dictionary<string, NDOReference> references = null; |
| 50 | ········bool debug; |
| 51 | ········string binFile; |
| 52 | ········string objPath; |
| 53 | ········string projPath; |
| 54 | ········string assemblyName; |
| 55 | ········ConfigurationOptions options; |
| 56 | ········string keyFile = string.Empty; |
| 57 | ········public string FileName { get; set; } |
| 58 | |
| 59 | ········public string KeyFile |
| 60 | ········{ |
| 61 | ············get { return keyFile; } |
| 62 | ············set { keyFile = value; } |
| 63 | ········} |
| 64 | |
| 65 | ········public ConfigurationOptions ConfigurationOptions |
| 66 | ········{ |
| 67 | ············get { return options; } |
| 68 | ········} |
| 69 | |
| 70 | ········public string AssemblyName |
| 71 | ········{ |
| 72 | ············get { return assemblyName; } |
| 73 | ············set { assemblyName = value; } |
| 74 | ········} |
| 75 | |
| 76 | ········public ProjectDescription(string fileName, string targetFramework) |
| 77 | ········{ |
| 78 | ············this.FileName = fileName; |
| 79 | ············// GetFullPath: a file name without directory would result in the root directory "/" |
| 80 | ············this.projPath = Path.GetDirectoryName(Path.GetFullPath(fileName)) + Path.DirectorySeparatorChar; |
| 81 | ············XmlDocument doc = new XmlDocument(); |
| 82 | ············try |
| 83 | ············{ |
| 84 | ················doc.Load(fileName); |
| 85 | ············} |
| 86 | ············catch(XmlException ex) |
| 87 | ············{ |
| 88 | ················throw new Exception("Parameter file '" + fileName + "' is not a valid Xml file. Line: " + ex.LineNumber.ToString() + " Position: " + ex.LinePosition.ToString()); |
| 89 | ············} |
| 90 | ············XmlHelper.AddNamespace(doc); |
| 91 | ············Load(doc, targetFramework); |
| 92 | ············options = new ConfigurationOptions(this, doc); |
| 93 | ········} |
| 94 | |
| 95 | ········string AbsolutePath(string path) |
| 96 | ········{ |
| 97 | ············// .ndoproj files contain Windows paths |
| 98 | ············path = path.Replace( '\\', Path.DirectorySeparatorChar ); |
| 99 | ············if (Path.IsPathRooted(path)) |
| 100 | ················return Path.GetFullPath(path); |
| 101 | ············else |
| 102 | ················return Path.GetFullPath(Path.Combine(projPath, path)); |
| 103 | ········} |
| 104 | |
| 105 | ········void Load(XmlDocument doc, string targetFramework) |
| 106 | ········{ |
| 107 | ············string pns = XmlHelper.Pns(doc); |
| 108 | |
| 109 | ············XmlNode node = doc.SelectSingleNode("//" + pns + "Enhancer/" + pns + "ProjectDescription", XmlHelper.Nsmgr); |
| 110 | ············if (node == null) |
| 111 | ················throw new Exception("Parameters must have at least one //Enhancer/ProjectDescription entry."); |
| 112 | ············ |
| 113 | ············this.binFile = AbsolutePath((string) XmlHelper.GetNode(node, pns + "BinPath")) |
| 114 | ················.Replace( "$(TargetFramework)", targetFramework ); |
| 115 | ············this.objPath = AbsolutePath((string) XmlHelper.GetNode(node, pns + "ObjPath")) |
| 116 | ················.Replace( "$(TargetFramework)", targetFramework ); |
| 117 | |
| 118 | ············this.keyFile = (string)XmlHelper.GetNode(node, pns + "KeyFile", string.Empty); |
| 119 | ············if (this.keyFile != string.Empty) |
| 120 | ················this.keyFile = AbsolutePath(keyFile); |
| 121 | |
| 122 | ············this.assemblyName = (string)XmlHelper.GetNode(node, pns + "AssemblyName"); |
| 123 | ············this.debug = (bool) XmlHelper.GetNode(node, pns + "Debug", false); |
| 124 | ············XmlNodeList refList = doc.SelectNodes("//" + pns + "Enhancer/" + pns + "ProjectDescription/" + pns + "References/" + pns + "Reference", XmlHelper.Nsmgr); |
| 125 | ············this.references = new Dictionary<string, NDOReference>(); |
| 126 | ············foreach(XmlNode rnode in refList) |
| 127 | ············{ |
| 128 | ················string assName = (string) XmlHelper.GetAttribute(rnode, "AssemblyName"); |
| 129 | ················string assPath = AbsolutePath((string) XmlHelper.GetAttribute(rnode, "AssemblyPath")); |
| 130 | ················bool processDLL = true; |
| 131 | ················XmlAttribute attr = rnode.Attributes["CheckThisDLL"]; |
| 132 | ················if ( attr != null && string.Compare( attr.Value, "True", true ) != 0 ) |
| 133 | ····················processDLL = false; |
| 134 | |
| 135 | ················AddReference(assName, assPath, processDLL); |
| 136 | ············} |
| 137 | ········} |
| 138 | |
| 139 | ········public string ObjPath |
| 140 | ········{ |
| 141 | ············get { return objPath; } |
| 142 | ············set { objPath = value; } |
| 143 | ········} |
| 144 | |
| 145 | ········public string BinFile |
| 146 | ········{ |
| 147 | ············get { return binFile; } |
| 148 | ············set { binFile = value; } |
| 149 | ········} |
| 150 | |
| 151 | ········public bool Debug |
| 152 | ········{ |
| 153 | ············get { return debug; } |
| 154 | ············set { debug = value; } |
| 155 | ········} |
| 156 | |
| 157 | ········public string ProjPath |
| 158 | ········{ |
| 159 | ············get { return projPath; } |
| 160 | ············set { projPath = value; } |
| 161 | ········} |
| 162 | |
| 163 | ········private void AddReference( string name, string path, bool checkThisDLL ) |
| 164 | ········{ |
| 165 | ············if ( path.IndexOf( @"Microsoft.NET\Framework" ) > -1 ) |
| 166 | ················return; |
| 167 | ············if ( name.ToUpper() == "NDO" ) |
| 168 | ················return; |
| 169 | if ( name. ToUpper( ) == "NDOINTERFACES" ) |
| 170 | ················return; |
| 171 | |
| 172 | ············if ( !references.ContainsKey( name ) ) |
| 173 | ················references.Add( name, new NDOReference( name, path, checkThisDLL ) ); |
| 174 | ········} |
| 175 | |
| 176 | ········public string DefaultMappingFileName |
| 177 | ········{ |
| 178 | ············get |
| 179 | ············{ |
| 180 | ················return Path.Combine(this.projPath, "NDOMapping.xml"); |
| 181 | ············} |
| 182 | ········} |
| 183 | |
| 184 | ········public bool MappingFileExists |
| 185 | ········{ |
| 186 | ············get |
| 187 | ············{ |
| 188 | ················return CheckedMappingFileName != null; |
| 189 | ············} |
| 190 | ········} |
| 191 | |
| 192 | ········/// <summary> |
| 193 | ········/// Returns the mapping file, if the file exists, or null otherwise |
| 194 | ········/// </summary> |
| 195 | ········public string CheckedMappingFileName |
| 196 | ········{ |
| 197 | ············get |
| 198 | ············{ |
| 199 | ················if (File.Exists(DefaultMappingFileName)) |
| 200 | ····················return DefaultMappingFileName; |
| 201 | ················if (assemblyName == null) |
| 202 | ····················return null; |
| 203 | ················string mappingFile = Path.Combine(projPath, this.assemblyName + "ndo.xml"); |
| 204 | ················if (File.Exists(mappingFile)) |
| 205 | ····················return mappingFile; |
| 206 | ················return null; |
| 207 | ············} |
| 208 | ········} |
| 209 | |
| 210 | ········public Dictionary<string, NDOReference> References |
| 211 | ········{ |
| 212 | ············get |
| 213 | ············{ |
| 214 | ················if (references == null) |
| 215 | ····················references = new Dictionary<string,NDOReference>(); |
| 216 | ················return references; |
| 217 | ············} |
| 218 | ········} |
| 219 | |
| 220 | ····} |
| 221 | } |
| 222 |