async function test() {
(async () => {
var a = await this.test1();
var b = await this.test2(a);
var c = await this.test3(b);
this.doThis(a,b,c);
})();
}
Run Code Online (Sandbox Code Playgroud)
将方法(test1,test2,test3)放在里面意味着什么async () => {})()
?我发现它比
async function test() {
var a = await this.test1();
var b = await this.test2(a);
var c = await this.test3(b);
this.doThis(a,b,c);
}
Run Code Online (Sandbox Code Playgroud)
使用它有什么缺点?
使用Automapper的正确方法是什么?它是在控制器中还是在存储库模式中?对我来说,似乎把它们放在控制器中并不整洁无序.
所以,例如,
(控制器中使用的自动映射器):
- StudentController
public IActionResult Get()
{
var query = _context.Students.ToList();
var mapper = AutoMapper.Mapper.Map<List<Student>, List<StudentViewModel>>(query);
return new OkObjectResult(mapper);
}
Run Code Online (Sandbox Code Playgroud)
(存储库模式中使用的自动映像):
- StudentController
public IActionResult Get()
{
return new OkObjectResult(_studentRepository.GetAllStudents());
}
Run Code Online (Sandbox Code Playgroud)
- StudentRepository
public IEnumerable<StudentViewModel> GetAllStudents()
{
var query = _context.Students.ToList();
var mapper = AutoMapper.Mapper.Map<List<Student>, List<StudentViewModel>>(query);
return mapper;
}
Run Code Online (Sandbox Code Playgroud)
返回相同的结果,但实际上放置自动播放器设置的最佳位置是什么?使用.ProjectTo()以避免使用AutoMapper.Mapper.Map会更好吗?
根据我的研究,似乎.net核心不支持DataTable/DataSet.我最近转移到.net核心开发一个新的应用程序,但没有认识到.net核心首先没有库.我曾经使用dt/ds通过存储过程获取数据并填充类的集合.但现在,我很遗憾这个新问题,我必须找到替代dt/ds.更具体地说,我曾经这样做过:
我有一个存储过程,它接受四个输入参数并返回一个表.
ALTER PROCEDURE stp_Student
@Name nvarchar(450),
@StudentIds tvp_ArrayInt READONLY,
@StartDate date,
@EndDate date,
AS
blah blah
//returns student summary
SELECT stu.StudentId,
stu.StudentName,
CASE WHEN (COUNT(DISTINCT course.Id) IS NOT NULL) THEN COUNT(DISTINCT course.Id) ELSE 0 END AS CourseCount,
CASE WHEN (SUM(course.TotalCourses) IS NOT NULL) THEN SUM(course.TotalCourses) ELSE 0 END AS TotalCourses,
CASE WHEN (SUM(course.Hours) IS NOT NULL) THEN SUM(course.Hours) ELSE 0 END AS Hours
FROM #TempStudent AS #Temp
Run Code Online (Sandbox Code Playgroud)
并创建一个具有与我在存储过程中相同的字段的类.
public class StudentModel
{
public string StudentId { get; set; } …
Run Code Online (Sandbox Code Playgroud) 假设我有以下角色:
行政
用户
我希望 Admin 角色模拟具有 User 角色的特定用户帐户,但不知道该特定用户帐户的密码。
管理员应该能够模拟应用程序中的任何用户,并能够以用户自己的身份浏览应用程序。 我找到了一个链接,其中实际上是在 ASP.NET MVC 4.6 中实现的,但是在将其转换为 Core 版本时有点头疼。
主要是因为链接中的最后一行代码
authenticationManager.SignIn(new AuthenticationProperties()
{ IsPersistent = false }, impersonatedIdentity);
Run Code Online (Sandbox Code Playgroud)
SignIn
.NET Core 中的where参数不允许IdentityResult
再传递类 (impersonatedIdentity)。它现在只能采取ClaimsPrincipal
。
所以我最终做的是这个,
public async Task<IActionResult> ImpersonateUserAsync(string userName)
{
var impersonatedUser = await _userManager.FindByNameAsync(userName);
var claims = new List<Claim> {
new Claim(ClaimTypes.Name, impersonatedUser.FirstName, ClaimValueTypes.String),
new Claim(ClaimTypes.Surname, impersonatedUser.LastName, ClaimValueTypes.String),
new Claim(ClaimTypes.Email, impersonatedUser.Email, ClaimValueTypes.String)
};
var user = new ClaimsPrincipal(new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme));
var authenticationManager = _httpContextAccessor.HttpContext.Authentication;
await authenticationManager.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
await …
Run Code Online (Sandbox Code Playgroud) c# impersonation claims-based-identity asp.net-core-identity asp.net-core-1.1
string tableName = "TblStudents";
Dictionary<string, Type> myDictionary = new Dictionary<string, Type>()
{
{ "TblStudents", typeof(TblStudent) },
{ "TblTeachers", typeof(TblTeacher) }
};
// Context always same
DBContext dbContext = new DBContext();
DbSet dbSet = dbContext.Set(myDictionary[tableName]);
Run Code Online (Sandbox Code Playgroud)
上面的代码来自这篇文章,我可以DbSet
动态地。我怎样才能在 Entity Framework Core 中做到这一点?
我在
DbSet dbSet = dbContext.Set(myDictionary[tableName]);
Run Code Online (Sandbox Code Playgroud)
Set
新版本中似乎方法已更改。
帮助表示赞赏。
我正在尝试从 Azure webjob 运行 python 脚本。这是我按照此链接所做的
https://<webapp name>.scm.azurewebsites.net
并Python 364x86
通过站点扩展选项卡安装Python 364x86
安装在以下路径:D:\home\python364x86
trading.py
中D:\home\python364x86
run.bat
用这行代码创建文件D:\home\python364x86\python.exe trading.py
run.bat
和trading.py
在webjob zip文件[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Status changed to Initializing
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Run script 'run.bat' with script host - 'WindowsScriptHost'
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Status changed to Running
[09/07/2019 07:02:00 > 0dd02c: ERR ] The …
Run Code Online (Sandbox Code Playgroud) 当谈到特定货币对的 24 小时变更时,
这是如何计算的?
如果当前价格与 24 小时前的价格相比,则例如:
BTC 的当前价格9431
(2020 年 6 月 16 日下午 5 点)与 2020 年 6 月 15 日下午 5 点的价格进行比较9357
?
一小时后(下午6点)如果我再次看到它会与6/15/2020/6pm的价格进行比较吗?
foreach (string key in HttpContext.Current.Request.Form.AllKeys)
{
string value = HttpContext.Current.Request.Form[key];
}
Run Code Online (Sandbox Code Playgroud)
什么是上述代码的.net核心版本?好像.net核心取出AllKeys并用Keys代替它.我试图将上面的代码转换为.net核心方式,但它抛出了无效的操作异常.
HttpContext.Request.Form ='HttpContext.Request.Form'抛出类型'System.InvalidOperationException'的异常
转换代码:
foreach (string key in HttpContext.Request.Form.Keys)
{
}
Run Code Online (Sandbox Code Playgroud) 我正在 Azure VM (Windows Server 2016) 上运行 mirth,并尝试从 Meditech 获取 HL7 消息。不太熟悉 tcp/ip 概念,因此在此感谢帮助。当 Meditech 向我的服务器(VM)发送 HL7 消息时,我应该如何配置 mirth 频道中的设置?
例如,在Listener Settings
面板中,
1.选择Specific interface
并输入我的VM的公共IP地址。
2.将我在入站规则中设置的端口号放入Local Port
或者我把Meditech的IP地址和端口号放进去Listener Settings
?
我有一个登录对话框,并希望在按下 Enter 时防止它自动关闭。
更具体地说,当用户输入凭据并按下 Enter 并且凭据响应作为错误返回时,我希望对话框保持不变(因此我可以向他们显示一些错误消息并让用户再次尝试)。
所以这就是我所做的:
export class LoginComponent {
constructor(public dialogRef: MatDialogRef<LoginComponent>) { }
onSubmit(): void {
this.authService.login(...)
.subscribe(res => {
...
},
error => {
this.dialogRef.disableClose = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
this.dialogRef.disableClose = true;
即使响应作为错误返回,仍然关闭对话框。
我该怎么做?
编辑
登录.component.ts
<mat-toolbar>
<span>Login</span>
</mat-toolbar>
<mat-card class="my-card">
<div *ngIf="error" style="color: red;">{{error}}</div><br />
<form (ngSubmit)="onSubmit()" [formGroup]="loginForm">
<mat-card-content>
<mat-form-field appearance="outline" class="full-width">
<mat-label>Email</mat-label>
<input matInput placeholder="Email"
formControlName="email"
[formControl]="emailFormControl"
[errorStateMatcher]="matcher" />
<mat-error *ngIf="emailFormControl.hasError('email') && !emailFormControl.hasError('required')">
Enter valid email address
</mat-error>
<mat-error *ngIf="emailFormControl.hasError('required')">
Required field
</mat-error> …
Run Code Online (Sandbox Code Playgroud) bytes9 private _randomness;
function getRandomness() public view returns (uint256) {
return uint256(keccak256(abi.encode(_randomness, address(this))));
}
modifier updateRandomness() {
bytes32 randomness = _randomness;
assembly {
// Pick any of the last 256 blocks psuedorandomly for the blockhash.
// Store the blockhash, the current `randomness` and the `coinbase()`
// into the scratch space.
mstore(0x00, blockhash(sub(number(), add(1, byte(0, randomness)))))
// `randomness` is left-aligned.
// `coinbase()` is right-aligned.
// `difficulty()` is right-aligned.
// After the merge, if [EIP-4399](https://eips.ethereum.org/EIPS/eip-4399)
// is implemented, the randomness will be …
Run Code Online (Sandbox Code Playgroud) 我已经将我的项目从 cli 5 升级到 cli 7,但我遇到了一些问题
import { Component, Input, Output, OnInit, EventEmitter } from '@angular/core'
import { Observable, Subscription } from 'rxjs/Rx';
@Component({
selector: 'countdown',
template: '{{ countDown | async | formatTime }}'
})
export class CountdownComponent implements OnInit {
@Input() seconds: string;
@Output() checkTime: EventEmitter<number> = new EventEmitter();
countDown: any;
constructor() {}
ngOnInit() {
const start = parseInt(this.seconds, 10);
this.countDown = Observable.timer(0, 1000)
.map(i => start - i) // decrement the stream's value and return
.takeWhile(i => i …
Run Code Online (Sandbox Code Playgroud) c# ×5
asp.net-core ×3
angular6 ×1
angular7 ×1
api ×1
async-await ×1
automapper ×1
binance ×1
chainlink ×1
dataset ×1
datatable ×1
dbset ×1
dialog ×1
hl7 ×1
httpcontext ×1
javascript ×1
mirth ×1
python ×1
rxjs ×1
solidity ×1
tcp ×1
timer ×1