-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginMain.cs
193 lines (162 loc) · 5.26 KB
/
PluginMain.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// <copyright file="Plugin.cs" company="N/A">
// Copyright (c) 2008 All Right Reserved
// </copyright>
// <author>mechgt</author>
// <email>mechgt@gmail.com</email>
// <date>2008-12-23</date>
namespace QuadrantAnalysis
{
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using QuadrantAnalysis.Settings;
using QuadrantAnalysis.Util;
using System.Text;
using ZoneFiveSoftware.Common.Data.Fitness;
using ZoneFiveSoftware.Common.Visuals.Fitness;
/// <summary>
/// Plugin class provides interface to the main application and logbook.
/// </summary>
class PluginMain : IPlugin
{
#region Private fields
private static IApplication application;
private static ILogbook logbook;
#endregion
#region Mechgt Licensing
/// <summary>
/// Plugin product Id as listed in license application
/// </summary>
internal static string ProductId
{
get
{
return "qa";
}
}
/// <summary>
/// Number of days in history that data will be displayed.
/// This is the amount of data that will be displayed, not a number of days for a trial version.
/// </summary>
internal static int EvalDays
{
get { return 90; }
}
internal static string SupportEmail
{
get
{
return "support@mechgt.com";
}
}
#endregion
#region IPlugin Members
/// <summary>
/// Sets interface to SportTracks application
/// </summary>
public IApplication Application
{
set { application = value; }
}
/// <summary>
/// Gets plugin GUID
/// </summary>
public Guid Id
{
// This GUID is currently being used to store/retreive settings data from logbook
get { return GUIDs.PluginMain; }
}
/// <summary>
/// Gets plugin Name
/// </summary>
public string Name
{
get { return "Quadrant Analysis"; }
}
/// <summary>
/// Gets plugin Version
/// </summary>
public string Version
{
get { return GetType().Assembly.GetName().Version.ToString(3); }
}
public void ReadOptions(XmlDocument xmlDoc, XmlNamespaceManager nsmgr, XmlElement pluginNode)
{
try
{
// Deserialization
GlobalSettings settings;
XmlSerializer xs = new XmlSerializer(typeof(GlobalSettings));
MemoryStream memoryStream = new MemoryStream(Utilities.StringToUTF8ByteArray(pluginNode.InnerText));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
object deserialize = xs.Deserialize(memoryStream);
settings = (GlobalSettings)deserialize;
}
catch
{ }
}
public void WriteOptions(XmlDocument xmlDoc, XmlElement pluginNode)
{
// Serialization
string xmlizedString;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof(GlobalSettings));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, GlobalSettings.Instance);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
xmlizedString = Utilities.UTF8ByteArrayToString(memoryStream.ToArray());
pluginNode.InnerText = xmlizedString;
}
#endregion
#region Methods
/// <summary>
/// Main SportTracks application
/// </summary>
/// <returns>Returns application interface</returns>
public static IApplication GetApplication()
{
return application;
}
/// <summary>
/// Currently loaded logbook
/// </summary>
/// <returns>Returns currently loaded logbook</returns>
public static ILogbook GetLogbook()
{
logbook = GetApplication().Logbook;
return logbook;
}
/// <summary>
/// Plugin folder - plugins\data\{guid}\
/// </summary>
internal static string DataFolder
{
get
{
string path = Path.Combine(application.Configuration.CommonPluginsDataFolder, GUIDs.PluginMain.ToString("D"));
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
return path;
}
}
/// <summary>
/// Plugin folder - plugins\installed\{guid}\
/// </summary>
internal static string PluginFolder
{
get
{
string path = Path.Combine(application.Configuration.CommonPluginsInstalledFolder, GUIDs.PluginMain.ToString("D"));
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
return path;
}
}
#endregion
}
}