Exemplo n.º 1
0
        private void AttachApplets()
        {
            string path = Environment.CurrentDirectory;
            path += "\\applets";

            string[] dlls = System.IO.Directory.GetFiles(path, "*.dll");

            if (dlls.Length == 0)
                throw new Exception("Exception in PersonalDictionary.App.xaml.cs.AttachApplets().At list one applet must be in the \\applets\\.. directory");

            foreach (var dll_ka in dlls)
            {
                var asm = Assembly.LoadFrom(dll_ka);

                var types = asm.GetTypes().Where((t, obj) => t.IsClass).ToList();

                foreach (var item in types)
                {
                    IApplet obj = null;
                    try { obj = asm.CreateInstance(item.FullName) as IApplet; }
                    catch { }
                    if (obj != null)
                    {
                        applets.Add(obj.ToType().FullName, obj);

                        //Регистрация апплета в БД для сохранения результатов (прогресса)
                        string applet_uid = asm.ManifestModule.Name.Substring(0, asm.ManifestModule.Name.LastIndexOf('.'));
                        applet_uid += "." + obj.ToType().FullName;

                        if (DB.GetInstance().ApplestsData.Where(app => app.AppletID == applet_uid).ToArray().Length == 0)
                        {
                            AppletData appletData = new AppletData();
                            appletData.AppletID = applet_uid;
                            appletData.AppletDisplay = obj.DisplayName();
                            DB.GetInstance().RegisterApplet(appletData);
                        }
                    }

                }
            }
        }