我听说人们一直在写这些程序,我知道他们做了什么,但他们是如何做到的呢?我正在寻找一般概念.
screen-scraping html-content-extraction pdf-scraping web-scraping console-scraping
因此情况是这样的:用户执行某些操作(例如获得徽章或解锁某些内容)并发送电子邮件通知.一个给用户(有一条消息,比如"你已解锁XYZ ......"),然后向他们的每个朋友发送一条不同的消息("你的朋友已解锁XYZ ......").
public interface INotify
{
void Notify(User user, User friend);
}
public class NotificationService
{
private IEnumerable<INotify> _notifiers;
public NotificationService(IEnumerable<INotify> notifiers)
{
_notifiers = notifiers;
}
public SendNotifications()
{
User user = GetUser();
IEnumerable<User> friends = GetFriends();
foreach(var notifier in _notifiers)
{
//Send notification to user
notifier.Notify(user, null);
//send notification to users friends
foreach(var friend in friends)
notifier.Notify(user, friend);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用moq来测试每个通知符被称为2x.一旦将null作为第二个参数传递,第二次将值传递给两个参数.
[Test]
public void MakeSureEveryoneIsNotified()
{
var notifierMock = new Mock<INotifier>();
var svc = new NotificationService(new …
Run Code Online (Sandbox Code Playgroud) 我知道这里有一个非常相似的问题,但我希望能有更好的探索.如果HttpContext真的在后台使用HttpRuntime.Cache,为什么我会使用HttpContext.Cache而不是HttpRuntime.Cache?
在使用ASP.NET模拟Windows服务来运行预定作业的文章中, Omar使用HttpContext来存储他的缓存项,但是当Jeff Atwood 在这里实现它时,他选择使用HttpRuntime.显然,在这种特殊情况下,它是有意义的,因为您不必执行Web请求将缓存项添加回HttpContext.
但是,我正在寻找一些关于何时使用一个与另一个的好指针.
如何在VB中创建泛型的默认值?在C#我可以打电话:
T variable = default(T);
Run Code Online (Sandbox Code Playgroud)
基本上我希望能够做到这一点:
session.ExecuteSql("...");
我不需要它映射到任何实体或返回任何值.有什么建议?
我正在尝试从xml文件中提取一些信息,并根据需要更新/创建应用程序池.这是我正在阅读的xml:
<?xml version="1.0" encoding="utf-8"?>
<appPool name="MyAppPool">
<enable32BitAppOnWin64>true</enable32BitAppOnWin64>
<managedPipelineMode>Integrated</managedPipelineMode>
<managedRuntimeVersion>v4.0</managedRuntimeVersion>
<autoStart>true</autoStart>
</appPool>
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试用它做的事情:
#read in the xml
$appPoolXml = [xml](Get-Content $file)
#get the name of the app pool
$name = $appPoolXml.appPool.name
#iterate over the nodes and update the app pool
$appPoolXml.appPool.ChildNodes | % {
#this is where the problem exists
set-itemproperty IIS:\AppPools\$name -name $_.Name -value $_.Value
}
Run Code Online (Sandbox Code Playgroud)
$_.Name
返回节点的名称,(即enable32BitAppOnWin64
)是正确的,但.Value
属性不返回任何内容.如何提取我想要的数据?
每当用户点击iframe中不是来自同一域的网页上的链接时,我都会收到通知.我知道xss限制,但我需要知道的是在iframe中提供的当前页面.有没有办法在不违反xss规则的情况下执行此操作?
我一直在使用我的MV-VM开发一个非常大的LOB应用程序,我称之为MV-MC(Model-View-ModelController),它是MVC和MV-VM之间的一种组合.我已经发布了这个答案,关于如何在MV-VM中实例化视图,问题是" 什么是最常见的错误 - 在wpf开发中制造 ".
Sam就我的回答发表了以下评论:
这会产生一个后续问题:如何创建视图?我使用RelayCommands将视图中的操作绑定到ViewModel,因此视图甚至不知道某个操作已被触发,也不知道他应该打开一个新视图.解决方案:在VM中创建一个事件以供View订阅?
当我最初开始MV-VM开发时,我认为一切都应该存在于ViewModel中,并且已经研究了很多像Josh Smith和Karl Shifflett这样的人的例子.但是,我还没有提出一个很好的例子,说明命令何时需要存在于ViewModel中.
例如,假设我有一个显示客户的ListView,以及我点击的按钮,允许我编辑当前选定的客户.ListView(View)绑定到CustomerVM(ViewModel).单击该按钮将触发EditCustomerCommand,这将打开一个弹出窗口,允许我编辑CustomerVM的所有属性.这个EditCustomerCommand在哪里?如果它涉及打开一个窗口(UI功能),它不应该在视图的代码隐藏中定义吗?
有没有人有任何关于何时应该在View和ViewModel中定义命令的例子?
Matthew Wright在下面说:
从列表中删除和删除将是很好的例子.在这些情况下,会添加空白记录或ViewModel删除当前记录.视图采取的任何操作都应该响应发生的事件.
所以,如果我点击新按钮,会发生什么?Customer ViewModel创建了一个CustomerVM的新实例并添加到它的集合中吗?那么我的编辑屏幕怎么会打开呢?该视图应该创建Customer ViewModel的新实例,并将其传递给ParentVM.Add(newlyCreatedVM)方法吗?
假设我通过VM上的DeleteCommand删除客户记录.VM调用业务层并尝试删除记录.它不能这样它会向VM返回一条消息.我想在对话框中显示此消息.视图如何从命令操作中获取消息?
这是一个难以制定的问题.我想知道HttpContext.Current如何为每个请求分配一个唯一的实例,因为它是一个静态对象?
谢谢!
这是一个奇怪的.我正在运行MVC 3并且具有自定义操作结果,该结果包装异常并返回消息以及标准HTTP错误.
public class ExceptionResult : ActionResult
{
private readonly Exception _exception;
public ExceptionResult(Exception exception)
{
_exception = exception;
}
public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
response.ClearHeaders();
response.Cache.SetNoStore();
response.ContentType = ContentType.Json;
var baseEx = _exception as BaseException ?? new ServerException(_exception);
var result = baseEx.GetResult();
var json = result.ToJSON();
response.Write(json);
response.StatusCode = (int)result.Status.Code;
}
}
Run Code Online (Sandbox Code Playgroud)
当我在本地运行时,我得到了我期望的结果:
HTTP/1.1 400 Bad Request
Cache-Control: no-store
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
Date: Thu, 01 Dec 2011 19:00:03 GMT
Content-Length: …
Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×2
asp.net ×2
httpcontext ×2
vb.net ×2
.net-4.0 ×1
asp.net-mvc ×1
caching ×1
generics ×1
iframe ×1
iis ×1
jquery ×1
mocking ×1
moq ×1
mvvm ×1
nhibernate ×1
pdf-scraping ×1
powershell ×1
testing ×1
web-scraping ×1
wpf ×1
xml ×1