aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Prebuild/src/Core/Nodes/DatabaseProjectNode.cs
blob: 278ecd81ce9f74655fe5c4e532849faf2aafebbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

using Prebuild.Core.Attributes;
using Prebuild.Core.Interfaces;
using Prebuild.Core.Utilities;

namespace Prebuild.Core.Nodes
{
    [DataNode("DatabaseProject")]
    public class DatabaseProjectNode : DataNode
    {
        string name;
        string path;
        string fullpath;
        Guid guid = Guid.NewGuid();
        readonly List<AuthorNode> authors = new List<AuthorNode>();
        readonly List<DatabaseReferenceNode> references = new List<DatabaseReferenceNode>();

        public Guid Guid
        {
            get { return guid; }
        }

        public string Name
        {
            get { return name; }
        }

        public string Path
        {
            get { return path; }
        }

        public string FullPath
        {
            get { return fullpath; }
        }

        public IEnumerable<DatabaseReferenceNode> References
        {
            get { return references; }
        }

        public override void Parse(XmlNode node)
        {
            name = Helper.AttributeValue(node, "name", name);
            path = Helper.AttributeValue(node, "path", name);

            try
            {
                fullpath = Helper.ResolvePath(path);
            }
            catch
            {
                throw new WarningException("Could not resolve Solution path: {0}", path);
            }

            Kernel.Instance.CurrentWorkingDirectory.Push();

            try
            {
                Helper.SetCurrentDir(fullpath);

                if (node == null)
                {
                    throw new ArgumentNullException("node");
                }

                foreach (XmlNode child in node.ChildNodes)
                {
                    IDataNode dataNode = Kernel.Instance.ParseNode(child, this);

                    if (dataNode == null)
                        continue;

                    if (dataNode is AuthorNode)
                        authors.Add((AuthorNode)dataNode);
                    else if (dataNode is DatabaseReferenceNode)
                        references.Add((DatabaseReferenceNode)dataNode);
                }
            }
            finally
            {
                Kernel.Instance.CurrentWorkingDirectory.Pop();
            }

            base.Parse(node);
        }
    }
}