コード例 #1
0
 public MainWindow()
 {
     InitializeComponent();
     TheIncident = new Incident();
     foreach (string script in scripts_)
         listBox1.Items.Add(script);
     listBox1.SelectedIndex = 0;
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: WinWrap/WinWrapExamples
 public Form1()
 {
     InitializeComponent();
     TheIncident = new Incident();
     foreach (string script in Scripts)
         listBoxScripts.Items.Add(script);
     listBoxScripts.SelectedIndex = 0;
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: WinWrap/WinWrapExamples
        private void buttonRunScript_Click(object sender, EventArgs e)
        {
            TheIncident = new Incident();
            using (var basicNoUIObj = new WinWrap.Basic.BasicNoUIObj())
            {
                basicNoUIObj.Begin += basicNoUIObj_Begin;
                basicNoUIObj.DoEvents += basicNoUIObj_DoEvents;
                basicNoUIObj.ErrorAlert += basicNoUIObj_ErrorAlert;
                basicNoUIObj.Pause_ += basicNoUIObj_Pause_;
                basicNoUIObj.Secret = new System.Guid("00000000-0000-0000-0000-000000000000");
                basicNoUIObj.Initialize();
                /// Extend WinWrap Basic scripts with Examples.Extensions assembly
                /// Add "Imports Examples.Extensions" to all WinWrap Basic scripts
                /// Add "Imports Examples.Extensions.ScriptingLanguage" all WinWrap Basic scripts
                basicNoUIObj.AddScriptableObjectModel(typeof(ScriptingLanguage));

                basicNoUIObj.Sandboxed = true;
                try
                {
                    if (!basicNoUIObj.LoadModule(ScriptPath("Globals.bas")))
                        throw basicNoUIObj.Error.Exception;

                    using (var module = basicNoUIObj.ModuleInstance(ScriptPath(Script), false))
                    {
                        if (module == null)
                            throw basicNoUIObj.Error.Exception;

                        // Execute script code via an event
                        ScriptingLanguage.TheIncident.Start(this.Text);
                    }
                }
                catch (Exception ex)
                {
                    basicNoUIObj.ReportError(ex);
                }
            }

            TheIncident = null;
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: WinWrap/WinWrapExamples
        private void ExecuteWinWrapBasic()
        {
            TheIncident = new Incident();
            using (var basicNoUIObj = new WinWrap.Basic.BasicNoUIObj())
            {
                basicNoUIObj.Begin += basicNoUIObj_Begin;
                basicNoUIObj.DoEvents += basicNoUIObj_DoEvents;
                basicNoUIObj.ErrorAlert += basicNoUIObj_ErrorAlert;
                basicNoUIObj.Pause_ += basicNoUIObj_Pause_;
                basicNoUIObj.Secret = new System.Guid("00000000-0000-0000-0000-000000000000");
                basicNoUIObj.Initialize();
                // Extend WinWrap Basic scripts with Examples.Extensions assembly
                // Add "Imports Examples.Extensions" to all WinWrap Basic scripts
                // Add "Imports Examples.Extensions.ScriptingLanguage" all WinWrap Basic scripts
                basicNoUIObj.AddScriptableObjectModel(typeof(ScriptingLanguage));

                try
                {
                    if (!basicNoUIObj.LoadModule(ScriptPath("Globals.bas")))
                        throw basicNoUIObj.Error.Exception;

                    using (var module = basicNoUIObj.ModuleInstance(ScriptPath(Script), false))
                    {
                        if (module == null) // script parsing error
                            throw basicNoUIObj.Error.Exception;

                        using (var instance = basicNoUIObj.CreateInstance(ScriptPath(Script) + "<IncidentAction"))
                        {
                            // Execute script code via an interface
                            IIncidentAction action = instance.Cast<IIncidentAction>();
                            TheIncident.Start(action, this.Text);
                        }
                    }
                }
                catch (WinWrap.Basic.TerminatedException)
                {
                    // script execution terminated, ignore error
                }
                catch (Exception ex)
                {
                    // script caused an exception
                    basicNoUIObj.ReportError(ex);
                }
            }
            TheIncident = null;
        }
コード例 #5
0
        private void WinWrapExecute()
        {
            TheIncident = new Incident();
            using (var basicNoUIObj = new WinWrap.Basic.BasicNoUIObj())
            {
                basicNoUIObj.Begin += basicNoUIObj_Begin;
                basicNoUIObj.DoEvents += basicNoUIObj_DoEvents;
                basicNoUIObj.ErrorAlert += basicNoUIObj_ErrorAlert;
                basicNoUIObj.Pause_ += basicNoUIObj_Pause_;
                basicNoUIObj.Secret = new Guid(GetPatternString("Guid[(]\"(.*)\"[)]"));
                basicNoUIObj.Initialize();
                basicNoUIObj.AddScriptableObjectModel(typeof(ScriptingLanguage));

                try
                {
                    if (!basicNoUIObj.LoadModule(ScriptPath("Globals.bas")))
                        throw basicNoUIObj.Error.Exception;

                    using (var module = basicNoUIObj.ModuleInstance(ScriptPath(Script), false))
                    {
                        if (module == null)
                            throw basicNoUIObj.Error.Exception;

                        // Execute script code via an event
                        ScriptingLanguage.TheIncident.Start("Default.aspx");
                    }
                }
                catch (Exception ex)
                {
                    basicNoUIObj.ReportError(ex);
                }
            }
            TheIncident = null;
        }
コード例 #6
0
        private void WinWrapExecute(bool debug)
        {
            TheIncident = new Incident();
            using (var basicNoUIObj = new WinWrap.Basic.BasicNoUIObj())
            {
                basicNoUIObj.Begin += basicNoUIObj_Begin;
                basicNoUIObj.DoEvents += basicNoUIObj_DoEvents;
                basicNoUIObj.End += basicNoUIObj_End;
                basicNoUIObj.ErrorAlert += basicNoUIObj_ErrorAlert;
                basicNoUIObj.Pause_ += basicNoUIObj_Pause_;
                basicNoUIObj.Resume += basicNoUIObj_Resume;
                basicNoUIObj.Synchronizing += basicNoUIObj_Synchronizing;
                basicNoUIObj.Secret = new Guid(AzureOnlyStrings.GetNamedString("Guid", "00000000-0000-0000-0000-000000000000"));
                basicNoUIObj.Initialize();
                basicNoUIObj.AddScriptableObjectModel(typeof(ScriptingLanguage));

                if (debug)
                {
                    // prepare for debugging
                    basicNoUIObj.Synchronized = true;
                    Log("Debugging...");
                }

                try
                {
                    if (!basicNoUIObj.LoadModule(ScriptPath("Globals.bas")))
                        throw basicNoUIObj.Error.Exception;

                    using (var module = basicNoUIObj.ModuleInstance(ScriptPath(Script), false))
                    {
                        if (module == null)
                            throw basicNoUIObj.Error.Exception;

                        if (debug)
                        {
                            // step into the script event handler
                            module.StepInto = true;
                            timelimit_ = DateTime.Now + new TimeSpan(0, 0, 30); // timeout in 30 seconds
                        }

                        // Execute script code via an event
                        ScriptingLanguage.TheIncident.Start("Default.aspx");
                    }
                }
                catch (Exception ex)
                {
                    if (debug)
                    {
                        // report error and allow remote to catch up
                        basicNoUIObj.ReportError(ex);
                        basicNoUIObj.Wait(3);
                    }

                    basicNoUIObj.ReportError(ex);
                }

                if (debug)
                {
                    basicNoUIObj.Wait(3);
                    Log("Debugging complete.");
                }
            }
            TheIncident = null;
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: WinWrap/WinWrapExamples
        private void buttonRunScript_Click(object sender, EventArgs e)
        {
            TheIncident = new Incident();

            InstanceAndTimestamp mt = new InstanceAndTimestamp();
            string path = ScriptPath(Script);
            DateTime timestamp = File.GetLastWriteTimeUtc(path);
            if (mts.TryGetValue(path, out mt) && mt.timestamp != timestamp)
            {
                // file has changed, dump instance from cache
                mt.Dispose();
                mts.Remove(path);
                mt = new InstanceAndTimestamp();
            }

            try
            {
                if (mt.module == null)
                {
                    // module has not been parsed
                    mt.module = basicNoUIObj.ModuleInstance(path, false);
                    if (mt.module == null)
                    {
                        // script parsing error
                        LogError(basicNoUIObj.Error);
                    }
                    else
                    {
                        // create an instance
                        mt.instance = basicNoUIObj.CreateInstance(path + "<IncidentAction");
                        // cache the instance with a timestamp
                        mt.timestamp = File.GetLastWriteTimeUtc(path);
                        mts.Add(path, mt);
                    }
                }

                if (mt.instance != null)
                {
                    // Execute script code via an interface
                    DateTime tstart2 = DateTime.Now;
                    IIncidentAction action = mt.instance.Cast<IIncidentAction>();
                    ScriptingLanguage.TheIncident.Start(action, "Form1");
                    TimeSpan ts2 = DateTime.Now - tstart2;
                    Debug.Print(ts2.ToString());
                }
            }
            catch (WinWrap.Basic.TerminatedException)
            {
                // script execution terminated, ignore error
            }
            catch (Exception ex)
            {
                // script caused an exception
                basicNoUIObj.ReportError(ex);
            }

            if (mt.instance == null && mt.module != null)
            {
                // release module
                mt.Dispose();
            }

            TheIncident = null;
        }