你的位置:首页 > 软件开发 > ASP.net > [翻译+山寨]Hangfire Highlighter Tutorial

[翻译+山寨]Hangfire Highlighter Tutorial

发布时间:2016-05-12 22:00:16
前言Hangfire是一个开源且商业免费使用的工具函数库。可以让你非常容易地在ASP.NET应用(也可以不在ASP.NET应用)中执行多种类型的后台任务,而无需自行定制开发和管理基于Windows Service后台任务执行器。且任务信息可以被持久保存。内置提供集成化的控制台。 ...

前言

Hangfire是一个开源且商业免费使用的工具函数库。可以让你非常容易地在get='_blank'>ASP.NET应用(也可以不在ASP.NET应用)中执行多种类型的后台任务,而无需自行定制开发和管理基于Windows Service后台任务执行器。且任务信息可以被持久保存。内置提供集成化的控制台。 原文

Hangfire目前资料不多,官方文档提供两个教程 Sending Mail in Background with ASP.NET MVC 和 Highlighter Tutorial,根据第二个教程山寨了一把,把文中的Entity Framework 改成了 Dapper,Sql Server数据库改成了LocalDB。结合自己的理解把原文翻译一下(第一次翻译,如有不妥尽情拍砖)

Simple sample :https://github.com/odinserj/Hangfire.Highlighter

Full sample:http://highlighter.hangfire.io, sources

 目录 

  • Overview 概述
  • Setting up the project 设置项目
    • Prerequisites  前置条件
    • Creating a project 创建项目
    • Hiliting the code  醒目代码
  • The problem
  • Solving a problem
    • Installing Hangfire
    • Moving to background
  • Conclusion

概述

  考虑到你正在构建一个像GitHub Gists的代码片段库web应用程序,并且想实现语法高亮的特性。为了提供用户体验,甚至你想让它在一个用户禁用JavaScript的浏览器中也能正常工作。

  为了支持这种场景,并且缩短项目开发时间,你会选择使用一个Web Service实现语法高亮,比如:http://pygments.appspot.com or http://www.hilite.me.

Note

Although this feature can be implemented without web services (using different syntax highlighter libraries for .NET), we are using them just to show some pitfalls regarding to their usage in web applications.

You can substitute this example with real-world scenario, like using external SMTP server, another services or even long-running CPU-intensive task. 这段不翻译了,难。

 

设置项目

Tip

This section contains steps to prepare the project. However, if you don’t want to do the boring stuff or if you have problems with project set-up, you can download the tutorial source code and go straight to The problem section.

前置条件

这个教程使用VS2012 (安装了Web Tools 2013 for Visual Studio 2012 补丁),你也可以使用VS2013。这个项目用到了.NET4.5,ASP.NET MVC5 和SQL Server 2008 Express 或更高版本。

注意:那个补丁就是为了在创建项目时有Asp.net MVC5 Empty Project 这个默认的项目模板,我下载了安装报错,找不到对应的包。SqlServer 2008 是为了存储代码片段和Hangfire的任务数据,他还用到了EF做为orm框架。

我这里使用VS2013+LocalDB+Dapper实现类似功能。

创建项目

      打开VS2013->Web->ASP.NET Web 应用程序->弹出框里选择 MVC 模板,身份验证 我改成了 无身份验证

[翻译+山寨]Hangfire Highlighter Tutorial

 

创建完成之后默认就有个HomeController.cs 控制器。其中的Index Action 看起来是这样的:

 public class HomeController : Controller  {    public ActionResult Index()    {      return View();    }    public ActionResult About()    {      ViewBag.Message = "Your application description page.";      return View();    }    public ActionResult Contact()    {      ViewBag.Message = "Your contact page.";      return View();    }  }

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:[翻译+山寨]Hangfire Highlighter Tutorial

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录