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 ...
随机推荐
- C# WebBrowser 设置代理完全解决方案
微软webbrowser控件也就是IE插件,他的所有功能就像IE类似,当然设置也是一样的,下面介绍下webbrowser如何设置代理,可不要用这个对抗广告联盟哦 You can change the ...
- fix org.openqa.selenium.NoSuchWindowException when find element on windows8.1 ie11.
Steps:1.I was able to resolve the issue after adding the site URL under trusted sites of IE. The sam ...
- Qt之等待提示框(QTimer)
简述 上节讲述了关于QPropertyAnimation实现等待提示框的显示,本节我们使用另外一种方案来实现-使用定时器QTimer,通过设置超时时间定时更新图标达到旋转效果. 简述 效果 资源 源码 ...
- 使用Aspose.Cells组件生成Excel文件
生成带表头的Excel文件,格式如下显示. 当然更复杂的一些也可以通过 合并单元格的方法 public void Merge(int firstRow, int firstColumn, int to ...
- linux系统查看磁盘分区使用空间
Df命令是linux系统以磁盘分区使用空间:df -hl
- php的setcookie
不同浏览器对cookie的原理不同,导致cookie的过期时间有些模糊. 经测试:火狐浏览器的cookie过期时间设置是根据增量原则.服务器端设置time()+num,或者time()-num,传递到 ...
- XE7 - 程序图标及启动画面图片的注意事项
还是继续昨晚写的,年前已经解决了这个问题,现在补记下.启动画面失真是本篇笔记的重点.搜索了很多文章,基本上大同小异,几乎都没怎么提及启动画面失真的问题.不知道是不是我的操作不对头,. Project ...
- Android Studio 小技巧合集
本文翻译自 Android Studio Tips by Philippe Breault,一共收集了62个 Android Studio 使用小技巧和快捷键. 根据这些小技巧的使用场景,本文将这62 ...
- 如何定义java中的类
3步走,如下示例代码所示: package com.imooc; //1.定义一个类 public class Telphone { //2.属性(成员变量)有什么 float screen; flo ...
- c# 修改appConfig文件节点
配置文件对于程序的帮助是不可小视的,尤其是java工程师们,当然了,我这里说的是c#的配置文件.废话不多说了,直接上代码了,想必大家一看就会明白了 private string UpdateConfi ...