I have put together some example macros that I will include in the Solution as well when I fix the resource problem. I have create 5 working macros for examples. One of them isn't 100% usable yet and depends on what the CodePlex API will return about the releases because it creates a link to a release based on the release Id.
Yahoo Publisher Network macro: This will add Yahoo ads to the feed item
example: @{YahooPublisherNetwork(12341541541,345754,http://google.com/feed)}This macro takes 3 arguments, the first is the publisher ID, the second is the feed id, the final argument is the url to the feed item
[code language="C#"]using System;
using System.Collections.Generic;
using System.Text;
using CamalotDesigns.CCNet.Publishers.Macros;
using System.Text.RegularExpressions;
namespace CamalotDesigns.RBP.ExampleMacros {
public class YahooPublisherNetwork : IMacro {
#region IMacro Members
public string Execute ( ThoughtWorks.CruiseControl.Core.IIntegrationResult result, string args ) {
try {
string[] values = args.Split ( new char[] { ',' } );
if ( values.Length != 3 )
return string.Format ( Properties.Strings.ArgumentLengthMessage, this.GetType ( ).Name );
string sb = Properties.Strings.AdCode;
Regex regex = new Regex ( string.Format ( Properties.Strings.ReplacePattern, Properties.Strings.YPNFeedIdName ), RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline );
sb = regex.Replace ( sb, values[ 1 ] );
regex = new Regex ( string.Format ( Properties.Strings.ReplacePattern, Properties.Strings.YPNFeedIdName ), RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline );
sb = regex.Replace ( sb, values[ 0 ] );
regex = new Regex ( string.Format ( Properties.Strings.ReplacePattern, Properties.Strings.EncodedUrlName ), RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline );
sb = regex.Replace ( sb, System.Web.HttpUtility.UrlEncode ( values[ 2 ] ) );
return sb;
} catch ( Exception ex ) {
return string.Format ( "MacroError: {0}", ex.Message );
}
}
#endregion
}
}
[/code]
The KickIt macro will place a "kick it" image and link in the feed.
example: @{KickIt(http://yourdomain.com/your/page.aspx)}This macro accepts 1 argument, the url to the article
[code language="C#"]using System;
using System.Collections.Generic;
using System.Text;
using CamalotDesigns.CCNet.Publishers.Macros;
namespace CamalotDesigns.RBP.ExampleMacros {
public class KickIt : IMacro {
#region IMacro Members
public string Execute ( ThoughtWorks.CruiseControl.Core.IIntegrationResult result, string args ) {
try {
string[] values = args.Split ( new char[] { ',' } );
if ( values.Length != 1 )
return string.Format ( Properties.Strings.ArgumentLengthMessage, this.GetType ( ).Name );
return string.Format ( Properties.Strings.KickItCode, values[ 0 ] );
} catch ( Exception ex ) {
return string.Format ( "MacroError: {0}", ex.Message );
}
}
#endregion
}
}[/code]
The CodePlexChangeset macro links to the specified change set for download.
example: @{CodePlexChangeset(ccnetconfig,21110)}This accepts 2 arguments, the first is the url name of the project, the second is the change set Id
[code language="C#"]using System;
using System.Collections.Generic;
using System.Text;
using CamalotDesigns.CCNet.Publishers.Macros;
namespace CamalotDesigns.RBP.ExampleMacros {
public class CodePlexChangeset : IMacro {
#region IMacro Members
public string Execute ( ThoughtWorks.CruiseControl.Core.IIntegrationResult result, string args ) {
try {
string[] values = args.Split ( new char[] { ',' } );
if ( values.Length < 2 )
return string.Format ( Properties.Strings.ArgumentLengthMessage, this.GetType ( ).Name );
string text = string.IsNullOrEmpty ( values[ 2 ] ) ? string.Format ( "CodePlex Change Set {0}", values[ 1 ] ) : values[ 2 ];
string linkFormat = @">a href="" http://www.codeplex.com/{0}/sourcecontrol/downloadsourcecode.aspx?changesetid={1}""<>img src=""http://www.codeplex.com/app_themes/codeplex/images/icon_dwnld.gif"" alt=""{2}"" title="" {2}""< {2}/<>/a<";
return string.Format ( linkFormat, values[ 0 ], values[ 1 ], text );
} catch ( Exception ex ) {
return string.Format ( "MacroError: {0}", ex.Message );
}
}
#endregion
}
}
[/code]
The DiggThis macro creates a digg button which allows user to "digg" the story.
This macro has 1 required argument, that is the url to the story, but can have the following arguments as well.
- Url
- Title
- Body
- Category
- Color
example: @{DiggThis(http://google.com/mystory/)}
[code language="C#"]using System;
using System.Collections.Generic;
using System.Text;
using CamalotDesigns.CCNet.Publishers.Macros;
using System.Net;
using System.Web;
using System.IO;
namespace CamalotDesigns.RBP.ExampleMacros {
public class DiggThis : IMacro {
#region IMacro Members
public string Execute ( ThoughtWorks.CruiseControl.Core.IIntegrationResult result, string args ) {
try {
string[] values = args.Split ( new char[] { ',' } );
if ( values.Length < 1 )
return string.Format ( Properties.Strings.ArgumentLengthMessage, this.GetType ( ).Name );
string url = string.Format ( "http://digg.com/tools/diggthis.php?u={0}&t={1}&b={2}&c={3}&k={4}",
Escape ( values[ 0 ] ), values.Length > 1 ? Escape ( values[ 1 ] ) : string.Empty,
values.Length > 2 ? Escape ( values[ 2 ] ) : string.Empty,
values.Length > 3 ? Escape ( values[ 3 ] ) : string.Empty,
values.Length > 4 ? Escape ( values[ 4 ] ) : string.Empty );
HttpWebRequest request = HttpWebRequest.Create ( url ) as HttpWebRequest;
request.UserAgent = "Rss Builds Publisher for CC.NET ( http://codeplex.com/rssbuildspublisher/ ) - Digg It Macro";
HttpWebResponse response = request.GetResponse ( ) as HttpWebResponse;
StreamReader reader = new StreamReader ( response.GetResponseStream ( ) );
string respString = string.Empty;
using ( reader ) {
respString = reader.ReadToEnd ( );
}
return respString;
} catch ( Exception ex ) {
return string.Format ( "MacroError: {0}", ex.Message );
}
}
#endregion
private string Escape ( string str ) {
return HttpUtility.UrlEncode ( str ).Replace ( @"\", "%2b" );
}
}
}[/code]
The last macro is the one that can not be 100% automated by ccnet, and might not be able to be, that will depend on the CodePlex Api set to be released on the 24th of this month. This macro takes the url project name and the release Id as arguments
example: @{CodePlexRelease(ccnetconfig,12345)}
[code language="C#"]using System;
using System.Collections.Generic;
using System.Text;
using CamalotDesigns.CCNet.Publishers.Macros;
namespace CamalotDesigns.RBP.ExampleMacros {
public class CodePlexRelease : IMacro {
#region IMacro Members
public string Execute ( ThoughtWorks.CruiseControl.Core.IIntegrationResult result, string args ) {
try {
string[] values = args.Split ( new char[] { ',' } );
if ( values.Length < 2 )
return string.Format ( Properties.Strings.ArgumentLengthMessage, this.GetType ( ).Name );
string text = string.IsNullOrEmpty ( values[ 2 ] ) ? string.Format ( "CodePlex Release {0}", values[ 1 ] ) : values[ 2 ];
string linkFormat = @"<a href=""http://www.codeplex.com/{0}/release/projectreleases.aspx?releaseid={1}""><img src=""http://www.codeplex.com/app_themes/codeplex/images/project_icon_sm.gif"" alt=""{2}"" title=""{2}"" /> {2}</a>";
return string.Format ( linkFormat, values[ 0 ], values[ 1 ], text );
} catch ( Exception ex ) {
return string.Format ( "MacroError: {0}", ex.Message );
}
}
#endregion
}
}[/code]
I don't have a download available for these macros yet, but they will be included in the Rss Builds Publisher releases starting with the next nightly.