Folks,
伙计们,
We have just launched a survey application recently, its MVC using LINQ to entity.
我们最近刚刚发布了一个调查应用程序,它的MVC使用LINQ to entity。
We have a SurveyStatus table.
我们有一个测量状态表。
Every monday we want to run an automatic query that will check if a survey is complete. If the survey is complete then send an email to inform the user.
每个星期一,我们都想运行一个自动查询,它将检查一个调查是否完成。如果调查完成,然后发送电子邮件通知用户。
Previously we had done this using a scheduled task that ran a VB script to linked to the database. However now we would like to create this EmailService within the project to take advnatge of the Model and services already there.
在此之前,我们使用了一个调度任务,该任务运行一个VB脚本以链接到数据库。然而,现在我们希望在项目中创建这个电子邮件服务,以接受已经存在的模型和服务的建议。
Can anybody give me some advice on the best way to achieve this?
有人能给我一些建议吗?
Thanks in advance
谢谢提前
4 个解决方案
#1
1
Please take a look at the Revalee open source project.
请查看Revalee开源项目。
Revalee is a service that allows you to schedule web callbacks to your ASP.NET MVC application. Revalee manages task persistence and scheduling using a Windows Service, but leverages your ASP.NET MVC application to handle the processing effort (i.e., "the work").
Revalee是一种允许您将web回调调度到您的ASP的服务。净MVC应用程序。Revalee使用Windows服务管理任务持久性和调度,但是利用您的ASP。NET MVC应用程序来处理处理工作(例如。“工作”)。
The following is the workflow of an MVC application that uses Revalee:
下面是使用Revalee的MVC应用程序的工作流程:
Revalee Workflow http://revalee.sageanalytic.com/Images/workflow.png
Revalee工作流http://revalee.sageanalytic.com/Images/workflow.png
In your case, you would schedule a future callback (when the user submits the survey) to trigger an action in your MVC application that would inspect your survey results. The outcome of that inspection would then trigger (or not) a subsequent email message to be sent to the user.
在您的例子中,您将安排一个未来的回调(当用户提交调查时)来触发MVC应用程序中的一个操作,该操作将检查您的调查结果。检查的结果将触发(或不)随后的电子邮件消息发送给用户。
<edit>
<编辑>
Something else to consider...
别的考虑……
You may want to change the way you approach your problem domain. Instead of scheduling a fixed task "every Monday" (that is, execute a process that tests all surveys all at the same time), flip the processing around: process each survey individually. Understandably this is problematic without a callback solution, like Revalee. But with Revalee, you can schedule each user's survey to be processed +48 hours (for example) after they submit it. This does two things:
您可能想要改变处理问题域的方式。与其“每周一”调度一个固定的任务(也就是说,执行一个同时测试所有调查的过程),不如改变处理:逐个处理每个调查。可以理解,如果没有Revalee这样的回调解决方案,这是有问题的。但是使用Revalee,您可以将每个用户的调查安排在提交后的48小时内进行处理(例如)。这两件事:
-
It alters the survey inspection "work" from testing all surveys to testing a survey.
它改变了测量检查的“工作”,从测试所有的测量到测试一个测量。
-
It spreads out the inspection processing throughout all days of the week (and hours of the day). That is, it will no longer be limited to processing every Monday at exactly, say, 8 o'clock in the morning.
它将检查过程扩展到一周的所有时间(以及一天中的几个小时)。也就是说,它将不再局限于每周一上午8点进行处理。
To register a more individualized callback using Revalee, you might register a future callback like this:
要使用Revalee注册一个更个性化的回调,您可以注册一个未来的回调:
private void ScheduleSurveyInspection(int surveyId)
{
// The callback will be 48 hours from now
DateTimeOffset callbackTime = DateTimeOffset.Now.AddHours(48.0);
// The callback URL will include the ID of the survey to be reviewed
Uri callbackUrl = new Uri(
string.Format(
"http://mywebapp.com/Survey/Inspect/{0}",
surveyId
)
);
// Register the callback request with the Revalee service
RevaleeRegistrar.ScheduleCallback(callbackTime, callbackUrl);
}
When your MVC application is called back 48 hours later, your SurveyController
would process the callback using the following Inspect
action:
当您的MVC应用程序在48小时后被调用时,您的SurveyController将使用以下检查动作处理回调:
[AllowAnonymous]
[CallbackAction]
public ActionResult Inspect(int surveyId)
{
// TODO Lookup the survey's information and perform the necessary review
// ...
return new EmptyResult();
}
Naturally, if your current processing workflow cannot be changed from occurring once a week every Monday to occurring +48 hours after survey submission, then Revalee can still be used to schedule that task. Your callbackUrl
would simply be:
当然,如果您当前的处理工作流程不能从每周一次的每周一次更改为在调查提交后的48小时内发生,那么Revalee仍然可以用来安排这个任务。您的回调url将简单地为:
Uri callbackUrl = new Uri("http://mywebapp.com/Survey/InspectAll");
</edit>
< /编辑>
I hope this helps. Good luck!
我希望这可以帮助。好运!
Disclaimer: I was one of the developers involved with the Revalee project. To be clear, however, Revalee is free, open source software. The source code is available on GitHub.
免责声明:我是Revalee项目的开发人员之一。不过,需要澄清的是,Revalee是免费的开源软件。在GitHub上可以找到源代码。
#2
0
You have quite a few options here, but since this is an MVC project, you should definitely check out the MVC Mailer.
这里有很多选项,但由于这是一个MVC项目,所以一定要检查MVC Mailer。
What's nice about this, is that you can use a master page as a layout for your email, and a standard MVC view as the content for it. It's pretty easy to wire up, and there is some great documentation and examples to help you get started.
这样做的好处是,您可以使用主页作为电子邮件的布局,使用标准的MVC视图作为内容。连接起来非常容易,有一些很好的文档和示例可以帮助您入门。
Also, if you have to make changes to your emails depending on which user you're sending it to, you can just add those parameters to the controller methods that are serving up the email views - now you can format content based on who you're sending to, on the fly.
另外,如果你要根据你发送的用户的不同,对你的电子邮件进行修改,你可以把这些参数添加到提供电子邮件视图的控制器方法中——现在你可以根据你发送给谁的内容来格式化内容了。
Aside from that, all you'll need is an SMTP server to actually send the message, which it sounds like you already have.
除此之外,您所需要的只是一个SMTP服务器来实际发送消息,这听起来好像您已经有了。
#3
0
I suggest you to use FluentScheduler.
我建议你使用FluentScheduler。
A task scheduler that uses fluent interface to configure schedules. Useful for running cron jobs/automated tasks from your application.
一个任务调度程序,它使用流畅的接口来配置调度。对于从应用程序运行cron作业/自动任务非常有用。
This way you can use your already implemented methods.
通过这种方式,您可以使用已经实现的方法。
using FluentScheduler;
public class MyRegistry : Registry
{
public MyRegistry()
{
// Schedule an ITask to run at an interval
Schedule<MyTask>().ToRunNow().AndEvery(2).Seconds();
// Schedule an ITask to run once, delayed by a specific time interval.
Schedule<MyTask>().ToRunOnceIn(5).Seconds();
// Schedule a simple task to run at a specific time
Schedule(() => Console.WriteLine("Timed Task - Will run every day at 9:15pm: " + DateTime.Now)).ToRunEvery(1).Days().At(21, 15);
// Schedule a more complex action to run immediately and on an monthly interval
Schedule(() =>
{
Console.WriteLine("Complex Action Task Starts: " + DateTime.Now);
Thread.Sleep(1000);
Console.WriteLine("Complex Action Task Ends: " + DateTime.Now);
}).ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);
//Schedule multiple tasks to be run in a single schedule
Schedule<MyTask>().AndThen<MyOtherTask>().ToRunNow().AndEvery(5).Minutes();
}
}
FluentScheduler Github页面
#4
0
What about a simple console application to trigger your automated emails? My suggestion would be to use either a console application or a windows service scheduled to run every Monday by the host system's scheduling software (Windows Task Scheduler, cron, etc.).
用一个简单的控制台应用程序来触发您的自动电子邮件怎么样?我的建议是使用主机系统的调度软件(windows任务调度程序、cron等)在每周一运行的控制台应用程序或windows服务。
Here and here is an interesting discussion on the similar requirement like yours.
这里和这里有一个关于类似要求的有趣讨论。
#1
1
Please take a look at the Revalee open source project.
请查看Revalee开源项目。
Revalee is a service that allows you to schedule web callbacks to your ASP.NET MVC application. Revalee manages task persistence and scheduling using a Windows Service, but leverages your ASP.NET MVC application to handle the processing effort (i.e., "the work").
Revalee是一种允许您将web回调调度到您的ASP的服务。净MVC应用程序。Revalee使用Windows服务管理任务持久性和调度,但是利用您的ASP。NET MVC应用程序来处理处理工作(例如。“工作”)。
The following is the workflow of an MVC application that uses Revalee:
下面是使用Revalee的MVC应用程序的工作流程:
Revalee Workflow http://revalee.sageanalytic.com/Images/workflow.png
Revalee工作流http://revalee.sageanalytic.com/Images/workflow.png
In your case, you would schedule a future callback (when the user submits the survey) to trigger an action in your MVC application that would inspect your survey results. The outcome of that inspection would then trigger (or not) a subsequent email message to be sent to the user.
在您的例子中,您将安排一个未来的回调(当用户提交调查时)来触发MVC应用程序中的一个操作,该操作将检查您的调查结果。检查的结果将触发(或不)随后的电子邮件消息发送给用户。
<edit>
<编辑>
Something else to consider...
别的考虑……
You may want to change the way you approach your problem domain. Instead of scheduling a fixed task "every Monday" (that is, execute a process that tests all surveys all at the same time), flip the processing around: process each survey individually. Understandably this is problematic without a callback solution, like Revalee. But with Revalee, you can schedule each user's survey to be processed +48 hours (for example) after they submit it. This does two things:
您可能想要改变处理问题域的方式。与其“每周一”调度一个固定的任务(也就是说,执行一个同时测试所有调查的过程),不如改变处理:逐个处理每个调查。可以理解,如果没有Revalee这样的回调解决方案,这是有问题的。但是使用Revalee,您可以将每个用户的调查安排在提交后的48小时内进行处理(例如)。这两件事:
-
It alters the survey inspection "work" from testing all surveys to testing a survey.
它改变了测量检查的“工作”,从测试所有的测量到测试一个测量。
-
It spreads out the inspection processing throughout all days of the week (and hours of the day). That is, it will no longer be limited to processing every Monday at exactly, say, 8 o'clock in the morning.
它将检查过程扩展到一周的所有时间(以及一天中的几个小时)。也就是说,它将不再局限于每周一上午8点进行处理。
To register a more individualized callback using Revalee, you might register a future callback like this:
要使用Revalee注册一个更个性化的回调,您可以注册一个未来的回调:
private void ScheduleSurveyInspection(int surveyId)
{
// The callback will be 48 hours from now
DateTimeOffset callbackTime = DateTimeOffset.Now.AddHours(48.0);
// The callback URL will include the ID of the survey to be reviewed
Uri callbackUrl = new Uri(
string.Format(
"http://mywebapp.com/Survey/Inspect/{0}",
surveyId
)
);
// Register the callback request with the Revalee service
RevaleeRegistrar.ScheduleCallback(callbackTime, callbackUrl);
}
When your MVC application is called back 48 hours later, your SurveyController
would process the callback using the following Inspect
action:
当您的MVC应用程序在48小时后被调用时,您的SurveyController将使用以下检查动作处理回调:
[AllowAnonymous]
[CallbackAction]
public ActionResult Inspect(int surveyId)
{
// TODO Lookup the survey's information and perform the necessary review
// ...
return new EmptyResult();
}
Naturally, if your current processing workflow cannot be changed from occurring once a week every Monday to occurring +48 hours after survey submission, then Revalee can still be used to schedule that task. Your callbackUrl
would simply be:
当然,如果您当前的处理工作流程不能从每周一次的每周一次更改为在调查提交后的48小时内发生,那么Revalee仍然可以用来安排这个任务。您的回调url将简单地为:
Uri callbackUrl = new Uri("http://mywebapp.com/Survey/InspectAll");
</edit>
< /编辑>
I hope this helps. Good luck!
我希望这可以帮助。好运!
Disclaimer: I was one of the developers involved with the Revalee project. To be clear, however, Revalee is free, open source software. The source code is available on GitHub.
免责声明:我是Revalee项目的开发人员之一。不过,需要澄清的是,Revalee是免费的开源软件。在GitHub上可以找到源代码。
#2
0
You have quite a few options here, but since this is an MVC project, you should definitely check out the MVC Mailer.
这里有很多选项,但由于这是一个MVC项目,所以一定要检查MVC Mailer。
What's nice about this, is that you can use a master page as a layout for your email, and a standard MVC view as the content for it. It's pretty easy to wire up, and there is some great documentation and examples to help you get started.
这样做的好处是,您可以使用主页作为电子邮件的布局,使用标准的MVC视图作为内容。连接起来非常容易,有一些很好的文档和示例可以帮助您入门。
Also, if you have to make changes to your emails depending on which user you're sending it to, you can just add those parameters to the controller methods that are serving up the email views - now you can format content based on who you're sending to, on the fly.
另外,如果你要根据你发送的用户的不同,对你的电子邮件进行修改,你可以把这些参数添加到提供电子邮件视图的控制器方法中——现在你可以根据你发送给谁的内容来格式化内容了。
Aside from that, all you'll need is an SMTP server to actually send the message, which it sounds like you already have.
除此之外,您所需要的只是一个SMTP服务器来实际发送消息,这听起来好像您已经有了。
#3
0
I suggest you to use FluentScheduler.
我建议你使用FluentScheduler。
A task scheduler that uses fluent interface to configure schedules. Useful for running cron jobs/automated tasks from your application.
一个任务调度程序,它使用流畅的接口来配置调度。对于从应用程序运行cron作业/自动任务非常有用。
This way you can use your already implemented methods.
通过这种方式,您可以使用已经实现的方法。
using FluentScheduler;
public class MyRegistry : Registry
{
public MyRegistry()
{
// Schedule an ITask to run at an interval
Schedule<MyTask>().ToRunNow().AndEvery(2).Seconds();
// Schedule an ITask to run once, delayed by a specific time interval.
Schedule<MyTask>().ToRunOnceIn(5).Seconds();
// Schedule a simple task to run at a specific time
Schedule(() => Console.WriteLine("Timed Task - Will run every day at 9:15pm: " + DateTime.Now)).ToRunEvery(1).Days().At(21, 15);
// Schedule a more complex action to run immediately and on an monthly interval
Schedule(() =>
{
Console.WriteLine("Complex Action Task Starts: " + DateTime.Now);
Thread.Sleep(1000);
Console.WriteLine("Complex Action Task Ends: " + DateTime.Now);
}).ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);
//Schedule multiple tasks to be run in a single schedule
Schedule<MyTask>().AndThen<MyOtherTask>().ToRunNow().AndEvery(5).Minutes();
}
}
FluentScheduler Github页面
#4
0
What about a simple console application to trigger your automated emails? My suggestion would be to use either a console application or a windows service scheduled to run every Monday by the host system's scheduling software (Windows Task Scheduler, cron, etc.).
用一个简单的控制台应用程序来触发您的自动电子邮件怎么样?我的建议是使用主机系统的调度软件(windows任务调度程序、cron等)在每周一运行的控制台应用程序或windows服务。
Here and here is an interesting discussion on the similar requirement like yours.
这里和这里有一个关于类似要求的有趣讨论。