📄 campaigner.asmx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.Text;
using System.Web.Services.Protocols;
using System.Xml;
using System.IO;
using AWC.Reporter.Web.RS;
namespace AWC.Reporter.Web
{
/// <summary>
/// Summary description for Campaigner.
/// </summary>
public class Campaigner : System.Web.Services.WebService
{
public Campaigner()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
#region Component Designer generated code
//Required by the Web Services Designer
private IContainer components = null;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
[WebMethod]
public string StartCampaign(int CampaignID)
{
// Render arguments
byte[] result = null;
string reportPath = "/AWReporter/Sales Promotion";
string format = "XML";
string historyID = null;
string devInfo = null;
DataSourceCredentials[] credentials = null;
string showHideToggle = null;
string encoding;
string mimeType;
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;
string status = null;
ReportingService rs = new ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Prepare report parameters.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "SpecialOfferID";
parameters[0].Value = CampaignID.ToString();
try
{
// render the report
result = rs.Render(reportPath, format, historyID, devInfo, parameters, credentials,
showHideToggle, out encoding, out mimeType, out reportHistoryParameters, out warnings,
out streamIDs);
// update the RSS blog file
AddSpecialOffer(result);
status = "success";
}
catch (SoapException ex)
{
status = ex.Detail.InnerText;
}
catch (System.Exception ex)
{
status = ex.Message;
}
return status;
}
private static void AddSpecialOffer(byte[] specialOffer)
{
// load the special offer XML
MemoryStream stream = new MemoryStream(specialOffer);
XmlDocument specialOfferDoc = new XmlDocument();
specialOfferDoc.Load(stream);
XmlNode specialItem = specialOfferDoc.DocumentElement;
// load the blog file
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(System.Web.HttpContext.Current.Server.MapPath("AWCSpecialDeals.xml"));
// clone the first item
XmlNode channel = rssDoc.SelectSingleNode("//channel");
XmlNode item = channel.SelectSingleNode("./item");
XmlNode itemClone = item.Clone();
// copy the information
XmlNode tempNode = itemClone.SelectSingleNode("./title");
tempNode.InnerText = specialItem.SelectSingleNode("./title").InnerText;
tempNode = itemClone.SelectSingleNode("./pubDate");
tempNode.InnerText = specialItem.SelectSingleNode("./pubDate").InnerText;
tempNode = itemClone.SelectSingleNode("./description");
tempNode.InnerText = specialItem.SelectSingleNode("./description").InnerText;
tempNode = itemClone.SelectSingleNode("./link");
tempNode.InnerText = specialItem.SelectSingleNode("./link").InnerText;
channel.AppendChild(itemClone);
// persist the changes
rssDoc.Save(System.Web.HttpContext.Current.Server.MapPath("AWCSpecialDeals.xml"));
}
/// <summary>
/// Fires a new data-driven subscription programitically
/// </summary>
/// <param name="reportPath">The path to the report, e.g. "/AWReporter/Customer Orders"</param>
/// <param name="userName">The subscription owner name in the format DOMAINNAME/USERNAME</param>
[WebMethod]
public void FireSubscription(string reportPath, string userName)
{
ReportingService rs = new ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
DataRetrievalPlan dataRetrievalPlan = null;
ExtensionSettings extSettings;
string desc;
ActiveState active;
string status;
string eventType;
string matchData;
Subscription[] subscriptions = null;
ParameterValueOrFieldReference[] extensionParams = null;
try
{
// get the list of subscriptions associated with this report and user
subscriptions = rs.ListSubscriptions(reportPath, userName );
if ( subscriptions != null )
{
// get the data-driven subscription properties
// NOTE: Assumptions
// Only one subsription is associated with this user and report
// The subscription is data-driven
rs.GetDataDrivenSubscriptionProperties( subscriptions[0].SubscriptionID, out extSettings, out dataRetrievalPlan, out desc, out active, out status, out eventType, out matchData, out extensionParams );
// Fire the event to kick off the subscription
rs.FireEvent(eventType, matchData);
}
}
catch ( SoapException e )
{
Console.WriteLine( e.Detail.InnerXml.ToString() );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -