~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/Core/Project/Src/AddInTree/AddIn/Manifest.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using System.Collections.ObjectModel;
 
7
using System.Xml;
 
8
 
 
9
namespace ICSharpCode.Core
 
10
{
 
11
        /// <summary>
 
12
        /// Stores information about the manifest of an AddIn.
 
13
        /// </summary>
 
14
        public class AddInManifest
 
15
        {
 
16
                List<AddInReference> dependencies = new List<AddInReference>();
 
17
                List<AddInReference> conflicts = new List<AddInReference>();
 
18
                Dictionary<string, Version> identities = new Dictionary<string, Version>();
 
19
                Version primaryVersion;
 
20
                string primaryIdentity;
 
21
                
 
22
                public string PrimaryIdentity {
 
23
                        get {
 
24
                                return primaryIdentity;
 
25
                        }
 
26
                }
 
27
                
 
28
                public Version PrimaryVersion {
 
29
                        get {
 
30
                                return primaryVersion;
 
31
                        }
 
32
                }
 
33
                
 
34
                public Dictionary<string, Version> Identities {
 
35
                        get {
 
36
                                return identities;
 
37
                        }
 
38
                }
 
39
                
 
40
                public ReadOnlyCollection<AddInReference> Dependencies {
 
41
                        get {
 
42
                                return dependencies.AsReadOnly();
 
43
                        }
 
44
                }
 
45
                
 
46
                public ReadOnlyCollection<AddInReference> Conflicts {
 
47
                        get {
 
48
                                return conflicts.AsReadOnly();
 
49
                        }
 
50
                }
 
51
                
 
52
                void AddIdentity(string name, string version, string hintPath)
 
53
                {
 
54
                        if (name.Length == 0)
 
55
                                throw new AddInLoadException("Identity needs a name");
 
56
                        foreach (char c in name) {
 
57
                                if (!char.IsLetterOrDigit(c) && c != '.' && c != '_') {
 
58
                                        throw new AddInLoadException("Identity name contains invalid character: '" + c + "'");
 
59
                                }
 
60
                        }
 
61
                        Version v = AddInReference.ParseVersion(version, hintPath);
 
62
                        if (primaryVersion == null) {
 
63
                                primaryVersion = v;
 
64
                        }
 
65
                        if (primaryIdentity == null) {
 
66
                                primaryIdentity = name;
 
67
                        }
 
68
                        identities.Add(name, v);
 
69
                }
 
70
                
 
71
                public void ReadManifestSection(XmlReader reader, string hintPath)
 
72
                {
 
73
                        if (reader.AttributeCount != 0) {
 
74
                                throw new AddInLoadException("Manifest node cannot have attributes.");
 
75
                        }
 
76
                        if (reader.IsEmptyElement) {
 
77
                                throw new AddInLoadException("Manifest node cannot be empty.");
 
78
                        }
 
79
                        while (reader.Read()) {
 
80
                                switch (reader.NodeType) {
 
81
                                        case XmlNodeType.EndElement:
 
82
                                                if (reader.LocalName == "Manifest") {
 
83
                                                        return;
 
84
                                                }
 
85
                                                break;
 
86
                                        case XmlNodeType.Element:
 
87
                                                string nodeName = reader.LocalName;
 
88
                                                Properties properties = Properties.ReadFromAttributes(reader);
 
89
                                                switch (nodeName) {
 
90
                                                        case "Identity":
 
91
                                                                AddIdentity(properties["name"], properties["version"], hintPath);
 
92
                                                                break;
 
93
                                                        case "Dependency":
 
94
                                                                dependencies.Add(AddInReference.Create(properties, hintPath));
 
95
                                                                break;
 
96
                                                        case "Conflict":
 
97
                                                                conflicts.Add(AddInReference.Create(properties, hintPath));
 
98
                                                                break;
 
99
                                                        default:
 
100
                                                                throw new AddInLoadException("Unknown node in Manifest section:" + nodeName);
 
101
                                                }
 
102
                                                break;
 
103
                                }
 
104
                        }
 
105
                }
 
106
        }
 
107
}