在最新版本的Asp.Net SignalR中,添加了一种使用"IUserIdProvider"接口向特定用户发送消息的新方法.
public interface IUserIdProvider
{
string GetUserId(IRequest request);
}
public class MyHub : Hub
{
public void Send(string userId, string message)
{
Clients.User(userId).send(message);
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:我如何知道我向谁发送信息?这种新方法的解释非常肤浅.SignalR 2.0.0的声明草案带有这个bug并且没有编译.有没有人实现过这个功能?
更多信息:http://www.asp.net/signalr/overview/signalr-20/hubs-api/mapping-users-to-connections#IUserIdProvider
拥抱.
我想知道如何获取从下拉菜单中选择的TEXT的值,只记得我的下拉菜单中有固定数据,并且没有填充"ko.observableArray()".有任何想法吗?
当我选择想要的选项时:值和文本选择.
<p>
Select a car:
<select data-bind="value: selectedValue, optionsText:???">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</p>
<span data-bind="text: selectedValue"></span>
<br/>
<span data-bind="text: selectedText"></span>
Run Code Online (Sandbox Code Playgroud)
我的ko ViewModel:
var viewModel = {
selectedValue : ko.observable(),
selectedText : ko.observable()
};
ko.applyBindings(viewModel);
Run Code Online (Sandbox Code Playgroud)
看到这个小提琴:JSFiddle
我有这个例子JSFIDDLE包含一个圆圈,但我很难根据它的内容使其响应,在上面的例子中,当内容很长时,它会溢出圆圈.
.cd-single-point {
margin:50px;
position: absolute;
border-radius: 50%;
}
.cd-single-point > a {
position: relative;
text-align:center;
padding:2px;
text-decoration: none;
z-index: 2;
display: block;
width: 20px;
height: 20px;
border-radius: inherit;
background: #d95353;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
-webkit-transition: background-color 0.2s;
-moz-transition: background-color 0.2s;
transition: background-color 0.2s;
}
.cd-single-point::after {
/* this is used to create the pulse animation */
content: '';
position: absolute;
z-index: …Run Code Online (Sandbox Code Playgroud) 我需要测试一个 type 的方法void,它只是使用 LOG 框架(Serilog)在我的 LOG 变量上插入一条消息。
见实现示例:
public class MyClass
{
public MyClass(ILogger<IProcess> logger)
{
this.logger = logger;
}
private readonly ILogger logger;
//...Anothers methods...
public void LogInit(Guid processId, string folder, string[] args)
{
var myObject = new
{
ProcessId = processId,
Folder = folder,
Arguments = args
};
this.logger.LogWarning("{@myObject}", myObject);
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们需要为 LogInit (...)
这个方法真的需要测试吗?或者更确切地说,它的存在有意义吗?
我在读一些关于:
“如果你的方法没有副作用,也没有返回任何东西,那么它就没有做任何事情。”
在这种情况下,该方法只是“单独”创建以维护代码的组织并进一步分离类的职责。
那讲得通?
编辑: @PeterBons
我们无权访问在接口 ( logger) 中注册的消息,例如:this.logger.GiveMeWarningLogs()...
我的AsyncController中有以下异步方法:
public async Task<Dashboard> GetFeeds()
{
var movies = new HttpClient().GetStringAsync("http://netflix/api/MyMovies");
var tweets = new HttpClient().GetStringAsync("http://twitter/api/MyTweets");
await Task.WhenAll(movies, tweets);
Dashboard dash = new Dashboard();
dash.Movies = Deserialize<Movies >(movies.Result);
dash.Tweets = Deserialize<Tweets >(tweets.Result);
return dash;
}
Run Code Online (Sandbox Code Playgroud)
在这个方法中做不同的调用API,一个具有彼此不同的返回时间.我无法理解的Task<>是因为我必须等待两人的回归才能更新我的客户?因为我正在创造新的线程.

想象一下我在PartialView中播放每个API的返回,我认为结果会得到:
- 首先我会有我的电影列表(它只需要5s), - >显示给我的用户
- 然后我的推文列表 - >显示给我的用户
但我看到的是:
- 虽然Twitter请求没有结束,但我没有在屏幕上为我的用户播放我从Netflix获得的数据.
最大的问题是:A Task<>仅用于加快处理速度吗?
我根据我订购的每个API的周转时间无法在屏幕上播放信息?
这是对我的方法的调用
public async Task<ActionResult> Index()
{
var feeds = await GetFeeds();
return View(feeds);
}
Run Code Online (Sandbox Code Playgroud)
我承认,我很困惑,或者,也许你不明白这个概念Task<>.
我有这个通用的方法:
public static T FindObject<T> (this GameObject gameObject, string objectName, Type type)
{
var ret = gameObject.GetComponentsInChildren(type).Where(w => w.name == objectName).First();
return (T)Convert.ChangeType(ret, type);
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼它:
var myVar = UI_POINTS.FindObject("Score", typeof(Text));
Run Code Online (Sandbox Code Playgroud)
但我给出以下错误:
无法从用法中推断出方法'ExtensionMethods.FindObject(GameObject,string,Type)'的类型参数.尝试显式指定类型参数.
为什么他不懂方法调用?
先感谢您.
我有以下代码
$(document).ready(function () {
VerifyCustomerFilter();
$("#ToDateStor").on("DateSet", function () {
...
);
function VerifyCustomerFilter() {
if(toDate != "")
$("#ToDateStor").trigger('DateSet'); //This does not work
}
}
Run Code Online (Sandbox Code Playgroud)
当我在函数'VerifyCustomerFilter()'中的条件为真时,无法触发我创建的自定义事件.
但是,当我在DatePicker的事件中触发事件时,它可以完美地工作:请参阅
$("#calTo").datepicker({
showButtonPanel: false,
onClose: function (dateText, inst) {
var ToDate = $(this).val().toString();
$('#ToDateStor').html(ToDate).trigger('DateSet'); // This works!
}
});
Run Code Online (Sandbox Code Playgroud)
也已经尝试过使用了triggerHandler().
我该怎么做错了?
是否有一个函数可以在JSON字符串上选择多个"节点"?
样品:
var myJson = @"{
'channel' : 'nine',
'segment' : 'mobile',
'food' : 'pizza'
}";
var myObjectFromJson = JObject.Parse(myJson);
var channelFoodNodes = myObjectFromJson.SelectTokens("channel, food"); //<- This call not works!
Run Code Online (Sandbox Code Playgroud)
预期结果:
{
"channel" : "nine",
"food" : "pizza"
}
Run Code Online (Sandbox Code Playgroud)
参考:
c# ×4
asp.net-mvc ×2
.net ×1
asp.net ×1
async-await ×1
css ×1
css-shapes ×1
css3 ×1
generics ×1
geometry ×1
jquery ×1
json ×1
json.net ×1
knockout.js ×1
logging ×1
methods ×1
real-time ×1
select-menu ×1
serilog ×1
signalr ×1
unit-testing ×1
void ×1