~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-addins/Mono.Addins/Mono.Addins.Database/SetupDomain.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// SetupDomain.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez Gual <lluis@novell.com>
 
6
// 
 
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
 
8
// 
 
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:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
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
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Collections.Specialized;
 
29
 
 
30
namespace Mono.Addins.Database
 
31
{
 
32
        class SetupDomain: ISetupHandler
 
33
        {
 
34
                AppDomain domain;
 
35
                RemoteSetupDomain remoteSetupDomain;
 
36
                int useCount;
 
37
                
 
38
                public void Scan (IProgressStatus monitor, AddinRegistry registry, string scanFolder, string[] filesToIgnore)
 
39
                {
 
40
                        RemoteProgressStatus remMonitor = new RemoteProgressStatus (monitor);
 
41
                        try {
 
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);
 
46
                        } finally {
 
47
                                System.Runtime.Remoting.RemotingServices.Disconnect (remMonitor);
 
48
                                ReleaseDomain ();
 
49
                        }
 
50
                }
 
51
                
 
52
                public void GetAddinDescription (IProgressStatus monitor, AddinRegistry registry, string file, string outFile)
 
53
                {
 
54
                        RemoteProgressStatus remMonitor = new RemoteProgressStatus (monitor);
 
55
                        try {
 
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);
 
60
                        } finally {
 
61
                                System.Runtime.Remoting.RemotingServices.Disconnect (remMonitor);
 
62
                                ReleaseDomain ();
 
63
                        }
 
64
                }
 
65
                
 
66
                RemoteSetupDomain GetDomain ()
 
67
                {
 
68
                        lock (this) {
 
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);
 
72
                                }
 
73
                                return remoteSetupDomain;
 
74
                        }
 
75
                }
 
76
                
 
77
                void ReleaseDomain ()
 
78
                {
 
79
                        lock (this) {
 
80
                                if (--useCount == 0) {
 
81
                                        AppDomain.Unload (domain);
 
82
                                        domain = null;
 
83
                                        remoteSetupDomain = null;
 
84
                                }
 
85
                        }
 
86
                }
 
87
        }
 
88
        
 
89
        class RemoteSetupDomain: MarshalByRefObject
 
90
        {
 
91
                public override object InitializeLifetimeService ()
 
92
                {
 
93
                        return null;
 
94
                }
 
95
                
 
96
                public void Scan (IProgressStatus monitor, string registryPath, string startupDir, string addinsDir, string databaseDir, string scanFolder, string[] filesToIgnore)
 
97
                {
 
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);
 
104
                }
 
105
                
 
106
                public void GetAddinDescription (IProgressStatus monitor, string registryPath, string startupDir, string addinsDir, string databaseDir, string file, string outFile)
 
107
                {
 
108
                        AddinDatabase.RunningSetupProcess = true;
 
109
                        AddinRegistry reg = new AddinRegistry (registryPath, startupDir, addinsDir, databaseDir);
 
110
                        reg.ParseAddin (monitor, file, outFile);
 
111
                }
 
112
        }
 
113
        
 
114
        class RemoteProgressStatus: MarshalByRefObject, IProgressStatus
 
115
        {
 
116
                IProgressStatus local;
 
117
                StringCollection progessLog = new StringCollection ();
 
118
                
 
119
                public RemoteProgressStatus (IProgressStatus local)
 
120
                {
 
121
                        this.local = local;
 
122
                }
 
123
                
 
124
                public StringCollection ProgessLog {
 
125
                        get { return progessLog; }
 
126
                }
 
127
                
 
128
                public override object InitializeLifetimeService ()
 
129
                {
 
130
                        return null;
 
131
                }
 
132
                
 
133
                public void SetMessage (string msg)
 
134
                {
 
135
                        local.SetMessage (msg);
 
136
                }
 
137
                
 
138
                public void SetProgress (double progress)
 
139
                {
 
140
                        local.SetProgress (progress);
 
141
                }
 
142
                
 
143
                public void Log (string msg)
 
144
                {
 
145
                        if (msg.StartsWith ("plog:"))
 
146
                                progessLog.Add (msg.Substring (5));
 
147
                        else
 
148
                                local.Log (msg);
 
149
                }
 
150
                
 
151
                public void ReportWarning (string message)
 
152
                {
 
153
                        local.ReportWarning (message);
 
154
                }
 
155
                
 
156
                public void ReportError (string message, Exception exception)
 
157
                {
 
158
                        local.ReportError (message, exception);
 
159
                }
 
160
                
 
161
                public void Cancel ()
 
162
                {
 
163
                        local.Cancel ();
 
164
                }
 
165
                
 
166
                public int LogLevel {
 
167
                        get {
 
168
                                return local.LogLevel;
 
169
                        }
 
170
                }
 
171
                
 
172
                public bool IsCanceled {
 
173
                        get {
 
174
                                return local.IsCanceled;
 
175
                        }
 
176
                }
 
177
        }
 
178
}