Datei: NDOPackage/ConfigurationOptions.cs

Last Commit (946ad0e)
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
New Commit (33e9857)
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