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();
			}
			
		}
示例#2
0
		public void Write(){
			
			if(string.IsNullOrEmpty(AppName)) AppName="App";
			
			if(string.IsNullOrEmpty(Define))
				Define= string.Format("{0}.view.{1}.List",AppName,type.Name.ToLower());
						
			if(string.IsNullOrEmpty(Extend))
				Extend= Config.List;
			
			if(string.IsNullOrEmpty(Alias))
				Alias= string.Format("widget.{0}list",type.Name.ToLower());
			
			if(string.IsNullOrEmpty(Store))
				Store= string.Format(type.Name);
			
			
			
			List<ListColumn> cols = new List<ListColumn>();
			
			foreach(PropertyInfo pi in type.GetProperties()){
				
				if(pi.Name== OrmLiteConfig.IdField) continue;
				
				ListColumn col = new ListColumn();
				col.text=string.Format("'{0}'", pi.Name);
				col.dataIndex= string.Format("'{0}'", pi.Name);
				col.sortable= true;
				if (cols.Count==0)  col.flex= 1;
				
				if(pi.PropertyType== typeof(DateTime) || pi.PropertyType== typeof(DateTime?))
				{
					col.renderer="Ext.util.Format.dateRenderer('d.m.Y')";
				}
				else if(pi.PropertyType== typeof(Int16) || pi.PropertyType== typeof(Int16?)
				        || pi.PropertyType== typeof(Int32) || pi.PropertyType== typeof(Int32?)
				        || pi.PropertyType== typeof(Int64) || pi.PropertyType== typeof(Int64?))
				{
					col.renderer="<FormatInt/>";
				}
				else if(pi.PropertyType== typeof(decimal) || pi.PropertyType== typeof(decimal?)
				        || pi.PropertyType== typeof(double) || pi.PropertyType== typeof(double?)
				        || pi.PropertyType== typeof(float) || pi.PropertyType== typeof(float?))
				{
					col.renderer="<FormatNumber/>";
				}
				else if(pi.PropertyType== typeof(bool) || pi.PropertyType== typeof(bool?))
				{
					col.xtype="'booleancolumn'";
					col.trueText= "'Si'";
					col.falseText= "'No'";
					col.align="'center'";
				}
				
				cols.Add(col);
			}
			
			string sCols= cols.SerializeAndFormat().
				Replace("<FormatInt/>", Config.FormatInt).
			    Replace("<FormatNumber/>", Config.FormatNumber).
				Replace("True","true").
				Replace("False","false");
			
			if(string.IsNullOrEmpty(OutputDirectory))
				OutputDirectory= Path.Combine(Directory.GetCurrentDirectory(), "modules");				
			
			if (!Directory.Exists(OutputDirectory))
					Directory.CreateDirectory(OutputDirectory);
			
			string viewDir = Path.Combine(Path.Combine(OutputDirectory, Config.ViewDirectory),type.Name.ToLower());				
			
			if (!Directory.Exists(viewDir))
					Directory.CreateDirectory(viewDir);
						
			if(string.IsNullOrEmpty(FileName))
				FileName= "List.js";
			
			
			using (TextWriter tw = new StreamWriter(Path.Combine(viewDir, FileName)))
			{
				tw.Write(string.Format(template, Define, Extend, Alias, Store, sCols));
				tw.Close();
			}
			
		}
示例#3
0
		public ExtModel ()
		{
			fields= new List<ExtModelField>();
		}
示例#4
0
		public void Write()
		{
			if(string.IsNullOrEmpty(AppName)) AppName="App";
			
			if(string.IsNullOrEmpty(Define))
				Define= string.Format("{0}.view.{1}.Form",AppName, type.Name.ToLower());
						
			if(string.IsNullOrEmpty(Extend))
				Extend= Config.Form;
			
			if(string.IsNullOrEmpty(Alias))
				Alias= string.Format("widget.{0}form",type.Name.ToLower());
			
			
			List<FormItem> items= new List<FormItem>();
			
			foreach(PropertyInfo pi in type.GetProperties())
			{
				FormItem item = new FormItem();
				item.name= string.Format("'{0}'",pi.Name);
				if(pi.Name== OrmLiteConfig.IdField)
				{
					item.xtype="'hidden'";
					items.Add(item);
					continue; 
				}
				
				item.fieldLabel=string.Format("'{0}'",pi.Name);
				
				if(!pi.PropertyType.ToString().StartsWith("System.Nullable") && pi.PropertyType!=typeof(string) )
				   item.allowBlank=false;
				   
				if( pi.PropertyType == typeof(string) )
				{
					RequiredAttribute ra = pi.FirstAttribute<RequiredAttribute>();
					if(ra != null)
					{
						item.allowBlank=false;
					}
					
					StringLengthAttribute la = pi.FirstAttribute<StringLengthAttribute>();
					if( la !=null )
					{
						item.maxLength= la.MaximumLength;
						item.enforceMaxLength=true;
					}
					if(pi.Name.ToUpper().Contains("MAIL") || pi.Name.ToUpper().Contains("CORREO"))
						item.vtype="'email'";
				}
				else if( pi.PropertyType == typeof(DateTime) || pi.PropertyType == typeof(DateTime?))
				{
					item.xtype="'datefield'";
					item.format="'d.m.Y'";
				}
				else if(pi.PropertyType== typeof(Int16) || pi.PropertyType== typeof(Int16?)
				        || pi.PropertyType== typeof(Int32) || pi.PropertyType== typeof(Int32?)
				        || pi.PropertyType== typeof(Int64) || pi.PropertyType== typeof(Int64?))
				{
					item.xtype="'numberfield'";
					item.allowDecimals=false;
				}
				else if(pi.PropertyType== typeof(decimal) || pi.PropertyType== typeof(decimal?)
				        || pi.PropertyType== typeof(double) || pi.PropertyType== typeof(double?)
				        || pi.PropertyType== typeof(float) || pi.PropertyType== typeof(float?))
				{
					item.xtype="'numberfield'";
				}
				else if(pi.PropertyType==typeof(bool) || pi.PropertyType==typeof(bool?))
				{
					item.xtype="'checkboxfield'";
				}
				
				items.Add(item);
			}
			
			int height = 90;
			
			int ic= items.Count(i=>i.xtype!="'hidden'");
			
			if(ic==2) height=145;
			else if (ic==3) height=150;
			else if (ic==4) height=170;
			else if (ic>=5) height=40*ic;
			if( height>350) height=350;
			
			string sItems= items.SerializeAndFormat().Replace("True","true").Replace("False","false");

			if(string.IsNullOrEmpty(OutputDirectory))
				OutputDirectory= Path.Combine(Directory.GetCurrentDirectory(), "modules");				
			
			if (!Directory.Exists(OutputDirectory))
					Directory.CreateDirectory(OutputDirectory);
			
			string viewDir = Path.Combine(Path.Combine(OutputDirectory, Config.ViewDirectory),type.Name.ToLower());				
			
			if (!Directory.Exists(viewDir))
					Directory.CreateDirectory(viewDir);
			
			if(string.IsNullOrEmpty(FileName))
				FileName= "Form.js";
			
				
			using (TextWriter tw = new StreamWriter(Path.Combine(viewDir, FileName)))
			{
				tw.Write(string.Format(template, Define, Extend, Alias, sItems, height));
				tw.Close();
			}
			
			
		}