-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionUpdater.aspx.cs
104 lines (94 loc) · 4.27 KB
/
TransactionUpdater.aspx.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
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class TransactionUpdater : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void updateButton_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
try
{
string filePath = FileUpload1.FileName;
StreamReader reader = new StreamReader(FileUpload1.FileContent);
int transactionNum = 1;
string updatedFile = "";
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Contains("lr_start_transaction"))
{
int startIndex = line.IndexOf("lr_start_transaction") + 20;
int endIndex = line.IndexOf("\"", startIndex + 1);
string transactionName = line.Substring(startIndex + 1, endIndex - startIndex - 1);
// Update the transaction name
transactionName = txtAppCICode.Text + "_" + txtScriptName.Text + "_"
+ txtFuncName.Text + "_" + string.Format("{0:D2}", transactionNum) + "_"
+ transactionName;
line = line.Substring(0, startIndex + 1) + transactionName + line.Substring(endIndex);
// Increment the transaction number
transactionNum++;
}
if (line.Contains("lr_end_transaction"))
{
int startIndex = line.IndexOf("lr_end_transaction") + 18;
int endIndex = line.IndexOf("\"", startIndex + 1);
string transactionName = line.Substring(startIndex + 1, endIndex - startIndex - 1);
// Update the transaction name
transactionName = txtAppCICode.Text + "_" + txtScriptName.Text + "_"
+ txtFuncName.Text + "_" + string.Format("{0:D2}", transactionNum - 1) + "_"
+ transactionName;
line = line.Substring(0, startIndex + 1) + transactionName + line.Substring(endIndex);
}
updatedFile += line + "\n";
}
reader.Close();
// Write the updated file as the output
StreamWriter writer = new StreamWriter(filePath);
writer.Write(updatedFile);
writer.Close();
/*
// Write the updated file as the output
byte[] fileBytes = Encoding.UTF8.GetBytes(updatedFile);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(fileBytes);
Response.End();
Response.Close();
*/
lblMessage.Text = "File updated successfully!";
byte[] fileBytes = Encoding.UTF8.GetBytes(updatedFile);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
//Response.TransmitFile(filePath);
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(fileBytes);
Response.End();
Response.Close();
// Delete all the files in the folder "E:/LoadRunnerScripts/"
DirectoryInfo dir = new DirectoryInfo(@"E:/LoadRunnerScripts/");
foreach (FileInfo file in dir.GetFiles())
{
file.Delete();
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "refresh", "setTimeout(function(){window.location.reload(true);}, 1000);", true);
}
catch (Exception ex)
{
lblMessage.Text = "Error updating file: " + ex.Message;
}
}
else
{
lblMessage.Text = "Please select a file to update.";
}
}
}