/// <summary> /// Synchronize database and initialize data. /// <param name="pathOfFolderOrFile"> /// Path of folder or file. /// 1. If the value is null, find .apgen file in '~/App_Code' virtual path. /// 2. If the value is suffix '.apgen' file, find the file. /// 3. If the value is folder, find .apgen file in the folder. /// </param> /// </summary> public static void SyncAndInitData(string pathOfFolderOrFile = null) { if (!initData) { foreach (APGen gen in APGenManager.Gens(pathOfFolderOrFile)) { gen.SyncData(); gen.InitData(); } } initData = true; }
/// <summary> /// Generate the code from .apgen file. /// </summary> /// <param name="assemblyBuilder">AssemblyBuilder</param> public override void GenerateCode(AssemblyBuilder assemblyBuilder) { if (!flag && BuildManager.CodeAssemblies != null && getProfileMethodCount > 0) { getProfileMethodCount = 0; flag = true; } string path = Path.Combine( HttpRuntime.AppDomainAppPath, VirtualPath.Substring(HttpRuntime.AppDomainAppVirtualPath.Length + (HttpRuntime.AppDomainAppVirtualPath.Length == 1 ? 0 : 1))); using (TextWriter writer = assemblyBuilder.CreateCodeFile(this)) { APGen gen = APGenManager.OpenGenDocument(path); CodeDomProvider provider = assemblyBuilder.CodeDomProvider; provider.GenerateCodeFromCompileUnit(gen.Generate(), writer, null); writer.Flush(); writer.Close(); } }