|
@@ -43,31 +43,22 @@ namespace TestTool.RemoteTriggerAPP
|
|
|
public partial class MainWindow : Window
|
|
|
{
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
string action = "";
|
|
|
List<UploadFile> publishes = new List<UploadFile>();
|
|
|
- FTPClient UploadClient = new FTPClient(@"ftp://test.evsocket.phihong.com.cn", "testocpp", "testocpp");
|
|
|
+
|
|
|
string chargingProfilePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SetChargingProfile.json");
|
|
|
string dataTransferPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataTransfer.json");
|
|
|
int selectedPublish = -1;
|
|
|
bool isDestroyMode = false;
|
|
|
public MainWindow()
|
|
|
{
|
|
|
- var oo = new { idToken = "3345678", price = "Connection Fee: $2.11 NTD/time; Current Rate: $2.22 NTD/kWh;Occupancy Fee: $2.33 NTD/hr; Account Balance: $2444 NTD" };
|
|
|
-
|
|
|
-
|
|
|
- var tt = new DataTransferRequest()
|
|
|
- {
|
|
|
- vendorId = "Phihong Technology",
|
|
|
- messageId = "SetUserPrice",
|
|
|
- data = JsonConvert.SerializeObject(oo)
|
|
|
- };
|
|
|
-
|
|
|
- var ttt = JsonConvert.SerializeObject(tt);
|
|
|
-
|
|
|
|
|
|
InitializeComponent();
|
|
|
Loaded += MainWindow_Loaded;
|
|
|
- UploadClient.OnUploadProgress += UploadClient_OnUploadProgress;
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -98,7 +89,7 @@ namespace TestTool.RemoteTriggerAPP
|
|
|
{
|
|
|
switch (action)
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
#region Core Profile
|
|
|
case "ChangeAvailability_Inoperative":
|
|
|
{
|
|
@@ -598,9 +589,9 @@ namespace TestTool.RemoteTriggerAPP
|
|
|
// status = AuthorizationStatus.ConcurrentTx
|
|
|
// }
|
|
|
//});
|
|
|
-
|
|
|
|
|
|
- for (int i = 0; i < size ; i++)
|
|
|
+
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
{
|
|
|
request.localAuthorizationList.Add(new AuthorizationData()
|
|
|
{
|
|
@@ -940,96 +931,86 @@ namespace TestTool.RemoteTriggerAPP
|
|
|
uxMsgTb.Text = "Please select upload file!";
|
|
|
return;
|
|
|
}
|
|
|
+ string filePath = uxUploadFileTb.Text;
|
|
|
|
|
|
- FileInfo f = new FileInfo(uxUploadFileTb.Text);
|
|
|
-
|
|
|
- int size = (int)f.Length;
|
|
|
- string md5 = "";
|
|
|
- string filePreUrl = ConfigurationManager.AppSettings["UpdateFWPreUrl"];
|
|
|
- using (WebClient client = new WebClient())
|
|
|
- {
|
|
|
- client.UseDefaultCredentials = false;
|
|
|
- client.Headers.Add("Content-Type", "application/octet-stream");
|
|
|
- using (Stream fileStream = File.OpenRead(uxUploadFileTb.Text))
|
|
|
- {
|
|
|
- var _md5 = MD5.Create();
|
|
|
- var hash = _md5.ComputeHash(fileStream);
|
|
|
- md5 = BitConverter.ToString(hash).Replace("-", String.Empty).ToLowerInvariant();
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- UploadFile ufObj = new UploadFile();
|
|
|
- ufObj.CreatedOn = DateTime.Now.ToUniversalTime();
|
|
|
- ufObj.FileExtensionName = System.IO.Path.GetExtension(uxUploadFileTb.Text);
|
|
|
- ufObj.Id = Guid.NewGuid().ToString();
|
|
|
- ufObj.FileName = md5 + ufObj.FileExtensionName;
|
|
|
- ufObj.FilePath = "~/UploadFiles/Fw/" + ufObj.FileName;
|
|
|
- ufObj.FileSize = size;
|
|
|
- ufObj.FileMD5 = md5;
|
|
|
- ufObj.OriginName = System.IO.Path.GetFileName(uxUploadFileTb.Text);
|
|
|
- ufObj.FileUrl = new Uri(Properties.Settings.Default.UpdateFWPreUrl + ufObj.FilePath.Replace("~/", "")).ToString();
|
|
|
- ufObj.VendorId = "TestTool";
|
|
|
- ufObj.ModelName = "TestTool";
|
|
|
- ufObj.ModuleId = 0;
|
|
|
-
|
|
|
- using (var db = new MainDBContext())
|
|
|
- {
|
|
|
- db.UploadFile.Add(ufObj);
|
|
|
- db.SaveChanges();
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
- string filePath = uxUploadFileTb.Text;
|
|
|
- uxMsgTb.Text = "Uploading........";
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
{
|
|
|
- await UploadTask(filePath, ufObj.FileName);
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
+ await UploadTask(filePath, false);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- private async Task UploadTask(string filePath, string fileName)
|
|
|
+ private async Task UploadTask(string filepath, bool isFTP)
|
|
|
{
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await Dispatcher.BeginInvoke(new Action(() =>
|
|
|
+ {
|
|
|
+ uxMsgTb.Text = "Uploading........";
|
|
|
|
|
|
- bool uploadResult = UploadClient.FtpUploadBroken(filePath, @"ftp://ocpp.phihong.com.tw/" + fileName);
|
|
|
+ }));
|
|
|
|
|
|
- await Dispatcher.BeginInvoke(new Action(() =>
|
|
|
- {
|
|
|
- if (uploadResult)
|
|
|
+ FileInfo f = new FileInfo(filepath);
|
|
|
+ int size = (int)f.Length;
|
|
|
+ string fileMD5 = ""; //get file md5
|
|
|
+ using (var md5 = MD5.Create())
|
|
|
{
|
|
|
- uxMsgTb.Text = "Current Progress :100 %";
|
|
|
- Thread.CurrentThread.Join(100);
|
|
|
+ using (var stream = File.OpenRead(filepath))
|
|
|
+ {
|
|
|
+ fileMD5 = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", String.Empty).ToLower();
|
|
|
+ }
|
|
|
}
|
|
|
- uxMsgTb.Text = "Upload File Result :" + (uploadResult ? "Success" : "Fail");
|
|
|
-
|
|
|
+ string filePreUrl = isFTP ? Properties.Settings.Default.FTPUpdateFWPreUrl : Properties.Settings.Default.UpdateFWPreUrl;
|
|
|
+
|
|
|
+ UploadFile ufObj = new UploadFile();
|
|
|
+ ufObj.CreatedOn = DateTime.Now.ToUniversalTime();
|
|
|
+ ufObj.FileExtensionName = System.IO.Path.GetExtension(filepath);
|
|
|
+ ufObj.Id = Guid.NewGuid().ToString();
|
|
|
+ ufObj.FileName = fileMD5 + System.IO.Path.GetExtension(filepath);
|
|
|
+ ufObj.FilePath = isFTP ? "~/" + ufObj.FileName : "~/UploadFiles/FW/" + ufObj.FileName;
|
|
|
+ ufObj.FileSize = size;
|
|
|
+ ufObj.FileMD5 = fileMD5;
|
|
|
+ ufObj.OriginName = System.IO.Path.GetFileName(filepath);
|
|
|
+ ufObj.FileUrl = new Uri(filePreUrl + ufObj.FilePath.Replace("~/", "")).ToString();
|
|
|
+ ufObj.VendorId = "TestTool";
|
|
|
+ ufObj.ModelName = "TestTool";
|
|
|
+ ufObj.ModuleId = 0;
|
|
|
+
|
|
|
+ using (var db = new MainDBContext())
|
|
|
+ {
|
|
|
+ db.UploadFile.Add(ufObj);
|
|
|
+ await db.SaveChangesAsync();
|
|
|
|
|
|
- }));
|
|
|
+ }
|
|
|
|
|
|
+ FluentFTPClient ftpClient = new FluentFTPClient("ocpp.phihong.com.tw", 5002, "testocpp", "testocpp", "/");
|
|
|
+ //Properties.Settings.Default.UpdateFWPreUrl
|
|
|
+ bool uploadResult = await ftpClient.UploadFileAsync(filepath, ufObj.FileName);
|
|
|
|
|
|
+ await Dispatcher.BeginInvoke(new Action(() =>
|
|
|
+ {
|
|
|
+ if (uploadResult)
|
|
|
+ {
|
|
|
+ uxMsgTb.Text = "Current Progress :100 %";
|
|
|
+ Thread.CurrentThread.Join(100);
|
|
|
+ }
|
|
|
+ uxMsgTb.Text = "Upload File Result :" + (uploadResult ? "Success" : "Fail");
|
|
|
|
|
|
|
|
|
- }
|
|
|
+ }));
|
|
|
|
|
|
- private void UploadClient_OnUploadProgress(double percent)
|
|
|
- {
|
|
|
- Dispatcher.BeginInvoke(new Action(() =>
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- uxMsgTb.Text = "Current Progress :" + (int)percent + " %";
|
|
|
|
|
|
- }));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void uxFTPUploadBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(uxUploadFileTb.Text))
|
|
@@ -1084,7 +1065,7 @@ namespace TestTool.RemoteTriggerAPP
|
|
|
|
|
|
Task.Run(async () =>
|
|
|
{
|
|
|
- await UploadTask(filePath, ufObj.FileName);
|
|
|
+ await UploadTask(filePath, true);
|
|
|
});
|
|
|
|
|
|
|