Beispiel #1
0
        static ActiveRunner PrepareRunner(string endpointName, EndpointBehaviour endpointBehaviour)
        {
            var domainSetup = new AppDomainSetup
            {
                ApplicationBase    = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                LoaderOptimization = LoaderOptimization.SingleDomain
            };

            var endpoint = ((IEndpointConfigurationFactory)Activator.CreateInstance(endpointBehaviour.EndpointBuilderType)).Get();

            if (endpoint.AppConfigPath != null)
            {
                domainSetup.ConfigurationFile = endpoint.AppConfigPath;
            }

            var appDomain = AppDomain.CreateDomain(endpointName, AppDomain.CurrentDomain.Evidence, domainSetup);


            return(new ActiveRunner
            {
                Instance = (EndpointRunner)appDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(EndpointRunner).FullName),
                AppDomain = appDomain,
                EndpointName = endpointName
            });
        }
Beispiel #2
0
        static string GetEndpointNameForRun(RunDescriptor runDescriptor, EndpointBehaviour endpointBehaviour)
        {
            var endpointName = Conventions.EndpointNamingConvention(endpointBehaviour.EndpointBuilderType) + "." +
                               runDescriptor.Key;

            return(endpointName);
        }
Beispiel #3
0
 public EndpointBehaviorBuilder(Type type)
 {
     behaviour = new EndpointBehaviour(type)
     {
         Givens = new List <IGivenDefinition>(),
         Whens  = new List <IWhenDefinition>()
     };
 }
Beispiel #4
0
        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))
                {
                    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();

                executeWhens = Task.Factory.StartNew(() =>
                {
                    while (!stopped)
                    {
                        if (!contextChanged.Wait(TimeSpan.FromSeconds(5)))
                        //we spin around each 5s since the callback mechanism seems to be shaky
                        {
                            continue;
                        }

                        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 initialize endpoint " + endpointName, ex);
                return(Result.Failure(ex));
            }
        }