コード例 #1
0
ファイル: Program.cs プロジェクト: JanRou/RebusSamples
        static void Main()
        {
            using (var appContainer = new WindsorContainer().Install(FromAssembly.This()))
            {
                Configure.With(new WindsorContainerAdapter(appContainer))
                    .Logging(l => l.ColoredConsole(minLevel: LogLevel.Warn))
                    .Transport(t => t.UseMsmq("sample.usercontextheaders.input", "sample.usercontextheaders.error"))

                    .AutomaticallyTransferUserContext()   //< this one is special :)

                    .CreateBus()
                    .Start();

                while (true)
                {
                    Console.Write(@"Type name of person whose context to impersonate, or leave empty to quit
            > ");
                    var name = Console.ReadLine();

                    if (string.IsNullOrWhiteSpace(name)) break;

                    var notAnActualId = name.GetHashCode();

                    var userContext = new UserContext {Name = name, UserId = notAnActualId};

                    using (new AmbientUserContext(userContext))
                    {
                        var bus = appContainer.Resolve<IBus>();
                        var greeting = PreFabGreetings.GetOne();

                        var message = new SomeRandomMessage(greeting);

                        bus.SendLocal(message);
                    }
                }
            }
        }
コード例 #2
0
 public void Dispose()
 {
     _current = null;
 }
コード例 #3
0
 public AmbientUserContext(UserContext context)
 {
     _current = context;
 }
コード例 #4
0
ファイル: RebusEx.cs プロジェクト: JanRou/RebusSamples
 static string Encode(UserContext current)
 {
     return string.Format("{0}={1};{2}={3}",
         EncodedUserIdKey, current.UserId,
         EncodedNameKey, current.Name);
 }