我尝试更换扬声器,但我没有在SpeechSynthesizer课堂上列出所有已安装的扬声器(乔治、苏珊、雅库布),另一方面,我有一个根本没有安装的扬声器(齐拉)。
这里发生了什么事?我可以以某种方式将特定的扬声器添加到我的项目中(例如作为 .dll 或其他内容)以不依赖于计算机语言/区域吗?
我只是好奇,在Java中,@Transactional可以在方法名称上方放置一个属性,并且由于几乎每个应用程序服务方法都使用事务,因此可以简化代码。
// Java example
public class FooApplicationService {
@Transactional
public void DoSomething()
{
// do something ...
}
}
Run Code Online (Sandbox Code Playgroud)
目前,这是在.NET中完成的方式
// .NET example
public class FooApplicationService {
public void DoSomething()
{
using (var transaction = new TransactionScope())
{
// do something ...
transaction.Complete();
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否也可以通过.NET Core中的注释属性来管理事务的?
我在课堂上定义了简单的事件
class Request
{
protected virtual void OnStateChanged()
{
StateChanged?.Invoke(this, EventArgs.Empty);
}
public event EventHandler StateChanged;
public void Approve()
{
OnStateChanged();
}
}
Run Code Online (Sandbox Code Playgroud)
我如何知道此事件已引发?
我尝试了一行事件处理程序实现
bool eventRaised = false;
request.StateChanged += (obj, eventArgs) => eventRaised = true;
request.Approve();
Assert.True(eventRaised);
Run Code Online (Sandbox Code Playgroud)
它有效,但是有更好的方法吗?没搞懂,怎么用Assert.Raises()
我在excel中有以下vba命令
wbImportFrom.Sheets("Sheet 3").Cells(n, 8).Value
Run Code Online (Sandbox Code Playgroud)
这让我回来了
0,128888889
Run Code Online (Sandbox Code Playgroud)
我可以把它变成百分比
Format(wbImportFrom.Sheets("Sheet 3").Cells(n, 8).Value,"Percent")
-- returns 13.00 %
Run Code Online (Sandbox Code Playgroud)
如何将百分比数字舍入为整数(13%)?其他例子
0,057 => 6%
0,088571429 => 9%
0,15 => 15%
0,048461538 => 5%
0,128888889 => 13%
0,03 => 3%
0 => 0%
Run Code Online (Sandbox Code Playgroud)
我尝试使用Round和Val函数,但它对我不起作用:p
我有这两个合集
var materials = new List<Models.Material>();
materials.Add(new Models.Material { Number = 111, Value = null });
materials.Add(new Models.Material { Number = 222, Value = null });
var db_materials = new List<Models.DB_Material>();
db_materials.Add(new Models.DB_Material { Number = 111, ValueColumn = 10});
db_materials.Add(new Models.DB_Material { Number = 222, ValueColumn = 20 });
db_materials.Add(new Models.DB_Material { Number = 333, ValueColumn = 30 });
db_materials.Add(new Models.DB_Material { Number = 444, ValueColumn = 40 });
Run Code Online (Sandbox Code Playgroud)
我需要使用db_materials集合中的ValueColumn更新材料集合中的所有Value属性。
这个怎么做 ?
我想保存Activity.Current?.Id ?? HttpContext.TraceIdentifier到数据库中,因为这是用户在默认错误视图中看到的请求 ID。但如何呢?HttpContext在startup.cs 中不可用,我尝试在LayoutRenderer中访问HttpContext未成功。
HomeController 中的错误方法
public IActionResult Error()
{
var model = new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier };
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
我尝试过布局渲染器
namespace Copacking.Web.Utils
{
[LayoutRenderer("requestid")]
public class NLogRequestIdLayoutRenderer : LayoutRenderer
{
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
builder.Append(Activity.Current?.Id ?? HttpContext.TraceIdentifier);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到HttpContext错误,因为需要对象引用。
我该如何解决它?在Nlog.config文件中${aspnet-traceidentifier}正在工作,但${activityid}变量为空:/
我无法弄清楚为什么 TransactionScope 正在启动分布式事务(未在 SQL Server 上配置)。我想改用本地事务,当两个数据库位于同一个 SQL Server 实例中时可以使用本地事务。我的代码有什么问题,我该如何修复它?我可以强制 Transaction Scope 首先尝试本地事务吗?
数据库
应用程序设置.json
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=DESKTOP;Initial Catalog=test;Integrated Security=True",
"Test2Connection": "Data Source=DESKTOP;Initial Catalog=test2;Integrated Security=True"
}
}
Run Code Online (Sandbox Code Playgroud)
startup.cs注册 TestContext 和 Test2Context
services.AddDbContext<TestContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDbContext<Test2Context>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Test2Connection")));
services.AddTransient<ICustomerRepository, CustomerRepository>();
services.AddTransient<IMaterialRepository, MaterialRepository>();
// This service inject TestContext and Test2Context
services.AddTransient<ICustomerService, CustomerService>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
Run Code Online (Sandbox Code Playgroud)
使用 TestContext 的CustomerRepository
public class CustomerRepository : ICustomerRepository
{
private readonly TestContext _context;
public CustomerRepository(TestContext context)
{
_context = context;
}
public Customer Retrieve(int id) …Run Code Online (Sandbox Code Playgroud) sql-server transactionscope distributed-transactions dbcontext entity-framework-core
将其发布到 Azure 云后,我无法运行调用剧作家测试的 azure 函数。
\n异常如下
\n Playwright Test or Playwright was just installed or updated. \n\xe2\x95\x91 \xe2\x95\x91 Please run the following command to download new browsers: \xe2\x95\x91 \xe2\x95\x91 \n\xe2\x95\x91 \xe2\x95\x91 playwright install \xe2\x95\x91 \xe2\x95\x91 \n\xe2\x95\x91 \xe2\x95\x91 <3 Playwright Team \xe2\x95\x91\nRun Code Online (Sandbox Code Playgroud)\n问题是我不知道如何运行playwright install。
有一些远程构建的可能性,但文档不包含详细信息。
\n所以我尝试遵循
\n%USERPROFILE%\\AppData\\Local\\ms-playwright\\chrome-win到项目文件夹中。.csproj后 chrome 浏览器将位于输出目录并输出 zip<ItemGroup>\n <Content Include="chrome-win\\**">\n <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\n </Content>\n</ItemGroup>\nRun Code Online (Sandbox Code Playgroud)\n我有appsettings.json
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionString": "Server=...;Database=...;Trusted_Connection=True;"
}
Run Code Online (Sandbox Code Playgroud)
和数据库类
public class Database : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(@"Server=...;Database=...;Trusted_Connection=True;");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Material>().ToTable("vw_Material", schema: "query");
}
public virtual DbSet<Material> Material { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何更换这条线
optionsBuilder.UseSqlServer(@"Server=...;Database=...;Trusted_Connection=True;");
Run Code Online (Sandbox Code Playgroud)
从appsettings的价值?
我遇到了异常
Microsoft.EntityFrameworkCore.Database.Transaction.AmbientTransactionWarning:已检测到环境事务
但我不知道如何解决这个异常。当我调用SaveChanges()inside时,我的代码失败了TransactionScope。可能是因为TransactionScope本身是内部SQLite context交易,但是如何处理这个问题呢?
我想测试的方法
它使用 TransactionScope,因为我想确定,Request当我与他一起操作时,加载的对象(类)不会改变。
public void Handle(Create cmd)
{
// Wrap via transaction
using (var transaction = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead }))
{
// Load request object from repository.
Request request = _repository.Find(cmd.RequestId);
// Create detail object
var detail = new Detail(requestId: cmd.RequestId);
// Add created detail object into Request object
request.CreateDetail(detail);
// Save request into repository.
_repository.SaveChanges(); // <--- HERE IS THE …Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net-core ×3
.net-core ×1
appsettings ×1
dbcontext ×1
events ×1
excel ×1
excel-vba ×1
linq ×1
nlog ×1
playwright ×1
sql-server ×1
sqlite ×1
unit-testing ×1
vba ×1
xunit ×1