-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
270 lines (238 loc) · 8.79 KB
/
Form1.cs
File metadata and controls
270 lines (238 loc) · 8.79 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
using ReportDeploy.ReportService;
namespace ReportDeploy
{
public partial class Form1 : Form
{
public static DeployModel Model;
public Form1()
{
InitializeComponent();
Model = GetDeployList();
CheckForIllegalCrossThreadCalls = false;
}
private void btnSelectFile_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtConsole.AppendText("Currently Choose Deploy Report:\r\n");
foreach (string fileName in openFileDialog1.SafeFileNames)
{
txtConsole.AppendText(fileName);
txtConsole.AppendText("\r\n");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < Model.Corps.Count; i++)
{
Corp corp = Model.Corps[i];
var checkBox = new CheckBox();
checkBox.AutoSize = true;
//checkBox.Width = 130;
//checkBox.Name = corp.CorpName;
checkBox.Text = corp.CorpName;
checkBox.Location = new Point(i/15*150 + 10, i%15*25 + 20);
groupBox1.Controls.Add(checkBox);
}
}
private DeployModel GetDeployList()
{
DeployModel model;
try
{
var serializer = new XmlSerializer(typeof (DeployModel));
using (Stream stream = new FileStream(Environment.CurrentDirectory + "\\Corp.xml", FileMode.Open))
{
model = serializer.Deserialize(stream) as DeployModel;
}
}
catch (Exception exception)
{
throw;
}
return model;
}
private void checkAll_CheckedChanged(object sender, EventArgs e)
{
if (checkAll.Checked)
{
foreach (object control in groupBox1.Controls)
{
if (control is CheckBox)
{
(control as CheckBox).Checked = true;
}
}
}
else
{
foreach (object control in groupBox1.Controls)
{
if (control is CheckBox)
{
(control as CheckBox).Checked = false;
}
}
}
}
private void btnDeploy_Click(object sender, EventArgs e)
{
if (!(radioTest.Checked || radioTrue.Checked))
{
MessageBox.Show("Please Choose test Oractual", "Tip");
return;
}
List<CheckBox> checkBoxs = GetCheckedBox();
if (checkBoxs.Count <= 0)
{
MessageBox.Show("Please Choose Deploy Corp", "Tip");
return;
}
if (!openFileDialog1.FileNames.Any())
{
MessageBox.Show("Please Choose Deploy Report Files", "Tip");
return;
}
//try
//{
//}
//catch (Exception exception)
//{
// txtConsole.Select(txtConsole.TextLength,);
//}
new TaskFactory().StartNew(RunsOnWorkerThread);
}
private void RunsOnWorkerThread()
{
try
{
btnSelectFile.Enabled = false;
btnDeploy.Enabled = false;
Deploy();
btnSelectFile.Enabled = true;
btnDeploy.Enabled = true;
}
catch (Exception exception)
{
btnDeploy.Enabled = true;
WriteError(exception.Message + "\r\n" + exception.StackTrace);
}
//new Action(Deploy).Invoke();
}
private void Deploy()
{
var failure = new Dictionary<string, List<string>>();
List<CheckBox> checkBoxs = GetCheckedBox();
var reporting = new ReportingService2010();
if (radioTest.Checked)
{
Server server = Model.Servers.FirstOrDefault(a => a.ServerName == "test");
reporting.Url = server.ServerUrl;
reporting.Credentials = new NetworkCredential(server.UserName, server.Password);
}
txtConsole.AppendText("\r\n");
List<Corp> corps =
checkBoxs.Select(checkBox => Model.Corps.First(a => a.CorpName == checkBox.Text)).ToList();
foreach (Corp corp in corps)
{
txtConsole.AppendText("Begin DeployCorp:" + corp.CorpName + "\r\n");
if (radioTrue.Checked)
{
Server server = Model.Servers.FirstOrDefault(a => a.ServerName == corp.ServerName);
reporting.Url = server.ServerUrl;
reporting.Credentials = new NetworkCredential(server.UserName, server.Password);
}
string itemParentPath = corp.DefaultPath;
var list = new List<string>();
foreach (string file in openFileDialog1.FileNames)
{
byte[] fileBytes = File.ReadAllBytes(file);
string fileFullName = Path.GetFileName(file);
string fileExtension = Path.GetExtension(fileFullName);
string fileName = fileFullName.Substring(0, fileFullName.Length - fileExtension.Length);
//var fileName = file.Substring(file.LastIndexOf("\\"), file.LastIndexOf(".") - file.LastIndexOf("\\"));
//txtConsole.AppendText("Begin DeployReport:" + fileFullName + "\r\n");
Property[] properties = null;
Warning[] warnings = null;
try
{
reporting.CreateCatalogItem("Report", fileName, itemParentPath, true, fileBytes, properties,
out warnings);
txtConsole.AppendText(fileFullName + "Deploy Finish\r\n");
}
catch (Exception exception)
{
WriteError(fileFullName + "Deploy Error:" + exception.Message);
list.Add(fileFullName);
}
//Warning[] warnings= reporting.SetItemDefinition(itemPath, fileBytes, properties);
//if (warnings != null)
//{
// var sb = new StringBuilder();
// sb.AppendLine("Warning:");
// foreach (var warning in warnings)
// {
// sb.AppendLine(warning.Message);
// }
// WriteError(sb.ToString());
//}
}
txtConsole.AppendText(corp.CorpName + "Deploy Finish\r\n\r\n");
if (list.Count > 0)
{
failure.Add(corp.CorpName, list);
}
}
if (failure.Count > 0)
{
var sb = new StringBuilder();
sb.AppendLine("Current Deploy Error Report:");
foreach (var f in failure)
{
sb.AppendLine(f.Key);
foreach (string report in f.Value)
{
sb.AppendLine(report);
}
sb.AppendLine();
}
WriteError(sb.ToString());
}
}
private void WriteError(string error)
{
int oldLength = txtConsole.TextLength;
txtConsole.AppendText(error + "\r\n");
txtConsole.Select(oldLength, error.Length);
txtConsole.SelectionColor = Color.Red;
}
private List<CheckBox> GetCheckedBox()
{
var checkBoxs = new List<CheckBox>();
foreach (object control in groupBox1.Controls)
{
var con = control as CheckBox;
if (con != null && con.Checked)
{
checkBoxs.Add(con);
}
}
return checkBoxs;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtConsole.ResetText();
}
}
}