我认为Qt中使用的模型/视图控件的术语是有缺陷的.在他们的解释页面上,他们说,他们通过合并View和Controller将MVC简化为MV,他们给出了以下图片:

不过我认为,他们错误地命名了对象的角色,我认为,
我说的是你在应用程序中使用Qt模型/视图组件的通常和理智的方式.原因如下:
Qt在他们的术语中是错误的,还是只是我不懂的?(顺便说一句:这不是学术问题的原因是我已经开始按照命名开始对我的项目进行编码,我很快就发现,代码显然不对.只有在我意识到之后,我应该不要尝试将模型逻辑放在他们称之为Model的模型中)
我无法弄清楚如何使C#Windows窗体应用程序从一个线程写入文本框.例如,在Program.cs中,我们有标准的main()来绘制表单:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Run Code Online (Sandbox Code Playgroud)
然后我们在Form1.cs中:
public Form1()
{
InitializeComponent();
new Thread(SampleFunction).Start();
}
public static void SampleFunction()
{
while(true)
WindowsFormsApplication1.Form1.ActiveForm.Text += "hi. ";
}
Run Code Online (Sandbox Code Playgroud)
我完全错了吗?
UPDATE
以下是bendewey提供的工作代码示例:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
new Thread(SampleFunction).Start();
}
public void AppendTextBox(string value)
{
if (InvokeRequired)
{
this.Invoke(new Action<string>(AppendTextBox), new object[] {value});
return;
}
textBox1.Text += value;
}
void SampleFunction()
{
// Gets executed on a seperate thread and
// doesn't block the …Run Code Online (Sandbox Code Playgroud) 我正在使用内置日志记录提供程序登录到Microsoft.Extensions.Logging.Console.NET Core控制台应用程序中的console().
每个日志记录条目在输出中生成两行.我想将每个条目放在一行中.有没有办法自定义输出格式?
以下是我如何使用它的示例:
static void Main(string[] args)
{
var serviceProvider = new ServiceCollection()
.AddLogging() // This adds the Microsoft logging.
.AddSingleton<IProjectGeneratorService, CSharpProjectGeneratorService>()
.BuildServiceProvider();
// Configure the console logging.
serviceProvider
.GetService<ILoggerFactory>()
.AddConsole(LogLevel.Debug);
// Write a logging entry
var logger = serviceProvider.GetService<ILoggerFactory>().CreateLogger<Program>();
logger.LogDebug("Application started...");
}
Run Code Online (Sandbox Code Playgroud)
我得到的是:
dbug: Generator.Program[0]
Application started...
Run Code Online (Sandbox Code Playgroud)
我想拥有的是这样的:
dbug: Generator.Program[0]: Application started...
Run Code Online (Sandbox Code Playgroud)
任何的想法?我知道,我可以写一个自定义记录器,但我想知道是否还有其他方法.
谢谢.
让我们考虑一下服务注册Startup.ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IFoo, FooA>();
}
Run Code Online (Sandbox Code Playgroud)
是否有可能改变IFoo登记FooB后AddTransient一直叫什么名字?它有助于测试目的(例如,在TestStartup子类中)或者我们对代码库的访问是有限的.
如果我们注册另一个IFoo实现:
services.AddTransient<IFoo, FooA>();
services.AddTransient<IFoo, FooB>();
Run Code Online (Sandbox Code Playgroud)
然后GetService<IFoo>返回FooB而不是FooA:
IFoo service = services.BuildServiceProvider().GetService<IFoo>();
Assert.True(service is FooB);
Run Code Online (Sandbox Code Playgroud)
但是,GetServices<IFoo>成功返回两个实现(并且相同GetService<IEnumerable<IFoo>>):
var list = services.BuildServiceProvider().GetServices<IFoo>().ToList();
Assert.Equal(2, list.Count);
Run Code Online (Sandbox Code Playgroud)
合同中有Remove(ServiceDescriptor)方法IServiceCollection.如何ServiceDescriptor修改服务注册?
有没有更多的packages在任何解决方案的文件夹csproj或project.json基于.NET的核心工程.
NuGet CLI获取使用的缓存文件夹列表:
nuget locals all -list
Run Code Online (Sandbox Code Playgroud)
响应:
http-cache: C:\Users\<foo>\AppData\Local\NuGet\v3-cache
global-packages: C:\Users\<foo>\.nuget\packages\
temp: C:\Users\<foo>\AppData\Local\Temp\NuGetScratch
Run Code Online (Sandbox Code Playgroud)
如何更改或覆盖这些位置?
如果我使用项目属性页面在Visual Studio 2017中为.Net Core Web项目设置环境变量,我可以使用读取变量的值Environment.GetEnvironmentVariable; 但是,当我为xUnit测试项目设置环境变量然后调试测试时,Environment.GetEnvironmentVariable总是返回null.是否存在一个事实,即它是一个测试项目,应该阻止变量与Web项目一样使用?如果是这样,有没有办法可以为测试项目设置环境变量?谢谢.
让我们考虑一个常见的ASP.NET Core场景.首先我们添加中间件:
public void Configure(IApplicationBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = "MyCookie",
CookieName = "MyCookie",
LoginPath = new PathString("/Home/Login/"),
AccessDeniedPath = new PathString("/Home/AccessDenied/"),
AutomaticAuthenticate = true,
AutomaticChallenge = true
});
//...
}
Run Code Online (Sandbox Code Playgroud)
然后序列化一个委托人:
await HttpContext.Authentication.SignInAsync("MyCookie", principal);
Run Code Online (Sandbox Code Playgroud)
在这两次调用之后,加密的cookie将存储在客户端.你可以在任何浏览器devtools中看到cookie(在我的例子中它是分块的):
使用应用程序代码中的cookie不是问题(而不是问题).
我的问题是:如何在应用程序外解密cookie?我想这需要一个私钥,如何获得它?
我检查了文档,发现只有常用词:
这将创建一个加密的cookie并将其添加到当前响应中.调用SignInAsync时,还必须使用配置期间指定的AuthenticationScheme.
在封面下,使用的加密是ASP.NET的数据保护系统.如果您在多台计算机上进行托管,负载平衡或使用Web场,则需要配置数据保护以使用相同的密钥环和应用程序标识符.
那么,是否可以解密身份验证cookie,如果是,如何解密?
更新#1: 根据Ron C 的回答和评论,我最终得到了代码:
public class Startup
{
//constructor is omitted...
public void ConfigureServices(IServiceCollection services)
{
services.AddDataProtection().PersistKeysToFileSystem(
new DirectoryInfo(@"C:\temp-keys\"));
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationScheme = …Run Code Online (Sandbox Code Playgroud) security authentication cookies asp.net-core-mvc asp.net-core
我有一个主Web.config文件,下面有一个Web.Test.config,Web.Development.Config等等.
当我在Test config上通过SlowCheetah预览转换时,它似乎正确地转换了值.
当我将构建环境从开发切换到测试并尝试调试应用程序时,应用程序在主Web.config文件中的任何值下运行(即它不会转换任何内容).
如何使构建环境在调试时选择正确的配置而不是总是使用基本Web.config文件?这可能吗?
我一直无法找到合理的实现,JsonConvert.WriteJson这允许我在序列化特定类型时插入JSON属性.我的所有尝试都导致"JsonSerializationException:使用类型XXX检测到自引用循环".
关于我正在尝试解决的问题的更多背景:我使用JSON作为配置文件格式,我使用a JsonConverter来控制我的配置类型的类型解析,序列化和反序列化.$type我想使用更有意义的JSON值来解决正确的类型,而不是使用属性.
在我的简化示例中,这是一些JSON文本:
{
"Target": "B",
"Id": "foo"
}
Run Code Online (Sandbox Code Playgroud)
其中JSON属性"Target": "B"用于确定此对象应序列化为类型B.考虑到这个简单的例子,这种设计似乎并不那么引人注目,但它确实使配置文件格式更加有用.
我还希望配置文件是可循环访问的.我有反序列化的工作,我无法工作的是序列化案例.
我的问题的根源是我找不到JsonConverter.WriteJson使用标准JSON序列化逻辑的实现,并且不会抛出"自引用循环"异常.这是我的实现:
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
JProperty typeHintProperty = TypeHintPropertyForType(value.GetType());
//BUG: JsonSerializationException : Self referencing loop detected with type 'B'. Path ''.
// Same error occurs whether I use the serializer parameter or a separate serializer.
JObject jo = JObject.FromObject(value, serializer);
if (typeHintProperty != null)
{
jo.AddFirst(typeHintProperty);
}
writer.WriteToken(jo.CreateReader());
}
Run Code Online (Sandbox Code Playgroud)
在我看来,这是Json.NET中的一个错误,因为应该有办法做到这一点.不幸的是 …
我想做这个,但我也想能够在阵列传递到查询字符串.我尝试过这样的事情:
http://www.sitename.com/route?arr[]=this&arr[]=that
http://www.sitename.com/route?arr[]=this&that
http://www.sitename.com/route?arr[0]=this&arr[1]=that
http://www.sitename.com/route?arr0=this&arr1=that
http://www.sitename.com/route?arr=this&arr=that
Run Code Online (Sandbox Code Playgroud)
我在C#代码中的路由如下所示:
[Route("route")]
[HttpGet]
public void DoSomething(string[] values)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
但在所有这些情况下,当它到达C#代码时,值始终为null.我需要什么查询字符串来传递字符串数组?
c# ×6
.net-core ×4
asp.net-core ×3
app-config ×1
cookies ×1
json.net ×1
logging ×1
nuget ×1
qt ×1
query-string ×1
security ×1
slowcheetah ×1
winforms ×1
xunit.net ×1