- Timestamp:
- 07/01/15 14:59:47 (9 years ago)
- Location:
- stable
- Files:
-
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12146,12428-12430,12435,12442-12443,12445,12457,12514,12517,12519-12521,12523,12532,12542,12546,12552-12553,12556-12557,12559,12561 -
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Services.WebApp/3.3/PluginManager.cs
r12428 r12563 1 using System.Collections.Concurrent; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System.Collections.Concurrent; 2 23 using System.Collections.Generic; 3 24 using System.IO; … … 17 38 public HttpConfiguration Configuration { get; set; } 18 39 19 private string PluginsDirectory { 40 public IEnumerable<Plugin> Plugins { 41 get { return plugins.Values; } 42 } 43 44 public static string PluginsDirectory { 20 45 get { return string.Format(@"{0}WebApp\plugins", HttpRuntime.AppDomainAppPath); } 21 46 } … … 23 48 public PluginManager() { 24 49 plugins = new ConcurrentDictionary<string, Plugin>(); 50 var fileWatcher = new FileSystemWatcher(PluginsDirectory, "*") { 51 IncludeSubdirectories = true, 52 EnableRaisingEvents = true 53 }; 54 fileWatcher.Created += OnFilesChanged; 55 fileWatcher.Changed += OnFilesChanged; 56 fileWatcher.Deleted += OnFilesChanged; 57 fileWatcher.Renamed += OnFilesChanged; 58 } 59 60 private void OnFilesChanged(object sender, FileSystemEventArgs args) { 61 string path = args.FullPath.Remove(0, PluginsDirectory.Length + 1); 62 var pathParts = path.Split(Path.PathSeparator); 63 string pluginName = pathParts[0]; 64 if (pathParts.Length == 1) { 65 switch (args.ChangeType) { 66 case WatcherChangeTypes.Created: 67 GetPlugin(pluginName); 68 break; 69 70 case WatcherChangeTypes.Deleted: 71 plugins.Remove(pluginName); 72 break; 73 74 case WatcherChangeTypes.Renamed: 75 RenamedEventArgs renamedArgs = (RenamedEventArgs)args; 76 string oldPath = renamedArgs.OldFullPath.Remove(0, PluginsDirectory.Length + 1); 77 var oldPathParts = oldPath.Split(Path.PathSeparator); 78 string oldPluginName = oldPathParts[0]; 79 plugins.Remove(oldPluginName); 80 GetPlugin(pluginName); 81 break; 82 83 case WatcherChangeTypes.Changed: 84 Plugin plugin = LookupPlugin(pluginName); 85 if (plugin != null) { 86 plugin.ReloadControllers(); 87 } 88 break; 89 } 90 } 25 91 } 26 92 27 93 public Plugin GetPlugin(string name) { 28 Plugin plugin; 29 plugins.TryGetValue(name, out plugin); 94 Plugin plugin = LookupPlugin(name); 30 95 if (plugin == null) { 31 96 string directory = string.Format(@"{0}\{1}", PluginsDirectory, name); 32 97 if (Directory.Exists(directory)) { 33 plugin = new Plugin { 34 Name = name, 35 Directory = directory 36 }; 37 plugin.Configure(Configuration); 98 plugin = new Plugin(name, directory, Configuration); 38 99 plugins.Add(name, plugin); 39 100 } … … 43 104 44 105 public IEnumerable<Plugin> GetPlugins() { 45 DiscoverPlugins();46 106 return plugins.Values; 47 107 } 48 108 49 p rivatevoid DiscoverPlugins() {109 public void DiscoverPlugins() { 50 110 var pluginDirectories = Directory.GetDirectories(PluginsDirectory); 51 111 foreach (var directory in pluginDirectories) { 52 112 string pluginName = Path.GetFileName(directory); 53 Plugin plugin; 54 plugins.TryGetValue(pluginName, out plugin); 113 Plugin plugin = LookupPlugin(pluginName); 55 114 if (plugin == null) { 56 plugin = new Plugin { 57 Name = pluginName, 58 Directory = directory 59 }; 60 plugin.Configure(Configuration); 115 plugin = new Plugin(pluginName, directory, Configuration); 61 116 plugins.Add(pluginName, plugin); 62 117 } 63 118 } 64 119 } 120 121 private Plugin LookupPlugin(string name) { 122 Plugin plugin; 123 plugins.TryGetValue(name, out plugin); 124 return plugin; 125 } 65 126 } 66 127 }
Note: See TracChangeset
for help on using the changeset viewer.