初始化
This commit is contained in:
92
BLWLogProduce/Services/MyTimer.cs
Normal file
92
BLWLogProduce/Services/MyTimer.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BLWLogProduce.Models;
|
||||
using NLog;
|
||||
|
||||
namespace BLWLogProduce.Services
|
||||
{
|
||||
public class MyTimer : BackgroundService
|
||||
{
|
||||
public System.Timers.Timer jiankong_timer = null;
|
||||
public MyTimer()
|
||||
{
|
||||
|
||||
}
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
jiankong_timer = new System.Timers.Timer();
|
||||
jiankong_timer.Interval = 60000;
|
||||
jiankong_timer.Elapsed += Jiankong_timer_Elapsed;
|
||||
jiankong_timer.Start();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
public static Logger logger = LogManager.GetCurrentClassLogger();
|
||||
private void Jiankong_timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var df = WaiBuJianKong.data;
|
||||
|
||||
string NewStringData = WaiBuJianKong.Data;
|
||||
NewStringData = NewStringData.Replace("{1}", df.UDP_Upload)
|
||||
.Replace("{2}", df.UDP_Sent)
|
||||
.Replace("{3}", df.RCU_Online)
|
||||
.Replace("{4}", df.RCU_TakeCard)
|
||||
.Replace("{5}", df.RCU_Heart)
|
||||
.Replace("{6}", df.RCU_SearchHost)
|
||||
.Replace("{7}", df.Intercept)
|
||||
.Replace("{8}", df.WebUser)
|
||||
.Replace("{9}", df.Energy)
|
||||
.Replace("{10}", df.RCU_OE)
|
||||
.Replace("{15}",df.WireShark_UDPCapCount);
|
||||
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
int.TryParse(df.TCL_Ctr_D, out a);
|
||||
int.TryParse(df.TCL_Ctr_C, out b);
|
||||
NewStringData = NewStringData.Replace("{11}", (a + b).ToString());
|
||||
|
||||
|
||||
int c = 0;
|
||||
int d = 0;
|
||||
int.TryParse(df.TM_Ctr_D, out c);
|
||||
int.TryParse(df.TM_Ctr_C, out d);
|
||||
NewStringData = NewStringData.Replace("{12}", (c + d).ToString());
|
||||
|
||||
|
||||
int ee = 0;
|
||||
int ff = 0;
|
||||
int.TryParse(df.XD_Ctr_D, out ee);
|
||||
int.TryParse(df.XD_Ctr_C, out ff);
|
||||
NewStringData = NewStringData.Replace("{13}", (ee + ff).ToString()).Replace("{14}", "0");
|
||||
|
||||
|
||||
WanBuJianKong(NewStringData, "1.txt");
|
||||
File.WriteAllText("2.txt", NewStringData, Encoding.UTF8);
|
||||
Console.WriteLine("here");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
logger.Error(ex.Message);
|
||||
logger.Error(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void WanBuJianKong(string Data, string SourceTxt)
|
||||
{
|
||||
System.IO.File.WriteAllText(SourceTxt, Data, Encoding.UTF8);
|
||||
// 如果目标文件存在,先删除
|
||||
if (System.IO.File.Exists(WaiBuJianKong.WaiBuJianKongTargetFileName))
|
||||
{
|
||||
System.IO.File.Delete(WaiBuJianKong.WaiBuJianKongTargetFileName);
|
||||
}
|
||||
|
||||
// 重命名/移动文件
|
||||
System.IO.File.Move(SourceTxt, WaiBuJianKong.WaiBuJianKongTargetFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user