c#通过grpc和protobuf实现读取文件解析成list集合,并返回给客户端
Protobuf文件:
service Protobuf {
rpc GetFiles(msgRequest) returns(msgData){}
}
Grpc
[System.Obsolete]
public override Task<msgDatas> GetFile(msgRequest request, ServerCallContext context)
{
try
{
return Task.FromResult(Service.GetCommObservable(request.Note).FirstOrDefault());
}
catch (TaskCanceledException TCex)
{
}
}
public msgDatas GetFile(string pCondition)
{
var call = gRPCclient.GetFiles(new msgRequest() { Note = pCondition });
return call;
}
public List<msgData> GetFileData(string pCondition)
{
List<msgData> rtnValue = new List<msgData>();
string LocalDestinationFolder = System.Threading.Thread.GetDomain().BaseDirectory.TrimEnd('\\');//download to local path
string[] datStr = File.ReadAllLines(LocalDestinationFolder + "\\" + "20231011153021.dat");//largeBytes
var lists = new List<List<string>>();//lists
string tmpStr = string.Empty;//marker
var tmpLst = new List<string>();//tmpLst
foreach (var datstr in datStr)
{
if (datstr == tmpStr)
{
lists.Add(tmpLst);
tmpLst = new List<string>();
}
else
{
tmpLst.Add(datstr);
}
}
lists.Add(tmpLst);
foreach (var list in lists)
{
xxx = list[0].ToString();
xxx = list[1];
xxx = list[2];
xxx = list[3];
stringBuilder.Clear();
for (int n = 5; n < list.Count; n++)
{
stringBuilder.Append(list[n]).Append("\n");
}
text = stringBuilder.ToString();
rtnValue.Add(new msgData()
{
xxx = xxx,
xxx = xxx,
xxx = xxx,
xxx = xxx,
xxx = xxx
});
}
}
catch (Exception ex)
{
_logger.Info(ex);
}
return rtnValue;
}