在我的 .NET Core 应用程序中,我使用 MassTransit Job Consumer 来运行一些长时间运行的作业。然而,我注意到并发提交的作业(几秒钟内)似乎是按 LIFO 顺序分发给作业消费者的,这与普通消息消费者中的 FIFO 相反。这是预期的行为吗?如果是这样,我怎样才能使用 FIFO?仅供参考 - 我正在使用 Sql Server 作为 Saga 存储库。
我使用以下命令从 powershell CLI 快速查找特定文件。
[IO.Directory]::GetFiles($searchDir, $searchFile, [IO.EnumerationOptions] @{AttributesToSkip='Hidden,Device,Temporary,SparseFile'; RecurseSubdirectories=$true; IgnoreInaccessible=$true })
这是一个函数中的别名,当我运行它并且它找到了一个匹配项,但仍在搜索更多内容时,我无法中断 ( CTRL+C
) 调用,迫使我等待所有结果。
问:一旦找到匹配项,如何才能中断该过程?
我在 .NET MAUI 中制作了一个简单的应用程序,但我注意到当我使用 HorizontalStackLayout 时,我没有得到与 Orientation="Horizontal" 和 HorizontalOptions="FillAndExpand" 的 StackLayout 相同的结果。
这是我正在使用的 xaml:
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Entry x:Name="InfoNombre" Placeholder="Nombre" Text="{Binding EditorPerfil.conta.InfoNombre}" HorizontalOptions="FillAndExpand"/>
<Entry x:Name="InfoApellido" Placeholder="Apellido" Text="{Binding EditorPerfil.conta.InfoApellido}" HorizontalOptions="FillAndExpand"/>
</StackLayout>
VS
<HorizontalStackLayout HorizontalOptions="FillAndExpand"> <!--Note that using HorizontalOptions="Fill" gets me the same result-->
<Entry x:Name="InfoNombre" Placeholder="Nombre" Text="{Binding EditorPerfil.conta.InfoNombre}" HorizontalOptions="FillAndExpand"/>
<Entry x:Name="InfoApellido" Placeholder="Apellido" Text="{Binding EditorPerfil.conta.InfoApellido}" HorizontalOptions="FillAndExpand"/>
</HorizontalStackLayout>
下图比较结果:
设计结果 StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand"
我在 MudChipSet 中使用了几个 MudBlazors MudChip。确切的数量根据列表的长度而变化(在 MudChip 上创建该列表中的每个对象)。
现在我想根据保存的数据选择这些芯片之一。我的方法是创建一个 MudChips 列表,每个列表项一个(仅设置“文本”属性)。然后,我进行过滤以获取“Text”与我拥有的字符串匹配的结果,并将该结果设置为绑定“selectedChip”变量。
然而,这是行不通的。知道为什么吗?
我一直在寻找内置MSBuild 属性函数的代码(例如[MSBuild]::ValueOrDefault()),但我还没有找到任何代码。来源是否公开?如果是的话,在哪里?谢谢。
我有这样的文字:
asd dsa [SKU].[Analytic5].&[omg wtf] not found blah blah blah "&[omg wtf]". Query Text: <ccon>SELECT {[SKU].[Analytic5].&[omg wtf]} ON 0 FROM [Model_week] CELL PROPERTIES CELL_ORDINAL</ccon>
我需要从那里提取[SKU].[Analytic5].&[omg wtf] 。实际上是[SKU].[*].&[*]。
我做了这个正则表达式:
\[SKU\]\.\[.*\]\.\&\[.*\]
它有效......有点......它在第一次[天哪]之后抓住所有垃圾,直到最后一次[模型_周]见面。所以我的正则表达式的结果是:
[SKU].[Analytic5].&[omg wtf] not found blah blah blah "&[omg wtf]". Query Text: <ccon>SELECT {[SKU].[Analytic5].&[omg wtf]} ON 0 FROM [Model_week]
我只是不明白如何限制它。我尝试过添加 {1} 之类的方法,但没有帮助。
在VB.NET中如下代码:
Dim myBool As Boolean = False
Dim myDate As Date? = If(myBool, Date.Today, Nothing)
Console.WriteLine(myDate)
生产:
1/1/0001 12:00:00 AM
但是,如果我将其写为:
Dim myBool As Boolean = False
Dim myDate As Date?
If myBool Then
myDate = Date.Today
Else
myDate = Nothing
End If
Console.WriteLine(myDate)
然后它会如预期的那样打印 null/nothing。
这是怎么回事,我怎样才能用一个单行代码将日期或 null 分配给 VB.NET 中的可空 DateTime,而不使其实际上默认为01/01/0001 12:00:00 AM
?
我正在运行一个 .NET 应用程序并尝试对其进行 dockerize。我的docker compose如下:
version: '3.4'
services:
mssql:
container_name: mtg-mssql-db
hostname: mssql-db
image: mcr.microsoft.com/mssql/server:2022-latest
environment:
ACCEPT_EULA: 'Y'
MSSQL_SA_PASSWORD: 'Admin@123'
MSSQL_DATA_DIR: /var/opt/mssql/data
MSSQL_PID: 'Developer'
MSSQL_TCP_PORT: 1433
ports:
- "1455:1433"
volumes:
- ./data:/var/opt/mssql/data
- ./log:/var/opt/mssql/log
- ./secrets:/var/opt/mssql/secrets
mtgmvc:
image: ${DOCKER_REGISTRY-}mtgmvc
build:
context: .
dockerfile: MTGMVC/Dockerfile
我的应用程序设置是:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Data Source=localhost,1455;Initial Catalog=MTGCards;User ID=sa;Password=Admin@123;Integrated Security=True",
"Redis": "host.docker.internal:5005"
}
}
我已经检查了连接字符串,对我来说似乎不错,但我无法像这样访问数据库,我是否在这里错过了 Docker 的一些网络问题?
我正在制作一个食谱网站,用户可以上传自己的食谱。我正在努力处理我的 CreateRecipe 页面。我希望用户输入成分名称、成分数量和计量单位。然后他们按下“添加”按钮,将他们的输入添加到我的数据库中,然后在屏幕上显示他们的成分。我想动态地执行此操作,以便用户可以添加多种成分,而无需刷新页面并清除所有其他输入信息。我对“AddIngredient”和“AddInstruction”按钮也有同样的问题,我似乎无法用按钮调用这些函数。
@page "/create-recipe"
@using CookNet.Data
@inject RecipeService RecipeService
@inject NavigationManager NavigationManager
@using Microsoft.AspNetCore.Components.Forms
<h3>Create Recipe</h3>
<EditForm Model="@Recipe" OnValidSubmit="HandleSubmit" FormName="CreateRecipeForm">
<DataAnnotationsValidator />
<ValidationSummary />
<label>Name:</label>
<InputText @bind-Value="@Recipe.Name" />
<label>Description:</label>
<InputTextArea @bind-Value="@Recipe.Description" />
<label>Cook Time (minutes):</label>
<InputNumber @bind-Value="@Recipe.CookTime" />
<label>Ethnicity:</label>
<InputText @bind-Value="@Recipe.Ethnicity" />
<label>Category:</label>
<InputText @bind-Value="@Recipe.Category" />
<div class="form-group">
<label>Ingredient Name:</label>
<InputText @bind-Value="@NewIngredientName" />
</div>
<div class="form-group">
<label>Quantity:</label>
<InputNumber @bind-Value="@NewIngredientQuantity" />
</div>
<div class="form-group">
<InputSelect @bind-Value="@NewIngredientQuantityUnit">
<option value="teaspoon">tsp</option>
<option value="tablespoon">Tbsp</option>
<option value="cup">Cup</option>
<option value="gram">Gram</option>
<option value="ounce">Ounce</option>
</InputSelect>
</div>
<button type="button" class="btn btn-primary" @onclick="AddIngredientAsync">Add</button>
<div class="form-group">
<label>Instructions:</label>
<InputTextArea @bind-Value="NewInstructionText" />
</div>
<button type="button" class="btn btn-primary" @onclick="AddInstructionAsync">Add</button>
@if (AddedIngredients.Any())
{
<h4>Added Ingredients:</h4>
<ul>
@foreach (var ingredient in AddedIngredients)
{
<li>@($"{ingredient.Quantity} {ingredient.QuantityUnit} - {ingredient.Name}")</li>
}
</ul>
}
@if (AddedInstructions.Any())
{
<h4>Added Instructions:</h4>
<ul>
@foreach (var instruction in AddedInstructions)
{
int stepNum = 0;
<li>@($"{stepNum++}. {instruction}")</li>
}
</ul>
}
<button type="submit" class="btn btn-success">Submit</button>
</EditForm>
@code {
Recipe Recipe { get; set; } = new Recipe();
string NewIngredientName { get; set; }
int NewIngredientQuantity { get; set; }
string NewIngredientQuantityUnit { get; set; } = "tsp";
string NewInstructionText { get; set; }
List<Ingredient> AddedIngredients { get; set; } = new List<Ingredient>();
List<Instruction> AddedInstructions { get; set; } = new List<Instruction>();
private async Task AddIngredientAsync()
{
Console.WriteLine("BUTTON CLICKED!");
await RecipeService.AddIngredientToRecipeAsync(Recipe, NewIngredientName, NewIngredientQuantity, NewIngredientQuantityUnit);
AddedIngredients.Add(new Ingredient
{
Name = NewIngredientName,
Quantity = NewIngredientQuantity,
QuantityUnit = NewIngredientQuantityUnit
});
NewIngredientName = string.Empty;
NewIngredientQuantity = 0;
NewIngredientQuantityUnit = "tsp";
}
private async Task AddInstructionAsync()
{
Console.WriteLine("BUTTON CLICKED!");
await RecipeService.AddInstructionToRecipeAsync(Recipe, NewInstructionText);
AddedInstructions.Add(new Instruction
{
InstructionText = NewInstructionText
});
NewInstructionText = string.Empty;
}
async Task HandleSubmit()
{
Recipe.DateCreated = DateTime.Now;
await RecipeService.CreateRecipeAsync(Recipe);
NavigationManager.NavigateTo("/recipes");
}
}
有什么建议么?
我正在阅读一些 .NET 代码,并在DispatcherSynchronizationContext中发现以下内容
///
/// Wait for a set of handles.
///
///
/// Critical - Calls WaitForMultipleObjectsEx which has a SUC.
///
[SecurityCritical]
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.ControlPolicy|SecurityPermissionFlag.ControlEvidence)]
public override int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
if(_dispatcher._disableProcessingCount > 0)
{
// Call into native code directly in order to avoid the default
// CLR locking behavior which pumps messages under contention.
// Even though they try to pump only the COM messages, any
// messages that have been SENT to the window are also
// dispatched. This can lead to unpredictable reentrancy.
return MS.Win32.UnsafeNativeMethods.WaitForMultipleObjectsEx(waitHandles.Length, waitHandles, waitAll, millisecondsTimeout, false);
}
else
{
return SynchronizationContext.WaitHelper(waitHandles, waitAll, millisecondsTimeout);
}
}
“拥有 SUC”是什么意思?