在metro应用程序中,我需要执行许多WCF调用.有大量的调用,所以我需要在并行循环中进行调用.问题是并行循环在WCF调用完成之前退出.
你会如何重构这个按预期工作?
var ids = new List<string>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
var customers = new System.Collections.Concurrent.BlockingCollection<Customer>();
Parallel.ForEach(ids, async i =>
{
ICustomerRepo repo = new CustomerRepo();
var cust = await repo.GetCustomer(i);
customers.Add(cust);
});
foreach ( var customer in customers )
{
Console.WriteLine(customer.ID);
}
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud) 我的数据库中有3个相关表.
CREATE TABLE dbo.Group
(
ID int NOT NULL,
Name varchar(50) NOT NULL
)
CREATE TABLE dbo.User
(
ID int NOT NULL,
Name varchar(50) NOT NULL
)
CREATE TABLE dbo.Ticket
(
ID int NOT NULL,
Owner int NOT NULL,
Subject varchar(50) NULL
)
Run Code Online (Sandbox Code Playgroud)
用户属于多个组.这是通过多对多关系完成的,但在这种情况下无关紧要.票证可以由组或用户通过dbo.Ticket.Owner字段拥有.
什么是最正确的方式描述故障单和可选的用户或组之间的这种关系?
我想我应该在票证表中添加一个标志,说明拥有它的类型.
我通过原型设计创建了一个javascript对象.我正在尝试动态呈现表格.虽然渲染部分很简单并且工作正常,但我还需要处理动态渲染表的某些客户端事件.那也很容易.我遇到问题的地方是处理事件的函数内部的"this"引用.它不是"this"引用对象,而是引用引发事件的元素.
见代码.有问题的区域在"ticketTable.prototype.handleCellClick = function()"中
function ticketTable(ticks)
{
// tickets is an array
this.tickets = ticks;
}
ticketTable.prototype.render = function(element)
{
var tbl = document.createElement("table");
for ( var i = 0; i < this.tickets.length; i++ )
{
// create row and cells
var row = document.createElement("tr");
var cell1 = document.createElement("td");
var cell2 = document.createElement("td");
// add text to the cells
cell1.appendChild(document.createTextNode(i));
cell2.appendChild(document.createTextNode(this.tickets[i]));
// handle clicks to the first cell.
// FYI, this only works in FF, need a little more code …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个适用于android的java库,可以从FTP服务器下载和恢复文件.有谁知道这样的图书馆.我发现了很多客户端应用程序,但没有独立的库.
在我看来,让域服务需要一个IOptions实例来传递它配置是一个坏主意.现在我已经将额外的(不必要的?)依赖项拉入库中.我已经看到很多在网络上注入IOse的例子,但是我没有看到它带来的额外好处.
为什么不将实际的POCO注入服务?
services.AddTransient<IConnectionResolver>(x =>
{
var appSettings = x.GetService<IOptions<AppSettings>>();
return new ConnectionResolver(appSettings.Value);
});
Run Code Online (Sandbox Code Playgroud)
甚至使用这种机制:
AppSettings appSettings = new AppSettings();
Configuration.GetSection("AppSettings").Bind(appSettings);
services.AddTransient<IConnectionResolver>(x =>
{
return new ConnectionResolver(appSettings.SomeValue);
});
Run Code Online (Sandbox Code Playgroud)
使用设置:
public class MyConnectionResolver
{
// Why this?
public MyConnectionResolver(IOptions<AppSettings> appSettings)
{
...
}
// Why not this?
public MyConnectionResolver(AppSettings appSettings)
{
...
}
// Or this
public MyConnectionResolver(IAppSettings appSettings)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
为什么附加依赖?IOptions给我带来了什么而不是旧式的注入方式?
我正在使用ASP.NET Core为Android客户端提供API.Android以Google帐户登录,并将ID令牌JWT作为承载令牌传递给API.我有应用程序工作,它确实通过了身份验证检查,但我不认为它正在验证令牌签名.
根据Google的文档,我可以将此网址称为 https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123,但我无法在服务器端找到相应的挂钩来执行此操作.另外根据Google文档,我可以以某种方式使用客户端访问API来执行此操作,而无需每次都调用服务器.
我的配置代码:
app.UseJwtBearerAuthentication( new JwtBearerOptions()
{
Authority = "https://accounts.google.com",
Audience = "hiddenfromyou.apps.googleusercontent.com",
TokenValidationParameters = new TokenValidationParameters()
{
ValidateAudience = true,
ValidIssuer = "accounts.google.com"
},
RequireHttpsMetadata = false,
AutomaticAuthenticate = true,
AutomaticChallenge = false,
});
Run Code Online (Sandbox Code Playgroud)
如何让JWTBearer中间件验证签名?我已经接近放弃使用MS中间件并自行推出.
因此,我需要构建一个自助服务终端类型的应用程序,以便在网吧中使用.该应用程序需要加载并显示一些要做的事情选项.一种选择是启动IE浏览.另一种选择是玩游戏.
我一直在读我想要做的就是更换Windows shell并让它在操作系统加载时运行我的应用程序.我还必须禁用任务管理器.
这是一个多部分问题.
我需要将url参数连接到锚标记上.我该如何将其插入以下模板?
<tbody data-bind="foreach: Customers">
<tr class="rowEven">
<td data-bind="text: Name"></td>
<td data-bind="text: CustomerType"></td>
<td><a href="customers.aspx?customer=[CustomerAccountIDHere]">Manage</a><a href="#">Guest Admin</a></td>
</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
我试过这不会运气:
<tr class="rowEven">
<td data-bind="text: Name"></td>
<td data-bind="text: CustomerType"></td>
<td><a data-bind="attr: { href: 'customers.aspx?customer=' + CustomerAccount_BID}">Manage</a><a href="#">Guest Admin</a></td>
</tr>
Run Code Online (Sandbox Code Playgroud) 我有一些页面需要通过服务器端呈现,以使它们对搜索引擎友好.对于搜索引擎,它应该作为经典网站.对于用户,我想让界面更具互动性.我的想法是渲染页面服务器端,然后使用knockout和jquery通过ajax再次获取数据并将其绑定到页面.
我担心没有内容或重复内容的闪烁.对于这样的案例,是否有最佳实践/模式?
这个过程看起来像这样:
我要挂掉的部分是如何使用knockout/jquery预渲染,清除和重新渲染.
也许我的思考过程有点偏差,我很乐意听到反馈.
我正试图挂钩第三方应用程序,以便我可以绘制到它的屏幕.在屏幕上绘图是容易的,我需要它没有帮助,但我似乎有使用问题SetWindowsHookEx
来处理WH_GETMESSAGE
.我无法弄清楚最后两个参数传递的内容.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowDrawer
{
public partial class Form1 : Form
{
private delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
static IntPtr hHook;
IntPtr windowHandle;
uint processHandle;
HookProc PaintHookProcedure;
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern System.IntPtr FindWindowByCaption(int ZeroOnly, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowsHookEx", SetLastError = true)]
static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint …
Run Code Online (Sandbox Code Playgroud) c# ×5
asp.net-core ×2
knockout.js ×2
android ×1
async-await ×1
dom-events ×1
ftp ×1
google-api ×1
google-oauth ×1
java ×1
javascript ×1
jwt ×1
kiosk ×1
oop ×1
shell ×1
sql-server ×1
wcf ×1
windows ×1
wm-paint ×1