Esempio n. 1
0
 public bool TryGetValue(string name, out AppAnalyzer app)
 {
     if (_apps.TryGetValue(name, out var type))
     {
         var appInstance = Activator.CreateInstance(type) as IApp;
         app = new AppAnalyzer(appInstance);
         return(true);
     }
     app = null;
     return(false);
 }
Esempio n. 2
0
        public AppRegistry(IList <Assembly> asms)
        {
            var appNames = new SortedSet <string>();

            foreach (var asm in asms)
            {
                var asmName = asm.GetName().Name;
                foreach (var type in asm.GetTypes().Where(t => t.IsClass && t.GetInterfaces().Contains(typeof(IApp))))
                {
                    var app         = Activator.CreateInstance(type) as IApp;
                    var appAnalyzer = new AppAnalyzer(app);
                    var fullName    = $"{asmName}.{appAnalyzer.Name}";
                    _apps[fullName] = type;
                    appNames.Add(fullName);
                    if (appNames.Contains(appAnalyzer.Name))
                    {
                        _apps.Remove(appAnalyzer.Name);
                    }
                    else
                    {
                        appNames.Add(appAnalyzer.Name);
                        _apps[appAnalyzer.Name] = type;
                    }
                }
            }
            foreach (var kvp in _apps)
            {
                if (_reverseDictionary.TryGetValue(kvp.Value, out var key))
                {
                    var newKey = key.Append(kvp.Key).OrderBy(s => s.Length).ToArray();
                    _reverseDictionary[kvp.Value] = newKey;
                }
                else
                {
                    _reverseDictionary[kvp.Value] = new string[] { kvp.Key };
                }
            }
        }
Esempio n. 3
0
        public bool TryGetMeta(string name, out AppMeta meta)
        {
            meta = null;
            AppAnalyzer app = null;

            if (!TryGetValue(name, out app))
            {
                return(false);
            }
            string[] names = null;
            if (!TryGetNames(app, out names))
            {
                return(false);
            }
            meta = new AppMeta {
                Author      = app.Author ?? "",
                Version     = app.Version?.ToString() ?? "",
                Description = app.Description ?? ""
            };
            meta.Names.AddRange(names);
            foreach (var dep in app.Dependencies)
            {
                string[] depNames = null;
                if (!TryGetNames(dep, out depNames))
                {
                    return(false);
                }
                AppMeta depMeta = null;
                if (!TryGetMeta(depNames[0], out depMeta))
                {
                    return(false);
                }
                meta.Dependencies[dep.Name] = depMeta;
            }
            return(true);
        }
Esempio n. 4
0
 public bool TryGetNames(AppAnalyzer app, out string[] names) => _reverseDictionary.TryGetValue(app.App.GetType(), out names);