private object GetInstanceFromGenerator(ICodeFile file)
        {
            var  types = Utils.LoadTypes(_generatorManager.OutputBuildPath + "\\build");
            Type type  = types.Single(x => x.Name == file.Name);

            return(Activator.CreateInstance(type));
        }
Esempio n. 2
0
        /// <summary>
        /// Internal use
        /// </summary>
        /// <param name="lines">The lines.</param>
        /// <returns></returns>
        protected int Parse(IEnumerator lines)
        {
            string filename = currfilename = (lines as TokenEnumeratorBase).filename;

            codemodel = null;
            codemodel = new CodeFile(filename);
            ServiceHost.Error.ClearErrors(this);
            //scopetree.Clear();
            locstack.Clear();
            parsedtypes.Clear();
            scopestack.Clear();
            imports.Clear();
            //imports.Add(string.Empty, null);
            aliases.Clear();
            braces.Clear();
            scopestack.Push(new Location(0));
            Preparse(filename);
            this.lines = lines;
            int res = yyparse(lines);

            lasttoken  = LastToken;
            this.lines = null;
            Postparse();

            while (locstack.Count > 0)
            {
                Location l = locstack.Pop();
                cb.Invoke(l);
            }

            //cb.Invoke(locstack);

            return(res);
        }
Esempio n. 3
0
        public static ICodeFile CreateCodeMgr(CodeMgr mgr)
        {
            ICodeFile result = null;

            if (mgr.Type == UserTypeEnum.SVN)
            {
                result = new SVNCode(mgr.Source, mgr.Target, IdentityKey.CreateIdentityKey(mgr.UserName, mgr.Pwd, RTypeEnum.SVN));
            }
            return(result);
        }
Esempio n. 4
0
 private static void UpdateCode(ProjectSetting project)
 {
     if (project.CodeMgr != null)
     {
         ICodeFile codeMgr = CreateCodeMgr(project.CodeMgr);
         LogType.WriteLog(project.ProjectName, "签出代码文件", string.Format("正在签出代码文件:{0},请不要做其他操作", (project.CodeMgr.Source)));
         var rest = codeMgr.Clone();
         LogType.WriteLog(project.ProjectName, "签出代码文件", string.Format("代码文件签出成功:{0} msg:{1}", project.CodeMgr.Source, rest.Log));
     }
 }
Esempio n. 5
0
        public static void InitializeSynchronously(this ICodeFile file, GenerationRules rules, ICodeFileCollection parent, IServiceProvider?services)
        {
            var @namespace = parent.ToNamespace(rules);

            if (rules.TypeLoadMode == TypeLoadMode.Dynamic)
            {
                Console.WriteLine($"Generated code for {parent.ChildNamespace}.{file.FileName}");

                var generatedAssembly = parent.StartAssembly(rules);
                file.AssembleTypes(generatedAssembly);
                var serviceVariables = services?.GetService(typeof(IServiceVariableSource)) as IServiceVariableSource;

                var compiler = new AssemblyGenerator();
                compiler.Compile(generatedAssembly, serviceVariables);
                file.AttachTypesSynchronously(rules, generatedAssembly.Assembly, services, @namespace);

                return;
            }

            var found = file.AttachTypesSynchronously(rules, rules.ApplicationAssembly, services, @namespace);

            if (found)
            {
                Console.WriteLine($"Types from code file {parent.ChildNamespace}.{file.FileName} were loaded from assembly {rules.ApplicationAssembly.GetName()}");
            }

            if (!found)
            {
                if (rules.TypeLoadMode == TypeLoadMode.Static)
                {
                    throw new ExpectedTypeMissingException(
                              $"Could not load expected pre-built types for code file {file.FileName} ({file})");
                }

                var generatedAssembly = parent.StartAssembly(rules);
                file.AssembleTypes(generatedAssembly);
                var serviceVariables = services?.GetService(typeof(IServiceVariableSource)) as IServiceVariableSource;


                var compiler = new AssemblyGenerator();
                compiler.Compile(generatedAssembly, serviceVariables);

                file.AttachTypesSynchronously(rules, generatedAssembly.Assembly, services, @namespace);

                if (rules.SourceCodeWritingEnabled)
                {
                    var code = compiler.Code;
                    file.WriteCodeFile(parent, rules, code);
                }

                Console.WriteLine($"Generated and compiled code in memory for {parent.ChildNamespace}.{file.FileName}");
            }
        }
Esempio n. 6
0
 public static void WriteCodeFile(this ICodeFile file, ICodeFileCollection parent, GenerationRules rules, string code)
 {
     try
     {
         var directory = parent.ToExportDirectory(rules.GeneratedCodeOutputPath);
         var fileName  = Path.Combine(directory, file.FileName.Replace(" ", "_") + ".cs");
         File.WriteAllText(fileName, code);
         Console.WriteLine("Generated code to " + fileName.ToFullPath());
     }
     catch (Exception e)
     {
         Console.WriteLine("Unable to write code file");
         Console.WriteLine(e.ToString());
     }
 }
        private Type GetTypeFromGenerator(ICodeFile file)
        {
            var types = Utils.LoadTypes(_generatorManager.OutputBuildPath + "\\build");

            return(types.Single(x => x.Name == file.Name));
        }