Datei: NDOPackage/ConfigurationOptions.cs
Last Commit (bff399f)
1 | // |
2 | // Copyright ( c) 2002-2019 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 | |
23 | using System; |
24 | using System.IO; |
25 | using System.Xml; |
26 | |
27 | #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread |
28 | |
29 | namespace NDOVsPackage |
30 | { |
31 | ····/// <summary> |
32 | ····/// Attention!!!!! This code is essentially the same as in ConfigurationOptions.cs |
33 | ····/// in the project NDOEnhancer. |
34 | ····/// So, if you change one of them, be aware to change the second. |
35 | ····/// </summary> |
36 | ····internal class ConfigurationOptions |
37 | ····{ |
38 | ········string fileName = null; |
39 | |
40 | ········//void Anlegen() { } |
41 | |
42 | ········// This is called to check the options in the Add-in |
43 | ········public ConfigurationOptions(Project project) : this( GetNdoProjFileName( project.FullPath ) ) |
44 | ········{ |
45 | ········} |
46 | |
47 | ········public ConfigurationOptions(EnvDTE.Project project) : this (GetNdoProjFileName(project.FullName)) |
48 | ········{ |
49 | ········} |
50 | |
51 | ········private ConfigurationOptions( string fileName ) |
52 | ········{ |
53 | ············this.fileName = fileName; |
54 | ············this.TargetMappingFileName = "NDOMapping.xml"; // Set the default name. Can be overridden by the configuration. |
55 | ············this.Utf8Encoding = true; |
56 | ············if (File.Exists( this.fileName )) |
57 | ············{ |
58 | ················XmlDocument doc = new XmlDocument(); |
59 | ················doc.Load( fileName ); |
60 | ················Init( doc ); |
61 | ············} |
62 | ········} |
63 | |
64 | ········private void MakeNode(string name, object value, XmlNode parentNode) |
65 | ········{ |
66 | ············XmlElement el = parentNode.OwnerDocument.CreateElement(name); |
67 | ············parentNode.AppendChild(el); |
68 | ············if (value != null) |
69 | ················el.InnerText = value.ToString(); |
70 | ········} |
71 | |
72 | ········public void SaveAs(string fileName, ProjectDescription pd) |
73 | ········{ |
74 | ············string oldFileName = this.fileName;··// just in case... |
75 | ············this.fileName = fileName; |
76 | Save( pd) ; |
77 | ············this.fileName = oldFileName; |
78 | ········} |
79 | |
80 | public void Save( ProjectDescription projectDescription) |
81 | ········{ |
82 | ············if (fileName != null) |
83 | ············{ |
84 | ················XmlDocument doc = new XmlDocument(); |
85 | ················doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null)); |
86 | ················XmlElement docNode = doc.CreateElement("Enhancer"); |
87 | ················doc.AppendChild(docNode); |
88 | ················XmlElement optionsNode = doc.CreateElement("Options"); |
89 | ················docNode.AppendChild(optionsNode); |
90 | ················ |
91 | ················MakeNode("EnableAddIn", this.EnableAddIn, optionsNode); |
92 | ················MakeNode("EnableEnhancer", this.EnableEnhancer, optionsNode); |
93 | ················MakeNode("VerboseMode", this.VerboseMode, optionsNode); |
94 | ················MakeNode("NewMapping", this.NewMapping, optionsNode); |
95 | ················MakeNode("GenerateSQL", this.GenerateSQL, optionsNode); |
96 | ················MakeNode("DefaultConnection", this.DefaultConnection, optionsNode); |
97 | ················MakeNode("TargetMappingFileName", this.TargetMappingFileName, optionsNode); |
98 | ················MakeNode("GenerateChangeEvents", this.GenerateChangeEvents, optionsNode); |
99 | ················MakeNode("UseTimeStamps", this.UseTimeStamps, optionsNode); |
100 | ················MakeNode("Utf8Encoding", this.Utf8Encoding, optionsNode); |
101 | ················MakeNode("SQLScriptLanguage", this.SQLScriptLanguage, optionsNode); |
102 | ················MakeNode("SchemaVersion", this.SchemaVersion, optionsNode); |
103 | ················MakeNode("IncludeTypecodes", this.IncludeTypecodes, optionsNode); |
104 | ················MakeNode("DatabaseOwner", this.DatabaseOwner, optionsNode); |
105 | ················MakeNode("GenerateConstraints", this.GenerateConstraints, optionsNode); |
106 | ················MakeNode("UseMsBuild", this.UseMsBuild, optionsNode); |
107 | ················MakeNode("DropExistingElements", this.DropExistingElements, optionsNode); |
108 | |
109 | projectDescription. ToXml( docNode) ; |
110 | ················doc.Save(fileName); |
111 | ············} |
112 | ············else |
113 | ················throw new Exception("ConfigurationOptions.Save: file name is null"); |
114 | ········} |
115 | |
116 | ········public static string GetNdoProjFileName(string fullPath) |
117 | ········{ |
118 | ············string result; |
119 | ············if (Directory.Exists(fullPath)) // Web Projects have a directory as name |
120 | ············{ |
121 | ················string s = fullPath; |
122 | ················if (s.EndsWith("\\")) |
123 | ····················s = s.Substring(0, s.Length - 1); |
124 | ················int p = s.LastIndexOf(Path.DirectorySeparatorChar); |
125 | ················if (p > -1) |
126 | ····················s = s.Substring(p + 1); |
127 | ················s += ".ndoproj"; |
128 | ················result = Path.Combine(fullPath, s); |
129 | ············} |
130 | ············else |
131 | ················result = Path.ChangeExtension(fullPath, ".ndoproj"); |
132 | ············return result; |
133 | ········} |
134 | |
135 | ········public string FileName |
136 | ········{ |
137 | ············get { return fileName; } |
138 | ········} |
139 | |
140 | |
141 | ········public ConfigurationOptions(XmlDocument doc) |
142 | ········{ |
143 | ············Init(doc); |
144 | ········} |
145 | |
146 | ········private void Init(XmlDocument doc) |
147 | ········{ |
148 | ············string pns = XmlHelper.Pns(doc); |
149 | ············XmlNode node = doc.SelectSingleNode("//" + pns + "Enhancer/" + pns + "Options", XmlHelper.Nsmgr); |
150 | ············if (node == null) |
151 | ················throw new Exception("NDO Project file must have an //Enhancer/Options element."); |
152 | |
153 | ············this.NewMapping = (bool)XmlHelper.GetNode(node, pns + "NewMapping", false); |
154 | ············this.GenerateSQL = (bool)XmlHelper.GetNode(node, pns + "GenerateSQL", true); |
155 | ············this.SQLScriptLanguage = (string)XmlHelper.GetNode(node, pns + "SQLScriptLanguage", "SqlServer"); |
156 | ············this.SchemaVersion = (string)XmlHelper.GetNode(node, pns + "SchemaVersion", ""); |
157 | ············this.UseTimeStamps = (bool)XmlHelper.GetNode(node, pns + "UseTimeStamps", false); |
158 | ············this.DatabaseOwner = (string)XmlHelper.GetNode(node, pns + "DatabaseOwner", string.Empty); |
159 | ············this.DefaultConnection = (string)XmlHelper.GetNode(node, pns + "DefaultConnection", string.Empty); |
160 | ············this.EnableAddIn = (bool)XmlHelper.GetNode(node, pns + "EnableAddIn", true); |
161 | ············this.TargetMappingFileName = (string) XmlHelper.GetNode( node, pns + "TargetMappingFileName", "NDOMapping.xml" ); |
162 | ············this.EnableEnhancer = (bool) XmlHelper.GetNode( node, pns + "EnableEnhancer", true ); |
163 | ············this.IncludeTypecodes = (bool)XmlHelper.GetNode(node, pns + "IncludeTypecodes", false); |
164 | ············this.VerboseMode = (bool)XmlHelper.GetNode(node, pns + "VerboseMode", false); |
165 | ············this.GenerateChangeEvents = (bool)XmlHelper.GetNode(node, pns + "GenerateChangeEvents", false); |
166 | ············this.Utf8Encoding = (bool)XmlHelper.GetNode(node, pns + "Utf8Encoding", true); |
167 | ············this.DropExistingElements = (bool)XmlHelper.GetNode(node, pns + "DropExistingElements", true); |
168 | ············this.GenerateConstraints = (bool)XmlHelper.GetNode(node, pns + "GenerateConstraints", false); |
169 | ············this.UseMsBuild = (bool) XmlHelper.GetNode(node, pns + "UseMsBuild", false); |
170 | ········} |
171 | |
172 | |
173 | ········public bool EnableAddIn { get; set; } |
174 | ········public bool IncludeTypecodes { get; set; } |
175 | ········public bool UseTimeStamps { get; set; } |
176 | ········public bool GenerateChangeEvents { get; set; } |
177 | ········public bool EnableEnhancer { get; set; } |
178 | ········public bool VerboseMode { get; set; } |
179 | ········public bool Utf8Encoding { get; set; } |
180 | ········public bool GenerateSQL { get; set; } |
181 | ········public bool GenerateConstraints { get; set; } |
182 | ········public bool DropExistingElements { get; set; } |
183 | ········public bool UseMsBuild { get; set; } |
184 | ········public bool NewMapping { get; set; } |
185 | ········public string DefaultConnection { get; set; } |
186 | ········public string TargetMappingFileName { get; set; } |
187 | ········public string SQLScriptLanguage { get; set; } |
188 | ········public string SchemaVersion { get; set; } |
189 | ········public string DatabaseOwner { get; set; } |
190 | ····} |
191 | } |
192 | |
193 | #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread |
194 |
New Commit (90ec57c)
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 | |
23 | using Microsoft.VisualStudio.Threading; |
24 | using System; |
25 | using System.IO; |
26 | using System.Xml; |
27 | |
28 | #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread |
29 | |
30 | namespace NDOVsPackage |
31 | { |
32 | ····/// <summary> |
33 | ····/// Attention!!!!! This code is essentially the same as in ConfigurationOptions.cs |
34 | ····/// in the project NDOEnhancer. |
35 | ····/// So, if you change one of them, be aware to change the second. |
36 | ····/// </summary> |
37 | ····internal class ConfigurationOptions |
38 | ····{ |
39 | ········string fileName = null; |
40 | |
41 | ········//void Anlegen() { } |
42 | |
43 | ········// This is called to check the options in the Add-in |
44 | ········public ConfigurationOptions(Project project) : this( GetNdoProjFileName( project.FullPath ) ) |
45 | ········{ |
46 | ········} |
47 | |
48 | ········public ConfigurationOptions(EnvDTE.Project project) : this (GetNdoProjFileName(project.FullName)) |
49 | ········{ |
50 | ········} |
51 | |
52 | ········private ConfigurationOptions( string fileName ) |
53 | ········{ |
54 | ············this.fileName = fileName; |
55 | ············this.TargetMappingFileName = "NDOMapping.xml"; // Set the default name. Can be overridden by the configuration. |
56 | ············this.Utf8Encoding = true; |
57 | ············if (File.Exists( this.fileName )) |
58 | ············{ |
59 | ················XmlDocument doc = new XmlDocument(); |
60 | ················doc.Load( fileName ); |
61 | ················Init( doc ); |
62 | ············} |
63 | ········} |
64 | |
65 | ········private void MakeNode(string name, object value, XmlNode parentNode) |
66 | ········{ |
67 | ············XmlElement el = parentNode.OwnerDocument.CreateElement(name); |
68 | ············parentNode.AppendChild(el); |
69 | ············if (value != null) |
70 | ················el.InnerText = value.ToString(); |
71 | ········} |
72 | |
73 | ········public void SaveAs(string fileName, ProjectDescription pd) |
74 | ········{ |
75 | ············string oldFileName = this.fileName;··// just in case... |
76 | ············this.fileName = fileName; |
77 | ThreadHelper. JoinableTaskFactory. Run( async ( ) => await SaveAsync( pd ) ) ; |
78 | ············this.fileName = oldFileName; |
79 | ········} |
80 | |
81 | public async Task SaveAsync( ProjectDescription projectDescription) |
82 | ········{ |
83 | ············if (fileName != null) |
84 | ············{ |
85 | ················XmlDocument doc = new XmlDocument(); |
86 | ················doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null)); |
87 | ················XmlElement docNode = doc.CreateElement("Enhancer"); |
88 | ················doc.AppendChild(docNode); |
89 | ················XmlElement optionsNode = doc.CreateElement("Options"); |
90 | ················docNode.AppendChild(optionsNode); |
91 | ················ |
92 | ················MakeNode("EnableAddIn", this.EnableAddIn, optionsNode); |
93 | ················MakeNode("EnableEnhancer", this.EnableEnhancer, optionsNode); |
94 | ················MakeNode("VerboseMode", this.VerboseMode, optionsNode); |
95 | ················MakeNode("NewMapping", this.NewMapping, optionsNode); |
96 | ················MakeNode("GenerateSQL", this.GenerateSQL, optionsNode); |
97 | ················MakeNode("DefaultConnection", this.DefaultConnection, optionsNode); |
98 | ················MakeNode("TargetMappingFileName", this.TargetMappingFileName, optionsNode); |
99 | ················MakeNode("GenerateChangeEvents", this.GenerateChangeEvents, optionsNode); |
100 | ················MakeNode("UseTimeStamps", this.UseTimeStamps, optionsNode); |
101 | ················MakeNode("Utf8Encoding", this.Utf8Encoding, optionsNode); |
102 | ················MakeNode("SQLScriptLanguage", this.SQLScriptLanguage, optionsNode); |
103 | ················MakeNode("SchemaVersion", this.SchemaVersion, optionsNode); |
104 | ················MakeNode("IncludeTypecodes", this.IncludeTypecodes, optionsNode); |
105 | ················MakeNode("DatabaseOwner", this.DatabaseOwner, optionsNode); |
106 | ················MakeNode("GenerateConstraints", this.GenerateConstraints, optionsNode); |
107 | ················MakeNode("UseMsBuild", this.UseMsBuild, optionsNode); |
108 | ················MakeNode("DropExistingElements", this.DropExistingElements, optionsNode); |
109 | |
110 | await projectDescription. ToXmlAsync( docNode) ; |
111 | ················doc.Save(fileName); |
112 | ············} |
113 | ············else |
114 | ················throw new Exception("ConfigurationOptions.Save: file name is null"); |
115 | ········} |
116 | |
117 | ········public static string GetNdoProjFileName(string fullPath) |
118 | ········{ |
119 | ············string result; |
120 | ············if (Directory.Exists(fullPath)) // Web Projects have a directory as name |
121 | ············{ |
122 | ················string s = fullPath; |
123 | ················if (s.EndsWith("\\")) |
124 | ····················s = s.Substring(0, s.Length - 1); |
125 | ················int p = s.LastIndexOf(Path.DirectorySeparatorChar); |
126 | ················if (p > -1) |
127 | ····················s = s.Substring(p + 1); |
128 | ················s += ".ndoproj"; |
129 | ················result = Path.Combine(fullPath, s); |
130 | ············} |
131 | ············else |
132 | ················result = Path.ChangeExtension(fullPath, ".ndoproj"); |
133 | ············return result; |
134 | ········} |
135 | |
136 | ········public string FileName |
137 | ········{ |
138 | ············get { return fileName; } |
139 | ········} |
140 | |
141 | |
142 | ········public ConfigurationOptions(XmlDocument doc) |
143 | ········{ |
144 | ············Init(doc); |
145 | ········} |
146 | |
147 | ········private void Init(XmlDocument doc) |
148 | ········{ |
149 | ············string pns = XmlHelper.Pns(doc); |
150 | ············XmlNode node = doc.SelectSingleNode("//" + pns + "Enhancer/" + pns + "Options", XmlHelper.Nsmgr); |
151 | ············if (node == null) |
152 | ················throw new Exception("NDO Project file must have an //Enhancer/Options element."); |
153 | |
154 | ············this.NewMapping = (bool)XmlHelper.GetNode(node, pns + "NewMapping", false); |
155 | ············this.GenerateSQL = (bool)XmlHelper.GetNode(node, pns + "GenerateSQL", true); |
156 | ············this.SQLScriptLanguage = (string)XmlHelper.GetNode(node, pns + "SQLScriptLanguage", "SqlServer"); |
157 | ············this.SchemaVersion = (string)XmlHelper.GetNode(node, pns + "SchemaVersion", ""); |
158 | ············this.UseTimeStamps = (bool)XmlHelper.GetNode(node, pns + "UseTimeStamps", false); |
159 | ············this.DatabaseOwner = (string)XmlHelper.GetNode(node, pns + "DatabaseOwner", string.Empty); |
160 | ············this.DefaultConnection = (string)XmlHelper.GetNode(node, pns + "DefaultConnection", string.Empty); |
161 | ············this.EnableAddIn = (bool)XmlHelper.GetNode(node, pns + "EnableAddIn", true); |
162 | ············this.TargetMappingFileName = (string) XmlHelper.GetNode( node, pns + "TargetMappingFileName", "NDOMapping.xml" ); |
163 | ············this.EnableEnhancer = (bool) XmlHelper.GetNode( node, pns + "EnableEnhancer", true ); |
164 | ············this.IncludeTypecodes = (bool)XmlHelper.GetNode(node, pns + "IncludeTypecodes", false); |
165 | ············this.VerboseMode = (bool)XmlHelper.GetNode(node, pns + "VerboseMode", false); |
166 | ············this.GenerateChangeEvents = (bool)XmlHelper.GetNode(node, pns + "GenerateChangeEvents", false); |
167 | ············this.Utf8Encoding = (bool)XmlHelper.GetNode(node, pns + "Utf8Encoding", true); |
168 | ············this.DropExistingElements = (bool)XmlHelper.GetNode(node, pns + "DropExistingElements", true); |
169 | ············this.GenerateConstraints = (bool)XmlHelper.GetNode(node, pns + "GenerateConstraints", false); |
170 | ············this.UseMsBuild = (bool) XmlHelper.GetNode(node, pns + "UseMsBuild", false); |
171 | ········} |
172 | |
173 | |
174 | ········public bool EnableAddIn { get; set; } |
175 | ········public bool IncludeTypecodes { get; set; } |
176 | ········public bool UseTimeStamps { get; set; } |
177 | ········public bool GenerateChangeEvents { get; set; } |
178 | ········public bool EnableEnhancer { get; set; } |
179 | ········public bool VerboseMode { get; set; } |
180 | ········public bool Utf8Encoding { get; set; } |
181 | ········public bool GenerateSQL { get; set; } |
182 | ········public bool GenerateConstraints { get; set; } |
183 | ········public bool DropExistingElements { get; set; } |
184 | ········public bool UseMsBuild { get; set; } |
185 | ········public bool NewMapping { get; set; } |
186 | ········public string DefaultConnection { get; set; } |
187 | ········public string TargetMappingFileName { get; set; } |
188 | ········public string SQLScriptLanguage { get; set; } |
189 | ········public string SchemaVersion { get; set; } |
190 | ········public string DatabaseOwner { get; set; } |
191 | ····} |
192 | } |
193 | |
194 | #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread |
195 |