예제 #1
0
		public static void Main (string[] args)
		{
			Console.WriteLine ("Hello World!");
			
			Model model = new Model(typeof(Demo));
			
			model.Write<ExtModel,ExtModelField>();
			
			Store store = new Store(typeof(Demo));
			store.Write();
			
			List list = new List(typeof(Demo));
			list.Write();
			
			Form form = new Form(typeof(Demo));
			form.Write();
			
			Controller controller = new Controller(typeof(Demo));
			controller.Write();
			
			Application app = new Application(typeof(Demo));
			app.Write();
			
			Console.WriteLine ("This is The End my friend!");
		}
		public virtual void Write()
		{
			if(string.IsNullOrEmpty(AppName)) AppName="App";
			
			if(string.IsNullOrEmpty(Theme)) Theme="ext-all.css";
			
			string solutionDir=Path.Combine(Directory.GetCurrentDirectory(), SolutionName);
			
			if(!Directory.Exists(solutionDir))		
				Directory.CreateDirectory(solutionDir);
								
			OutputDirectory = Path.Combine(solutionDir, "src");
			
			if(!Directory.Exists(OutputDirectory))		
				Directory.CreateDirectory(OutputDirectory);
			
			string webAppDir=Path.Combine(OutputDirectory,string.Format("{0}.{1}",SolutionName, "WebApp"));
			
			if(!Directory.Exists(webAppDir))		
				Directory.CreateDirectory(webAppDir);
			
			
			string modulesDir=Path.Combine(webAppDir, "modules");
			
			if(!Directory.Exists(modulesDir))		
				Directory.CreateDirectory(modulesDir);
			
			
			string resourcesDir=Path.Combine(webAppDir, "resources");
			
			if(!Directory.Exists(resourcesDir))		
				Directory.CreateDirectory(resourcesDir);
			
			if(!string.IsNullOrEmpty(ExtDir))
			{
				string extDir= Path.Combine(webAppDir, "extjs");
				Util.Execute("ln", string.Format(" -s {0} {1}",ExtDir,extDir));
				Util.Execute("ln", string.Format("-s extjs/examples/ux/ {0}",
				                                 Path.Combine(webAppDir, "ux")));
			}
			
			
			var assembly = Assembly.LoadFrom(AssemblyName);
			Console.WriteLine("Starting js  generation for assembly:'{0}' ...", assembly);
			foreach(Type t in  assembly.GetTypes()){
				if (t.Namespace==NameSpace)
				{
					Console.Write("Generating js for class:'{0}'...", t.FullName);
					
					Model model = new Model(t){OutputDirectory=modulesDir,AppName=AppName};
			
					model.Write<ExtModel,ExtModelField>();
			
					Store store = new Store(t){OutputDirectory=modulesDir,AppName=AppName};;
					store.Write();
			
					List list = new List(t){OutputDirectory=modulesDir,AppName=AppName};;
					list.Write();
			
					Form form = new Form(t){OutputDirectory=modulesDir,AppName=AppName};;
					form.Write();
			
					Controller controller = new Controller(t){OutputDirectory=modulesDir,AppName=AppName};;
					controller.Write();
			
					Application app = new Application(t){OutputDirectory=modulesDir,AppName=AppName,Theme=Theme};;
					app.Write();
					
					Console.WriteLine(" Done.");
								
				}
			}
			
			Console.WriteLine("js for assembly:'{0}' Done", assembly);
			
			using (TextWriter twp = new StreamWriter(Path.Combine(webAppDir,"app.js")))
			{
				twp.Write(string.Format(appTemplate));				
				twp.Close();
			}
			
			using (TextWriter twp = new StreamWriter(Path.Combine(webAppDir,"index.html")))
			{
				twp.Write(string.Format( indexTemplate, AppTitle, Theme));				
				twp.Close();
			}
			
			using (TextWriter twp = new StreamWriter(Path.Combine(webAppDir,"intro.html")))
			{
				twp.Write(string.Format(introTemplate));				
				twp.Close();
			}
			
			using (TextWriter twp = new StreamWriter(Path.Combine(webAppDir,"license.txt")))
			{
				twp.Write(string.Format(licenseTemplate, AppTitle));				
				twp.Close();
			}
			
			
			using (TextWriter twp = new StreamWriter(Path.Combine(resourcesDir,"util.js")))
			{
				twp.Write(string.Format(utilJsTemplate));				
				twp.Close();
			}
			
			using (TextWriter twp = new StreamWriter(Path.Combine(resourcesDir,"util.css")))
			{
				twp.Write(string.Format(utilCssTemplate));				
				twp.Close();
			}
			
			string loginAppDir= Path.Combine(modulesDir,"login");
			if(! Directory.Exists(loginAppDir))
				Directory.CreateDirectory(loginAppDir);
			
			using (TextWriter twp = new StreamWriter(Path.Combine(loginAppDir,"app.js")))
			{
				twp.Write(string.Format(loginAppTemplate, AppName));				
				twp.Close();
			}
							
			string loginViewDir= Path.Combine( Path.Combine(modulesDir,"app"), "view");
			if(! Directory.Exists(loginViewDir))
				Directory.CreateDirectory(loginViewDir);
			
			using (TextWriter twp = new StreamWriter(Path.Combine(loginViewDir,"Login.js")))
			{
				twp.Write(string.Format(loginViewTemplate, AppName));				
				twp.Close();
			}
	
			string loginControllerDir= Path.Combine( Path.Combine(modulesDir,"app"), "controller");
			if(! Directory.Exists(loginControllerDir))
				Directory.CreateDirectory(loginControllerDir);
			
			using (TextWriter twp = new StreamWriter(Path.Combine(loginControllerDir,"Login.js")))
			{
				twp.Write(string.Format(loginControllerTemplate, AppName));				
				twp.Close();
			}
			
		}