~ubuntu-branches/ubuntu/karmic/mono-addins/karmic

« back to all changes in this revision

Viewing changes to Mono.Addins/Mono.Addins.Description/AddinDescription.cs

  • Committer: Bazaar Package Importer
  • Author(s): Mirco Bauer
  • Date: 2007-07-14 12:07:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070714120748-2elczfsjlrdsrpms
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// AddinDescription.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.Collections;
 
31
using System.IO;
 
32
using System.Xml;
 
33
using System.Xml.Serialization;
 
34
using System.Collections.Specialized;
 
35
using Mono.Addins.Serialization;
 
36
using Mono.Addins.Database;
 
37
 
 
38
namespace Mono.Addins.Description
 
39
{
 
40
        // This class represent an add-in configuration file. It has properties for getting
 
41
        // all information, and methods for loading and saving files.
 
42
        public class AddinDescription: IBinaryXmlElement
 
43
        {
 
44
                XmlDocument configDoc;
 
45
                string configFile;
 
46
                bool fromBinaryFile;
 
47
                AddinDatabase ownerDatabase;
 
48
                
 
49
                string id;
 
50
                string name;
 
51
                string ns;
 
52
                string version;
 
53
                string compatVersion;
 
54
                string author;
 
55
                string url;
 
56
                string copyright;
 
57
                string description;
 
58
                string category;
 
59
                string basePath;
 
60
                string sourceAddinFile;
 
61
                bool isroot;
 
62
                bool hasUserId;
 
63
                bool canWrite = true;
 
64
                bool defaultEnabled = true;
 
65
                
 
66
                ModuleDescription mainModule;
 
67
                ModuleCollection optionalModules;
 
68
                ExtensionNodeSetCollection nodeSets;
 
69
                ConditionTypeDescriptionCollection conditionTypes;
 
70
                ExtensionPointCollection extensionPoints;
 
71
                
 
72
                internal static BinaryXmlTypeMap typeMap;
 
73
                
 
74
                static AddinDescription ()
 
75
                {
 
76
                        typeMap = new BinaryXmlTypeMap ();
 
77
                        typeMap.RegisterType (typeof(AddinDescription), "AddinDescription");
 
78
                        typeMap.RegisterType (typeof(Extension), "Extension");
 
79
                        typeMap.RegisterType (typeof(ExtensionNodeDescription), "Node");
 
80
                        typeMap.RegisterType (typeof(ExtensionNodeSet), "NodeSet");
 
81
                        typeMap.RegisterType (typeof(ExtensionNodeType), "NodeType");
 
82
                        typeMap.RegisterType (typeof(ExtensionPoint), "ExtensionPoint");
 
83
                        typeMap.RegisterType (typeof(ModuleDescription), "ModuleDescription");
 
84
                        typeMap.RegisterType (typeof(ConditionTypeDescription), "ConditionType");
 
85
                        typeMap.RegisterType (typeof(Condition), "Condition");
 
86
                        typeMap.RegisterType (typeof(AddinDependency), "AddinDependency");
 
87
                        typeMap.RegisterType (typeof(AssemblyDependency), "AssemblyDependency");
 
88
                        typeMap.RegisterType (typeof(NodeTypeAttribute), "NodeTypeAttribute");
 
89
                }
 
90
                
 
91
                internal AddinDatabase OwnerDatabase {
 
92
                        get { return ownerDatabase; }
 
93
                        set { ownerDatabase = value; }
 
94
                }
 
95
                
 
96
                public string AddinFile {
 
97
                        get { return sourceAddinFile; }
 
98
                        set { sourceAddinFile = value; }
 
99
                }
 
100
                
 
101
                public string AddinId {
 
102
                        get { return Addin.GetFullId (Namespace, LocalId, Version); }
 
103
                }
 
104
                
 
105
                public string LocalId {
 
106
                        get { return id != null ? id : string.Empty; }
 
107
                        set { id = value; hasUserId = true; }
 
108
                }
 
109
 
 
110
                public string Namespace {
 
111
                        get { return ns != null ? ns : string.Empty; }
 
112
                        set { ns = value; }
 
113
                }
 
114
 
 
115
                public string Name {
 
116
                        get {
 
117
                                if (name != null && name.Length > 0)
 
118
                                        return name;
 
119
                                if (HasUserId)
 
120
                                        return AddinId;
 
121
                                else if (sourceAddinFile != null)
 
122
                                        return Path.GetFileNameWithoutExtension (sourceAddinFile);
 
123
                                else
 
124
                                        return string.Empty;
 
125
                        }
 
126
                        set { name = value; }
 
127
                }
 
128
 
 
129
                public string Version {
 
130
                        get { return version != null ? version : string.Empty; }
 
131
                        set { version = value; }
 
132
                }
 
133
 
 
134
                public string CompatVersion {
 
135
                        get { return compatVersion != null ? compatVersion : string.Empty; }
 
136
                        set { compatVersion = value; }
 
137
                }
 
138
 
 
139
                public string Author {
 
140
                        get { return author != null ? author : string.Empty; }
 
141
                        set { author = value; }
 
142
                }
 
143
 
 
144
                public string Url {
 
145
                        get { return url != null ? url : string.Empty; }
 
146
                        set { url = value; }
 
147
                }
 
148
 
 
149
                public string Copyright {
 
150
                        get { return copyright != null ? copyright : string.Empty; }
 
151
                        set { copyright = value; }
 
152
                }
 
153
 
 
154
                public string Description {
 
155
                        get { return description != null ? description : string.Empty; }
 
156
                        set { description = value; }
 
157
                }
 
158
 
 
159
                public string Category {
 
160
                        get { return category != null ? category : string.Empty; }
 
161
                        set { category = value; }
 
162
                }
 
163
                
 
164
                internal string BasePath {
 
165
                        get { return basePath != null ? basePath : string.Empty; }
 
166
                        set { basePath = value; }
 
167
                }
 
168
                
 
169
                public bool IsRoot {
 
170
                        get { return isroot; }
 
171
                        set { isroot = value; }
 
172
                }
 
173
                
 
174
                public bool EnabledByDefault {
 
175
                        get { return defaultEnabled; }
 
176
                        set { defaultEnabled = value; }
 
177
                }
 
178
                
 
179
                internal bool HasUserId {
 
180
                        get { return hasUserId; }
 
181
                        set { hasUserId = value; }
 
182
                }
 
183
                
 
184
                public StringCollection AllFiles {
 
185
                        get {
 
186
                                StringCollection col = new StringCollection ();
 
187
                                foreach (string s in MainModule.AllFiles)
 
188
                                        col.Add (s);
 
189
 
 
190
                                foreach (ModuleDescription mod in OptionalModules) {
 
191
                                        foreach (string s in mod.AllFiles)
 
192
                                                col.Add (s);
 
193
                                }
 
194
                                return col;
 
195
                        }
 
196
                }
 
197
                
 
198
                public ModuleDescription MainModule {
 
199
                        get {
 
200
                                if (mainModule == null) {
 
201
                                        if (RootElement == null)
 
202
                                                mainModule = new ModuleDescription ();
 
203
                                        else
 
204
                                                mainModule = new ModuleDescription (RootElement);
 
205
                                        mainModule.SetParent (this);
 
206
                                }
 
207
                                return mainModule;
 
208
                        }
 
209
                }
 
210
                
 
211
                public ModuleCollection OptionalModules {
 
212
                        get {
 
213
                                if (optionalModules == null) {
 
214
                                        optionalModules = new ModuleCollection (this);
 
215
                                        if (RootElement != null) {
 
216
                                                foreach (XmlElement mod in RootElement.SelectNodes ("Module"))
 
217
                                                        optionalModules.Add (new ModuleDescription (mod));
 
218
                                        }
 
219
                                }
 
220
                                return optionalModules;
 
221
                        }
 
222
                }
 
223
                
 
224
                public ModuleCollection AllModules {
 
225
                        get {
 
226
                                ModuleCollection col = new ModuleCollection (this);
 
227
                                col.Add (MainModule);
 
228
                                foreach (ModuleDescription mod in OptionalModules)
 
229
                                        col.Add (mod);
 
230
                                return col;
 
231
                        }
 
232
                }
 
233
                
 
234
                public ExtensionNodeSetCollection ExtensionNodeSets {
 
235
                        get {
 
236
                                if (nodeSets == null) {
 
237
                                        nodeSets = new ExtensionNodeSetCollection (this);
 
238
                                        if (RootElement != null) {
 
239
                                                foreach (XmlElement elem in RootElement.SelectNodes ("ExtensionNodeSet"))
 
240
                                                        nodeSets.Add (new ExtensionNodeSet (elem));
 
241
                                        }
 
242
                                }
 
243
                                return nodeSets;
 
244
                        }
 
245
                }
 
246
                
 
247
                public ExtensionPointCollection ExtensionPoints {
 
248
                        get {
 
249
                                if (extensionPoints == null) {
 
250
                                        extensionPoints = new ExtensionPointCollection (this);
 
251
                                        if (RootElement != null) {
 
252
                                                foreach (XmlElement elem in RootElement.SelectNodes ("ExtensionPoint"))
 
253
                                                        extensionPoints.Add (new ExtensionPoint (elem));
 
254
                                        }
 
255
                                }
 
256
                                return extensionPoints;
 
257
                        }
 
258
                }
 
259
                
 
260
                public ConditionTypeDescriptionCollection ConditionTypes {
 
261
                        get {
 
262
                                if (conditionTypes == null) {
 
263
                                        conditionTypes = new ConditionTypeDescriptionCollection (this);
 
264
                                        if (RootElement != null) {
 
265
                                                foreach (XmlElement elem in RootElement.SelectNodes ("ConditionType"))
 
266
                                                        conditionTypes.Add (new ConditionTypeDescription (elem));
 
267
                                        }
 
268
                                }
 
269
                                return conditionTypes;
 
270
                        }
 
271
                }
 
272
                
 
273
                public ExtensionPoint AddExtensionPoint (string path)
 
274
                {
 
275
                        ExtensionPoint ep = new ExtensionPoint ();
 
276
                        ep.Path = path;
 
277
                        ExtensionPoints.Add (ep);
 
278
                        return ep;
 
279
                }
 
280
                
 
281
                internal ExtensionNodeDescription FindExtensionNode (string path, bool lookInDeps)
 
282
                {
 
283
                        // Look in the extensions of this add-in
 
284
                        
 
285
                        foreach (Extension ext in MainModule.Extensions) {
 
286
                                if (path.StartsWith (ext.Path + "/")) {
 
287
                                        string subp = path.Substring (ext.Path.Length).Trim ('/');
 
288
                                        ExtensionNodeDescriptionCollection nodes = ext.ExtensionNodes;
 
289
                                        ExtensionNodeDescription node = null;
 
290
                                        foreach (string p in subp.Split ('/')) {
 
291
                                                if (p.Length == 0) continue;
 
292
                                                node = nodes [p];
 
293
                                                if (node == null)
 
294
                                                        break;
 
295
                                                nodes = node.ChildNodes;
 
296
                                        }
 
297
                                        if (node != null)
 
298
                                                return node;
 
299
                                }
 
300
                        }
 
301
                        
 
302
                        if (!lookInDeps || OwnerDatabase == null)
 
303
                                return null;
 
304
                        
 
305
                        // Look in dependencies
 
306
                        
 
307
                        foreach (Dependency dep in MainModule.Dependencies) {
 
308
                                AddinDependency adep = dep as AddinDependency;
 
309
                                if (adep == null) continue;
 
310
                                Addin ad = OwnerDatabase.GetInstalledAddin (adep.FullAddinId);
 
311
                                if (ad != null && ad.Description != null) {
 
312
                                        ExtensionNodeDescription node = ad.Description.FindExtensionNode (path, false);
 
313
                                        if (node != null)
 
314
                                                return node;
 
315
                                }
 
316
                        }
 
317
                        return null;
 
318
                }
 
319
                
 
320
                XmlElement RootElement {
 
321
                        get {
 
322
                                if (configDoc != null)
 
323
                                        return configDoc.DocumentElement;
 
324
                                else
 
325
                                        return null;
 
326
                        }
 
327
                }
 
328
                
 
329
                public string FileName {
 
330
                        get { return configFile; }
 
331
                        set { configFile = value; }
 
332
                }
 
333
                
 
334
                public void Save (string fileName)
 
335
                {
 
336
                        configFile = fileName;
 
337
                        Save ();
 
338
                }
 
339
                
 
340
                public void Save ()
 
341
                {
 
342
                        if (configFile == null)
 
343
                                throw new InvalidOperationException ("File name not specified.");
 
344
                        
 
345
                        SaveXml ();
 
346
 
 
347
                        using (StreamWriter sw = new StreamWriter (configFile)) {
 
348
                                XmlTextWriter tw = new XmlTextWriter (sw);
 
349
                                tw.Formatting = Formatting.Indented;
 
350
                                configDoc.Save (tw);
 
351
                        }
 
352
                }
 
353
                
 
354
                public XmlDocument SaveToXml ()
 
355
                {
 
356
                        SaveXml ();
 
357
                        return configDoc;
 
358
                }
 
359
                
 
360
                void SaveXml ()
 
361
                {
 
362
                        if (!canWrite)
 
363
                                throw new InvalidOperationException ("Can't write incomplete description.");
 
364
                        
 
365
                        XmlElement elem;
 
366
                        
 
367
                        if (configDoc == null) {
 
368
                                configDoc = new XmlDocument ();
 
369
                                configDoc.AppendChild (configDoc.CreateElement ("Addin"));
 
370
                        }
 
371
                        
 
372
                        elem = configDoc.DocumentElement;
 
373
                        
 
374
                        if (HasUserId)
 
375
                                elem.SetAttribute ("id", id);
 
376
                        else
 
377
                                elem.RemoveAttribute ("id");
 
378
                        
 
379
                        elem.SetAttribute ("version", version);
 
380
                        elem.SetAttribute ("namespace", ns);
 
381
                        
 
382
                        if (isroot)
 
383
                                elem.SetAttribute ("isroot", "true");
 
384
                        else
 
385
                                elem.RemoveAttribute ("isroot");
 
386
                        
 
387
                        // Name will return the file name when HasUserId=false
 
388
                        if (Name.Length > 0)
 
389
                                elem.SetAttribute ("name", Name);
 
390
                        else
 
391
                                elem.RemoveAttribute ("name");
 
392
                                
 
393
                        if (compatVersion != null && compatVersion.Length > 0)
 
394
                                elem.SetAttribute ("compatVersion", compatVersion);
 
395
                        else
 
396
                                elem.RemoveAttribute ("compatVersion");
 
397
                        
 
398
                        if (defaultEnabled)
 
399
                                elem.RemoveAttribute ("defaultEnabled");
 
400
                        else
 
401
                                elem.SetAttribute ("defaultEnabled", "false");
 
402
                                
 
403
                        if (author != null && author.Length > 0)
 
404
                                elem.SetAttribute ("author", author);
 
405
                        else
 
406
                                elem.RemoveAttribute ("author");
 
407
                                
 
408
                        if (url != null && url.Length > 0)
 
409
                                elem.SetAttribute ("url", url);
 
410
                        else
 
411
                                elem.RemoveAttribute ("url");
 
412
                                
 
413
                        if (copyright != null && copyright.Length > 0)
 
414
                                elem.SetAttribute ("copyright", copyright);
 
415
                        else
 
416
                                elem.RemoveAttribute ("copyright");
 
417
                                
 
418
                        if (description != null && description.Length > 0)
 
419
                                elem.SetAttribute ("description", description);
 
420
                        else
 
421
                                elem.RemoveAttribute ("description");
 
422
                                
 
423
                        if (category != null && category.Length > 0)
 
424
                                elem.SetAttribute ("category", category);
 
425
                        else
 
426
                                elem.RemoveAttribute ("category");
 
427
                                
 
428
                        if (mainModule != null) {
 
429
                                mainModule.Element = elem;
 
430
                                mainModule.SaveXml (elem);
 
431
                        }
 
432
                                
 
433
                        if (optionalModules != null)
 
434
                                optionalModules.SaveXml (elem);
 
435
                                
 
436
                        if (nodeSets != null)
 
437
                                nodeSets.SaveXml (elem);
 
438
                                
 
439
                        if (extensionPoints != null)
 
440
                                extensionPoints.SaveXml (elem);
 
441
                }
 
442
                
 
443
 
 
444
                public static AddinDescription Read (string configFile)
 
445
                {
 
446
                        AddinDescription config;
 
447
                        using (Stream s = File.OpenRead (configFile)) {
 
448
                                config = Read (s, Path.GetDirectoryName (configFile));
 
449
                        }
 
450
                        config.configFile = configFile;
 
451
                        return config;
 
452
                }
 
453
                
 
454
                public static AddinDescription Read (Stream stream, string basePath)
 
455
                {
 
456
                        AddinDescription config = new AddinDescription ();
 
457
                        
 
458
                        try {
 
459
                                config.configDoc = new XmlDocument ();
 
460
                                config.configDoc.Load (stream);
 
461
                        } catch (Exception ex) {
 
462
                                throw new InvalidOperationException ("The add-in configuration file is invalid.", ex);
 
463
                        }
 
464
                        
 
465
                        XmlElement elem = config.configDoc.DocumentElement;
 
466
                        config.id = elem.GetAttribute ("id");
 
467
                        config.ns = elem.GetAttribute ("namespace");
 
468
                        config.name = elem.GetAttribute ("name");
 
469
                        config.version = elem.GetAttribute ("version");
 
470
                        config.compatVersion = elem.GetAttribute ("compatVersion");
 
471
                        config.author = elem.GetAttribute ("author");
 
472
                        config.url = elem.GetAttribute ("url");
 
473
                        config.copyright = elem.GetAttribute ("copyright");
 
474
                        config.description = elem.GetAttribute ("description");
 
475
                        config.category = elem.GetAttribute ("category");
 
476
                        config.basePath = elem.GetAttribute ("basePath");
 
477
                        
 
478
                        string s = elem.GetAttribute ("isRoot");
 
479
                        if (s.Length == 0) s = elem.GetAttribute ("isroot");
 
480
                        config.isroot = s == "true" || s == "yes";
 
481
                        
 
482
                        s = elem.GetAttribute ("defaultEnabled");
 
483
                        config.defaultEnabled = s.Length == 0 || s == "true" || s == "yes";
 
484
                        
 
485
                        if (config.id.Length > 0)
 
486
                                config.hasUserId = true;
 
487
                        
 
488
                        return config;
 
489
                }
 
490
                
 
491
                internal static AddinDescription ReadBinary (FileDatabase fdb, string configFile)
 
492
                {
 
493
                        AddinDescription description = (AddinDescription) fdb.ReadSharedObject (configFile, typeMap);
 
494
                        if (description != null) {
 
495
                                description.FileName = configFile;
 
496
                                description.fromBinaryFile = true;
 
497
                                description.canWrite = !fdb.IgnoreDescriptionData;
 
498
                        }
 
499
                        return description;
 
500
                }
 
501
                
 
502
                internal static AddinDescription ReadHostBinary (FileDatabase fdb, string basePath, string addinId, string addinFile)
 
503
                {
 
504
                        string fileName;
 
505
                        AddinDescription description = (AddinDescription) fdb.ReadSharedObject (basePath, addinId, ".mroot", Util.GetFullPath (addinFile), typeMap, out fileName);
 
506
                        if (description != null) {
 
507
                                description.FileName = fileName;
 
508
                                description.fromBinaryFile = true;
 
509
                                description.canWrite = !fdb.IgnoreDescriptionData;
 
510
                        }
 
511
                        return description;
 
512
                }
 
513
                
 
514
                internal void SaveBinary (FileDatabase fdb, string file)
 
515
                {
 
516
                        configFile = file;
 
517
                        SaveBinary (fdb);
 
518
                }
 
519
                
 
520
                internal void SaveBinary (FileDatabase fdb)
 
521
                {
 
522
                        if (!canWrite)
 
523
                                throw new InvalidOperationException ("Can't write incomplete description.");
 
524
                        fdb.WriteSharedObject (AddinFile, FileName, typeMap, this);
 
525
//                      BinaryXmlReader.DumpFile (configFile);
 
526
                }
 
527
                
 
528
                internal void SaveHostBinary (FileDatabase fdb, string basePath)
 
529
                {
 
530
                        if (!canWrite)
 
531
                                throw new InvalidOperationException ("Can't write incomplete description.");
 
532
                        if (!fromBinaryFile)
 
533
                                FileName = null;
 
534
                        FileName = fdb.WriteSharedObject (basePath, AddinId, ".mroot", AddinFile, FileName, typeMap, this);
 
535
                }
 
536
                
 
537
                public StringCollection Verify ()
 
538
                {
 
539
                        StringCollection errors = new StringCollection ();
 
540
                        
 
541
                        if (IsRoot) {
 
542
                                if (OptionalModules.Count > 0)
 
543
                                        errors.Add ("Root add-in hosts can't have optional modules.");
 
544
                                if (MainModule.Dependencies.Count > 0)
 
545
                                        errors.Add ("Root add-in hosts can't have dependencies.");
 
546
                        }
 
547
                        
 
548
                        if (AddinId.Length == 0 || Version.Length == 0) {
 
549
                                if (ExtensionPoints.Count > 0)
 
550
                                        errors.Add ("Add-ins which define new extension points must have an Id and Version.");
 
551
                        }
 
552
 
 
553
                        MainModule.Verify ("", errors);
 
554
                        OptionalModules.Verify ("", errors);
 
555
                        ExtensionNodeSets.Verify ("", errors);
 
556
                        ExtensionPoints.Verify ("", errors);
 
557
                        ConditionTypes.Verify ("", errors);
 
558
                        
 
559
                        foreach (ExtensionNodeSet nset in ExtensionNodeSets) {
 
560
                                if (nset.Id.Length == 0)
 
561
                                        errors.Add ("Attribute 'id' can't be empty for global node sets.");
 
562
                        }
 
563
                        
 
564
                        string bp = null;
 
565
                        if (BasePath.Length > 0)
 
566
                                bp = BasePath;
 
567
                        else if (sourceAddinFile != null && sourceAddinFile.Length > 0)
 
568
                                bp = Path.GetDirectoryName (AddinFile);
 
569
                        else if (configFile != null && configFile.Length > 0)
 
570
                                bp = Path.GetDirectoryName (configFile);
 
571
                                
 
572
                        if (bp != null) {
 
573
                                foreach (string file in AllFiles) {
 
574
                                        string asmFile = Path.Combine (BasePath, file);
 
575
                                        if (!File.Exists (asmFile))
 
576
                                                errors.Add ("The file '" + file + "' referenced in the manifest could not be found.");
 
577
                                }
 
578
                        }
 
579
                        
 
580
                        return errors;
 
581
                }
 
582
                
 
583
                internal void SetExtensionsAddinId (string addinId)
 
584
                {
 
585
                        foreach (ExtensionPoint ep in ExtensionPoints)
 
586
                                ep.SetExtensionsAddinId (addinId);
 
587
                                
 
588
                        foreach (ExtensionNodeSet ns in ExtensionNodeSets)
 
589
                                ns.SetExtensionsAddinId (addinId);
 
590
                }
 
591
                
 
592
                internal void UnmergeExternalData (Hashtable addins)
 
593
                {
 
594
                        // Removes extension types and extension sets coming from other add-ins.
 
595
                        foreach (ExtensionPoint ep in ExtensionPoints)
 
596
                                ep.UnmergeExternalData (AddinId, addins);
 
597
                                
 
598
                        foreach (ExtensionNodeSet ns in ExtensionNodeSets)
 
599
                                ns.UnmergeExternalData (AddinId, addins);
 
600
                }
 
601
                
 
602
                internal void MergeExternalData (AddinDescription other)
 
603
                {
 
604
                        // Removes extension types and extension sets coming from other add-ins.
 
605
                        foreach (ExtensionPoint ep in other.ExtensionPoints) {
 
606
                                ExtensionPoint tep = ExtensionPoints [ep.Path];
 
607
                                if (tep != null)
 
608
                                        tep.MergeWith (AddinId, ep);
 
609
                        }
 
610
                                
 
611
                        foreach (ExtensionNodeSet ns in other.ExtensionNodeSets) {
 
612
                                ExtensionNodeSet tns = ExtensionNodeSets [ns.Id];
 
613
                                if (tns != null)
 
614
                                        tns.MergeWith (AddinId, ns);
 
615
                        }
 
616
                }
 
617
                
 
618
                void IBinaryXmlElement.Write (BinaryXmlWriter writer)
 
619
                {
 
620
                        writer.WriteValue ("id", id);
 
621
                        writer.WriteValue ("ns", ns);
 
622
                        writer.WriteValue ("isroot", isroot);
 
623
                        writer.WriteValue ("name", name);
 
624
                        writer.WriteValue ("version", version);
 
625
                        writer.WriteValue ("compatVersion", compatVersion);
 
626
                        writer.WriteValue ("hasUserId", hasUserId);
 
627
                        writer.WriteValue ("author", author);
 
628
                        writer.WriteValue ("url", url);
 
629
                        writer.WriteValue ("copyright", copyright);
 
630
                        writer.WriteValue ("description", description);
 
631
                        writer.WriteValue ("category", category);
 
632
                        writer.WriteValue ("basePath", basePath);
 
633
                        writer.WriteValue ("sourceAddinFile", sourceAddinFile);
 
634
                        writer.WriteValue ("defaultEnabled", defaultEnabled);
 
635
                        writer.WriteValue ("MainModule", MainModule);
 
636
                        writer.WriteValue ("OptionalModules", OptionalModules);
 
637
                        writer.WriteValue ("NodeSets", ExtensionNodeSets);
 
638
                        writer.WriteValue ("ExtensionPoints", ExtensionPoints);
 
639
                        writer.WriteValue ("ConditionTypes", ConditionTypes);
 
640
                }
 
641
                
 
642
                void IBinaryXmlElement.Read (BinaryXmlReader reader)
 
643
                {
 
644
                        id = reader.ReadStringValue ("id");
 
645
                        ns = reader.ReadStringValue ("ns");
 
646
                        isroot = reader.ReadBooleanValue ("isroot");
 
647
                        name = reader.ReadStringValue ("name");
 
648
                        version = reader.ReadStringValue ("version");
 
649
                        compatVersion = reader.ReadStringValue ("compatVersion");
 
650
                        hasUserId = reader.ReadBooleanValue ("hasUserId");
 
651
                        author = reader.ReadStringValue ("author");
 
652
                        url = reader.ReadStringValue ("url");
 
653
                        copyright = reader.ReadStringValue ("copyright");
 
654
                        description = reader.ReadStringValue ("description");
 
655
                        category = reader.ReadStringValue ("category");
 
656
                        basePath = reader.ReadStringValue ("basePath");
 
657
                        sourceAddinFile = reader.ReadStringValue ("sourceAddinFile");
 
658
                        defaultEnabled = reader.ReadBooleanValue ("defaultEnabled");
 
659
                        mainModule = (ModuleDescription) reader.ReadValue ("MainModule");
 
660
                        optionalModules = (ModuleCollection) reader.ReadValue ("OptionalModules", new ModuleCollection (this));
 
661
                        nodeSets = (ExtensionNodeSetCollection) reader.ReadValue ("NodeSets", new ExtensionNodeSetCollection (this));
 
662
                        extensionPoints = (ExtensionPointCollection) reader.ReadValue ("ExtensionPoints", new ExtensionPointCollection (this));
 
663
                        conditionTypes = (ConditionTypeDescriptionCollection) reader.ReadValue ("ConditionTypes", new ConditionTypeDescriptionCollection (this));
 
664
                        
 
665
                        if (mainModule != null)
 
666
                                mainModule.SetParent (this);
 
667
                }
 
668
        }
 
669
}