[Owasp-o2-platform] Execute browser scripts?

dinis cruz dinis.cruz at owasp.org
Fri Jan 13 03:32:45 UTC 2012


Hi Christopher,

Don't worry, that is quite a common problem/error when starting to write O2
scripts :)

What happens is that when you use one of the O2 Script environments (for
example the ones you get when selecting the 'O2 Script' , 'IE Script' or
'Graph Script' from the main O2 GUI) you get a GUI that has a Windows Form
Panel at the top and a script editor at the bottom, for example something
like this:

[image: tmp8753-tmp.jpeg?w=486&h=334]

99% of the error 'The name 'panel' does not exist in the current
context::' cases are
caused by trying to run DIRECTLY an script with a reference to this 'panel'
variable (ie clicking on an *.h2 script directly from windows explorer vs
running it from inside the 'O2 Script' environment). This doesn't work
because when the script is executed outside of an 'O2 Script' environment,
that Windows Form Panel is not there :)

The solution is very easy. What you need to do is to create/use a Windows
form Popup to contain your panel.

For example, instead of doing this

var treeView = panel.clear().add_TreeView(); If you do this instead:

var topPanel = panel.clear().add_Panel(); var treeView
topPanel.add_TreeView()

You can easily remove the dependency to the 'panel' variable by
(eventually) replacing the first line with:

//var topPanel = panel.clear().add_Panel();   var topPanel = "My Windows
Form popup".popupWindow(1000,400); var treeView = topPanel.add_TreeView()

The key difference between these two scripts is that the first will open
the treeview in the top panel of the 'O2 Scripts' environment and the last
will open it a new window (I use the 'O2 Scripts' mode while developing the
script and the popup mode when publishing it)

Here are a number of blog posts where you can see this in action:

   -
   http://o2platform.wordpress.com/2011/12/07/quickly-testing-regexes-and-util-text-regex-using-fuzzdb-h2-o2-script/
   - note the change between the first last of the last 2 scripts
   -
   http://o2platform.wordpress.com/2011/07/28/o2-scripting-solving-the-missing-references-compilation-problem-using-fvdl-as-an-example/-
this script shows a common workflow that I have (where I start with
the
   'O2 Script' environment and end up with a stand alone tool (search for
   'popupWindow' to see the exact moment the transition happened))
   - http://o2platform.wordpress.com/?s=popupWindow  - for lots more code
   samples using popup Window Forms

Finally, if you want to see what is happening under the hood, when in the
'O2 Script' environment, right-click on the editor and select the context
menu item: 'current source code' - > 'show/hide generated code' (maximize
the window to see it properly)

In there you will see that the code you write in the 'O2 Script' editor:

//var topPanel = O2Gui.open<Panel>("{name}",700,400);
var topPanel = panel.*clear*().*add_Panel*();
var textBox = topPanel.*add_TextBox*(*true*);
textBox.*set_Text*("hello world - AAAAAA");
is actually changed into this (which is what gets compiled):

*using *O2.XRules.Database.Utils.O2;
*using *O2.XRules.Database.Utils;
*using *O2.XRules.Database.APIs;
*using *O2.External.SharpDevelop.Ascx;
*using *O2.External.SharpDevelop.ExtensionMethods;
*using *O2.DotNetWrappers.Network;
*using *O2.DotNetWrappers.DotNet;
*using *O2.DotNetWrappers.Windows;
*using *O2.DotNetWrappers.ExtensionMethods;
*using *O2.Views.ASCX.classes.MainGUI;
*using *O2.Views.ASCX.CoreControls;
*using *O2.Views.ASCX.ExtensionMethods;
*using *O2.Kernel.ExtensionMethods;
*using *O2.Kernel;
*using *O2.Interfaces;
*using *System.Linq;
*using *System.Xml.Linq;
*using *System.Xml;
*using *System.Collections.Generic;
*using *System.Windows.Forms;
*using *System.Drawing;
*using *System;

*public *class DynamicType
{
   //var topPanel = O2Gui.open<Panel>("{name}",700,400);


*   public *void *dynamicMethod*(object returnData, *System.Windows.Forms.Panel
panel*)
   {
      var topPanel = panel.*clear*().*add_Panel*();
      var textBox = topPanel.*add_TextBox*(*true*);
      textBox.*set_Text*("hello world - AAAAAA);
  }
}
Note the extra parameter on the dynamicMethod function called 'panel' (in
red). THAT is the cause of your problem since in you case that parameter is
not there when you run the *.h2 script directly.

Does this make sense?

Let me know if it works

Dinis Cruz

Blog: http://diniscruz.blogspot.com
Twitter: http://twitter.com/DinisCruz
Web: http://www.owasp.org/index.php/O2


On 12 January 2012 22:32, Christopher Canova <chris.canova at avanade.com>wrote:

>  I’m trying to execute a browser test script from a h2 file I’ve written.
> The problem occurs when I load the O2 Dev Env or double click the script,
> it complains about the panel object. I assume that I’m not operating in the
> correct context and my assemblies aren’t lining up. Is there a workaround?
> ****
>
> ** **
>
> cc****
>
> ** **
>
> [2:28:24 PM] ERROR: Compilation failed****
>
> [2:28:24 PM] ERROR: [CSharp_FastCompiler] Compilation Error:
> 32::4::CS0103::The name 'panel' does not exist in the current
> context::c:\Users\chris.canova\AppData\Local\Temp\31w-0735.0.cs****
>
> [2:28:24 PM] ERROR: [CSharp_FastCompiler] Compilation Error:
> 31::9::CS0103::The name 'panel' does not exist in the current
> context::c:\Users\chris.canova\AppData\Local\Temp\31w-0735.0.cs****
>
> [2:28:24 PM] ERROR: [CSharp_FastCompiler] Compilation Error:
> 29::12::CS0103::The name 'panel' does not exist in the current
> context::c:\Users\chris.canova\AppData\Local\Temp\31w-0735.0.cs****
>
> [2:28:24 PM] INFO: Compiling Source Code (Size: 2073)****
>
> _______________________________________________
> Owasp-o2-platform mailing list
> Owasp-o2-platform at lists.owasp.org
> https://lists.owasp.org/mailman/listinfo/owasp-o2-platform
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.owasp.org/pipermail/owasp-o2-platform/attachments/20120113/168caac3/attachment-0001.html>


More information about the Owasp-o2-platform mailing list