-
Notifications
You must be signed in to change notification settings - Fork 9
/
Program.cs
162 lines (135 loc) · 6.18 KB
/
Program.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Configuration.IO;
using Common;
using Microsoft.EnterpriseManagement.Packaging;
namespace MPViewer
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
if (args.Length == 1)
{
if (args[0].Length > 0)
{
if (args[0].Equals("--help", StringComparison.InvariantCultureIgnoreCase))
{
MessageBox.Show("Command line usage examples: \n MPViewer.exe c:\\Microsoft.Windows.Server.2003.mp c:\\win2003.html AlertGeneratingWorkflowsOnly \n MPViewer.exe c:\\Microsoft.Windows.Server.2003.mp c:\\win2003.html \n MPViewer.exe c:\\Microsoft.Windows.Server.2003.mp c:\\win2003.xls", "MPViewer Help");
return;
}
else
{
MessageBox.Show("Unsupported number of arguments or format. Launching MPViewer.exe with no parameters will bring up the UI, or use MPViewer.exe --help to get help on the implemented command line options.");
return;
}
}
}
// gotta love the undocumented command line usage for bulk HTML export... only works for MPs at this point, not MPBs
// TODO - refactor so only one piece of code is used to load the MP/MPB, rather than this duplicate logic...
if (args.Length >= 2)
{
try
{
if (args[0].Length == 0)
{
throw new ApplicationException("Invalid management pack file path");
}
if (args[1].Length == 0)
{
throw new ApplicationException("Invalid file path");
}
//HTML output desired
if ((args[1].EndsWith(".html", StringComparison.InvariantCultureIgnoreCase)) || (args[1].EndsWith(".htm", StringComparison.InvariantCultureIgnoreCase)))
{
GenerateHTMLForMP(args);
}
//Excel output desired
if ((args[1].EndsWith(".xls", StringComparison.InvariantCultureIgnoreCase)) || (args[1].EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase)))
{
GenerateExcelForMP(args);
}
}
catch(Exception exception)
{
//Console.WriteLine(exception.Message);
MessageBox.Show(exception.Message);
}
}
// load the GUI - standard execution path
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MPViewer());
}
}
private static ManagementPack LoadManagementPack(string[] args)
{
ManagementPackBundle bundle;
ManagementPackFileStore store = Utilities.GetManagementPackStoreFromPath(args[0]);
ManagementPack mp;
if (System.IO.Path.GetExtension(args[0]).Equals(".mpb"))
{
ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
bundle = reader.Read(args[0], store);
// 1 at the time is ok
if (bundle.ManagementPacks.Count == 1)
{
mp = bundle.ManagementPacks[0];
return mp;
}
else
{
// too many MPs contained in this MPB! - can onlhy open one at the time!
// do something sensible here
throw new ApplicationException("This MPB contains multiple MPs. " +
"In an upcoming version a dialog will open, asking you to choose which one you want to see. " +
"For now, we just are going to crash.");
}
}
else // we are dealing with an MP or XML - the old stuff works as it did for 2007
{
mp = new ManagementPack(args[0], store);
return mp;
}
}
private static void GenerateHTMLForMP(string[] args)
{
try
{
bool exportAlertGeneratingWorkflowsOnly = false;
ManagementPack mp = LoadManagementPack(args);
DatasetCreator datasetCreator = new DatasetCreator(mp);
ReportGenerator reportGenerator = new ReportGenerator(datasetCreator.Dataset,mp);
exportAlertGeneratingWorkflowsOnly = (args.Length == 3 && string.Compare(args[2],"AlertGeneratingWorkflowsOnly",true) == 0);
reportGenerator.GenerateHTMLReport(args[1], exportAlertGeneratingWorkflowsOnly);
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
private static void GenerateExcelForMP(string[] args)
{
try
{
bool exportAlertGeneratingWorkflowsOnly = false;
ManagementPack mp = LoadManagementPack(args);
DatasetCreator datasetCreator = new DatasetCreator(mp);
ReportGenerator reportGenerator = new ReportGenerator(datasetCreator.Dataset, mp);
exportAlertGeneratingWorkflowsOnly = (args.Length == 3 && string.Compare(args[2], "AlertGeneratingWorkflowsOnly", true) == 0);
if (exportAlertGeneratingWorkflowsOnly)
Console.WriteLine("AlertGeneratingWorkflowsOnly command line switch doesn't work with Excel export, only HTML.");
reportGenerator.GenerateExcelReport(args[1]);
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
}
}
}