Esempio n. 1
0
        private IApplication[] FindMatchApplications(IEnumerable <IApplication> applications, SystemWindow window)
        {
            var byFileName = new List <IApplication>();
            var byTitle    = new List <IApplication>();
            var byClass    = new List <IApplication>();

            foreach (var app in applications)
            {
                switch (app.MatchUsing)
                {
                case MatchUsing.WindowClass:
                    byClass.Add(app);
                    break;

                case MatchUsing.WindowTitle:
                    byTitle.Add(app);
                    break;

                case MatchUsing.ExecutableFilename:
                    byFileName.Add(app);
                    break;

                case MatchUsing.All:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            List <IApplication> result = new List <IApplication>();
            string windowMatchString;

            if (byClass.Count != 0)
            {
                try
                {
                    windowMatchString = window.ClassName;
                    result.AddRange(byClass.Where(a => a.MatchString != null && CompareString(a.MatchString, windowMatchString, a.IsRegEx)));
                }
                catch
                {
                    // ignored
                }
            }
            if (byTitle.Count != 0)
            {
                try
                {
                    windowMatchString = window.Title;
                    result.AddRange(byTitle.Where(a => a.MatchString != null && CompareString(a.MatchString, windowMatchString, a.IsRegEx)));
                }
                catch
                {
                    // ignored
                }
            }
            if (byFileName.Count != 0)
            {
                try
                {
                    windowMatchString = Path.GetFileName(window.GetProcessFilePath());
                    result.AddRange(byFileName.Where(a => a.MatchString != null && CompareString(a.MatchString, windowMatchString, a.IsRegEx)));
                }
                catch
                {
                    // ignored
                }
            }
            return(result.ToArray());
        }