コード例 #1
0
ファイル: Form1.cs プロジェクト: LeoLiu1/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;
        }
コード例 #2
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;
        }