aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs
blob: d929c5825a7dc30ec1b842f8e538ac5a0ebd608c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Tango.DispenserAnalyzer.UI.Analysis
{
    public class AnalysisService
    {
        public static IAnalyzer GetAnalyzer(String fileName)
        {
            var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IAnalyzer).IsAssignableFrom(x)).ToList();
            var words = fileName.Split().Select(x => x.Trim(' '));
            var analyzerType = analyzerTypes.FirstOrDefault(x => words.Contains(x.GetCustomAttribute<AnalyzerAttribute>().Name, StringComparer.OrdinalIgnoreCase));
            return (analyzerType != null) ? Activator.CreateInstance(analyzerType) as IAnalyzer : null;
            
        }
        public static string GetTestName(String fileName)
        {
            var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IAnalyzer).IsAssignableFrom(x)).ToList();
            var analyzerType = analyzerTypes.SingleOrDefault(x => fileName.Contains(x.GetCustomAttribute<AnalyzerAttribute>().Name));
            return analyzerType.GetCustomAttribute<AnalyzerAttribute>().Name;
        }
    }
}