private CMTaskFactoryBase GetTaskFactory(string taskTypeName)
 {
     if (!TaskFactoriesByTaskType.ContainsKey(taskTypeName))
     {
         throw new InvalidOperationException($"Unable to create a task of type '{taskTypeName}'. The task factory for this task was not found.");
     }
     return(TaskFactoriesByTaskType[taskTypeName]);
 }
        private void InitCatalog()
        {
            var catalog = new AggregateCatalog();

            // Add a catalog that scans the same directory this dll is in for task factories
            catalog.Catalogs.Add(new DirectoryCatalog(AssemblyDirectory));

            // mcbtodo: Also scan {the datastore directory}\Tasks  .. This will provide a way to add user created tasks instead of just builtin

            container = new CompositionContainer(catalog);

            try
            {
                // Start the search and fill in the Tasks property
                container.ComposeParts(this);
            }
            catch //(CompositionException cex)
            {
                // mcbtodo: if there is an error here then the program won't work anyway
                // mcbtodo: might as well blow up with the full and correct stack trace.
                throw;
            }

            foreach (var taskFactory in TaskFactories)
            {
                foreach (var taskType in taskFactory.GetTaskTypes())
                {
                    if (TaskFactoriesByTaskType.ContainsKey(taskType))
                    {
                        throw new InvalidOperationException($"Unable to register task of type '{taskType}'. There are more than 1 task factories that support this type.");
                    }

                    TaskFactoriesByTaskType[taskType] = taskFactory;
                }
            }
        }