110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
# File 'lib/shaml/command.rb', line 110
def run
if ARGV.length == 0 then
puts "S#aml architecture: ASP.NET MVC 2 and NHibernate 2.1 on mono 2.4.4+"
puts " version: #{SHAML_VERSION}"
puts
puts "Usage:"
puts " shaml command [parameters]"
puts
puts "Where command might be:"
puts " generate"
puts " app AppName : Create new shaml application"
puts " resource ResName "
puts " {haml|asp} [desc] : Create new CRUD resource with"
puts " a model, a view and a controller"
puts " controller Controller "
puts " {haml|asp} [desc] : Create a standalone controller"
puts " model Model [desc] : Create a standalone model"
puts
puts " compile : Compiles the solution using {ms|x}build"
puts " server : Runs xsp2"
puts
puts " gconsole : Starts a gsharp console"
puts " console : Starts a csharp console"
puts " runner script_name.cs : Runs the script"
puts " test : Runs the tests"
puts
puts "Examples: "
puts " shaml generate app Blog"
puts " shaml generate resource Post"
puts " shaml compile"
puts
puts "The console and runner parameters will preload the solutions"
puts "assemblies and configuration files, and loads everything you need to get"
puts "working with the domain objects"
puts
puts "The optional [desc] parameter describes the base schema of the model to"
puts "create the scaffold. Here is an example how it looks like:"
puts " name:string;email:string;birthdate:DateTime"
else
command = ARGV.shift
case command
when "generate" then
type = ARGV.shift
name = ARGV.shift
if name then
case type
when "app" then
unzip_file(File.join(TEMPLATEDIR,"shaml_base_template.dat"), ".shaml_extract_temp")
Dir.glob(".shaml_extract_temp/**/*").each do |filename|
infname = filename
outfname = filename.gsub("WebBase",name).gsub(".shaml_extract_temp",name);
if File.directory?(infname) then
FileUtils.mkdir_p(outfname)
else
FileUtils.mkdir_p(File.dirname(outfname))
end
unless File.directory?(infname)
File.open(infname,"rb") do |infile|
File.open(outfname,"wb+") do |outfile|
puts "Writing #{outfname}"
if infname=~/\.dll/ then
outfile.write infile.read
else
outfile.write infile.read.gsub("WebBase",name);
end
end
end
end
end
FileUtils.rm_rf ".shaml_extract_temp"
puts
puts "Your S#aml-architecture web application is created"
puts "Before compilation you need to create a model or resource using"
puts " shaml generate resource ResourceName [resourcedescriptors]"
puts
puts "After generation fix it's tests and run \"shaml compile\","
puts "\"shaml runner Scripts/run_create_schema.cs\" and \"shaml server\""
puts
when "resource"
desc = ARGV.shift || nil
type = "haml"
if desc=~/^asp([x])?/ then
type="asp"
desc = ARGV.shift || nil
elsif desc=~/^haml/ then
desc = ARGV.shift || nil
end
appname = getappname
xmlname = File.join("App","Core","#{appname}.Core.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join("App","Core","WebSample.cs"),appname,name,desc,xmlname,:compile)
xmlname = File.join("App","Data","#{appname}.Data.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSampleMap.cs"),File.join("App","Data","WebSampleMap.cs"),appname,name,desc,xmlname,:compile)
xmlname = File.join("App","Controllers","#{appname}.Controllers.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join("App","Controllers","WebSamplesController.cs"),appname,name,desc,xmlname,:compile)
xmlname = "#{appname}.csproj"
if type=="haml" then
copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join("App","Views","WebSamples","_WebSampleForm.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join("App","Views","WebSamples","Create.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join("App","Views","WebSamples","Delete.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join("App","Views","WebSamples","Edit.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join("App","Views","WebSamples","Index.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join("App","Views","WebSamples","Show.haml"),appname,name,desc,xmlname,:content)
else
copy_file(File.join(TEMPLATEDIR,"WebSampleForm.ascx"),File.join("App","Views","WebSamples","WebSampleForm.ascx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Create.aspx"),File.join("App","Views","WebSamples","Create.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Delete.aspx"),File.join("App","Views","WebSamples","Delete.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Edit.aspx"),File.join("App","Views","WebSamples","Edit.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Index.aspx"),File.join("App","Views","WebSamples","Index.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Show.aspx"),File.join("App","Views","WebSamples","Show.aspx"),appname,name,desc,xmlname,:content)
end
xmlname = File.join("Tests","#{appname}.Tests.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join("Tests","Core","WebSampleTests.cs"),appname,name,desc,xmlname,:compile)
copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join("Tests","Controllers","WebSamplesControllerTests.cs"),appname,name,desc,xmlname,:compile)
fix_with_model(name)
when "model"
desc = ARGV.shift || nil
appname = getappname
xmlname = File.join("App","Core","#{appname}.Core.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSample.cs"),File.join("App","Core","WebSample.cs"),appname,name,desc,xmlname,:compile)
xmlname = File.join("App","Data","#{appname}.Data.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSampleMap.cs"),File.join("App","Data","WebSampleMap.cs"),appname,name,desc,xmlname,:compile)
xmlname = File.join("Tests","#{appname}.Tests.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSampleTests.cs"),File.join("Tests","Core","WebSampleTests.cs"),appname,name,desc,xmlname,:compile)
fix_with_model(name)
when "controller"
desc = ARGV.shift || nil
type = "haml"
if desc=~/^asp([x])?/ then
type="asp"
desc = ARGV.shift || nil
elsif desc=~/^haml/ then
desc = ARGV.shift || nil
end
appname = getappname
xmlname = File.join("App","Controllers","#{appname}.Controllers.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSamplesController.cs"),File.join("App","Controllers","WebSamplesController.cs"),appname,name,desc,xmlname,:compile)
xmlname = "#{appname}.csproj"
if type=="haml" then
copy_file(File.join(TEMPLATEDIR,"_WebSampleForm.haml"),File.join("App","Views","WebSamples","_WebSampleForm.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Create.haml"),File.join("App","Views","WebSamples","Create.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Delete.haml"),File.join("App","Views","WebSamples","Delete.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Edit.haml"),File.join("App","Views","WebSamples","Edit.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Index.haml"),File.join("App","Views","WebSamples","Index.haml"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Show.haml"),File.join("App","Views","WebSamples","Show.haml"),appname,name,desc,xmlname,:content)
else
copy_file(File.join(TEMPLATEDIR,"WebSampleForm.ascx"),File.join("App","Views","WebSamples","WebSampleForm.ascx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Create.aspx"),File.join("App","Views","WebSamples","Create.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Delete.aspx"),File.join("App","Views","WebSamples","Delete.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Edit.aspx"),File.join("App","Views","WebSamples","Edit.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Index.aspx"),File.join("App","Views","WebSamples","Index.aspx"),appname,name,desc,xmlname,:content)
copy_file(File.join(TEMPLATEDIR,"Show.aspx"),File.join("App","Views","WebSamples","Show.aspx"),appname,name,desc,xmlname,:content)
end
xmlname = File.join("Tests","#{appname}.Tests.csproj")
copy_file(File.join(TEMPLATEDIR,"WebSamplesControllerTests.cs"),File.join("Tests","Controllers","WebSamplesControllerTests.cs"),appname,name,desc,xmlname,:compile)
else
puts 'S#aml ERROR: unknown generate argument'
end
else
puts 'S#aml ERROR: no name specified'
end
when "compile"
appname = getappname
begin
FileUtils::rm_rf "bin"
rescue Exception => e
end
if Mono.mono_found then
puts "Compiling using xbuild"
Mono.load_mono_app("/mono/2.0/xbuild.exe","#{appname}.sln")
else
puts "Mono not found. Compiling using msbuild"
system("msbuild #{appname}.sln")
end
puts "Compiling stylesheets"
system("compass -c Config/compass_config.rb")
when "server"
appname = getappname
puts "Starting xsp2 #{ARGV.join(" ")}"
if Mono.is_unix then
Mono.load_mono_app("/mono/2.0/xsp2.exe",ARGV.join(" "))
else
Mono.load_mono_app("/mono/2.0/WinHack/xsp2.exe",ARGV.join(" "))
end
puts "Done..."
when "test"
puts "Running tests"
appname = getappname
if Mono.mono_found then
Mono.load_app(File.join("libraries","nunit-console.exe"),File.join("bin","#{appname}.Tests.dll"))
else
system("#{File.join("libraries","nunit-console.exe")} #{File.join("bin","#{appname}.Tests.dll")}")
end
when "console"
appname = getappname
script = File.read(File.join("Scripts","setup","common.cs"))
script << File.read(File.join("Scripts","setup","csharp.cs"))
script = script.gsub("WebBase",appname);
Mono.load_csharp(script,"");
when "gconsole"
appname = getappname
script = File.read(File.join("Scripts","setup","common.cs"))
script << File.read(File.join("Scripts","setup","gsharp.cs"))
script = script.gsub("WebBase",appname);
Mono.load_gsharp(script,"");
when "runner"
appname = getappname
command = ARGV.shift
script = File.read(File.join("Scripts","setup","common.cs"))
script << File.read(File.join("Scripts","setup","runner.cs"))
script = script.gsub("WebBase",appname);
Mono.load_csharp(script,"#{command}");
else
puts 'S#aml ERROR: unknown command'
end
end
end
|