-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSASBuildTask.cs
88 lines (76 loc) · 2.87 KB
/
SSASBuildTask.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.AnalysisServices;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using SsasHelper;
namespace SsasBuilder
{
/// <summary>
/// MSBuild task to create a .ASDatabase file from a Visual Studio SSAS project.
/// The task will de-serialize the project, validate it against a Server Edition,
/// and create the .ASDatabase file if the project is validated successfully.
/// </summary>
public class SsasBuildASDatabaseFileTask : Task
{
#region Public Properties
/// <summary>
/// SSAS Project File to de-serialize and compile.
/// </summary>
[Required]
public string SsasProjectFile { get; set; }
/// <summary>
/// Name and location of the .ASDatabase file to write.
/// </summary>
[Required]
public string SsasTargetFile { get; set; }
/// <summary>
/// Server Edition of the target server. Required for accurate validation of the project.
/// Enterprise, Developer, Standard
/// </summary>
[Required]
public string SsasServerEdition { get; set; }
#endregion
#region Public Methods
public override bool Execute()
{
Log.LogMessage(MessageImportance.Normal, "Project File : {0}", SsasProjectFile);
Log.LogMessage(MessageImportance.Normal, "Target File : {0}", SsasTargetFile);
Log.LogMessage(MessageImportance.Normal, "Server Edition: {0}", SsasServerEdition);
// Validate Project File Exists
if (!File.Exists(SsasProjectFile))
{
throw new FileNotFoundException(string.Format("'{0}' does not exist.", SsasProjectFile));
}
try
{
Database database = ProjectHelper.DeserializeProject(SsasProjectFile);
// ... Verify our project doesn't have any errors ...
ValidationResultCollection results;
bool isValidated = ProjectHelper.ValidateDatabase(database, SsasServerEdition, out results);
// If the database doesn't validate (i.e., a build error)
// log the errors and return failure.
foreach (ValidationResult result in results)
{
Log.LogError(result.Description);
}
if (!isValidated)
{
return false;
}
// Build the .ASDatabase file
ProjectHelper.GenerateASDatabaseFile(database, SsasTargetFile);
}
catch (Exception ex)
{
Log.LogErrorFromException(ex);
return false;
}
return true;
}
#endregion
}
}