Skip to content

Commit 46c7f5c

Browse files
committed
Merge branch 'polydep-41' into 'development'
polydep-41 See merge request !5
2 parents 76b4c3a + 006dd80 commit 46c7f5c

File tree

7 files changed

+130
-83
lines changed

7 files changed

+130
-83
lines changed

DeployClient/API.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static void AddPackageAsync(string sessionGuid, Stream stream, string fil
9292
}
9393
}
9494

95-
public static bool Install(string sessionGuid, out Dictionary<string, dynamic> response)
95+
public static bool Install(string sessionGuid, out SortedList<string, dynamic> response)
9696
{
9797
string endpoint = string.Format("Remote/Install?sessionGuid={0}", sessionGuid);
9898

@@ -112,7 +112,7 @@ public static bool Install(string sessionGuid, out Dictionary<string, dynamic> r
112112
{
113113
success = true;
114114
string json = httpResponse.Content.ReadAsStringAsync().Result;
115-
response = jsonSer.Deserialize<Dictionary<string, dynamic>>(json);
115+
response = jsonSer.Deserialize<SortedList<string, dynamic>>(json);
116116
}
117117
}
118118
catch (Exception ex)

DeployClient/Program.cs

+40-15
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static void Main(string[] args)
145145
JavaScriptSerializer jsonSer = new JavaScriptSerializer();
146146

147147
// Start.
148-
Dictionary<string, dynamic> results = null;
148+
SortedList<string, dynamic> results = null;
149149

150150
if (!API.Install(sessionGuid, out results))
151151
{
@@ -172,19 +172,16 @@ static void Main(string[] args)
172172
if (response.ContainsKey("Response"))
173173
{
174174
// Yes, get the response.
175-
results = jsonSer.Deserialize<Dictionary<string, dynamic>>(response["Response"]);
175+
results = jsonSer.Deserialize<SortedList<string, dynamic>>(response["Response"]);
176176
}
177177

178178
// As long as we have something.
179179
if (status != -1 && results != null)
180-
{
181-
// Get the installed and failed lists.
182-
ArrayList installed = results.ContainsKey("Installed") ? results["Installed"] : null;
183-
ArrayList failed = results.ContainsKey("Failed") ? results["Failed"] : null;
184-
185-
// Give some feedback on it, only if it's changed.
186-
string print = string.Format("\t{0} module archives processed, {0}/{1} succeeded.", installed.Count + failed.Count, installed.Count);
180+
{
181+
// Build feedback.
182+
string print = BuildUpdateString(results);
187183

184+
// Same as previous feedback?
188185
if (print != previousPrint)
189186
{
190187
WriteLine(print);
@@ -204,15 +201,14 @@ static void Main(string[] args)
204201
}
205202
else
206203
{
207-
// Get the installed and failed lists.
208-
ArrayList installed = results.ContainsKey("Installed") ? results["Installed"] : null;
209-
ArrayList failed = results.ContainsKey("Failed") ? results["Failed"] : null;
204+
// Build feedback.
205+
string print = BuildUpdateString(results);
210206

211-
// Give some feedback on it.
212-
WriteLine(string.Format("\t{0} module archives processed, {0}/{1} succeeded.", installed.Count + failed.Count, installed.Count));
213-
207+
// Print feedback.
208+
WriteLine(print);
214209
}
215210

211+
// Finished install.
216212
WriteLine(string.Format("Finished installation in {0} ms.", (DateTime.Now - installStartTime).TotalMilliseconds));
217213
ReadLine();
218214
}
@@ -227,6 +223,35 @@ static void Main(string[] args)
227223
}
228224
}
229225

226+
private static string BuildUpdateString(SortedList<string, dynamic> results)
227+
{
228+
// Get counts.
229+
int attempted = 0;
230+
int succeeded = 0;
231+
int failed = 0;
232+
233+
foreach (KeyValuePair<string, dynamic> kvp in results)
234+
{
235+
Dictionary<string, dynamic> module = kvp.Value;
236+
237+
if (module.ContainsKey("Attempted") && (bool)module["Attempted"])
238+
{
239+
attempted++;
240+
241+
if (module.ContainsKey("Success") && (bool)module["Success"])
242+
{
243+
succeeded++;
244+
}
245+
else
246+
{
247+
failed++;
248+
}
249+
}
250+
}
251+
252+
return string.Format("\t{0}/{1} module archives processed, {2}/{0} succeeded.", attempted, results.Count, succeeded);
253+
}
254+
230255
private static void WriteException(Exception ex, int maxDepth = 10, int depth = 0)
231256
{
232257
WriteLine(ex.Message);

PolyDeploy/Clients/Core/src/js/services/SessionDataService.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
// Parse if we need to.
1818
if (data.Response) {
19-
data.Response = JSON.parse(data.Response);
19+
data.Response = parseSessionResponse(data.Response);
2020
} else {
2121
data.Response = undefined;
2222
}
@@ -38,7 +38,7 @@
3838

3939
// Parse if we need to.
4040
if (data.Response) {
41-
data.Response = JSON.parse(data.Response);
41+
data.Response = parseSessionResponse(data.Response);
4242
} else {
4343
data.Response = undefined;
4444
}
@@ -107,6 +107,28 @@
107107
$http.get(controllerUrl + 'Install?guid=' + guid);
108108
}
109109

110+
function parseSessionResponse(rawResponse) {
111+
112+
// Parse to json.
113+
var response = JSON.parse(rawResponse);
114+
115+
var newResponse = [];
116+
117+
// Tidy the response to make it easier to deal with.
118+
for (var key in response) {
119+
120+
var modulePackage = response[key];
121+
122+
modulePackage.Order = parseInt(key);
123+
124+
newResponse.push(modulePackage);
125+
}
126+
127+
console.log(newResponse);
128+
129+
return newResponse;
130+
}
131+
110132
return {
111133
create: create,
112134
get: get,

PolyDeploy/Clients/Deploy/src/js/controllers/ResultController.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,18 @@
3232
var response = session.Response;
3333

3434
// Get counts.
35-
var installed = response.Installed.length;
36-
var failed = response.Failed.length;
35+
var installed = 0;
36+
var failed = 0;
37+
38+
response.forEach(function (modPackage) {
39+
40+
// Attempted install?
41+
if (modPackage.Attempted) {
42+
43+
// Success?
44+
modPackage.Success ? installed++ : failed++;
45+
}
46+
});
3747

3848
// Create start of string.
3949
var installStatus = 'Installation ';
@@ -57,4 +67,22 @@
5767
return installStatus;
5868
};
5969

70+
// Get CSS class to apply to module panel.
71+
$scope.panelStatus = function (modPackage) {
72+
73+
// Default class.
74+
var panelClass = 'panel-default';
75+
76+
// Attempted install?
77+
if (modPackage.Attempted) {
78+
79+
// Success?
80+
panelClass = modPackage.Success ? 'panel-success' : 'panel-danger';
81+
}
82+
83+
console.log(panelClass);
84+
85+
return panelClass;
86+
};
87+
6088
}];

PolyDeploy/Clients/Deploy/src/js/templates/result.html

+14-37
Original file line numberDiff line numberDiff line change
@@ -21,59 +21,36 @@ <h4>{{ currentStatus(session) }}</h4>
2121

2222
<div class="row">
2323

24-
<!-- Installed -->
25-
<div class="col-xs-12 col-md-6">
26-
<div class="panel panel-success">
24+
<!-- Packages -->
25+
<div ng-repeat="packageZip in session.Response" class="col-xs-12 col-md-6">
26+
<div class="panel" ng-class="panelStatus(packageZip)">
2727
<div class="panel-heading">
28-
<h4 class="panel-title">Installed</h4>
28+
<h4 class="panel-title">{{ packageZip.Name }}</h4>
2929
</div>
3030
<div class="panel-body">
31-
<div class="module-info" ng-repeat="module in session.Response.Installed">
32-
<h4>{{ module.Name }}</h4>
31+
<div class="module-info">
32+
3333
<h5>Packages</h5>
34-
<div ng-repeat="package in module.Packages">
34+
<div ng-repeat="package in packageZip.Packages">
3535
<ul class="package-info">
3636
<li><strong>Name:</strong> {{ package.Name }}</li>
3737
<li><strong>Version:</strong> {{ package.VersionStr }}</li>
3838
</ul>
3939
</div>
40-
<hr />
41-
</div>
42-
</div>
43-
</div>
44-
</div>
45-
<!-- /Installed -->
4640

47-
<!-- Failures -->
48-
<div class="col-xs-12 col-md-6">
49-
<div class="panel panel-danger">
50-
<div class="panel-heading">
51-
<h4 class="panel-title">Failures</h4>
52-
</div>
53-
<div class="panel-body">
54-
<div class="module-info" ng-repeat="module in session.Response.Failed">
55-
56-
<h5>Packages</h5>
57-
<div ng-repeat="package in module.Packages">
58-
<ul class="package-info">
59-
<li><strong>Name:</strong> {{ package.Name }}</li>
60-
<li><strong>Version:</strong> {{ package.VersionStr }}</li>
41+
<div ng-show="packageZip.Failures && packageZip.Failures.length > 0">
42+
<h5>Failures</h5>
43+
<ul>
44+
<li ng-repeat="failure in packageZip.Failures">
45+
{{ failure }}
46+
</li>
6147
</ul>
6248
</div>
63-
64-
<h5>Failures</h5>
65-
<ul>
66-
<li ng-repeat="failure in module.Failures">
67-
{{ failure }}
68-
</li>
69-
</ul>
70-
<hr />
71-
7249
</div>
7350
</div>
7451
</div>
7552
</div>
76-
<!-- /Failures -->
53+
<!-- /Packages -->
7754

7855
</div>
7956

PolyDeploy/Components/Deployment.cs

+11-19
Original file line numberDiff line numberDiff line change
@@ -66,46 +66,38 @@ public SortedList<int, InstallJob> Summary()
6666
public void Deploy()
6767
{
6868
// Do the install.
69-
List<InstallJob> successJobs = new List<InstallJob>();
70-
List<InstallJob> failedJobs = new List<InstallJob>();
71-
72-
Dictionary<string, List<InstallJob>> results = new Dictionary<string, List<InstallJob>>();
73-
74-
results.Add("Installed", successJobs);
75-
results.Add("Failed", failedJobs);
76-
7769
JavaScriptSerializer jsonSer = new JavaScriptSerializer();
7870
SessionDataController dc = new SessionDataController();
7971

8072
// Set as started.
8173
Session.Status = SessionStatus.InProgess;
8274
dc.Update(Session);
8375

76+
// Install in order.
8477
foreach (KeyValuePair<int, InstallJob> keyPair in OrderedInstall)
8578
{
79+
// Get install job.
8680
InstallJob job = keyPair.Value;
8781

88-
if (job.Install())
89-
{
90-
successJobs.Add(job);
91-
}
92-
else
82+
// Attempt install.
83+
job.Install();
84+
85+
// Make sorted list serialisable.
86+
SortedList<string, InstallJob> serOrderedInstall = new SortedList<string, InstallJob>();
87+
88+
foreach(KeyValuePair<int, InstallJob> pair in OrderedInstall)
9389
{
94-
failedJobs.Add(job);
90+
serOrderedInstall.Add(pair.Key.ToString(), pair.Value);
9591
}
9692

9793
// After each install job, update response.
98-
Session.Response = jsonSer.Serialize(results);
94+
Session.Response = jsonSer.Serialize(serOrderedInstall);
9995
dc.Update(Session);
10096
}
10197

10298
// Done.
10399
Session.Status = SessionStatus.Complete;
104100
dc.Update(Session);
105-
106-
// Log failures.
107-
LogAnyFailures(successJobs);
108-
LogAnyFailures(failedJobs);
109101
}
110102

111103
protected virtual void LogAnyFailures(List<InstallJob> jobs)

PolyDeploy/Components/InstallJob.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ internal class InstallJob
1313
public string Name { get; set; }
1414
public List<PackageJob> Packages { get; set; }
1515
public List<string> Failures { get; set; }
16+
public bool Attempted { get; set; }
17+
public bool Success { get; set; }
1618

1719
public bool CanInstall
1820
{
@@ -37,6 +39,8 @@ public InstallJob(string path)
3739
Name = Path.GetFileName(path);
3840
Packages = new List<PackageJob>();
3941
Failures = new List<string>();
42+
Attempted = false;
43+
Success = false;
4044
Installer = new Installer(new FileStream(path, FileMode.Open, FileAccess.Read), Globals.ApplicationMapPath, true, false);
4145

4246
foreach (KeyValuePair<int, PackageInstaller> orderedPackage in Installer.Packages)
@@ -62,14 +66,15 @@ public void CheckDependencies(List<PackageJob> packageJobs)
6266
}
6367
}
6468

65-
public bool Install()
69+
public void Install()
6670
{
67-
bool installSuccess = false;
71+
// Record that we have attempted an install.
72+
Attempted = true;
6873

6974
// Can this be installed at this point?
7075
if (CanInstall)
7176
{
72-
// Possibly need to recreate the installer at the point.
77+
// Possibly need to recreate the installer at this point.
7378
Installer = new Installer(Installer.TempInstallFolder, ModuleManifestName(Installer.TempInstallFolder), Globals.ApplicationMapPath, true);
7479

7580
// Is the installer valid?
@@ -86,7 +91,7 @@ public bool Install()
8691
Installer.Install();
8792

8893
// Did the package install successfully?
89-
installSuccess = Installer.IsValid;
94+
Success = Installer.IsValid;
9095
}
9196

9297
// Record failures.
@@ -100,8 +105,6 @@ public bool Install()
100105
}
101106
}
102107
}
103-
104-
return installSuccess;
105108
}
106109

107110
private bool FindDependency(string name, List<PackageJob> packageJobs)

0 commit comments

Comments
 (0)