aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Base/PluginManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Base/PluginManager.cs')
-rw-r--r--OpenSim/Server/Base/PluginManager.cs555
1 files changed, 555 insertions, 0 deletions
diff --git a/OpenSim/Server/Base/PluginManager.cs b/OpenSim/Server/Base/PluginManager.cs
new file mode 100644
index 0000000..6248e74
--- /dev/null
+++ b/OpenSim/Server/Base/PluginManager.cs
@@ -0,0 +1,555 @@
1
2/*
3 * Copyright (c) Contributors, http://opensimulator.org/
4 * See CONTRIBUTORS.TXT for a full list of copyright holders.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the OpenSimulator Project nor the
14 * names of its contributors may be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30using System;
31using System.Text;
32using System.Linq;
33using System.Collections;
34using System.Collections.Generic;
35using System.Collections.ObjectModel;
36using Mono.Addins;
37using Mono.Addins.Setup;
38using Mono.Addins.Description;
39using OpenSim.Framework;
40
41namespace OpenSim.Server.Base
42{
43 public class PluginManager : SetupService
44 {
45 protected AddinRegistry PluginRegistry;
46
47 internal PluginManager(AddinRegistry registry): base (registry)
48 {
49 PluginRegistry = registry;
50
51 }
52
53 /// <summary>
54 /// Installs the plugin.
55 /// </summary>
56 /// <returns>
57 /// The plugin.
58 /// </returns>
59 /// <param name='args'>
60 /// Arguments.
61 /// </param>
62 public bool InstallPlugin(int ndx, out Dictionary<string, object> result)
63 {
64 Dictionary<string, object> res = new Dictionary<string, object>();
65
66 PackageCollection pack = new PackageCollection();
67 PackageCollection toUninstall;
68 DependencyCollection unresolved;
69
70 IProgressStatus ps = new ConsoleProgressStatus(false);
71
72 AddinRepositoryEntry[] available = GetSortedAvailbleAddins();
73
74 if (ndx > (available.Length - 1))
75 {
76 MainConsole.Instance.Output("Selection out of range");
77 result = res;
78 return false;
79 }
80
81 AddinRepositoryEntry aentry = available[ndx];
82
83 Package p = Package.FromRepository(aentry);
84 pack.Add(p);
85
86 ResolveDependencies(ps, pack, out toUninstall, out unresolved);
87
88 // Attempt to install the plugin disabled
89 if (Install(ps, pack) == true)
90 {
91 PluginRegistry.Update(ps);
92 Addin addin = PluginRegistry.GetAddin(aentry.Addin.Id);
93 PluginRegistry.DisableAddin(addin.Id);
94 addin.Enabled = false;
95
96 MainConsole.Instance.Output("Installation Success");
97 ListInstalledAddins(out res);
98 result = res;
99 return true;
100 }
101 else
102 {
103 MainConsole.Instance.Output("Installation Failed");
104 result = res;
105 return false;
106 }
107 }
108
109 // Remove plugin
110 /// <summary>
111 /// Uns the install.
112 /// </summary>
113 /// <param name='args'>
114 /// Arguments.
115 /// </param>
116 public void UnInstall(int ndx)
117 {
118 Addin[] addins = GetSortedAddinList("RobustPlugin");
119
120 if (ndx > (addins.Length -1))
121 {
122 MainConsole.Instance.Output("Selection out of range");
123 return;
124 }
125
126 Addin addin = addins[ndx];
127 MainConsole.Instance.OutputFormat("Uninstalling plugin {0}", addin.Id);
128 AddinManager.Registry.DisableAddin(addin.Id);
129 addin.Enabled = false;
130 IProgressStatus ps = new ConsoleProgressStatus(false);
131 Uninstall(ps, addin.Id);
132 MainConsole.Instance.Output("Uninstall Success - restart to complete operation");
133 return;
134 }
135
136 /// <summary>
137 /// Checks the installed.
138 /// </summary>
139 /// <returns>
140 /// The installed.
141 /// </returns>
142 public string CheckInstalled()
143 {
144 return "CheckInstall";
145 }
146
147 /// <summary>
148 /// Lists the installed addins.
149 /// </summary>
150 /// <param name='result'>
151 /// Result.
152 /// </param>
153 public void ListInstalledAddins(out Dictionary<string, object> result)
154 {
155 Dictionary<string, object> res = new Dictionary<string, object>();
156
157 Addin[] addins = GetSortedAddinList("RobustPlugin");
158 if(addins.Count() < 1)
159 {
160 MainConsole.Instance.Output("Error!");
161 }
162 int count = 0;
163 foreach (Addin addin in addins)
164 {
165 Dictionary<string, object> r = new Dictionary<string, object>();
166 r["enabled"] = addin.Enabled == true ? true : false;
167 r["name"] = addin.LocalId;
168 r["version"] = addin.Version;
169
170 res.Add(count.ToString(), r);
171
172 count++;
173 }
174 result = res;
175 return;
176 }
177
178 // List compatible plugins in registered repositories
179 /// <summary>
180 /// Lists the available.
181 /// </summary>
182 /// <param name='result'>
183 /// Result.
184 /// </param>
185 public void ListAvailable(out Dictionary<string, object> result)
186 {
187 Dictionary<string, object> res = new Dictionary<string, object>();
188
189 AddinRepositoryEntry[] addins = GetSortedAvailbleAddins();
190
191 int count = 0;
192 foreach (AddinRepositoryEntry addin in addins)
193 {
194 Dictionary<string, object> r = new Dictionary<string, object>();
195 r["name"] = addin.Addin.Name;
196 r["version"] = addin.Addin.Version;
197 r["repository"] = addin.RepositoryName;
198
199 res.Add(count.ToString(), r);
200 count++;
201 }
202 result = res;
203 return;
204 }
205
206 // List available updates ** 1
207 /// <summary>
208 /// Lists the updates.
209 /// </summary>
210 public void ListUpdates()
211 {
212 IProgressStatus ps = new ConsoleProgressStatus(true);
213 Console.WriteLine ("Looking for updates...");
214 Repositories.UpdateAllRepositories (ps);
215 Console.WriteLine ("Available add-in updates:");
216 bool found = false;
217 AddinRepositoryEntry[] entries = Repositories.GetAvailableUpdates();
218
219 foreach (AddinRepositoryEntry entry in entries)
220 {
221 Console.WriteLine(String.Format("{0}",entry.Addin.Id));
222 }
223 }
224
225 // Sync to repositories
226 /// <summary>
227 /// Update this instance.
228 /// </summary>
229 public string Update()
230 {
231 IProgressStatus ps = new ConsoleProgressStatus(true);
232 Repositories.UpdateAllRepositories(ps);
233 return "Update";
234 }
235
236 // Register a repository
237 /// <summary>
238 /// Register a repository with our server.
239 /// </summary>
240 /// <returns>
241 /// result of the action
242 /// </returns>
243 /// <param name='repo'>
244 /// The URL of the repository we want to add
245 /// </param>
246 public bool AddRepository(string repo)
247 {
248 Repositories.RegisterRepository(null, repo, true);
249 return true;
250 }
251
252 /// <summary>
253 /// Gets the repository.
254 /// </summary>
255 public void GetRepository()
256 {
257 Repositories.UpdateAllRepositories(new ConsoleProgressStatus(false));
258 }
259
260 // Remove a repository from the list
261 /// <summary>
262 /// Removes the repository.
263 /// </summary>
264 /// <param name='args'>
265 /// Arguments.
266 /// </param>
267 public void RemoveRepository(string[] args)
268 {
269 AddinRepository[] reps = Repositories.GetRepositories();
270 Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
271 if (reps.Length == 0)
272 {
273 MainConsole.Instance.Output("No repositories have been registered.");
274 return;
275 }
276
277 int n = Convert.ToInt16(args[2]);
278 if (n > (reps.Length -1))
279 {
280 MainConsole.Instance.Output("Selection out of range");
281 return;
282 }
283
284 AddinRepository rep = reps[n];
285 Repositories.RemoveRepository(rep.Url);
286 return;
287 }
288
289 // Enable repository
290 /// <summary>
291 /// Enables the repository.
292 /// </summary>
293 /// <param name='args'>
294 /// Arguments.
295 /// </param>
296 public void EnableRepository(string[] args)
297 {
298 AddinRepository[] reps = Repositories.GetRepositories();
299 Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
300 if (reps.Length == 0)
301 {
302 MainConsole.Instance.Output("No repositories have been registered.");
303 return;
304 }
305
306 int n = Convert.ToInt16(args[2]);
307 if (n > (reps.Length -1))
308 {
309 MainConsole.Instance.Output("Selection out of range");
310 return;
311 }
312
313 AddinRepository rep = reps[n];
314 Repositories.SetRepositoryEnabled(rep.Url, true);
315 return;
316 }
317
318 // Disable a repository
319 /// <summary>
320 /// Disables the repository.
321 /// </summary>
322 /// <param name='args'>
323 /// Arguments.
324 /// </param>
325 public void DisableRepository(string[] args)
326 {
327 AddinRepository[] reps = Repositories.GetRepositories();
328 Array.Sort(reps, (r1,r2) => r1.Title.CompareTo(r2.Title));
329 if (reps.Length == 0)
330 {
331 MainConsole.Instance.Output("No repositories have been registered.");
332 return;
333 }
334
335 int n = Convert.ToInt16(args[2]);
336 if (n > (reps.Length -1))
337 {
338 MainConsole.Instance.Output("Selection out of range");
339 return;
340 }
341
342 AddinRepository rep = reps[n];
343 Repositories.SetRepositoryEnabled(rep.Url, false);
344 return;
345 }
346
347 // List registered repositories
348 /// <summary>
349 /// Lists the repositories.
350 /// </summary>
351 /// <param name='result'>
352 /// Result.
353 /// </param>
354 public void ListRepositories(out Dictionary<string, object> result)
355 {
356 Dictionary<string, object> res = new Dictionary<string, object>();
357 result = res;
358
359 AddinRepository[] reps = GetSortedAddinRepo();
360 if (reps.Length == 0)
361 {
362 MainConsole.Instance.Output("No repositories have been registered.");
363 return;
364 }
365
366 int count = 0;
367 foreach (AddinRepository rep in reps)
368 {
369 Dictionary<string, object> r = new Dictionary<string, object>();
370 r["enabled"] = rep.Enabled == true ? true : false;
371 r["name"] = rep.Name;
372 r["url"] = rep.Url;
373
374 res.Add(count.ToString(), r);
375 count++;
376 }
377 return;
378 }
379
380 /// <summary>
381 /// Updates the registry.
382 /// </summary>
383 public void UpdateRegistry()
384 {
385 PluginRegistry.Update();
386 }
387
388 // Show plugin info
389 /// <summary>
390 /// Addins the info.
391 /// </summary>
392 /// <returns>
393 /// The info.
394 /// </returns>
395 /// <param name='args'>
396 /// Arguments.
397 /// </param>
398 public bool AddinInfo(int ndx, out Dictionary<string, object> result)
399 {
400 Dictionary<string, object> res = new Dictionary<string, object>();
401 result = res;
402
403 Addin[] addins = GetSortedAddinList("RobustPlugin");
404
405 if (ndx > (addins.Length - 1))
406 {
407 MainConsole.Instance.Output("Selection out of range");
408 return false;
409 }
410 // author category description
411 Addin addin = addins[ndx];
412
413 res["author"] = addin.Description.Author;
414 res["category"] = addin.Description.Category;
415 res["description"] = addin.Description.Description;
416 res["name"] = addin.Name;
417 res["url"] = addin.Description.Url;
418 res["file_name"] = addin.Description.FileName;
419
420 result = res;
421 return true;
422 }
423
424 // Disable a plugin
425 /// <summary>
426 /// Disables the plugin.
427 /// </summary>
428 /// <param name='args'>
429 /// Arguments.
430 /// </param>
431 public void DisablePlugin(string[] args)
432 {
433 Addin[] addins = GetSortedAddinList("RobustPlugin");
434
435 int n = Convert.ToInt16(args[2]);
436 if (n > (addins.Length -1))
437 {
438 MainConsole.Instance.Output("Selection out of range");
439 return;
440 }
441
442 Addin addin = addins[n];
443 AddinManager.Registry.DisableAddin(addin.Id);
444 addin.Enabled = false;
445 return;
446 }
447
448 // Enable plugin
449 /// <summary>
450 /// Enables the plugin.
451 /// </summary>
452 /// <param name='args'>
453 /// Arguments.
454 /// </param>
455 public void EnablePlugin(string[] args)
456 {
457 Addin[] addins = GetSortedAddinList("RobustPlugin");
458
459 int n = Convert.ToInt16(args[2]);
460 if (n > (addins.Length -1))
461 {
462 MainConsole.Instance.Output("Selection out of range");
463 return;
464 }
465
466 Addin addin = addins[n];
467
468 addin.Enabled = true;
469 AddinManager.Registry.EnableAddin(addin.Id);
470 // AddinManager.Registry.Update();
471 if(PluginRegistry.IsAddinEnabled(addin.Id))
472 {
473 ConsoleProgressStatus ps = new ConsoleProgressStatus(false);
474 if (!AddinManager.AddinEngine.IsAddinLoaded(addin.Id))
475 {
476 AddinManager.Registry.Rebuild(ps);
477 AddinManager.AddinEngine.LoadAddin(ps, addin.Id);
478 }
479 }
480 else
481 {
482 MainConsole.Instance.OutputFormat("Not Enabled in this domain {0}", addin.Name);
483 }
484 return;
485 }
486
487
488
489 #region Util
490 private void Testing()
491 {
492 Addin[] list = Registry.GetAddins();
493
494 var addins = list.Where( a => a.Description.Category == "RobustPlugin");
495
496 foreach (Addin addin in addins)
497 {
498 MainConsole.Instance.OutputFormat("Addin {0}", addin.Name);
499 }
500 }
501
502 // These will let us deal with numbered lists instead
503 // of needing to type in the full ids
504 private AddinRepositoryEntry[] GetSortedAvailbleAddins()
505 {
506 ArrayList list = new ArrayList();
507 list.AddRange(Repositories.GetAvailableAddins());
508
509 AddinRepositoryEntry[] addins = list.ToArray(typeof(AddinRepositoryEntry)) as AddinRepositoryEntry[];
510
511 Array.Sort(addins,(r1,r2) => r1.Addin.Id.CompareTo(r2.Addin.Id));
512
513 return addins;
514 }
515
516 private AddinRepository[] GetSortedAddinRepo()
517 {
518 ArrayList list = new ArrayList();
519 list.AddRange(Repositories.GetRepositories());
520
521 AddinRepository[] repos = list.ToArray(typeof(AddinRepository)) as AddinRepository[];
522 Array.Sort (repos,(r1,r2) => r1.Name.CompareTo(r2.Name));
523
524 return repos;
525 }
526
527 private Addin[] GetSortedAddinList(string category)
528 {
529
530 ArrayList xlist = new ArrayList();
531 ArrayList list = new ArrayList();
532 try
533 {
534 list.AddRange(PluginRegistry.GetAddins());
535 }
536 catch(Exception e)
537 {
538 Addin[] x = xlist.ToArray(typeof(Addin)) as Addin[];
539 return x;
540 }
541
542 foreach (Addin addin in list)
543 {
544 if (addin.Description.Category == category)
545 xlist.Add(addin);
546 }
547
548 Addin[] addins = xlist.ToArray(typeof(Addin)) as Addin[];
549 Array.Sort(addins,(r1,r2) => r1.Id.CompareTo(r2.Id));
550
551 return addins;
552 }
553 #endregion Util
554 }
555} \ No newline at end of file