-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathBenchmark.aspx
More file actions
848 lines (728 loc) · 35.1 KB
/
Copy pathBenchmark.aspx
File metadata and controls
848 lines (728 loc) · 35.1 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
<%@ Page Title="" Async="true" Language="C#" MasterPageFile="~/masterPage1.Master" AutoEventWireup="true" CodeBehind="Benchmark.aspx.cs" Inherits="System.pages.Benchmark" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style>
.divconfig textarea {
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
width: 800px;
height: 40px;
}
.maintb tr td:first-child {
text-align: right;
}
.progress-container {
width: 100%;
height: 30px;
background-color: #e0e0e0;
border-radius: 15px;
overflow: hidden;
margin-bottom: 20px;
}
.progress-bar {
height: 100%;
background-color: #4CAF50;
width: 0%;
transition: width 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
}
.main-info {
background-color: #f9f9f9;
padding: 15px;
border-radius: 5px;
margin-bottom: 20px;
}
.main-info div {
margin: 8px 0;
}
.main-info label {
font-weight: bold;
display: inline-block;
width: 120px;
}
.stage-section {
margin: 20px 0;
border-top: 2px solid #e0e0e0;
padding-top: 15px;
}
.stage-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 15px;
color: #333;
}
.rounds-container {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.round-block {
flex: 1;
min-width: 280px;
border: 1px solid #ddd;
border-radius: 5px;
padding: 15px;
transition: all 0.3s ease;
}
.round-block.pending {
background-color: #f5f5f5;
border-color: #ccc;
}
.round-block.started {
background-color: #e3f2fd;
border-color: #2196F3;
}
.round-block.completed {
background-color: #e8f5e9;
border-color: #4CAF50;
}
.round-block.error {
background-color: #ffebee;
border-color: #f44336;
}
.round-title {
font-weight: bold;
margin-bottom: 10px;
font-size: 16px;
}
.round-info div {
margin: 5px 0;
font-size: 14px;
}
.round-info label {
font-weight: 600;
display: inline-block;
width: 100px;
color: #666;
}
.error-message {
color: #d32f2f;
margin-top: 10px;
padding: 10px;
background-color: #ffebee;
border-radius: 4px;
display: none;
}
.error-message.show {
display: block;
}
.status-indicator {
display: inline-block;
padding: 2px 8px;
border-radius: 3px;
font-size: 12px;
font-weight: bold;
}
.status-indicator.pending {
background-color: #e0e0e0;
color: #666;
}
.status-indicator.started {
background-color: #2196F3;
color: white;
}
.status-indicator.completed {
background-color: #4CAF50;
color: white;
}
.status-indicator.error {
background-color: #f44336;
color: white;
font-weight: bold;
}
.error-banner {
animation: slideDown 0.3s ease-out;
}
@keyframes slideDown {
from {
opacity: 0;
transform: translateY(-20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.error-message.show {
color: #f44336;
font-weight: bold;
margin-top: 10px;
}
.remarks-section {
margin-top: 30px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
padding: 20px;
}
.remarks-title {
font-size: 18px;
font-weight: bold;
margin-bottom: 15px;
color: #333;
border-bottom: 2px solid #4CAF50;
padding-bottom: 10px;
}
.remarks-content {
background-color: #f5f5f5;
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 15px;
margin: 0;
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
font-size: 12px;
line-height: 1.5;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
max-height: 400px;
overflow-y: auto;
}
/* Scrollbar styling for the remarks */
.remarks-content::-webkit-scrollbar {
width: 8px;
height: 8px;
}
.remarks-content::-webkit-scrollbar-track {
background: #f1f1f1;
}
.remarks-content::-webkit-scrollbar-thumb {
background: #888;
border-radius: 4px;
}
.remarks-content::-webkit-scrollbar-thumb:hover {
background: #555;
}
ul ul {
list-style-type: "-";
padding-left: 20px; /* Controls indentation distance */
}
ul ul li {
padding-left: 10px; /* Controls distance between symbol and text */
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="div-center-framed-content">
<asp:Panel ID="panelSetup" runat="server">
<h1>Benchmark</h1>
Performance test and comparison of Backup and Restore using MySqlBackup.NET, MySqlDump, and MySQL (instance).
<br />
Notes:
<ul>
<li>Running this test in the Visual Studio IDE debugging environment will slow down the process by 2-4 times.</li>
<li>For optimum speed, build this project with the [Release] profile and publish it to a folder. Use Windows IIS to run this ASP.NET app.</li>
<li>Executing mysqldump.exe and mysql.exe in ASP.NET:
<ul>
<li><strong>Local Windows 10/11 IIS:</strong> Works with default ApplicationPoolIdentity (no privilege changes needed).</li>
<li><strong>Shared Web Hosting:</strong> Executable restrictions prevent running mysql.exe and mysqldump.exe.</li>
<li><strong>Self-owned Windows Server/VPS:</strong> May (may not) require granting file system permissions to ApplicationPoolIdentity or changing to a custom account with MySQL access.</li>
</ul>
</li>
</ul>
<hr />
Please manually enter the file path of the following instance:
<table class="maintb divconfig">
<tr>
<td style="padding-top: 10px; padding-bottom: 0; vertical-align: top;">Initial Schema</td>
<td>
<asp:TextBox ID="txtInitialSchema" runat="server" Width="200px"></asp:TextBox><br />
*This database is expected to have already been populated with rows of data.
</td>
</tr>
<tr>
<td style="padding-top: 10px; padding-bottom: 0; vertical-align: top;">MySqlDump</td>
<td>
<asp:TextBox ID="txtFilePathMySqlDump" runat="server" Width="800px"></asp:TextBox><br />
*The executable file path of mysqldump.exe
</td>
</tr>
<tr>
<td style="padding-top: 10px; padding-bottom: 0; vertical-align: top;">MySql</td>
<td>
<asp:TextBox ID="txtFilePathMySql" runat="server" Width="800px"></asp:TextBox><br />
*The executable file path of mysql.exe
</td>
</tr>
<tr>
<td style="padding-top: 10px; padding-bottom: 0; vertical-align: top;">Output Folder</td>
<td>
<asp:TextBox ID="txtOutputFolder" runat="server" TextMode="MultiLine"></asp:TextBox><br />
*Destination folder of exported dump files
</td>
</tr>
<tr>
<td style="padding-top: 10px; padding-bottom: 0; vertical-align: top;">Report File</td>
<td>
<asp:TextBox ID="txtReportFilePath" runat="server" TextMode="MultiLine"></asp:TextBox><br />
*Full file path location for saving the report
</td>
</tr>
<tr>
<td></td>
<td>
<div style="border: 1px solid #71c668;">
<div style="border-bottom: 1px solid #71c668; padding: 10px; background: #ecf6ff;">
Select mysql.exe Instance Execution Method:
</div>
<div style="padding: 10px; line-height: 300%;">
<asp:CheckBox ID="cbMySqlInstanceExecuteDirect" runat="server" ClientIDMode="Static" Checked="true" Style="vertical-align: middle;" />
<label for="cbMySqlInstanceExecuteDirect" style="vertical-align: middle;">Execute mysql.exe directly with SOURCE command</label>
<br />
<asp:CheckBox ID="cbMySqlInstanceExecuteCmdShell" runat="server" ClientIDMode="Static" Style="vertical-align: middle;" />
<label for="cbMySqlInstanceExecuteCmdShell" style="vertical-align: middle;">Execute mysql.exe through CMD shell with file redirection ( < )</label>
<script>
const directCheckbox = document.getElementById('cbMySqlInstanceExecuteDirect');
const cmdShellCheckbox = document.getElementById('cbMySqlInstanceExecuteCmdShell');
directCheckbox.addEventListener('change', function () {
if (this.checked) {
cmdShellCheckbox.checked = false;
}
});
cmdShellCheckbox.addEventListener('change', function () {
if (this.checked) {
directCheckbox.checked = false;
}
});
</script>
</div>
</div>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:TextBox ID="txtTotalRound" runat="server" TextMode="Number" Width="40px" Text="3" min="1" max="3"></asp:TextBox>
Total round for each stage (min: 1, max: 3)</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbGetSystemInfo" runat="server" Checked="true" />
Get System Info</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbRunStage1" runat="server" Checked="true" />
Run Stage 1: Backup/Export - MySqlBackup.NET - Single Thread</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbRunStage2" runat="server" Checked="true" />
Run Stage 2: Backup/Export - MySqlBackup.NET - Parallel Processing</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbRunStage3" runat="server" Checked="true" />
Run Stage 3: Backup/Export - MySqlDump.exe</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbRunStage4" runat="server" Checked="true" />
Run Stage 4: Restore/Import - MySqlBackup.NET - Single Thread</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbRunStage5" runat="server" Checked="true" />
Run Stage 5: Restore/Import - MySqlBackup.NET - Parallel Processing</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbRunStage6" runat="server" Checked="true" />
Run Stage 6: Restore/Import - mysql.exe</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbCleanDatabaseAfterUse" runat="server" Checked="true" />
Clean Up Database After Use</td>
</tr>
<tr>
<td></td>
<td>
<asp:CheckBox ID="cbDeleteDumpFile" runat="server" Checked="true" />
Delete dump file immediately after each process. Note: The first dump file must be kept for the import test</td>
</tr>
</table>
<div style="height: 10px;"></div>
<asp:Button ID="btRun" runat="server" ClientIDMode="Static" Text="Begin Performance Benchmark Test" OnClick="btRun_Click" OnClientClick="hideButton(this);" />
</asp:Panel>
<asp:Panel ID="panelResult" runat="server" Visible="false">
<div id="div-benchmark-report"></div>
<asp:Literal ID="literalTaskId" runat="server"></asp:Literal>
<script>
let intervalId = null;
let totalRounds = 3; // Default value, will be updated from backend data
const stageNames = {
1: "Export/Backup - MySqlBackup.NET",
2: "Export/Backup - MySqlBackup.NET - Parallel Processing",
3: "Export/Backup - MySqlDump (mysqldump.exe)",
4: "Import/Restore - MySqlBackup.NET",
5: "Import/Restore - MySqlBackup.NET - Parallel Processing",
6: "Import/Restore - MySql (mysql.exe) Instance"
};
function getActiveStages(pr) {
const activeStages = [];
if (pr.dicStageInfo) {
for (let stageId in pr.dicStageInfo) {
const stage = pr.dicStageInfo[stageId];
if (stage.RunStage) {
activeStages.push(parseInt(stageId));
}
}
}
return activeStages.sort();
}
function getTotalRoundsFromTasks(pr) {
// Determine total rounds from the actual tasks
let maxRound = 0;
if (pr.dicTask) {
for (let taskId in pr.dicTask) {
const task = pr.dicTask[taskId];
if (task.ActiveTask && task.Round > maxRound) {
maxRound = task.Round;
}
}
}
return maxRound > 0 ? maxRound : 3; // Default to 3 if no tasks found
}
function drawUI() {
const container = document.getElementById('div-benchmark-report');
let html = `
<h1>Benchmark Results</h1>
<div class="progress-container">
<div class="progress-bar" id="main-progress-bar">0%</div>
</div>
<div class="main-info">
<div><label>Task ID:</label> <span id="span-main-taskid">${taskid}</span></div>
<div><label>Status:</label> <span id="span-main-status" class="status-indicator pending">Pending</span></div>
<div><label>Time Start:</label> <span id="span-main-TimeStart">-</span></div>
<div><label>Time End:</label> <span id="span-main-TimeEnd">-</span></div>
<div><label>Time Used:</label> <span id="span-main-TimeUsed">-</span></div>
<div><label>Has Error:</label> <span id="span-main-HasError">No</span></div>
<div class="error-message" id="main-error-message"></div>
</div>
<div id="stages-container">
<!-- Stages will be dynamically added here -->
</div>
<div class="remarks-section">
<div class="remarks-title">Process Logs</div>
<pre id="span-main-Remarks" class="remarks-content">Waiting for process to start...</pre>
</div>
`;
container.innerHTML = html;
}
function updateStagesUI(activeStages, totalRounds) {
const stagesContainer = document.getElementById('stages-container');
let html = '';
for (let stage of activeStages) {
html += `
<div class="stage-section" id="stage-section-${stage}">
<div class="stage-title">Stage ${stage}: ${stageNames[stage]}</div>
<div class="rounds-container">
`;
// Create rounds based on actual totalRounds
for (let round = 1; round <= totalRounds; round++) {
html += `
<div class="round-block pending" id="block-${stage}-${round}">
<div class="round-title">Round ${round}</div>
<div class="round-info">
<div><label>Status:</label> <span id="span-${stage}-${round}-status" class="status-indicator pending">Pending</span></div>
<div><label>Time Start:</label> <span id="span-${stage}-${round}-TimeStart">-</span></div>
<div><label>Time End:</label> <span id="span-${stage}-${round}-TimeEnd">-</span></div>
<div><label>Time Used:</label> <span id="span-${stage}-${round}-TimeUsed">-</span></div>
<div><label>Has Error:</label> <span id="span-${stage}-${round}-HasError">No</span></div>
<div class="error-message" id="error-${stage}-${round}"></div>
</div>
</div>
`;
}
html += `
</div>
</div>
`;
}
stagesContainer.innerHTML = html;
}
function updateProgress(pr) {
const activeStages = getActiveStages(pr);
const actualTotalRounds = getTotalRoundsFromTasks(pr);
const totalTasks = activeStages.length * actualTotalRounds;
let completedTasks = 0;
// Count completed tasks for active stages only
if (pr.dicTask) {
for (let taskId in pr.dicTask) {
const task = pr.dicTask[taskId];
if (task.ActiveTask && task.Completed && activeStages.includes(task.Stage)) {
completedTasks++;
}
}
}
const percentage = totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0;
const progressBar = document.getElementById('main-progress-bar');
if (progressBar) {
progressBar.style.width = percentage + '%';
progressBar.textContent = percentage + '%';
}
}
function fillValues(pr) {
const activeStages = getActiveStages(pr);
const actualTotalRounds = getTotalRoundsFromTasks(pr);
// Update totalRounds if it has changed
if (totalRounds !== actualTotalRounds) {
totalRounds = actualTotalRounds;
}
// Update stages UI if not already done or if stages/rounds changed
const stagesContainer = document.getElementById('stages-container');
if (stagesContainer.children.length === 0) {
updateStagesUI(activeStages, totalRounds);
}
// Update main info
if (pr.Started) {
if (pr.HasError) {
document.getElementById('span-main-status').textContent = 'Error';
document.getElementById('span-main-status').className = 'status-indicator error';
} else if (pr.Completed) {
document.getElementById('span-main-status').textContent = 'Completed';
document.getElementById('span-main-status').className = 'status-indicator completed';
} else {
document.getElementById('span-main-status').textContent = 'In Progress';
document.getElementById('span-main-status').className = 'status-indicator started';
}
}
document.getElementById('span-main-TimeStart').textContent = pr.TimeStartDisplay || '-';
document.getElementById('span-main-TimeEnd').textContent = pr.TimeEndDisplay || '-';
document.getElementById('span-main-TimeUsed').textContent = pr.TimeUsedDisplay || '-';
document.getElementById('span-main-HasError').textContent = pr.HasError ? 'Yes' : 'No';
if (pr.HasError && pr.LastError) {
const errorMsg = document.getElementById('main-error-message');
if (errorMsg) {
errorMsg.textContent = pr.LastError.Message || 'Unknown error';
errorMsg.classList.add('show');
}
}
// Update remarks/logs
if (pr.Remarks) {
let span_main_Remarks = document.getElementById('span-main-Remarks');
if (span_main_Remarks) {
span_main_Remarks.textContent = pr.Remarks;
span_main_Remarks.scrollTop = span_main_Remarks.scrollHeight;
}
}
// Update progress
updateProgress(pr);
// Update each task for active stages only
if (pr.dicTask) {
for (let taskId in pr.dicTask) {
const task = pr.dicTask[taskId];
// Skip inactive tasks
if (!task.ActiveTask) {
continue;
}
const stage = task.Stage;
const round = task.Round;
// Skip if this stage is not active
if (!activeStages.includes(stage)) {
continue;
}
// Skip if this round is beyond what we're displaying
if (round > totalRounds) {
continue;
}
// Update block status
const block = document.getElementById(`block-${stage}-${round}`);
if (block) {
block.className = 'round-block ';
if (task.HasError) {
block.className += 'error';
} else if (task.Completed) {
block.className += 'completed';
} else if (task.Started) {
block.className += 'started';
} else {
block.className += 'pending';
}
}
// Update status indicator
const statusSpan = document.getElementById(`span-${stage}-${round}-status`);
if (statusSpan) {
if (task.HasError) {
statusSpan.textContent = 'Error';
statusSpan.className = 'status-indicator error';
} else if (task.Completed) {
statusSpan.textContent = 'Completed';
statusSpan.className = 'status-indicator completed';
} else if (task.Started) {
statusSpan.textContent = 'Running';
statusSpan.className = 'status-indicator started';
} else {
statusSpan.textContent = 'Pending';
statusSpan.className = 'status-indicator pending';
}
}
// Update times
const timeStartSpan = document.getElementById(`span-${stage}-${round}-TimeStart`);
if (timeStartSpan) timeStartSpan.textContent = task.TimeStartDisplay || '-';
const timeEndSpan = document.getElementById(`span-${stage}-${round}-TimeEnd`);
if (timeEndSpan) timeEndSpan.textContent = task.TimeEndDisplay || '-';
const timeUsedSpan = document.getElementById(`span-${stage}-${round}-TimeUsed`);
if (timeUsedSpan) timeUsedSpan.textContent = task.TimeUsedDisplay || '-';
const hasErrorSpan = document.getElementById(`span-${stage}-${round}-HasError`);
if (hasErrorSpan) hasErrorSpan.textContent = task.HasError ? 'Yes' : 'No';
// Show error message if exists
if (task.HasError && task.ErrorMsg) {
const errorDiv = document.getElementById(`error-${stage}-${round}`);
if (errorDiv) {
errorDiv.textContent = task.ErrorMsg;
errorDiv.classList.add('show');
}
}
}
}
}
function fetchProgress() {
console.log(`Fetching progress for task ${taskid} at ${new Date().toLocaleTimeString()}`);
fetch(`/apiBenchmark?id=${taskid}`)
.then(response => {
console.log('Response status:', response.status);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Received data:', data);
// Check if this is an API error
if (data.Error) {
console.error('API Error:', data.Error);
// Stop the polling
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
// Show error to user
showApiError(data.Error);
return;
}
// Normal processing
fillValues(data);
if (data.Completed && intervalId) {
clearInterval(intervalId);
intervalId = null;
console.log('Task completed, stopping polling');
}
})
.catch(error => {
console.error('Fetch error:', error);
// Stop polling on network errors
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
// Show error to user
showNetworkError(error.message);
});
}
function showApiError(errorMessage) {
// Update the main status to show error
const statusSpan = document.getElementById('span-main-status');
if (statusSpan) {
statusSpan.textContent = 'Error';
statusSpan.className = 'status-indicator error';
}
// Show the error message
const mainErrorDiv = document.getElementById('main-error-message');
if (mainErrorDiv) {
mainErrorDiv.textContent = `API Error: ${errorMessage}`;
mainErrorDiv.classList.add('show');
}
// Optional: Show a more prominent error message
const container = document.getElementById('div-benchmark-report');
if (container) {
const errorBanner = document.createElement('div');
errorBanner.className = 'error-banner';
errorBanner.innerHTML = `
<div style="background-color: #f44336; color: white; padding: 20px; margin: 20px 0; border-radius: 4px;">
<h3 style="margin: 0 0 10px 0;">Error: Process Stopped</h3>
<p style="margin: 0;">${errorMessage}</p>
<button onclick="retryFetch()" style="margin-top: 10px; padding: 5px 15px; background: white; color: #f44336; border: none; border-radius: 3px; cursor: pointer;">Retry</button>
</div>
`;
container.insertBefore(errorBanner, container.firstChild);
}
}
// Add this function to show network errors
function showNetworkError(errorMessage) {
const statusSpan = document.getElementById('span-main-status');
if (statusSpan) {
statusSpan.textContent = 'Connection Error';
statusSpan.className = 'status-indicator error';
}
const mainErrorDiv = document.getElementById('main-error-message');
if (mainErrorDiv) {
mainErrorDiv.textContent = `Network Error: ${errorMessage}`;
mainErrorDiv.classList.add('show');
}
// Show retry option
const container = document.getElementById('div-benchmark-report');
if (container) {
const errorBanner = document.createElement('div');
errorBanner.className = 'error-banner';
errorBanner.innerHTML = `
<div style="background-color: #ff9800; color: white; padding: 20px; margin: 20px 0; border-radius: 4px;">
<h3 style="margin: 0 0 10px 0;">Connection Error</h3>
<p style="margin: 0;">Unable to connect to the server. The connection may have been lost.</p>
<button onclick="retryFetch()" style="margin-top: 10px; padding: 5px 15px; background: white; color: #ff9800; border: none; border-radius: 3px; cursor: pointer;">Retry</button>
</div>
`;
container.insertBefore(errorBanner, container.firstChild);
}
}
// Add retry functionality
function retryFetch() {
// Remove any error banners
const errorBanners = document.querySelectorAll('.error-banner');
errorBanners.forEach(banner => banner.remove());
// Reset error messages
const errorMessages = document.querySelectorAll('.error-message.show');
errorMessages.forEach(msg => {
msg.textContent = '';
msg.classList.remove('show');
});
// Restart polling
if (!intervalId) {
fetchProgress(); // Initial fetch
intervalId = setInterval(fetchProgress, 1000);
console.log('Restarted polling');
}
}
// Add input validation for total rounds
function hideButton(button) {
const totalRoundInput = document.getElementById('txtTotalRound');
if (totalRoundInput) {
let value = parseInt(totalRoundInput.value) || 1;
if (value < 1) value = 1;
if (value > 3) value = 3;
totalRoundInput.value = value;
}
button.style.display = 'none';
}
// Initialize
drawUI();
// Start polling
fetchProgress(); // Initial fetch
intervalId = setInterval(fetchProgress, 1000); // Poll every second
</script>
</asp:Panel>
</div>
</asp:Content>