-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileReportEventHandlers.cs
More file actions
86 lines (78 loc) · 2.61 KB
/
FileReportEventHandlers.cs
File metadata and controls
86 lines (78 loc) · 2.61 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
using AGVSystemCommonNet6.Configuration;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AGVSystemCommonNet6
{
public static class PathExtensions
{
public const string REPORT_FAIL_TEMP_FILE_STORE_FOLDER_NAME = "AGVS_Report_Fail_Temp_File_Store";
public static bool IsReportPath(this string path)
{
return path.Contains(AGVSConfigulator.SysConfigs.AutoSendDailyData.SavePath);
}
public static string GetTempPathToSaveReportFailFile(this string originalFilePath)
{
string folder = AGVSConfigulator.LogFolder;
folder = Path.Combine(folder, REPORT_FAIL_TEMP_FILE_STORE_FOLDER_NAME);
string fileName = "temp_" + Path.GetFileName(originalFilePath);
string _temp = Path.Combine(folder, fileName);
return _temp;
}
}
public class FileReportEventHandlers
{
public static event EventHandler<AutoReportFailEventArgs> OnDataAutoReportFail;
public static void RaiseDataAutoReportFail(object? sender, AutoReportFailEventArgs e)
{
OnDataAutoReportFail?.Invoke(sender, e);
}
}
public class AutoReportFailEventArgs : EventArgs
{
public string tempFilePath { get; private set; }
public string destineFilePath { get; private set; }
public int retryCount { get; set; } = 0;
public string jsonFilePath
{
get
{
string fileName = Path.GetFileNameWithoutExtension(tempFilePath);
string jsonFilePath = Path.Combine(Path.GetDirectoryName(tempFilePath), $"{fileName}.json");
return jsonFilePath;
}
}
public AutoReportFailEventArgs(string tempFilePath, string destineFilePath)
{
this.tempFilePath = tempFilePath;
this.destineFilePath = destineFilePath;
}
public void StoreInfoAsJson()
{
try
{
string json = this.ToJson();
File.WriteAllText(jsonFilePath, json);
}
catch (Exception ex)
{
throw ex;
}
}
public void DeleteRelatedFiles()
{
try
{
File.Delete(jsonFilePath);
File.Delete(tempFilePath);
}
catch (Exception ex)
{
throw ex;
}
}
}
}