Пример #1
0
        private static void LoadEngines()
        {
            ZeusConfig           config = ZeusConfig.Current;
            IZeusScriptingEngine engine;

            _engines = new Hashtable();

            engine = new DotNetScript.DotNetScriptEngine();
            _engines.Add(engine.EngineName, engine);

            engine = new MicrosoftScript.MicrosoftScriptEngine();
            _engines.Add(engine.EngineName, engine);

            string   path;
            Assembly assembly;

            foreach (string unparsedpath in config.ScriptingEngines)
            {
                if (unparsedpath.EndsWith("MicrosoftScriptingEngine.dll", StringComparison.CurrentCultureIgnoreCase) ||
                    unparsedpath.EndsWith("DotNetScriptingEngine.dll", StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }
                else
                {
                    path     = FileTools.ResolvePath(unparsedpath, true);
                    assembly = DynamicAssemblyTools.LoadDynamicAssembly(path);

                    if (assembly != null)
                    {
                        object[] tmp = DynamicAssemblyTools.InstantiateClassesByType(assembly, typeof(IZeusScriptingEngine));

                        for (int i = 0; i < tmp.Length; i++)
                        {
                            engine = tmp[i] as IZeusScriptingEngine;

                            if (engine != null)
                            {
                                _engines.Add(engine.EngineName, engine);
                            }
                        }
                    }
                    else
                    {
                        throw new ZeusDynamicException(ZeusDynamicExceptionType.ScriptingEnginePluginInvalid, path);
                    }

                    assembly = null;
                }
            }
        }
Пример #2
0
        private static void LoadEngines()
        {
            ArrayList            dllNames = new ArrayList();
            IZeusScriptingEngine engine   = new DotNetScriptEngine();

            //TODO:FIX THIS!!!
            string prefix = @"E:\pub\Source Code\MyGeneration\SourceControl\zeus\source\ZeusSolution\ZeusExtremeTest\bin\debug\";

            _engines = new Hashtable();
            _engines.Add(engine.EngineName, engine);

            // Load text File with DLL file names
            if (File.Exists(prefix + ENGINE_CONFIG_FILE))
            {
                StreamReader reader = new StreamReader(prefix + ENGINE_CONFIG_FILE, Encoding.UTF8);

                string line = reader.ReadLine();
                while (line != null)
                {
                    dllNames.Add(line);
                    line = reader.ReadLine();
                }
                reader.Close();

                Assembly assembly;
                foreach (string dllPath in dllNames)
                {
                    assembly = DynamicAssemblyTools.LoadDynamicAssembly(prefix + dllPath);

                    if (assembly != null)
                    {
                        object[] tmp = DynamicAssemblyTools.InstantiateClassesByType(assembly, typeof(IZeusScriptingEngine));

                        for (int i = 0; i < tmp.Length; i++)
                        {
                            engine = tmp[i] as IZeusScriptingEngine;

                            if (engine != null)
                            {
                                _engines.Add(engine.EngineName, engine);
                            }
                        }
                    }
                }
            }
        }
Пример #3
0
        protected static void PopulateContextObjects(IZeusContext icontext)
        {
            ZeusContext context = icontext as ZeusContext;

            if (icontext != null)
            {
                ZeusConfig config = ZeusConfig.Current;
                context.SetIntrinsicObjects(ZeusFactory.IntrinsicObjectsArray);

                foreach (ZeusIntrinsicObject obj in config.IntrinsicObjects)
                {
                    Type     intrinsicObjectType = null;
                    Assembly newassembly         = null;
                    object[] objs = null;

                    if (!context.Objects.Contains(obj.VariableName) && !obj.Disabled)
                    {
                        newassembly = obj.Assembly;
                        // First thing, try to create the type without knowing the assembly.

                        /*try
                         * {
                         *  intrinsicObjectType = Type.GetType(obj.ClassPath);
                         * }
                         * catch
                         * {
                         *  intrinsicObjectType = null;
                         * }*/

                        if (intrinsicObjectType == null)
                        {
                            try
                            {
                                if (obj.AssemblyPath != string.Empty)
                                {
                                    string assemblyPath = obj.AssemblyPath;

                                    if (newassembly == null)
                                    {
                                        assemblyPath = FileTools.ResolvePath(assemblyPath, true);
                                        FileInfo finf        = new FileInfo(assemblyPath);
                                        FileInfo callingfinf = new FileInfo(Assembly.GetCallingAssembly().Location);
                                        if (callingfinf.FullName == finf.FullName)
                                        {
                                            newassembly = Assembly.GetCallingAssembly();
                                        }
                                    }

                                    if (newassembly == null)
                                    {
                                        throw new ZeusDynamicException(ZeusDynamicExceptionType.IntrinsicObjectPluginInvalid, "Invalid Assembly: " + assemblyPath);
                                    }
                                    else
                                    {
                                        intrinsicObjectType = newassembly.GetType(obj.ClassPath);
                                    }
                                }
                                else
                                {
                                    intrinsicObjectType = Type.GetType(obj.ClassPath);
                                }
                            }
                            catch (ZeusDynamicException zex)
                            {
                                context.Objects[obj.VariableName] = zex.Message;
                            }
                        }

                        if (intrinsicObjectType != null)
                        {
                            try
                            {
                                if (intrinsicObjectType != null)
                                {
                                    if (newassembly != null)
                                    {
                                        objs = DynamicAssemblyTools.InstantiateClassesByType(newassembly, newassembly.GetType(obj.ClassPath));
                                    }
                                    else
                                    {
                                        objs    = new object[1];
                                        objs[0] = DynamicAssemblyTools.InstantiateClassByType(intrinsicObjectType);
                                    }
                                }
                                else
                                {
                                    throw new ZeusDynamicException(ZeusDynamicExceptionType.IntrinsicObjectPluginInvalid, "Invalid Type: " + obj.ClassPath);
                                }

                                if (objs != null)
                                {
                                    if (objs.Length > 0)
                                    {
                                        context.Objects[obj.VariableName] = objs[0];
                                    }
                                }
                            }
                            catch (ZeusDynamicException zex)
                            {
                                context.Objects[obj.VariableName] = zex.Message;
                            }
                        }
                    }
                }
            }
        }