かなりダサいスクリプトクラス


http://lsl.way-nifty.com/dogadesc/

上サイトで「動画説明君」という動画学習ソフトを作っていますが、現段階でのスクリプトクラスのソースがテキトーなものです。
C言語ののりで書いています。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using System.Net;

namespace dougakushu.UserClass
{
    public class Script
    {
        public static WMPLib.WindowsMediaPlayer mediaPlayer = new WMPLib.WindowsMediaPlayer();


        private List nodes = new List();

        public void Read(string script)
        {
            string sep = { "\n" };
            string lines = script.Split(sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (string line in lines)
            {
                if (line.StartsWith("//")) continue;
                if (string.IsNullOrEmpty(line.Trim())) continue;
                string sep2 = { ":" };
                //string parts = line.Split(sep2, StringSplitOptions.RemoveEmptyEntries);
                string parts = new string[2];
                parts[0] = line.Substring(0,line.IndexOf(':')).Trim();
                parts[1] = line.Substring(line.IndexOf(':')+1, line.Length - line.IndexOf(':') - 1 ).Trim();

                //前後の空白を削除
                for (int i = 0; i < parts.Length; i++)
                {
                    parts[i] = parts[i].Trim();
                }
                if (parts.Length >= 2)
                {
                    this.nodes.Add(new ScriptNode(parts[0], parts[1]));
                }
                else if (parts.Length == 1)
                {
                    this.nodes.Add(new ScriptNode(parts[0], ""));
                }
            }
        }

        public void Run(frmMain frmmain)
        {
            int currentVideoLineNo = 0;
            int prevVideoLineNo = -1;
            int headSerachVideoLineNo = 0;
            bool isHeadSearch = false;

            //foreach (ScriptNode node in this.nodes)
            for( int i = 0; i < this.nodes.Count; i++ )
            {

                ScriptNode node = this.nodes[i];
                switch (node.nodeid)
                {
                    case NodeID.CLIPBOARD:
                        ClipboardNodeParameter pc = node.param as ClipboardNodeParameter;
                        if (pc != null)
                        {
                            Clipboard.SetText(pc.cliptext);
                        }
                        break;
                    case NodeID.SIZE:
                        SizeNodePraameter ps = node.param as SizeNodePraameter;
                        if (ps != null)
                        {
                            int x = 0;
                            int y = 0;

                            int.TryParse(ps.xsize, out x );
                            int.TryParse(ps.ysize, out y );

                            if( x <= 0 ) x = 500;
                            if( y <= 0 ) y = 300;

                            frmmain.setVideoSize(x, y);
                            for (int j = 0; j < 10; j++)
                            {
                                System.Threading.Thread.Sleep(100);
                                System.Windows.Forms.Application.DoEvents();
                            }
                        }
                        break;
                    case NodeID.PAUSEKEY:
                        //一時停止ショートカットキーをスクリプトでは設定しないようにした。
                        /*
                        PauseKeyNodeParameter pp = node.param as PauseKeyNodeParameter;
                        if (pp != null)
                        {
                            frmmain.setPauseVKeyCode(pp.pausevkey);
                        }
                        break;
                        */
                        break;
                    case NodeID.VIDEO:
                        currentVideoLineNo++;

                        if (( isHeadSearch && ( currentVideoLineNo >= headSerachVideoLineNo ) )
                            || !isHeadSearch)
                        {
                            isHeadSearch = false;

                            VideoNodeParameter pv = node.param as VideoNodeParameter;
                            if (pv != null)
                            {
                                //frmmain.btnPlay_Click(this, new EventArgs());
                                this.isEnd = false;
                                /*
                                frmmain.playlist.Add( new frmMain.playItem(pv.videoid, this.hookOnEnd ));
                                while (isEnd == false)
                                {
                                    System.Windows.Forms.Application.DoEvents();
                                }
                                 */
                                frmmain.btnReady_ClickOuter(pv.videoid);
                                for (int j = 0; j < 10; j++)
                                {
                                    //System.Threading.Thread.Sleep(100);
                                    System.Windows.Forms.Application.DoEvents();
                                }
                                frmmain.btnPlay_Click(this, new EventArgs());
                                for (int j = 0; j < 10; j++)
                                {
                                    //System.Threading.Thread.Sleep(100);
                                    System.Windows.Forms.Application.DoEvents();
                                }
                                frmmain.OnVideoEnd += this.hookOnEnd;
                                
                                this.isEnd = false;
                                this.IsToPrev = false;
                                this.isformClose = false;

                                while (isEnd == false)
                                {
                                    //System.Threading.Thread.Sleep(100);
                                    System.Windows.Forms.Application.DoEvents();
                                }
                                frmmain.OnVideoEnd -= this.hookOnEnd;

                                frmmain.setPlayStateSTOP();

                                if (this.isformClose)
                                {
                                    return;
                                }

                                if (this.IsToPrev)
                                {
                                    headSerachVideoLineNo = currentVideoLineNo - 1;
                                    isHeadSearch = true;
                                    currentVideoLineNo = 0;
                                    i = -1;
                                    continue;
                                }
                            }
                        }
                        break;
                    case NodeID.MP3:
                        MP3NodeParameter p3 = node.param as MP3NodeParameter;
                        if (p3 != null)
                        {

                            /*
                            WebClient wc = new WebClient();

                            wc.DownloadFile(
                                  p3.url,
                                  @"sound.mp3");


                            //再生するファイル名
                            string aliasName = "MediaFile";

                            string fileName = Application.StartupPath + @"\sound.mp3";

                            string cmd;

                             */

                            //再生しているオーディオを停止する
                            mediaPlayer.controls.stop();

                            //オーディオファイルを指定する(自動的に再生される)
                            mediaPlayer.URL = p3.url;
                            //再生する
                            mediaPlayer.controls.play();

                        }
                        break;
                }
            }

            //最後に、再生しているオーディオを停止する
            mediaPlayer.controls.stop();
            
        }

        private bool isEnd = false;
        private bool IsToPrev = false;
        private bool isformClose = false;
        public void hookOnEnd(bool toPrev, bool formClose)
        {
            this.isEnd = true;
            this.IsToPrev = toPrev;
            this.isformClose = formClose;

        }
 
    }

    public enum NodeID
    {
        VIDEO,
        CLIPBOARD,
        SIZE,
        PAUSEKEY,
        MP3,
        EMPTY
    }

    public class ScriptNode
    {
        public NodeID nodeid = NodeID.EMPTY;
        public NodeParameter param = null;

        public ScriptNode(string cmdToken, string parameter)
        {
            switch (cmdToken)
            {
                case "video":
                    this.nodeid = NodeID.VIDEO;
                    this.param = new VideoNodeParameter(parameter);
                    break;
                case "clipboard":
                    this.nodeid = NodeID.CLIPBOARD;
                    this.param = new ClipboardNodeParameter(parameter);
                    break;
                case "size":
                    this.nodeid = NodeID.SIZE;
                    this.param = new SizeNodePraameter(parameter);
                    break;
                case "pausekey":
                    this.nodeid = NodeID.PAUSEKEY;
                    this.param = new PauseKeyNodeParameter(parameter);
                    break;
                case "mp3":
                    this.nodeid = NodeID.MP3;
                    this.param = new MP3NodeParameter(parameter);
                    break;
            }
        }
    }
    public class NodeParameter
    {
    }
    public class VideoNodeParameter : NodeParameter
    {
        public string videoid = "";
        public VideoNodeParameter(string videoid)
        {
            this.videoid = videoid;
        }
    }
    public class SizeNodePraameter : NodeParameter
    {
        public string xsize = "";
        public string ysize = "";
        public SizeNodePraameter(string param)
        {
            string sep = { "," };
            string[] devide = param.Split(sep, StringSplitOptions.RemoveEmptyEntries);
            if (devide.Length >= 2)
            {
                this.xsize = devide[0];
                this.ysize = devide[1];
            }
        }
    }
    public class ClipboardNodeParameter : NodeParameter
    {
        public string cliptext = "";
        public ClipboardNodeParameter(string cliptext)
        {
            this.cliptext = cliptext;
        }
    }
    public class MP3NodeParameter : NodeParameter
    {
        public string url = "";
        public MP3NodeParameter(string url)
        {
            this.url = url;
        }
    }
    public class PauseKeyNodeParameter : NodeParameter
    {
        public int pausevkey = 0;
        public PauseKeyNodeParameter(string  keytext)
        {
            switch (keytext)
            {
                case "ctrl":
                    this.pausevkey = win32api.VK_CONTROL;
                    break;
                case "lctrl":
                    this.pausevkey = win32api.VK_LCONTROL;
                    break;
                case "alt":
                    this.pausevkey = win32api.VK_ALT;
                    break;
                case "cap":
                    this.pausevkey = win32api.VK_CAPITAL;
                    break;
                case "insert":
                    this.pausevkey = win32api.VK_INSERT;
                    break;
            }
        }
    }
}

インターフェースとか使えよ。