Changeset 2527 for branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Advanced
- Timestamp:
- 11/23/09 20:27:43 (15 years ago)
- Location:
- branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Advanced
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Advanced/InstallationManager.cs
r2517 r2527 116 116 117 117 private static IEnumerable<string> GetDeclaredDependencies(PluginDescription desc) { 118 var plugin = DefaultApplicationManager.GetInstances<IPlugin>(desc).Single();118 var plugin = ApplicationManager.GetInstances<IPlugin>(desc).Single(); 119 119 return plugin.GetType().GetCustomAttributes(typeof(PluginDependencyAttribute), false).Cast<PluginDependencyAttribute>().Select(x => x.Dependency); 120 120 } … … 146 146 147 147 public void Install(IEnumerable<string> pluginNames) { 148 IEnumerable<PluginInformation> pluginsToInstall; 149 using (UpdateLocationClient updateLocation = new UpdateLocationClient()) { 150 pluginsToInstall = from pluginName in pluginNames 151 select GetMatchingPluginInformation(pluginName, updateLocation.GetAvailablePlugins()); 152 153 var args = new PluginInfrastructureCancelEventArgs("Installing", pluginsToInstall); 154 OnPreInstall(args); 155 foreach (var pluginInfo in pluginsToInstall) { 156 var s = updateLocation.GetPackedPlugin(pluginInfo); 157 Console.WriteLine("Downloading: {0} {1} {2}", pluginInfo.Name, pluginInfo.Version, pluginInfo.BuildDate); 158 } 159 } 160 OnInstalled(new PluginInfrastructureEventArgs("Installed", pluginsToInstall)); 161 } 162 163 private static PluginInformation GetMatchingPluginInformation(string pluginName, IEnumerable<PluginInformation> plugins) { 164 var exactMatch = from pluginDesc in plugins 165 where string.Equals(pluginName, pluginDesc.Name, StringComparison.InvariantCultureIgnoreCase) 166 select pluginDesc; 167 var inexactMatch = from pluginDesc in plugins 168 where MatchPluginNameInexact(pluginName, pluginDesc.Name) 169 select pluginDesc; 170 return exactMatch.Count() > 0 ? exactMatch.Single() : inexactMatch.First(); 171 } 148 throw new NotImplementedException(); 149 //IEnumerable<PluginInformation> pluginsToInstall; 150 //using (UpdateLocationClient updateLocation = new UpdateLocationClient()) { 151 // pluginsToInstall = from pluginName in pluginNames 152 // from matchingPlugin in updateLocation.GetAvailablePluginsByName(pluginName) 153 // select matchingPlugin; 154 155 // var args = new PluginInfrastructureCancelEventArgs("Installing", pluginsToInstall); 156 // OnPreInstall(args); 157 // foreach (var pluginInfo in pluginsToInstall) { 158 // var s = updateLocation.GetPluginFiles(pluginInfo); 159 // Console.WriteLine("Downloading: {0} {1} {2}", pluginInfo.Name, pluginInfo.Version, pluginInfo.BuildDate); 160 // } 161 //} 162 //OnInstalled(new PluginInfrastructureEventArgs("Installed", pluginsToInstall)); 163 } 164 165 //private static PluginInformation GetMatchingPluginInformation(string pluginName, IEnumerable<PluginInformation> plugins) { 166 // var exactMatch = from pluginDesc in plugins 167 // where string.Equals(pluginName, pluginDesc.Name, StringComparison.InvariantCultureIgnoreCase) 168 // select pluginDesc; 169 // var inexactMatch = from pluginDesc in plugins 170 // where MatchPluginNameInexact(pluginName, pluginDesc.Name) 171 // select pluginDesc; 172 // return exactMatch.Count() > 0 ? exactMatch.Single() : inexactMatch.First(); 173 //} 172 174 173 175 public void Remove(IEnumerable<string> pluginNames) { … … 188 190 189 191 public void Update(IEnumerable<string> pluginNames) { 190 throw new NotImplementedException(); 192 var pluginDescriptions = from name in pluginNames 193 select GetPluginDescription(name); 194 Dictionary<PluginInformation, string> matchingPlugins = new Dictionary<PluginInformation, string>(); 195 foreach (var updateLocation in HeuristicLab.PluginInfrastructure.Properties.Settings.Default.UpdateLocations) { 196 using (UpdateLocationClient client = new UpdateLocationClient("", updateLocation)) { 197 var updateLocationMatchingPlugins = from desc in pluginDescriptions 198 from info in client.GetAvailablePluginsByName(desc.Name) 199 select info; 200 foreach (PluginInformation info in updateLocationMatchingPlugins) { 201 // keep only the highest version and most recent build of any plugin 202 var existingPlugin = matchingPlugins.Keys.FirstOrDefault(x => x.Name == info.Name); 203 if (existingPlugin == null || existingPlugin.Version < info.Version || (existingPlugin.Version == info.Version && existingPlugin.BuildDate < info.BuildDate)) { 204 matchingPlugins.Remove(existingPlugin); 205 matchingPlugins.Add(info, updateLocation); 206 } 207 } 208 } 209 } 210 PluginInfrastructureCancelEventArgs args = new PluginInfrastructureCancelEventArgs("Updating", matchingPlugins.Keys); 211 OnPreUpdate(args); 212 if (!args.Cancel) { 213 var groupedInfos = matchingPlugins.GroupBy(x => x.Value); 214 foreach (var group in groupedInfos) { 215 using (UpdateLocationClient client = new UpdateLocationClient(group.Key)) { 216 foreach (var info in group) { 217 client.GetPluginFiles(info.Key); 218 } 219 } 220 } 221 OnUpdated(new PluginInfrastructureEventArgs("Updated", matchingPlugins.Keys)); 222 } 223 } 224 225 private void OnPreUpdate(PluginInfrastructureCancelEventArgs args) { 226 if (PreUpdatePlugin != null) PreUpdatePlugin(this, args); 227 } 228 229 private void OnUpdated(PluginInfrastructureEventArgs args) { 230 if (PluginUpdated != null) PluginUpdated(this, args); 191 231 } 192 232 -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Advanced/InstallationManagerConsole.cs
r2517 r2527 6 6 using System.IO; 7 7 using System.ComponentModel; 8 using HeuristicLab.PluginInfrastructure.UpdateLocationReference; 8 9 9 10 namespace HeuristicLab.PluginInfrastructure.Advanced { 10 11 public class InstallationManagerConsole { 11 12 private InstallationManager installManager; 12 public InstallationManagerConsole( ) {13 this.installManager = new InstallationManager( Path.GetFullPath(HeuristicLab.PluginInfrastructure.Properties.Settings.Default.PluginDir));13 public InstallationManagerConsole(string pluginDir) { 14 this.installManager = new InstallationManager(pluginDir); 14 15 installManager.PreInstallPlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreInstallPlugin); 15 16 installManager.PreRemovePlugin += new EventHandler<PluginInfrastructureCancelEventArgs>(installManager_PreRemovePlugin); … … 21 22 22 23 void installManager_PreUpdatePlugin(object sender, PluginInfrastructureCancelEventArgs e) { 23 throw new NotImplementedException(); 24 Console.WriteLine("Following plugins are updated:"); 25 var infos = (IEnumerable<PluginInformation>)e.Entity; 26 foreach (var info in infos) { 27 Console.WriteLine(info.Name + " " + info.Version + " " + info.BuildDate); 28 } 29 if (GetUserConfirmation()) e.Cancel = false; 30 else e.Cancel = true; 31 return; 24 32 } 25 33 26 34 void installManager_PluginUpdated(object sender, PluginInfrastructureEventArgs e) { 27 throw new NotImplementedException(); 35 foreach (var info in (IEnumerable<PluginInformation>)e.Entity) 36 Console.WriteLine("Updated: {0}", info.Name); 28 37 } 29 38 … … 45 54 46 55 void installManager_PreInstallPlugin(object sender, PluginInfrastructureCancelEventArgs e) { 47 56 48 57 } 49 58 50 59 void installManager_PluginInstalled(object sender, PluginInfrastructureEventArgs e) { 51 60 52 61 } 53 62
Note: See TracChangeset
for help on using the changeset viewer.