Ejemplo n.º 1
0
        private bool LoadExternalModule(string path)
        {
            bool     foundSnapIn  = false;
            Assembly theSnapInAsm = null;

            try
            {
                // Dynamically load the selected assembly.
                theSnapInAsm = Assembly.LoadFrom(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(foundSnapIn);
            }
            // Get all IAppFunctionality-compatible classes in assembly.
            var theClassTypes = from t in theSnapInAsm.GetTypes()
                                where t.IsClass &&
                                (t.GetInterface("IAppFunctionality") != null)
                                select t;

            // Now, create the object and call DoIt() method.
            foreach (Type t in theClassTypes)
            {
                foundSnapIn = true;
                // Use late binding to create the type.
                IAppFunctionality itfApp =
                    (IAppFunctionality)theSnapInAsm.CreateInstance(t.FullName, true);
                itfApp.DoIt();
                lstLoadedSnapIns.Items.Add(t.FullName);
            }
            return(foundSnapIn);
        }
Ejemplo n.º 2
0
        private bool LoadExternalModule(string path)
        {
            bool     foundSnapIn = false;
            Assembly asm         = null;

            try
            {
                asm = Assembly.LoadFrom(path);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(foundSnapIn);
            }

            var theClassTypes = from t in asm.GetTypes() where t.IsClass && (t.GetInterface("IAppFunctionality") != null) select t;

            foreach (Type t in theClassTypes)
            {
                foundSnapIn = true;

                IAppFunctionality itfApp = (IAppFunctionality)Activator.CreateInstance(t);

                itfApp.DoIt();
                lstLoadedSnapIns.Items.Add(t.FullName);
                DisplayCompanyData(t);
            }
            return(foundSnapIn);
        }
Ejemplo n.º 3
0
        private bool LoadExternalModule(string path)
        {
            bool     foundSnapIn  = false;
            Assembly theSnapInAsm = null;

            try
            {
                //Динамически загрузить выбранную сборку
                theSnapInAsm = Assembly.LoadFrom(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(foundSnapIn);
            }

            //Получить все совместные с IAppFunctionality классы в сборке
            var theClassTypes = from t in theSnapInAsm.GetTypes()
                                where t.IsClass &&
                                (t.GetInterface("IAppFunctionality") != null)
                                select t;

            foreach (Type t in theClassTypes)
            {
                foundSnapIn = true;

                //Использовать позднее связывание для создания экземпляра типа.

                IAppFunctionality itfApp =
                    (IAppFunctionality)theSnapInAsm.CreateInstance(t.FullName, true);
                itfApp.DoIt();
                lstLoadedSnapIns.Items.Add(t.FullName);
            }
            return(foundSnapIn);
        }
Ejemplo n.º 4
0
        private static bool LoadExternalModule(string path)
        {
            bool     foundSnapIn  = false;
            Assembly theSnapInAsm = null;

            try
            {
                // Dynamically load the selected assembly.
                theSnapInAsm = Assembly.LoadFrom(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred loading the snapin: {ex.Message}");
                return(foundSnapIn);
            }

            // Get all IAppFunctionality compatible classes in assembly.
            var theClassTypes = from t in theSnapInAsm.GetTypes()
                                where t.IsClass && (t.GetInterface("IAppFunctionality") != null)
                                select t;

            // Now, create the object and call DoIt() method.
            foreach (Type t in theClassTypes)
            {
                foundSnapIn = true;
                // Use late binding to create the type.
                IAppFunctionality itfApp = (IAppFunctionality)theSnapInAsm.CreateInstance(t.FullName, true);
                itfApp?.DoIt();
                //lstLoadedSnapIns.Items.Add(t.FullName);

                // Show company info.
                DisplayCompanyData(t);
            }
            return(foundSnapIn);
        }
Ejemplo n.º 5
0
        private static void LoadExternalModule(string path)
        {
            bool found = false;

            try {
                Assembly asm   = Assembly.LoadFrom(path);
                Type[]   types = asm.GetTypes();
                foreach (Type t in types)
                {
                    Type iAppFuncType = t.GetInterface("ModuleDefinition.IAppFunctionality");
                    if (iAppFuncType != null && t.IsClass)
                    {
                        found = true;
                        IAppFunctionality app = (IAppFunctionality)asm.CreateInstance(t.FullName, true);
                        app.DoIt();
                        PrintCompanyInformation(t);
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine("Error!");
                Console.WriteLine(ex);
            }

            if (!found)
            {
                Console.WriteLine("Module is incompatible!");
            }
        }
Ejemplo n.º 6
0
        private bool LoadExternalModule(string pathToAssembly)
        {
            bool     foundSnapIn = false;
            Assembly theSnapInAsm;

            try
            {
                // Динамическая загрузка выбранной сборки.
                theSnapInAsm = Assembly.LoadFrom(pathToAssembly);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }

            // Получение информации обо всех совместимых с IAppFunctionality классах в сборке.
            var theClassTypes = from t in theSnapInAsm.GetTypes()
                                where t.IsClass && (t.GetInterface("IAppFunctionality") != null)
                                select t;

            // Создание объекта и вызов метода DoIt().
            foreach (Type t in theClassTypes)
            {
                foundSnapIn = true;
                // Использование позднего связывания для создания типа.
                IAppFunctionality itfApp =
                    (IAppFunctionality)theSnapInAsm.CreateInstance(t.FullName, true);
                itfApp.DoIt();
                snapInListBox.Items.Add(t.FullName ?? throw new InvalidOperationException());
                // Отображение информации о компании.
                DisplayCompanyData(t);
            }
            return(foundSnapIn);
        }
Ejemplo n.º 7
0
        private static bool LoadExternalModule(string path)
        {
            bool     foundSnapIn  = false;
            Assembly theSnapInAsm = null;

            try
            {
                theSnapInAsm = Assembly.LoadFrom(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occured loading the snaping: {ex.Message}");
                return(foundSnapIn);
            }

            var theClassTypes = from t in theSnapInAsm.GetTypes()
                                where t.IsClass && (t.GetInterface("IAppFunctionality") != null)
                                select t;

            foreach (Type t in theClassTypes)
            {
                foundSnapIn = true;
                IAppFunctionality itfApp = (IAppFunctionality)theSnapInAsm.CreateInstance(t.FullName, true);
                itfApp?.DoIt();
                DisplayCompanyData(t);
            }
            return(foundSnapIn);
        }
Ejemplo n.º 8
0
        private static void LoadExternalModule(string assemblyName)
        {
            Assembly theSnapInAsm = null;

            try
            {
                // Dynamically load the selected assembly.
                theSnapInAsm = Assembly.LoadFrom(assemblyName);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred loading the snapin: {ex.Message}");
                return;
            }

            // Get all IAppFunctionality compatible classes in assembly.
            var theClassTypes =
                theSnapInAsm.GetTypes()
                .Where(t => t.IsClass && (t.GetInterface("IAppFunctionality") != null))
                .ToList();

            if (!theClassTypes.Any())
            {
                Console.WriteLine("Nothing implements IAppFunctionality!");
            }

            // Now, create the object and call DoIt() method.
            foreach (Type t in theClassTypes)
            {
                // Use late binding to create the type.
                IAppFunctionality itfApp = (IAppFunctionality)theSnapInAsm.CreateInstance(t.FullName, true);
                itfApp?.DoIt();
                //lstLoadedSnapIns.Items.Add(t.FullName);

                // Show company info.
                DisplayCompanyData(t);
            }
        }
Ejemplo n.º 9
0
        private static bool LoadExternalModule(string filePath)
        {
            bool     foundSnapIn = false;
            Assembly snapInAsm   = null;

            try {
                snapInAsm = Assembly.LoadFrom(filePath);
            } catch (Exception ex) {
                Console.WriteLine("Error while loading the assembly!");
                return(false);
            }

            (from type in snapInAsm.GetTypes() where type.IsClass && (type.GetInterface("IAppFunctionality") != null) select type).ToList().ForEach(x => {
                foundSnapIn           = true;
                IAppFunctionality app = (IAppFunctionality)snapInAsm.CreateInstance(x.FullName, true);
                if (app != null)
                {
                    app.DoIt();
                }
                DisplayCompanyInfo(x);
            });

            return(foundSnapIn);
        }