I’ve been using Rhino Service Bus in some projects and needed a way to bridge it with synchronous WCF calls. Here’s the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Rhino.ServiceBus.Sagas;
using Rhino.ServiceBus;
using System.Threading;
using Rhino.ServiceBus.Internal;
namespace Rhino.ServiceBus
{
public static class ReplyExtension
{
class ESBResult<R> : OccasionalConsumerOf<R>, IDisposable
{
ManualResetEvent waithandle;
IServiceBus bus;
IDisposable subscription;
TimeSpan patience;
public ESBResult(IServiceBus bus, ISagaMessage message, TimeSpan patience)
{
this.bus = bus;
this.patience = patience;
waithandle = new ManualResetEvent(false);
subscription = bus.AddInstanceSubscription(this);
bus.Send(message);
}
public ESBResult(IServiceBus bus, ISagaMessage message)
: this(bus, message, TimeSpan.FromSeconds(5))
{
}
public R Reply
{
get
{
waithandle.WaitOne(patience);
return m_Reply;
}
}
#region ConsumerOf<R> Members
R m_Reply = default(R);
public void Consume(R message)
{
m_Reply = message;
waithandle.Set();
}
#endregion
#region IDisposable Members
public void Dispose()
{
var b = bus;
subscription.Dispose();
}
#endregion
}
public static R SendAndWaitForReply<R>(this IServiceBus bus, ISagaMessage message)
{
using (var result = new ESBResult<R>(bus, message))
return result.Reply;
}
}
}
44efc8d9-038d-4b1c-afa2-6b25f47dc5ac|0|.0
I felt the need to contribute somewhere in the open source department. My first move was to start a provider for Euss enabling support for using SimpleDB as storage. Store your objects in the cloud! It’s buggy and the query language is only partially implemented. But anyway. It does work.
It has the immensely creative name “SimpleDB for Euss”. You can find the source and upcoming releases on codeplex.
0603f323-bd7e-4977-aaf7-68804ae9f6b7|0|.0
Thursday evening ViaNett announced a competition. To create the first application able to use their new service SMShttp. Guess what. I won! You can download the application called iMessage here and register for an account here.
The application uses WCF to connect to their webservice and WPF for GUI.
2fe9200f-54a0-4410-b297-7569224a9650|0|.0
I present to You, the first alpha release of RawPreview. For now it's only a preview handler for Windows Vista allowing preview of different raw image formats in the preview pane. I'm using dcraw to extract the embedded thumbnail. It currently only registers for *.pef, *.dng, *.nef.
Download the first version here: setup.zip
For the future:
- Support thumbnail creation on Vista and XP
- Be able to edit the file-types it's registered for in some kind of GUI
- Show exif information in the preview on Vista
References:
2cc989bf-5d1a-490f-9a54-cefe5d4bc4fb|0|.0
Found a good article on the visitor pattern using C# / .Net
Visitor Design Pattern revisited for .Net
818925e8-5292-4048-ac26-493f43745b57|0|.0
A simple yet efficient way of getting translation into .Net objects
Translatable name = newTranslatable();
Translatable splash = newTranslatable();
name[1033] = "Christmas";
name["nb-NO"] = "Jul";
splash["en-US"] = newForm();
splash[1044] = newForm();
string translatedname = name;
Form translatedform = splash;
All of this is possible with some use of generics and an implicit operator.
[Serializable]
public class Translatable
{
public T Default
{
get
{
bool hit = false;
if (TranslatedValues.Count == 1)
return TranslatedValues[0].TranslatedValue;
if (TranslatedValues.Count == 0)
{
if (!(typeof(T) == typeof(string)))
{
return default(T);
}
else
{
object o = string.Empty;
return (T)o;
}
}
System.Globalization.CultureInfo temp = System.Globalization.CultureInfo.CurrentUICulture;
T result = default(T);
while (temp != System.Globalization.CultureInfo.InvariantCulture)
{
Translated tres = TryGetTranslated(temp.Name);
if (tres != null)
{
result = tres.TranslatedValue;
hit = true;
break;
}
else
{
temp = temp.Parent;
}
}
if (!hit)
{
Translated tres = TryGetTranslated(string.Empty);
if (tres != null)
{
result = tres.TranslatedValue;
hit = true;
}
}
if (!hit && TranslatedValues.Count > 0)
result = TranslatedValues[0].TranslatedValue;
return result;
}
}
protected IList> m_TranslatedValues = new List>();
public virtual IList> TranslatedValues
{
get { return m_TranslatedValues; }
}
public T this[string languageCode]
{
get { return TryGetTranslatedValue(languageCode); }
set
{
Translated tr = TryGetTranslated(languageCode);
if (tr == null)
{
TranslatedValues.Add(new Translated(languageCode, value));
}
else
{
tr.TranslatedValue = value;
}
}
}
public T this[int LCID]
{
get { return this[new System.Globalization.CultureInfo(LCID).Name]; }
set { this[new System.Globalization.CultureInfo(LCID).Name] = value; }
}
protected Translated TryGetTranslated(string languageCode)
{
Translated result = null;
foreach (Translated tr in TranslatedValues)
{
if (tr.LanguageCode.Equals(languageCode))
{
result = tr;
break;
}
}
return result;
}
public T TryGetTranslatedValue(string languageCode)
{
Translated result = TryGetTranslated(languageCode);
if (result == null)
return default(T);
else
return result.TranslatedValue;
}
public static implicit operator T(Translatable val)
{
return val.Default;
}
public override string ToString()
{
if (Default != null)
return Default.ToString();
else
return base.ToString();
}
}
[Serializable]
public class Translated
{
protected Translated() { }
public Translated(string languageCode, T translatedValue)
{
m_LanguageCode = languageCode;
m_TranslatedValue = translatedValue;
}
protected T m_TranslatedValue = default(T);
public T TranslatedValue
{
get { return m_TranslatedValue; }
set { m_TranslatedValue = value; }
}
protected string m_LanguageCode = string.Empty;
public string LanguageCode
{
get { return m_LanguageCode; }
set { m_LanguageCode = value; }
}
}
3746808c-06a4-4d38-aa37-22058c9fe34e|1|5.0