Having the Result Set of a Stored Proc Sent to You by RSS Feed.
Having the Result Set of a Stored Proc Sent to You by RSS Feed.
by JBrooks 14. 十二月 2010 12:44
I wanted to monitor one of my system from my desk top and from my phone. I found a simple solution whereby I can subscribe to the result set of a stored proc by using RSS. So I can have this feed MS Outlook, my phone or my web browser.
First, Visual Studio 2010 makes creating an RSS feed a simple matter that is about 1 page of code.
I simply add an ASPX page to my project and remove most of the markup so it only has 2 lines:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="rss.aspx.cs" Inherits="RSS.rss" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>
Next the code behind simply calls the stored proc placing the results into a table and then loading up some of the RSS related collections VS2010 gives you.
using System;
using System.Data;
using System.ServiceModel.Syndication;
using System.Web;
using System.Collections.Generic;
using System.Xml;
namespace RSS
{
public partial class rss : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["id"];
// I don't want just anyone to subscribe, so you have to know the GUID.
if (id== null || id != "23F14EA1-1B20-443B-9B94-92C4EA4A8099")
throw new Exception("Guid not reconized");
Response.ContentType = "application/atom+xml";
// this gets the data from the database and populates a table.
DataTable dt = cDB.getFeed();
SyndicationFeed myFeed = new SyndicationFeed();
myFeed.Title = TextSyndicationContent.CreatePlaintextContent("SampleApp Activity");
myFeed.Description = TextSyndicationContent
.CreatePlaintextContent(@"A syndication of the most recently
SampleApp activity including exceptions.");
myFeed.Links.Add(SyndicationLink.CreateAlternateLink(
new Uri(GetFullyQualifiedUrl("/rss.aspx"))));
myFeed.Links.Add(SyndicationLink.CreateSelfLink(
new Uri(GetFullyQualifiedUrl(Request.RawUrl))));
myFeed.Copyright = TextSyndicationContent
.CreatePlaintextContent("Copyright SampleApp");
myFeed.Language = "en-us";
List<SyndicationItem> feedItems = new List<SyndicationItem>();
foreach (DataRow dr in dt.Rows)
{
SyndicationItem item = new SyndicationItem();
item.Title = TextSyndicationContent.CreatePlaintextContent(dr["title"].ToString());
SyndicationPerson authInfo = new SyndicationPerson();
authInfo.Email = "SampleApp@YourDomain.com";
item.Authors.Add(authInfo);
// RSS feeds can only have one author.
// The stored proc returns different categories of data that I am interested in.
switch (dr["category"].ToString())
{
case "WindFarms":
case "WindFarms ":
item.Links.Add(SyndicationLink.CreateAlternateLink(
new Uri(GetFullyQualifiedUrl("/WindFarms.aspx"))));
authInfo.Name = "SampleApp WindFarm";
break;
case "Exceptions":
item.Links.Add(SyndicationLink.CreateAlternateLink(
new Uri(GetFullyQualifiedUrl("/ErrorLog.aspx"))));
authInfo.Name = "SampleApp Exception";
break;
default:
authInfo.Name = "SampleApp";
break;
}
item.Summary = TextSyndicationContent.CreatePlaintextContent(
dr["summary"].ToString());
item.Categories.Add(new SyndicationCategory(dr["category"].ToString()));
item.PublishDate = DateTime.Parse(dr["pubdate"].ToString());
item.LastUpdatedTime = item.PublishDate;
item.Id = item.PublishDate.ToString();
// Add the item to the feed
feedItems.Add(item);
}
myFeed.Items = feedItems;
XmlWriter feedWriter = XmlWriter.Create(Response.OutputStream);
// Use Atom 1.0
Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(myFeed);
atomFormatter.WriteTo(feedWriter);
feedWriter.Close();
}
private string GetFullyQualifiedUrl(string s)
{
Uri u = new Uri(HttpContext.Current.Request.Url, s);
return u.ToString();
}
}
}
To have this feed my Outlook RSS folder I just need to right click “RSS Feeds” and select “Add a New RSS Feed…”.
![]()
Then enter the URL of my RSS feed. Don’t forget to add the GUID at the end with ?id=23F14EA1-1B20-443B-9B94-92C4EA4A8099
![]()
If you site uses authentication in your site you will have to turn it off for the rss.aspx page. To do this you would add an entry in your web config file:
<location path="rss.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
You should now have a folder in Outlook that will get populated by the feed.
Having the Result Set of a Stored Proc Sent to You by RSS Feed.的更多相关文章
- MySQL5.7: Paging using Mysql Stored Proc
-- 查询外键 涂聚文 (Geovin Du) select concat(table_name, '.', column_name) as 'foreign key', concat(referen ...
- Creating a SharePoint BCS .NET Connectivity Assembly to Crawl RSS Data in Visual Studio 2010
from:http://blog.tallan.com/2012/07/18/creating-a-sharepoint-bcs-net-assembly-connector-to-crawl-rss ...
- [转]How to get return values and output values from a stored procedure with EF Core?
本文转自:https://stackoverflow.com/questions/43935345/how-to-get-return-values-and-output-values-from-a- ...
- [转]SSIS Execute SQL Task : Mapping Parameters And Result Sets
本文转自:http://www.programmersedge.com/post/2013/03/05/ssis-execute-sql-task-mapping-parameters-and-res ...
- Support for multiple result sets
https://blueprints.launchpad.net/myconnpy/+spec/sp-multi-resultsets Calling a stored procedure can p ...
- Using Stored Programs with MySQLdb
http://flylib.com/books/en/1.142.1.125/1/ Using Stored Programs with MySQLdb The techniques for call ...
- [转]Entity Framework Sprocs with Multiple Result Sets
本文转自:https://msdn.microsoft.com/en-us/data/jj691402.aspx Entity Framework Sprocs with Multiple Resul ...
- Mini ORM——PetaPoco笔记
Mini ORM--PetaPoco笔记 记录一下petapoco官网博客的一些要点.这些博客记录了PetaPoco是如何一步步改进的. 目录: Announcing PetaPoco PetaPoc ...
- Mini ORM——PetaPoco笔记(转)
记录一下petapoco官网博客的一些要点.这些博客记录了PetaPoco是如何一步步改进的. 目录: Announcing PetaPoco PetaPoco-Improvements PetaPo ...
随机推荐
- [ionic开源项目教程] - 第2讲 新建项目,配置app.js和controllers.js搭建基础视图
新建项目 由项目功能架构图选择合适的页面架构,这里选用Tab,ionic新建项目,默认的模板就是tab. $ ionic start TongeNews Creating Ionic app in f ...
- 基于Bootstrap的超酷jQuery开关按钮插件
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJgAAAA2CAIAAAC0tsfoAAAB/0lEQVR4nO3bQWrCQBTGcc/mbVz0DD
- POJ 3261 (后缀数组 二分) Milk Patterns
这道题和UVa 12206一样,求至少重复出现k次的最长字串. 首先还是二分最长字串的长度len,然后以len为边界对height数组分段,如果有一段包含超过k个后缀则符合要求. #include & ...
- HDU 3032 (Nim博弈变形) Nim or not Nim?
博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当 ...
- LA 3971 (二分) Assemble
题意: 你有b块钱想要组装一台电脑.给出n个配件的种类,品质和价格,要求每个种类的配件各买一个总价格不超过b且“品质最差配件”的品质因子应尽量大. 这种情况下STL的map的确很好用,学习学习 这种最 ...
- 4612 warm up tarjan+bfs求树的直径(重边的强连通通分量)忘了写了,今天总结想起来了。
问加一条边,最少可以剩下几个桥. 先双连通分量缩点,形成一颗树,然后求树的直径,就是减少的桥. 本题要处理重边的情况. 如果本来就两条重边,不能算是桥. 还会爆栈,只能C++交,手动加栈了 别人都是用 ...
- poj 1236 Network of Schools(强连通、缩点、出入度)
题意:给出一个有向图.1:问至少选出多少个点,才能沿有向边遍历所有节点.2:问至少加多少条有向边,使原图强连通. 分析:第一个问题,缩点后找所有树根(入度为0).第二个问题,分别找出入度为0和出度为0 ...
- hadoop——配置eclipse下的map-reduce运行环境 1
1.通过修改实例模板程序来实现自己的map-reduce: 为了让示例程序run起来: 1)安装eclipse 2)安装map-reduce的eclipse插件 eclipse的map-reduce插 ...
- 转:移动开发中一些bug及解决方案
网页开发要面对各种各样的浏览器,让人很头疼,而移动开发中,你不但要面对浏览器,还要面对各种版本的手机,iOS好一点,而安卓就五花八门了,你可能在开发中也被它们折磨过,或者正在被它们折磨,我在这里说几个 ...
- svn log 不显示日志的问题
在你配好了Xcode里的SourceControl之后提交代码回复代码都很方便,可是为什么在Xcode上提交的log,在svn下面显示不出来! 解决办法是:在命令行下,先 svn update 一下, ...