Ejemplo n.º 1
0
 public static object CreateClass(string ClassToCall)
 {
     // --------------------------------------------------------------
     // Call a static/shared method of a class to perform the
     // necessary action.
     // --------------------------------------------------------------
     try
     {
         int PosPeriod = ClassToCall.IndexOf(".");
         if (PosPeriod == -1)
         {
             throw new Exception("No namespace specified in action: " + ClassToCall);
         }
         Type t = null;
         foreach (Assembly Assemb in AppDomain.CurrentDomain.GetAssemblies())
         {
             t = Assemb.GetType(ClassToCall, false, true);
             if (t != null)
             {
                 break;
             }
         }
         if ((t == null))
         {
             throw new Exception("Cannot find type: " + ClassToCall);
         }
         return(Activator.CreateInstance(t));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.GetBaseException().Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     return(null);
 }
Ejemplo n.º 2
0
        public static object CallMethodOfClass(string ClassToCall, string MethodToCall, List <object> Arguments)
        {
            // --------------------------------------------------------------
            // Call a static/shared method of a class with the specified
            // arguments.
            // --------------------------------------------------------------
            try
            {
                int PosPeriod = ClassToCall.IndexOf(".");
                if (PosPeriod == -1)
                {
                    throw new Exception("No namespace specified in action: " + ClassToCall);
                }

                string AssemblyNameToFind = ClassToCall.Substring(0, PosPeriod);
                Type   t = null;
                foreach (Assembly Assemb in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (AssemblyNameToFind == Assemb.GetName().Name)
                    {
                        t = Assemb.GetType(ClassToCall, true, true);
                    }
                }
                if (t == null)
                {
                    throw new Exception("Cannot find type: " + ClassToCall);
                }

                MethodInfo Method = t.GetMethod(MethodToCall);
                if (Method == null)
                {
                    throw new Exception("Cannot find method '" + MethodToCall + "' in class '" + ClassToCall + "'");
                }

                object[] Params = new object[Arguments.Count];
                Arguments.CopyTo(Params);
                return(Method.Invoke(null, Params));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.Message);
            }
        }
Ejemplo n.º 3
0
        public static object LoadAssembly(string tradetype)
        {
            var tt      = tradetype.Split('.');
            var dllpath = HostingEnvironment.MapPath("~") + "\\bin\\" + tt[0] + "\\" + tt[0] + ".Biz.dll";

            if (Assemb == null || FileVer.FileVersion != FileVersionInfo.GetVersionInfo(dllpath).FileVersion)
            {
                FileVer = FileVersionInfo.GetVersionInfo(dllpath);
                if (ConfigurationManager.AppSettings["enabledymc"] == "0")
                {
                    Assemb = Assembly.LoadFile(dllpath);
                }
                else
                {
                    Assemb = Assembly.LoadFile(dllpath);
                    //Assemb = Assembly.Load(File.ReadAllBytes(dllpath));
                }
            }
            return(Assemb.CreateInstance(tradetype, true));
        }