本文整理汇总了C#中Configure.CreateBus方法的典型用法代码示例。如果您正苦于以下问题:C# Configure.CreateBus方法的具体用法?C# Configure.CreateBus怎么用?C# Configure.CreateBus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configure
的用法示例。
在下文中一共展示了Configure.CreateBus方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public Result Initialize(RunDescriptor run, EndpointBehaviour endpointBehaviour, IDictionary<Type, string> routingTable, string endpointName)
{
try
{
behaviour = endpointBehaviour;
scenarioContext = run.ScenarioContext;
configuration = ((IEndpointConfigurationFactory)Activator.CreateInstance(endpointBehaviour.EndpointBuilderType)).Get();
configuration.EndpointName = endpointName;
if (!string.IsNullOrEmpty(configuration.CustomMachineName))
{
NServiceBus.Support.RuntimeEnvironment.MachineNameAction = () => configuration.CustomMachineName;
}
//apply custom config settings
endpointBehaviour.CustomConfig.ForEach(customAction => customAction(config));
config = configuration.GetConfiguration(run, routingTable);
if (scenarioContext != null)
{
config.Configurer.RegisterSingleton(scenarioContext.GetType(), scenarioContext);
scenarioContext.ContextPropertyChanged += scenarioContext_ContextPropertyChanged;
}
bus = config.CreateBus();
Configure.Instance.ForInstallationOn<Windows>().Install();
Task.Factory.StartNew(() =>
{
while (!stopped)
{
contextChanged.WaitOne(TimeSpan.FromSeconds(5)); //we spin around each 5 s since the callback mechanism seems to be shaky
lock (behaviour)
{
foreach (var when in behaviour.Whens)
{
if (executedWhens.Contains(when.Id))
continue;
if(when.ExecuteAction(scenarioContext, bus))
executedWhens.Add(when.Id);
}
}
}
});
return Result.Success();
}
catch (Exception ex)
{
Logger.Error("Failed to initalize endpoint " + endpointName, ex);
return Result.Failure(ex);
}
}
示例2: Initialize
public Result Initialize(RunDescriptor run, EndpointBehavior endpointBehavior,
IDictionary<Type, string> routingTable, string endpointName)
{
try
{
behavior = endpointBehavior;
scenarioContext = run.ScenarioContext;
configuration =
((IEndpointConfigurationFactory) Activator.CreateInstance(endpointBehavior.EndpointBuilderType))
.Get();
configuration.EndpointName = endpointName;
if (!string.IsNullOrEmpty(configuration.CustomMachineName))
{
RuntimeEnvironment.MachineNameAction = () => configuration.CustomMachineName;
}
//apply custom config settings
endpointBehavior.CustomConfig.ForEach(customAction => customAction(config));
config = configuration.GetConfiguration(run, routingTable);
if (scenarioContext != null)
{
config.Configurer.RegisterSingleton(scenarioContext.GetType(), scenarioContext);
scenarioContext.ContextPropertyChanged += scenarioContext_ContextPropertyChanged;
}
bus = config.CreateBus();
Configure.Instance.ForInstallationOn<Windows>().Install();
stopToken = stopSource.Token;
if (behavior.Whens.Count == 0)
{
executeWhens = Task.FromResult(0);
}
else
{
executeWhens = Task.Factory.StartNew(async () =>
{
var executedWhens = new List<Guid>();
while (!stopToken.IsCancellationRequested)
{
if (executedWhens.Count == behavior.Whens.Count)
{
break;
}
//we spin around each 5s since the callback mechanism seems to be shaky
await contextChanged.WaitAsync(TimeSpan.FromSeconds(5), stopToken);
if (stopToken.IsCancellationRequested)
break;
foreach (var when in behavior.Whens)
{
if (executedWhens.Contains(when.Id))
{
continue;
}
if (when.ExecuteAction(scenarioContext, bus))
{
executedWhens.Add(when.Id);
}
}
}
}, stopToken).Unwrap();
}
return Result.Success();
}
catch (Exception ex)
{
Logger.Error("Failed to initialize endpoint " + endpointName, ex);
return Result.Failure(ex);
}
}