在为Windows开发.NET 4.5桌面应用程序时,我习惯使用System.Net.Http.HttpClient后端Web API进行所有通信.我现在正在开发一个Windows应用商店应用程序并注意到它的存在Windows.Web.Http.HttpClient.我已经找到了两个客户之间的主要区别但没有运气的信息.
从MSDN我知道我应该开始Windows.Web.Http.HttpClient在我的Windows应用商店应用中使用,因为System.Net.Http.HttpClient可能会从API中删除:
注意 System.Net.Http和System.Net.Http.Headers命名空间可能在Windows的未来版本中不可用,以供Windows应用商店应用使用.从Windows 8.1和Windows Server 2012 R2开始,使用Windows.Web.Http命名空间中的Windows.Web.Http.HttpClient和相关的Windows.Web.Http.Headers和Windows.Web.Http.Filters命名空间代替Windows运行时应用程序.
但除了这些信息之外,我很难弄清楚主要区别是什么,使用的主要好处是Windows.Web.Http.HttpClient什么?它添加了什么,我们还没有进入System.Net.Http.HttpClient?
非常感谢官方文档支持的答案.
在knockoutJS中,可以订阅可观察的 viewmodel属性的更改,例如:
myViewModel.personName.subscribe(function(newValue) {
alert("The person's new name is " + newValue);
});
Run Code Online (Sandbox Code Playgroud)
我目前正在学习AngularJS,我想知道AngularJS中是否有相同的东西?我试过寻找这个,但没有运气.
根据这里的教程,
集合可以是数组或对象,也可以是JavaScript中的关联数组
这是否意味着所有的功能collection同样适用于对象文字.例如,我想根据条件选择值.说,
var obj = {
"1": {id: 1, val: 2},
"2": {id: 2, val: 5},
"3": {id: 3, val: 8},
"4": {id: 4, val: 1}
}
Run Code Online (Sandbox Code Playgroud)
我想找到val字段的最大值和最小值.看看API,我想pluck用来获取一个数组val,然后做min和max.
谢谢.
我刚刚在我的一个托管Bamboo远程代理的构建服务器(Win Server 2008 R2)上安装了nodejs.完成安装并重新启动后,我遇到了以下情况:
远程Bamboo构建代理作为具有用户MyDomain\MyUser的Windows服务运行.当使用内联powershell任务的构建正在执行时,它会因错误而失败(来自构建代理日志):
com.atlassian.utils.process.ProcessNotStartedException: powershell could not be started
...
java.io.IOException: Cannot run program "powershell"
...
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
以MyDomain\MyUser登录到服务器,我检查过powershell在路径中:
where powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Run Code Online (Sandbox Code Playgroud)
我试图重启服务并重启机器多次.没运气.唯一有效的方法是,如果我将脚本作为bat文件执行,并使用powershell的绝对路径 - 但我不希望这样.
我已经在这方面寻找解决方案,但即使这个看起来很相关:在更新到PowerShell 3之后Hudson找不到powershell - 提议的解决方案不起作用.
我在这里错过了什么?
我使用此代码获取MS Word 2007文档(.docx)中使用的标题字符串数组:
dynamic arr = Document.GetCrossReferenceItems(WdReferenceType.wdRefTypeHeading);
Run Code Online (Sandbox Code Playgroud)
使用调试器,我看到arr动态分配了一个String数组,其中包含文档中所有标题的标题(大约40个条目).到现在为止还挺好.
然后,我想访问字符串,但不管我怎么做,我得到以下异常:
InvalidCastException:
Unable to cast object of type 'System.String[*]' to type 'System.String[]'.
Run Code Online (Sandbox Code Playgroud)
我尝试过不同的访问字符串的方法:
按索引:
String arr_elem = arr[1];
Run Code Online (Sandbox Code Playgroud)
通过强制转换为IEnumerable:
IEnumerable list = (IEnumerable)arr;
Run Code Online (Sandbox Code Playgroud)
通过使用简单的foreach循环:
foreach (String str in arr)
{
Console.WriteLine(str);
}
Run Code Online (Sandbox Code Playgroud)
但是,无论我尝试什么,我总是会遇到如上所示的相同异常.
任何人都可以解释我在这里失踪/我做错了什么?特别是String[*]- 它是什么意思?
我们遇到了ReSharper(7/VS2010)的问题:当您使用它在同一个解决方案中将一个项目的引用添加到另一个项目时,它有时会向引用项目的输出添加二进制引用而不是项目引用.是否可以禁用此行为,理想情况下,它只添加项目引用,但无法完全禁用添加引用?
在Html课堂上,Android有:
public static Spanned fromHtml (String source)
Run Code Online (Sandbox Code Playgroud)
根据文件:
从提供的HTML字符串返回可显示的样式文本.
..并将其与:
public void setText (CharSequence text, TextView.BufferType type)
Run Code Online (Sandbox Code Playgroud)
根据该方法的TextView文档:
设置此TextView要显示的文本(请参阅setText(CharSequence)),并设置它是否存储在可设置样式/ spannable的缓冲区中以及是否可编辑.
..使得在TextView中显示带有HTML标记的字符串成为可能(来自此StackOverflow答案的示例):
String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);
Run Code Online (Sandbox Code Playgroud)
我的问题是 - 在iOS中与此相同的是什么?
我做了一些研究,似乎人们建议使用UIWebView这个目的 - 但这真的是唯一的解决方案吗?它是推荐的解决方案吗?
谢谢.
我正在编写一个与JavaScript一起使用的正则表达式.在测试时,我遇到了一些奇怪的行为,并将其归结为以下内容:
/^[a-z]/.test("abc"); // <-- returns true as expected
/^[a-z]/.test(null); // <-- returns true, but why?
Run Code Online (Sandbox Code Playgroud)
我假设最后一个案例将返回,false因为它不符合正则表达式(值为null,因此,不要从范围中的字符开始).那么,任何人都可以解释为什么不是这样吗?
如果我在C#中进行相同的测试:
var regex = new Regex("^[a-z]");
var res = regex.IsMatch(null); // <-- ArgumentNullException
Run Code Online (Sandbox Code Playgroud)
......我得到了一个ArgumentNullException有意义的东西.所以,我想在JavaScript中测试正则表达式时,你必须手动进行null检查吗?
我试图寻找解释,但没有任何运气.
如果我有这样的事件:
public delegate void MyEventHandler(object sender, EventArgs e);
public event MyEventHandler MyEvent;
Run Code Online (Sandbox Code Playgroud)
并添加这样的事件处理程序:
MyEvent += MyEventHandlerMethod;
Run Code Online (Sandbox Code Playgroud)
......那么有可能以某种方式注册吗?换句话说 - 是否可能有类似的东西:
MyEvent.OnSubscribe += MySubscriptionHandler;
Run Code Online (Sandbox Code Playgroud) Let's say I new up the HttpClient and send off a request to a protected endpoint like this:
var httpClient = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "url");
var response = await httpClient.SendAsync(request);
Run Code Online (Sandbox Code Playgroud)
I then get a response with the following headers:
HTTP/1.1 401 Unauthorized
Content-Type: text/html
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
WWW-Authenticate: Basic
Date ...
Run Code Online (Sandbox Code Playgroud)
From the response headers, I see that I have three different options to authenticate with the server (Negotiate, NTLM, Basic). I then update my …
我需要在单个视图上禁用表单的客户端验证.
我该怎么做呢?
我不想只是禁用以下JS文件:
<script src="@Url.Content("~/Scripts/jquery/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud) 从这个问题的答案:HttpClient和HttpClientHandler必须处理?,我发现最好的做法是不要处理System.Net.Http.HttpClient每个HTTP请求.特别指出:
HttpClient的标准用法是不要在每次请求后处理它.
这没关系.
我的问题是,这种"模式"是否也适用于此Windows.Web.Http.HttpClient?或者它应该按HTTP请求处理?我认为文档对此有点模糊.在其中一个样本中,它只是说明:
// Once your app is done using the HttpClient object call dispose to
// free up system resources (the underlying socket and memory used for the object)
httpclient.Dispose();
Run Code Online (Sandbox Code Playgroud)
我相信这可以通过两种方式阅读,因此对此有任何具体的意见.
我最近在我的ASP.NET MVC3应用程序中从0.4.0更新到SignalR 0.5.2.在SignalR 0.5.2中,Context实例上的"User"属性是null用户断开连接时 - 这是设计的吗?
从下面的"立即窗口"快照中可以看出,我所知道Context的客户端断开连接的时间是断开连接的客户端的ConnectionId.
Context
{SignalR.Hubs.HubCallerContext}
ConnectionId: "... some connection id ..."
Headers: null
QueryString: null
RequestCookies: null
ServerVariables: null
User: null
Run Code Online (Sandbox Code Playgroud)
简化,我的SignalR Hub实现如下:
public class MyHub : Hub, IDisconnect, IConnected
{
// some other code
public Task Disconnect()
{
var user = Context.User; // <-- This is null
// more code
}
}
Run Code Online (Sandbox Code Playgroud)
总结一下 - 我忘了这里的东西,还是设计Context.User null?如果是这样 - 为什么?:)
c# ×5
.net ×4
javascript ×3
.net-core ×1
angularjs ×1
asp.net-mvc ×1
bamboo ×1
events ×1
ios5 ×1
jquery ×1
ms-word ×1
node.js ×1
objective-c ×1
powershell ×1
regex ×1
resharper ×1
signalr ×1
validation ×1
windows ×1