/
Plugin.cs
153 lines (127 loc) · 4.9 KB
/
Plugin.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
/*
Copyright (C) 2009, 2010 Jan Ohlson
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.ComponentModel;
using ZoneFiveSoftware.Common.Visuals.Fitness;
using Janohl.ST2Funbeat.Settings;
using System.Windows.Forms;
using ZoneFiveSoftware.Common.Data.Fitness;
namespace Janohl.ST2Funbeat
{
class Plugin : IPlugin
{
private PropertyChangedEventHandler appEventHandler = null;
string logBookLocation = null;
public static FitnessDataHandler dataHandler = null;
internal static Dictionary<string, string> SportTrackActivityTypes
{
get
{
Dictionary<string, string> sportTrackActivityTypes = new Dictionary<string, string>();
IEnumerable<IActivityCategory> categories = application.Logbook.ActivityCategories;
sportTrackActivityTypes = new Dictionary<string, string>();
foreach (IActivityCategory cat in categories)
FlattenSportTrackActivityTypes(sportTrackActivityTypes, cat);
return sportTrackActivityTypes;
}
}
internal static Dictionary<string, string> SportTrackEquipment
{
get
{
Dictionary<string, string> sportTrackEquipment = new Dictionary<string, string>();
IEnumerable<IEquipmentItem> equipment = application.Logbook.Equipment;
foreach (IEquipmentItem eq in equipment)
sportTrackEquipment.Add(eq.ReferenceId, eq.Name);
return sportTrackEquipment;
}
}
private static void FlattenSportTrackActivityTypes(Dictionary<string, string> list, IActivityCategory category)
{
foreach (IActivityCategory sub in category.SubCategories)
{
list.Add(sub.ReferenceId, sub.Name);
FlattenSportTrackActivityTypes(list, sub);
}
}
internal static Guid PluginId
{
get
{
return new Guid(Properties.Resources.Plugin_GUID);
}
}
#region IPlugin Members
private static IApplication application;
public IApplication Application
{
set
{
application = value;
if (appEventHandler == null)
{
appEventHandler = new PropertyChangedEventHandler(OnApplicationChanged);
application.PropertyChanged += appEventHandler;
}
}
}
public Guid Id
{
get { return PluginId; }
}
public string Name
{
get { return Properties.Resources.Plugin_Name; }
}
public void ReadOptions(XmlDocument xmlDoc, XmlNamespaceManager nsmgr, XmlElement pluginNode)
{
Settings.Settings.PopulateInstance(pluginNode, nsmgr, xmlDoc);
}
public string Version
{
get { return GetType().Assembly.GetName().Version.ToString(3); }
}
public void WriteOptions(XmlDocument xmlDoc, XmlElement pluginNode)
{
Settings.Settings.WriteInstance(xmlDoc, pluginNode);
}
#endregion
public static IApplication GetApplication()
{
return application;
}
private void OnApplicationChanged(object sender, PropertyChangedEventArgs e)
{
// Check for changed logbook. If changed, call datahandler to check for custom data fields
if (application.Logbook != null)
{
if (application.Logbook.FileLocation != logBookLocation)
{
logBookLocation = application.Logbook.FileLocation;
if (dataHandler == null)
dataHandler = new FitnessDataHandler(application.Logbook, PluginId);
else
{
#if !ST_2_1
dataHandler.CheckCustomDataFields(application.Logbook, PluginId);
#endif
}
}
}
}
}
}