5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Specialized;
30
namespace Mono.Addins.Database
32
class SetupDomain: ISetupHandler
35
RemoteSetupDomain remoteSetupDomain;
38
public void Scan (IProgressStatus monitor, AddinRegistry registry, string scanFolder, string[] filesToIgnore)
40
RemoteProgressStatus remMonitor = new RemoteProgressStatus (monitor);
42
RemoteSetupDomain rsd = GetDomain ();
43
rsd.Scan (remMonitor, registry.RegistryPath, registry.StartupDirectory, registry.DefaultAddinsFolder, registry.AddinCachePath, scanFolder, filesToIgnore);
44
} catch (Exception ex) {
45
throw new ProcessFailedException (remMonitor.ProgessLog, ex);
47
System.Runtime.Remoting.RemotingServices.Disconnect (remMonitor);
52
public void GetAddinDescription (IProgressStatus monitor, AddinRegistry registry, string file, string outFile)
54
RemoteProgressStatus remMonitor = new RemoteProgressStatus (monitor);
56
RemoteSetupDomain rsd = GetDomain ();
57
rsd.GetAddinDescription (remMonitor, registry.RegistryPath, registry.StartupDirectory, registry.DefaultAddinsFolder, registry.AddinCachePath, file, outFile);
58
} catch (Exception ex) {
59
throw new ProcessFailedException (remMonitor.ProgessLog, ex);
61
System.Runtime.Remoting.RemotingServices.Disconnect (remMonitor);
66
RemoteSetupDomain GetDomain ()
69
if (useCount++ == 0) {
70
domain = AppDomain.CreateDomain ("SetupDomain", null, AppDomain.CurrentDomain.SetupInformation);
71
remoteSetupDomain = (RemoteSetupDomain) domain.CreateInstanceFromAndUnwrap (typeof(RemoteSetupDomain).Assembly.Location, typeof(RemoteSetupDomain).FullName);
73
return remoteSetupDomain;
80
if (--useCount == 0) {
81
AppDomain.Unload (domain);
83
remoteSetupDomain = null;
89
class RemoteSetupDomain: MarshalByRefObject
91
public override object InitializeLifetimeService ()
96
public void Scan (IProgressStatus monitor, string registryPath, string startupDir, string addinsDir, string databaseDir, string scanFolder, string[] filesToIgnore)
98
AddinDatabase.RunningSetupProcess = true;
99
AddinRegistry reg = new AddinRegistry (registryPath, startupDir, addinsDir, databaseDir);
100
StringCollection files = new StringCollection ();
101
for (int n=0; n<filesToIgnore.Length; n++)
102
files.Add (filesToIgnore[n]);
103
reg.ScanFolders (monitor, scanFolder, files);
106
public void GetAddinDescription (IProgressStatus monitor, string registryPath, string startupDir, string addinsDir, string databaseDir, string file, string outFile)
108
AddinDatabase.RunningSetupProcess = true;
109
AddinRegistry reg = new AddinRegistry (registryPath, startupDir, addinsDir, databaseDir);
110
reg.ParseAddin (monitor, file, outFile);
114
class RemoteProgressStatus: MarshalByRefObject, IProgressStatus
116
IProgressStatus local;
117
StringCollection progessLog = new StringCollection ();
119
public RemoteProgressStatus (IProgressStatus local)
124
public StringCollection ProgessLog {
125
get { return progessLog; }
128
public override object InitializeLifetimeService ()
133
public void SetMessage (string msg)
135
local.SetMessage (msg);
138
public void SetProgress (double progress)
140
local.SetProgress (progress);
143
public void Log (string msg)
145
if (msg.StartsWith ("plog:"))
146
progessLog.Add (msg.Substring (5));
151
public void ReportWarning (string message)
153
local.ReportWarning (message);
156
public void ReportError (string message, Exception exception)
158
local.ReportError (message, exception);
161
public void Cancel ()
166
public int LogLevel {
168
return local.LogLevel;
172
public bool IsCanceled {
174
return local.IsCanceled;