我有一个类型的缓冲区ReadOnlySequence<byte>。我想提取的亚序列(其中将包含0 - n条消息)通过知道从它与每一个消息结束0x1c, 0x0d(如所描述的在这里)。
我知道缓冲区有一个扩展方法PositionOf但它
返回第一次出现的位置
item的ReadOnlySequence<T>。
我正在寻找一种方法来返回最后一次出现的位置。我试图自己实现它,这是我迄今为止所拥有的
private SequencePosition? GetLastPosition(ReadOnlySequence<byte> buffer)
{
// Do not modify the real buffer
ReadOnlySequence<byte> temporaryBuffer = buffer;
SequencePosition? lastPosition = null;
do
{
/*
Find the first occurence of the delimiters in the buffer
This only takes a byte, what to do with the delimiters? { 0x1c, 0x0d }
*/
SequencePosition? foundPosition = temporaryBuffer.PositionOf(???);
// Is there still an occurence?
if (foundPosition …Run Code Online (Sandbox Code Playgroud) 我正在为我的 .NET Core 项目使用Microsoft.AspNetCore.Authentication.JwtBearer和System.IdentityModel.Tokens.Jwt包。
在配置服务时,我正在向OnTokenValidated事件添加逻辑。
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(jwtBearerOptions =>
{
// ... set TokenValidationParameters ...
jwtBearerOptions.Events = new JwtBearerEvents()
{
OnTokenValidated = (tokenValidatedContext) =>
{
JwtSecurityTokenHandler jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
string tokenWithoutSignature = jwtSecurityTokenHandler.WriteToken(tokenValidatedContext.SecurityToken);
// ... full token from request? ...
}
};
});
Run Code Online (Sandbox Code Playgroud)
由于我知道上下文只返回没有签名的令牌,我想知道我怎么做
tokenWithoutSignature字符串中如果这是不可能的:
我正在以这种方式生成新令牌
public string GenerateAccessToken(IDictionary<string, object> payload)
{
SymmetricSecurityKey symmetricSecurityKey = new SymmetricSecurityKey(Convert.FromBase64String("secret from config"));
SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
{
Claims = payload,
Expires …Run Code Online (Sandbox Code Playgroud) 我正在使用 hl7-dotnetcore 包来创建新的 HL7 消息。创建它们后,我想将其中一些序列化为字符串,将其中一些序列化为字节。我使用以下代码段创建了一个空的 .NET Core 控制台项目
internal class Program
{
private static void Main(string[] args)
{
Message mdmMessage = new Message();
mdmMessage.AddSegmentMSH(
"sendingApplication",
"sendingFacility",
"receivingApplication",
"receivingFacility",
string.Empty,
"MDM^T02",
$"Id{DateTime.Now.Ticks}",
"P",
"2.6");
HL7Encoding hl7Encoding = new HL7Encoding();
//################################
// Add a field e.g. TXA.1
Segment txaSegment = new Segment("TXA", hl7Encoding);
txaSegment.AddNewField("1", 1);
mdmMessage.AddNewSegment(txaSegment);
//################################
// Add a component field e.g. PID.5.1
Segment pidSegment = new Segment("PID", hl7Encoding);
Field patientNameField = new Field(hl7Encoding);
Component pidFamilyNameComponent = new Component("Doe", hl7Encoding);
patientNameField.AddNewComponent(pidFamilyNameComponent, …Run Code Online (Sandbox Code Playgroud) 我有一个包含多个项目和多个测试项目的 .Net 5 解决方案。我想确保测试涵盖所有内容或指定的百分比值(例如 80%)。我正在使用 xUnit 进行测试,并根据文档创建了以下 Powershell 脚本
dotnet test --collect:"XPlat Code Coverage";
reportgenerator -reports:'**/coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
[XML]$report = Get-Content CoverageReports/Cobertura.xml
if($report.coverage.'line-rate' -ge 20)
{
Write-Host "greater or equal than 20"
}
else
{
Write-Host "less than 20"
}
Read-Host -Prompt 'done'
Run Code Online (Sandbox Code Playgroud)
执行以下操作
现在我可以访问覆盖信息,例如线路速率。而不是虚拟 if 语句,我怎样才能实现以下示例?
if($report.coverage.percentage -lt 80)
{
Write-Host "Coverage is less than 80 percent"
}
Run Code Online (Sandbox Code Playgroud)
作为奖励,我可以写下尚未涵盖的内容列表。
这是从虚拟项目生成的 Cobertura.xml 文件的内容
<?xml version="1.0" encoding="utf-8"?> …Run Code Online (Sandbox Code Playgroud) 我正在使用带有 Tailwind 的 Vue 并想创建一个“NotFound”视图页面。此路由器视图上的内容应位于屏幕的中央。路由器视图上方是导航栏组件,因此在居中时我必须注意高度。
首先,我尝试使用h-screen路由器视图
<link href="https://unpkg.com/tailwindcss@1.8.12/dist/tailwind.min.css" rel="stylesheet"/>
<div>
<div class="bg-yellow-400 py-8">
my navbar
</div>
<div class="bg-green-400 flex justify-center items-center h-screen">
this content is not centered on screen
</div>
</div>Run Code Online (Sandbox Code Playgroud)
但是正如您所看到的,绿色容器中的内容不在屏幕中央。接下来我尝试与h-full
<link href="https://unpkg.com/tailwindcss@1.8.12/dist/tailwind.min.css" rel="stylesheet" />
<div class="h-screen">
<div class="bg-yellow-400 py-8">
my navbar
</div>
<div class="bg-green-400 flex justify-center items-center h-full">
this content is not centered on screen
</div>
</div>Run Code Online (Sandbox Code Playgroud)
但不幸的是,这仍然不能解决它。有人知道如何正确填充屏幕高度的其余部分,以便路由器视图的高度为100% - navbarComponentHeight?
我正在Swashbuckle.AspNetCore为我的 .NET Core web api 项目使用该包。我想添加 XML 注释支持,所以我必须true在应用程序设置中设置 Build => Output => XML 文档文件。
不幸的是,自动生成的路径是绝对的
C:\Users\myUser\...\repository\solution\project\project.xml
所以这只适用于我的机器。有没有办法使用占位符?例如
{{pathToProject}}\project.xml
所以它在本地调试和部署时工作?
我想计算本周的开始DateTime和结束DateTime时间。首先,我创建了一个包含两个信息的类
internal class ReportTimeSpan
{
public DateTime From { get; set; }
public DateTime To { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
之后这是我的计算
public ReportTimeSpan GetTimeSpanForThisWeek()
{
int amountOfDays = GetAmountOfWeekDays();
int currentDayIndex = GetCurrentWeekDayIndex();
DateTime weekStart = DateTime.Now.AddDays(-currentDayIndex);
int differenceCurrentDayIndexToLastDayIndex = amountOfDays - currentDayIndex;
DateTime weekEnd = DateTime.Now.AddDays(differenceCurrentDayIndexToLastDayIndex);
return new ReportTimeSpan()
{
From = weekStart,
To = weekEnd
};
}
private int GetAmountOfWeekDays()
{
string[] dayNames = Enum.GetNames(typeof(DayOfWeek));
return dayNames.Length;
}
private int GetCurrentWeekDayIndex()
{
DayOfWeek dayOfWeek …Run Code Online (Sandbox Code Playgroud) 我有一个服务,它接受一个 ip 字符串并尝试将它解析为IPAdress. 一些外部服务可能传入,127.0.0.1但有一些传入localhost,这会导致问题。
所以第一个有效,但第二个抛出错误
try
{
var foo = IPAddress.Parse("127.0.0.1");
}
catch
{
Console.WriteLine("parsing failed for foo");
}
try
{
var bar = IPAddress.Parse("localhost");
}
catch
{
Console.WriteLine("parsing failed for bar");
}
Run Code Online (Sandbox Code Playgroud)
我是否必须检查 ip 字符串是否等于localhost或有什么我可以使用的?