TG.WXCRM.V4/ConsoleApp2/Program.cs

194 lines
8.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp2
{
public class FileInfo
{
public FileInfo(string _name, string _packname)
{
this.name = _name;
this.packname = _packname;
}
public string name { get; set; }
public string packname { get; set; }
}
public class xinfo
{
public string filename { get; set; }
public string datetime { get; set; }
public string code { get; set; }
public string guid { get; set; }
public string plat { get; set; }
public string packlong { get; set; }
public string packname { get; set; }
public string mn { get; set; }
public string chid { get; set; }
public string rv { get; set; }
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("数据开始");
List<FileInfo> urlText = new List<FileInfo>() {
//new FileInfo("HzHQSysMarketDataPCServer_req_20230925.txt","HzHQSys.MarketDataPCServer_req_20230925(10.119).log"),
new FileInfo("HQSysMarketDataMPServer_req_20230925.txt","App_HQSys.MarketDataMPServer_req__20230925(11.52).log"),
new FileInfo("HQSysMarketDataPCServer_req_20230925.txt","App-PC_HQSys.MarketDataPCServer_req__20230925(11.53).log"),
new FileInfo("HQSysMarketDataPCServer_req_20230925_5.txt","HQSys.MarketDataPCServer_req__20230925(11.48).log"),
new FileInfo("HQSysMarketDataPCServer_req_20230925_6.txt","HQSys.MarketDataPCServer_req__20230925(11.54).log"),
new FileInfo("HQSysMarketDataPCServer_req_20230925_7.txt","HQSys.MarketDataPCServer_req__20230925(30.17).log"),
new FileInfo("HzHQSysMarketDataPCServer_req_20230925_2.txt","HzHQSys.MarketDataPCServer_req_20230925(10.120).log")
};
System.IO.StreamWriter sw = new System.IO.StreamWriter("D://9-25日志//xijie//已完成//result.txt", false);
Dictionary<string, string> dic = new Dictionary<string, string>();
sw.WriteLine("filename|datetime|code|guid|plat|packlong|packname|mn|chid|rv");
try
{
int bss = 0;
foreach (var filename in urlText)
{
bss++;
Console.WriteLine("开始处理:" + filename.name);
Dictionary<string, string> mmxssx = new Dictionary<string, string>();
Console.WriteLine("读取数据");
StreamReader sr = new StreamReader("D://9-25日志//xijie//已完成//" + filename.name, Encoding.Default);
String line;
int xxx = 0;
while ((line = sr.ReadLine()) != null)
{
xxx++;
string resid = line.ToString();
string[] longfileStr = resid.Split('|');
xinfo info = new xinfo()
{
filename = filename.packname,
datetime = longfileStr[0],
code = longfileStr[1],
guid = longfileStr[2],
plat = longfileStr[4],
};
for (int i = 0; i < longfileStr.Length; i++)
{
if (longfileStr[i].StartsWith("xua: SN="))
{
info.packlong = longfileStr[i];
foreach (var item in longfileStr[i].Split('&'))
{
if (item.StartsWith("xua"))
info.packname = item;
if (item.StartsWith("MN="))
info.mn = item;
if (item.StartsWith("CHID="))
info.chid = item;
if (item.StartsWith("RV="))
info.rv = item;
}
}
}
string printline = $"{info.filename}|{info.datetime}|{info.code}|{info.guid}|{info.plat}|{info.packlong}|{info.packname}|{info.mn}|{info.chid}|{info.rv}";
// public string filename { get; set; }
//public string datetime { get; set; }
//public string code { get; set; }
//public string guid { get; set; }
//public string plat { get; set; }
//public string packlong { get; set; }
//public string packname { get; set; }
//public string mn { get; set; }
//public string chid { get; set; }
//public string rv { get; set; }
sw.WriteLine(printline);
//int snindex = resid.IndexOf("xua: SN=");
//if (resid.Length > 10 && snindex > -1)
//{
// string packname = resid.Substring(snindex, 50);
// int xindex = packname.IndexOf("&");
// if (xindex > -1)
// packname = packname.Substring(0, xindex);
// if (mmxssx.ContainsKey(packname))
// continue;
// mmxssx.Add(packname, "");
//}
if (xxx % 1000 == 0)
{
Console.WriteLine("已处理:" + xxx);
}
}
//if (bss == 1)//临时都跳出
// break;
Console.WriteLine("处理完文件:" + filename.name);
}
}
catch
{
throw;
}
finally
{
sw.Close();
}
Console.WriteLine("执行完毕");
Console.ReadKey();
}
static async Task A()
{
Console.WriteLine("1线程ID{0}", Thread.CurrentThread.ManagedThreadId);
B();
Console.WriteLine("1线程ID{0}", Thread.CurrentThread.ManagedThreadId);
}
static async Task B()
{
Thread.Sleep(1000);
Console.WriteLine("2线程ID{0}", Thread.CurrentThread.ManagedThreadId);
}
static async Task TestAsync()
{
Console.WriteLine("②调用GetReturnResult()之前线程ID{0}。当前时间:{1}", Thread.CurrentThread.ManagedThreadId, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss"));
var name = GetReturnResult();
Console.WriteLine("④调用GetReturnResult()之后线程ID{0}。当前时间:{1}", Thread.CurrentThread.ManagedThreadId, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss"));
Console.WriteLine("⑥得到GetReturnResult()方法的结果一:{0}。当前时间:{1}", await name, DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss"));
Console.WriteLine("⑥得到GetReturnResult()方法的结果二:{0}。当前时间:{1}", name.GetAwaiter().GetResult(), DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss"));
}
static async Task<string> GetReturnResult()
{
Thread.Sleep(2000);
Console.WriteLine("③执行Task.Run之前, 线程ID{0}", Thread.CurrentThread.ManagedThreadId);
return await Task.Run(() =>
{
Thread.Sleep(2000);
Console.WriteLine("⑤GetReturnResult()方法里面线程ID: {0}", Thread.CurrentThread.ManagedThreadId);
return "我是返回值";
});
}
static void MyAction()
{
Console.WriteLine("1我是新进程线程ID" + Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(2000);
Console.WriteLine("2我是新进程线程ID" + Thread.CurrentThread.ManagedThreadId);
}
static string GetReturnStr()
{
Thread.Sleep(2000);
return "我是返回值线程ID" + Thread.CurrentThread.ManagedThreadId;
}
}
}