1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace WindowsApplication1
18 using System
.Collections
.Generic
;
21 using System
.Windows
.Forms
;
22 using IronPython
.Hosting
;
24 public partial class Form1
: Form
26 private PythonEngine eng
;
27 private EngineModule mod1
;
28 private CompiledCode scriptCompiledCode
;
32 EngineOptions options
= new EngineOptions();
33 eng
= new PythonEngine(options
);
35 System
.IO
.FileStream fs
= new System
.IO
.FileStream("scripting-log.txt", System
.IO
.FileMode
.Create
);
36 eng
.SetStandardOutput(fs
);
37 eng
.SetStandardError(fs
);
39 mod1
= eng
.CreateModule("mr", false);
41 InitializeComponent();
44 private void button2_Click(object sender
, EventArgs e
)
46 output
.Text
= String
.Empty
;
49 private void button1_Click(object sender
, EventArgs e
)
51 StringWriter writer
= new StringWriter();
52 Dictionary
<string,object> locals
= new Dictionary
<string, object>();
53 locals
.Add("output", writer
);
57 CompiledCode functionsCode
= eng
.Compile(functions
.Text
);
58 scriptCompiledCode
= eng
.Compile(script
.Text
);
60 functionsCode
.Execute(mod1
);
61 scriptCompiledCode
.Execute(mod1
, locals
);
65 output
.Text
+= Environment
.NewLine
+ ex
.Message
+
66 Environment
.NewLine
+ Environment
.NewLine
+
68 Environment
.NewLine
+ Environment
.NewLine
;
71 output
.Text
+= writer
.GetStringBuilder().ToString();
72 output
.Text
+= Environment
.NewLine
;
73 output
.Text
+= Environment
.NewLine
;
78 private void button3_Click(object sender
, EventArgs e
)
80 StringWriter writer
= new StringWriter();
81 Dictionary
<string, object> locals
= new Dictionary
<string, object>();
82 locals
.Add("output", writer
);
86 CompiledCode functionsCode
= eng
.Compile(functions
.Text
);
87 functionsCode
.Execute(mod1
);
89 scriptCompiledCode
.Execute(mod1
, locals
);
93 output
.Text
+= Environment
.NewLine
+ ex
.Message
+
94 Environment
.NewLine
+ Environment
.NewLine
+
96 Environment
.NewLine
+ Environment
.NewLine
;
99 output
.Text
+= writer
.GetStringBuilder().ToString();
100 output
.Text
+= Environment
.NewLine
;
101 output
.Text
+= Environment
.NewLine
;