aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Protobuf/CompilerFolderResult.cs
blob: 1b2f29151356bb45e096dd11f13b812be7d7e0fa (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
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Logging;

namespace Tango.Protobuf
{
    /// <summary>
    /// Represents an <see cref="IProtoCompiler"/> folder compilation result.
    /// </summary>
    /// <seealso cref="Tango.Protobuf.ICompilerResult" />
    public class CompilerFolderResult : ICompilerResult
    {
        private LogManager LogManager = LogManager.Default;

        /// <summary>
        /// Initializes a new instance of the <see cref="CompilerFolderResult"/> class.
        /// </summary>
        /// <param name="results">The results.</param>
        /// <param name="language">The language.</param>
        /// <param name="sourcePath">The source path.</param>
        /// <param name="relativePath">The relative path.</param>
        public CompilerFolderResult(IEnumerable<ICompilerResult> results, CompilerLanguage language, String sourcePath, String relativePath)
        {
            Results = results;
            Language = language;
            SourcePath = sourcePath;
            RelativePath = relativePath;
            Name = Path.GetFileName(sourcePath);
        }

        /// <summary>
        /// Gets the compiler results.
        /// </summary>
        public IEnumerable<ICompilerResult> Results { get; private set; }

        /// <summary>
        /// Gets the result language.
        /// </summary>
        public CompilerLanguage Language { get; private set; }

        /// <summary>
        /// Gets the result source path.
        /// </summary>
        public String SourcePath { get; private set; }

        /// <summary>
        /// Gets the result name.
        /// </summary>
        public String Name { get; private set; }

        /// <summary>
        /// Gets the result relative path.
        /// </summary>
        public String RelativePath { get; private set; }

        /// <summary>
        /// Saves the result to the specified folder.
        /// </summary>
        /// <param name="folder">The folder.</param>
        public void Save(string folder)
        {
            LogManager.Log("Saving " + folder + "...");

            foreach (var fileResult in Results.OfType<CompilerFileResult>())
            {
                fileResult.Save(folder);
            }

            foreach (var folderResult in Results.OfType<CompilerFolderResult>())
            {
                folderResult.Save(Path.Combine(folder, folderResult.RelativePath.TrimStart('\\','\\')));
            }
        }

        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            String output = Name + Environment.NewLine + ":";

            foreach (var fileResult in Results.OfType<CompilerFileResult>())
            {
                output += fileResult.ToString() + Environment.NewLine;
            }

            foreach (var folderResult in Results.OfType<CompilerFolderResult>())
            {
                output += folderResult.ToString() + Environment.NewLine;
            }

            return output;
        }
    }
}