forked from modelsbuilder/ModelsBuilder.Original
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualStudioOptions.cs
159 lines (134 loc) · 5.89 KB
/
VisualStudioOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.VisualStudio.Shell;
using Zbu.ModelsBuilder.CustomTool.VisualStudio;
namespace Zbu.ModelsBuilder.CustomTool
{
// see http://msdn.microsoft.com/en-us/library/bb166195.aspx
[ClassInterface(ClassInterfaceType.AutoDual)]
[CLSCompliant(false), ComVisible(true)] // that's for the grid
// [Guid("1D9ECCF3-5D2F-4112-9B25-264596873DC9")] // that's for the custom page
public class VisualStudioOptions : DialogPage
{
public const string OptionsCategory = "Zbu";
public const string OptionsPageName = "ModelsBuilder Options";
//[Category(OptionsCategory)]
//[DisplayName("Connection string")]
//[Description("The database connection string.")]
//public string ConnectionString { get; set; }
//[Category(OptionsCategory)]
//[DisplayName("Database provider")]
//[Description("The database provider.")]
//public string DatabaseProvider { get; set; }
//[Category(OptionsCategory)]
//[DisplayName("Bin directory")]
//[Description("The directory containing the project's binaries. By default it is the project's OutputPath. Can be relative to project's root.")]
//public string BinaryDirectory { get; set; }
[Category(OptionsCategory)]
[DisplayName("Umbraco Url")]
[Description("The base url of the Umbraco website.")]
public string UmbracoUrl { get; set; }
[Category(OptionsCategory)]
[DisplayName("Umbraco User")]
[Description("The user to connect to Umbraco (must be dev).")]
public string UmbracoUser { get; set; }
[Category(OptionsCategory)]
[DisplayName("Umbraco Password")]
[Description("The password to connecto to Umbraco.")]
public string UmbracoPassword { get; set; }
// by default "storage" is the registry
// we want to write to our own settings file,
// <solution>.sln.zbu.user
// and yes - we should prob. use true config sections,
// not parse XML...
private string OptionsFileName
{
get
{
var solution = VisualStudioHelper.GetSolution();
if (solution.EndsWith(".sln"))
solution = solution.Substring(0, solution.Length - ".sln".Length);
var filename = solution + ".ZbuModelsBuilder.user";
return filename;
}
}
public override void LoadSettingsFromStorage()
{
//base.LoadSettingsFromStorage();
var filename = OptionsFileName;
if (!File.Exists(filename)) return;
var text = File.ReadAllText(filename);
var xml = new XmlDocument();
xml.LoadXml(text);
var config = xml.SelectSingleNode("/configuration/zbu/modelsBuilder");
if (config == null || config.Attributes == null) return;
var attr = config.Attributes["version"];
if (attr == null) return;
var version = attr.Value;
// we're not version-dependent at the moment
//attr = config.Attributes["connectionString"];
//if (attr != null)
// ConnectionString = attr.Value;
//attr = config.Attributes["databaseProvider"];
//if (attr != null)
// DatabaseProvider = attr.Value;
//attr = config.Attributes["binaryDirectory"];
//if (attr != null)
// BinaryDirectory = attr.Value;
attr = config.Attributes["umbracoUrl"];
if (attr != null)
UmbracoUrl = attr.Value;
attr = config.Attributes["umbracoUser"];
if (attr != null)
UmbracoUser = attr.Value;
attr = config.Attributes["umbracoPassword"];
if (attr != null)
UmbracoPassword = attr.Value;
}
public override void SaveSettingsToStorage()
{
//base.SaveSettingsToStorage();
var filename = OptionsFileName;
if (File.Exists(filename))
File.Delete(filename);
var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
var sb = new StringBuilder();
var settings = new XmlWriterSettings
{
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true, // 'cos it's utf-16 and a pain to change
Indent = true,
NewLineChars = "\r\n"
};
var writer = XmlWriter.Create(sb, settings);
sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
writer.WriteStartElement("configuration");
writer.WriteStartElement("zbu");
writer.WriteStartElement("modelsBuilder");
writer.WriteAttributeString("version", version);
//writer.WriteAttributeString("connectionString", ConnectionString);
//writer.WriteAttributeString("databaseProvider", DatabaseProvider);
//writer.WriteAttributeString("binaryDirectory", BinaryDirectory);
writer.WriteAttributeString("umbracoUrl", UmbracoUrl);
writer.WriteAttributeString("umbracoUser", UmbracoUser);
writer.WriteAttributeString("umbracoPassword", UmbracoPassword);
writer.WriteEndElement(); // modelsBuilder
writer.WriteEndElement(); // zbu
writer.WriteEndElement(); // configuration
writer.Flush();
writer.Close();
File.WriteAllText(filename, sb.ToString());
}
// what about the FromXml / ToXml methods?!
// that would be for import/export?!
}
}