コード例 #1
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;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Adds a child tempalte to this template. This is used for the TemplateGroup type
 /// template.
 /// </summary>
 /// <param name="templatePath"></param>
 public void AddIncludedTemplatePath(string templatePath)
 {
     this._includedTemplatePaths.Add(FileTools.MakeRelative(templatePath, this.FilePath));
 }
コード例 #3
0
ファイル: ZeusContext.cs プロジェクト: xiabingqi/mygeneration
        /// <summary>
        /// Depricated! Use: Execute(string path, bool copyContext)
        /// </summary>
        /// <param name="path"></param>
        public void ExecuteTemplate(string path)
        {
            ZeusTemplate template = new ZeusTemplate(FileTools.MakeAbsolute(path, this.ExecutingTemplate.FilePath));

            template.Execute(this, 0, true);
        }