public void StartWorkers()
        {
            var assembly = System.Reflection.Assembly.GetEntryAssembly();
            // find all classes with CustomAttribute [ExternalTask("name")]
            var externalTaskWorkers =
                // from assembly in AppDomain.CurrentDomain.GetAssemblies()
                from t in assembly.GetTypes()
                let attributes = t.GetCustomAttributes(typeof(ExternalTaskTopic), true)
                                 where attributes != null && attributes.Length > 0
                                 select new { Type = t, Attributes = attributes.Cast <ExternalTaskTopic>() };

            foreach (var taskWorker in externalTaskWorkers)
            {
                var workerTopicName = taskWorker.Attributes.FirstOrDefault().TopicName;
                var retries         = taskWorker.Attributes.FirstOrDefault().Retries;
                var retryTimeout    = taskWorker.Attributes.FirstOrDefault().RetryTimeout;

                string[] variablesToFetch     = null;
                var      variableRequirements = taskWorker.Type.GetCustomAttributes(typeof(ExternalTaskVariableRequirements), true)
                                                .FirstOrDefault() as ExternalTaskVariableRequirements;
                if (variableRequirements != null)
                {
                    variablesToFetch = variableRequirements.VariablesToFetch;
                }

                var constructor = taskWorker.Type.GetConstructor(Type.EmptyTypes);
                IExternalTaskAdapter adapter = (IExternalTaskAdapter)constructor.Invoke(null);

                // Now register it!
                Console.WriteLine("Register Task Worker for Topic '" + workerTopicName + "'");
                ExternalTaskWorker worker = new ExternalTaskWorker(ExternalTaskService(), adapter, workerTopicName, retries, retryTimeout, variablesToFetch);
                workers.Add(worker);
                worker.StartWork();
            }
        }
Exemple #2
0
        public void StartWorkers()
        {
            var assembly            = System.Reflection.Assembly.GetEntryAssembly();
            var externalTaskWorkers = RetrieveExternalTaskWorkerInfo(assembly);

            foreach (var taskWorkerInfo in externalTaskWorkers)
            {
                Console.WriteLine($"Register Task Worker for Topic '{taskWorkerInfo.TopicName}'");
                ExternalTaskWorker worker = new ExternalTaskWorker(ExternalTaskService, taskWorkerInfo);
                _workers.Add(worker);
                worker.StartWork();
            }
        }
Exemple #3
0
        public void StartWorkers(string assemblyName)
        {
            var assemblys           = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains(assemblyName));
            var assembly            = (Assembly)assemblys.FirstOrDefault();
            var externalTaskWorkers = RetrieveExternalTaskWorkerInfo(assembly);

            foreach (var taskWorkerInfo in externalTaskWorkers)
            {
                Console.WriteLine($"Register Task Worker for Topic '{taskWorkerInfo.TopicName}'");
                ExternalTaskWorker worker = new ExternalTaskWorker(ExternalTaskService, taskWorkerInfo);
                _workers.Add(worker);
                worker.StartWork();
            }
        }