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