Apropos the Blogjecting Watchdog pattern, In addition to blogging I recently added to our system the ability to twitter. I am using Tweet# from DimeBrain (thanks Mark Nijhof for the tip via twitter).
Tweet# makes using tweeter really simple (I included the code below in case you find it useful).
The tweeter sender is part of a PostOffice service (I thought that it would be problematic to present it as SpamServer which was its original name :) ).
Update 11/05 Here it is working on our staging environment :)
A few points about our design in general that are interesting in this regards are
1: using System;
2: using System.Collections.Generic;
3: using System.Linq;
4: using System.Text;
5: using Dimebrain.TweetSharp.Fluent;
6:
7: namespace xsights.Apps.PostOffice.Server.Twitter
8: {
9: class TwitterSender
10: {
11: private string account;
12: private string password;
13: private string admin;
14:
15: public TwitterSender(string tweetAccount, string twitterPassword,string adminAccount)
16: {
17: account = tweetAccount;
18: password = twitterPassword;
19: admin = adminAccount;
20: }
21: public void Update(string msg)
22: {
23: foreach (var tweet in BreakToTwitts(msg))
24: {
25: var update =
26: FluentTwitter.CreateRequest().AuthenticateAs(account, password).Statuses().Update(tweet).AsJson();
27:
28: update.Request();
29: }
30: }
31:
32: public void SendAdminMessage(string msg)
33: {
34: foreach (var twit in BreakToTwitts(msg))
35: {
36: var dm =
37: FluentTwitter.CreateRequest().AuthenticateAs(account, password).DirectMessages().Send(admin, twit).AsJson();
38:
39: Retry(2,dm.Request,false);
40: }
41:
42: }
43:
44: private IList<string> BreakToTwitts(string originalString)
45: {
46: var list = new List<string>();
47: for (int i = 0; i < originalString.Length; i += 140)
48: {
49: var len = 140;
50: if (originalString.Length - i < 140) len = originalString.Length - i;
51: list.Add(originalString.Substring(i, len));
52: }
53: return list;
54: }
55:
56: private void Retry(int retries, Func<string> call,bool shouldThrow)
57: {
58:
59: try
60: {
61: call();
62: }
63: catch (Exception ex)
64: {
65:
66: if (retries > 0)
67: Retry(--retries, call,shouldThrow);
68: else
69: {
70: if (shouldThrow)
71: throw;
72: }
73: }
74: }
75:
76: }
77: }
78:
79: }
Subscribe to RSS headline updates from: