~cszikszoy/docky/mmv3

« back to all changes in this revision

Viewing changes to StandardPlugins/Weather/src/WeatherService.cs

  • Committer: Chris S.
  • Date: 2009-10-22 03:23:13 UTC
  • mfrom: (284.1.7 testaddins)
  • Revision ID: chris@szikszoy.com-20091022032313-2s9kikljologdsyt
enable lazy loading of addins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  
 
2
//  Copyright (C) 2009 Robert Dyer
 
3
// 
 
4
//  This program is free software: you can redistribute it and/or modify
 
5
//  it under the terms of the GNU General Public License as published by
 
6
//  the Free Software Foundation, either version 3 of the License, or
 
7
//  (at your option) any later version.
 
8
// 
 
9
//  This program is distributed in the hope that it will be useful,
 
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
//  GNU General Public License for more details.
 
13
// 
 
14
//  You should have received a copy of the GNU General Public License
 
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
// 
 
17
 
 
18
using System;
 
19
using System.Collections.Generic;
 
20
using System.Linq;
 
21
 
 
22
namespace WeatherDocklet
 
23
{
 
24
        /// <summary>
 
25
        /// A service to manage all weather sources.
 
26
        /// </summary>
 
27
        public class WeatherService
 
28
        {
 
29
                const string ExtensionPath = "/Docky/WeatherSource";
 
30
                
 
31
                /// <value>
 
32
                /// A <see cref="System.Collections.Generic.Dictionary"/> of all weather sources.
 
33
                /// </value>
 
34
                public Dictionary<string, AbstractWeatherSource> Sources { get; protected set; }
 
35
                
 
36
                /// <value>
 
37
                /// Returns an <see cref="System.Collections.Generic.IEnumerable"/> of all possible weather sources ordered by Name.
 
38
                /// </value>
 
39
                public IEnumerable<AbstractWeatherSource> WeatherSources {
 
40
                        get {
 
41
                                return Sources.Values.OrderBy (d => d.Name);
 
42
                        }
 
43
                }
 
44
                
 
45
                /// <value>
 
46
                /// Returns an <see cref="System.Collections.Generic.IEnumerable"/> of all possible weather sources.
 
47
                /// </value>
 
48
                public static IEnumerable<AbstractWeatherSource> MAWeatherSources {
 
49
                        get {
 
50
                                yield return GoogleWeatherSource.GetInstance ();
 
51
                                yield return WeatherChannelWeatherSource.GetInstance ();
 
52
                                yield return WunderWeatherSource.GetInstance ();
 
53
                        }
 
54
//                      get { return AddinManager.GetExtensionObjects (ExtensionPath).OfType<AbstractWeatherSource> (); }
 
55
                }
 
56
                
 
57
                /// <summary>
 
58
                /// Constructs and initializes a new WeatherService object.
 
59
                /// </summary>
 
60
                public WeatherService()
 
61
                {
 
62
//                      AddinManager.AddExtensionNodeHandler (ExtensionPath, HandleWeatherSourcesChanged);
 
63
                        
 
64
                        BuildSources ();
 
65
                }
 
66
                
 
67
                void BuildSources ()
 
68
                {
 
69
                        Sources = new Dictionary<string, AbstractWeatherSource> ();
 
70
                        
 
71
                        foreach (AbstractWeatherSource aws in MAWeatherSources)
 
72
                                Sources.Add (aws.Name, aws);
 
73
                }
 
74
                
 
75
                #region IDisposable implementation 
 
76
                
 
77
                public void Dispose ()
 
78
                {
 
79
//                      AddinManager.RemoveExtensionNodeHandler (ExtensionPath, HandleWeatherSourcesChanged);
 
80
                }
 
81
                
 
82
                #endregion 
 
83
        }
 
84
}