示例#1
0
        public void Load(ConfigNode parent)
        {
            ConfigNode node = parent.FindChildConfigNode("macro");

            if (node == null)
            {
                SetDefault();
            }
            else
            {
                ConfigNode var = node.FindChildConfigNode("variables");
                if (var != null)
                {
                    _environmentVariables = var.InnerHashtable;
                }

                foreach (ConfigNode ch in node.Children)
                {
                    if (ch.Name == "module")
                    {
                        MacroModule m = new MacroModule(_entries.Count);
                        m.Load(ch);
                        _entries.Add(m);
                    }
                }
            }
        }
示例#2
0
        public void ReplaceModule(MacroModule old, MacroModule module)
        {
            int i = _entries.IndexOf(old);

            Debug.Assert(i != -1);
            _entries[i] = module;
        }
示例#3
0
        public ModuleProperty(MacroList p, MacroModule mod, Keys shortcut)
        {
            _parent = p;
            _prevShortCut = shortcut;
            _module = mod==null? new MacroModule(0) : (MacroModule)mod.Clone();
            //
            // Windows �t�H�[�� �f�U�C�i �T�|�[�g�ɕK�v�ł��B
            //
            InitializeComponent();

            this._titleLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._titleLabel");
            this._pathLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._pathLabel");
            this._additionalAssemblyLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._additionalAssemblyLabel");
            this._shortcutLabel.Text = GApp.Strings.GetString("Form.ModuleProperty._shortcutLabel");
            this._debugOption.Text = GApp.Strings.GetString("Form.ModuleProperty._debugOption");
            this._okButton.Text = GApp.Strings.GetString("Common.OK");
            this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
            this.Text = GApp.Strings.GetString("Form.ModuleProperty.Text");

            if(mod!=null) {
                _title.Text = _module.Title;
                _path.Text = _module.Path;
                _additionalAssembly.Text = Concat(_module.AdditionalAssemblies);
                _debugOption.Checked = _module.DebugMode;
                _shortcut.Key = shortcut;
            }
        }
示例#4
0
        public object Clone()
        {
            MacroModule m = new MacroModule(_index);

            m._type  = _type;
            m._path  = _path;
            m._title = _title;
            m._additionalAssemblies = _additionalAssemblies;
            m._debugMode            = _debugMode;
            return(m);
        }
示例#5
0
 public MacroExecutor(MacroModule mod, MethodInfo ep)
 {
     _module = mod;
     _entryPoint = ep;
     if(mod.DebugMode) {
         _traceWindow = new MacroTraceWindow();
         _traceWindow.AdjustTitle(mod);
         _traceWindow.Owner = GApp.Frame;
         _traceWindow.Show();
     }
 }
示例#6
0
 public MacroExecutor(MacroModule mod, MethodInfo ep)
 {
     _module     = mod;
     _entryPoint = ep;
     if (mod.DebugMode)
     {
         _traceWindow = new MacroTraceWindow();
         _traceWindow.AdjustTitle(mod);
         _traceWindow.Owner = GApp.Frame;
         _traceWindow.Show();
     }
 }
示例#7
0
        public static Assembly LoadMacroAssembly(MacroModule mod)
        {
            if (mod.Type == MacroType.Assembly)
            {
                return(Assembly.LoadFrom(mod.Path));
            }
            else if (mod.Type == MacroType.JavaScript)
            {
                ICodeCompiler      compiler = new JScriptCodeProvider().CreateCompiler();
                CompilerParameters param    = new CompilerParameters();
                param.CompilerOptions   += "/debug";
                param.GenerateInMemory   = true;
                param.GenerateExecutable = true;
                //param.ReferencedAssemblies.Add("mscorlib"); //要るの?
                param.ReferencedAssemblies.Add("System.Drawing.dll");
                param.ReferencedAssemblies.Add(GetMyExePath());
                param.ReferencedAssemblies.Add(GetGTerminalPath());
                foreach (string x in mod.AdditionalAssemblies)
                {
                    if (x.Length > 0)
                    {
                        param.ReferencedAssemblies.Add(x);
                    }
                }

                CompilerResults result = compiler.CompileAssemblyFromFile(param, mod.Path);
                if (result.Errors.Count > 0)
                {
                    StringBuilder bld = new StringBuilder();
                    bld.Append(GApp.Strings.GetString("Message.MacroExec.FailedToCompileScript"));
                    foreach (CompilerError err in result.Errors)
                    {
                        bld.Append(String.Format("Line {0} Column {1} : {2}\n", err.Line, err.Column, err.ErrorText));
                    }
                    throw new Exception(bld.ToString());
                }

                return(result.CompiledAssembly);
            }
            else
            {
                throw new Exception("Unsupported macro module type " + mod.Type.ToString() + " is specified.");
            }
        }
示例#8
0
        private void InitSample()
        {
            string      b     = AppDomain.CurrentDomain.BaseDirectory + "macrosample\\";
            MacroModule hello = new MacroModule(0);

            hello.Title = GApp.Strings.GetString("Caption.MacroModule.SampleTitleHelloWorld");
            hello.Path  = b + "helloworld.js";
            GApp.Options.Commands.AddEntry(new Commands.MacroEntry(hello.Title, Keys.None, Keys.None, hello.Index));
            _entries.Add(hello);
            MacroModule telnet = new MacroModule(1);

            telnet.Title = GApp.Strings.GetString("Caption.MacroModule.SampleTitleAutoTelnet");
            telnet.Path  = b + "telnet.js";
            GApp.Options.Commands.AddEntry(new Commands.MacroEntry(telnet.Title, Keys.None, Keys.None, telnet.Index));
            _entries.Add(telnet);
            MacroModule bashrc = new MacroModule(2);

            bashrc.Title = GApp.Strings.GetString("Caption.MacroModule.SampleTitleOpenBashrc");
            bashrc.Path  = b + "bashrc.js";
            GApp.Options.Commands.AddEntry(new Commands.MacroEntry(bashrc.Title, Keys.None, Keys.None, bashrc.Index));
            _entries.Add(bashrc);
        }
示例#9
0
        public void Execute(IWin32Window parent, MacroModule mod)
        {
            if (_runningMacro != null)
            {
                GUtil.Warning(parent, GApp.Strings.GetString("Message.MacroModule.AlreadyRunning"));
                return;
            }

            if (mod.Type == MacroType.Unknown)
            {
                GUtil.Warning(parent, GApp.Strings.GetString("Message.MacroModule.UnknownModuleType"));
                return;
            }
            else
            {
                try {
                    GApp.Frame.Cursor = Cursors.WaitCursor;
                    Assembly   asm = MacroUtil.LoadMacroAssembly(mod);
                    MethodInfo ep  = asm.EntryPoint;
                    if (ep == null)
                    {
                        throw new Exception(GApp.Strings.GetString("Message.MacroModule.NoEntryPoint"));
                    }

                    _runningMacro = new MacroExecutor(mod, ep);
                    IndicateMacroStarted();
                    _runningMacro.AsyncExec();
                }
                catch (Exception ex) {
                    GUtil.Warning(parent, ex.Message);
                }
                finally {
                    GApp.Frame.Cursor = Cursors.Default;
                }
            }
        }
示例#10
0
 private string GetInfoString(MacroModule mod)
 {
     return mod.DebugMode? GApp.Strings.GetString("Caption.MacroList.Trace") : ""; //�Ƃ肠�����̓f�o�b�O���ǂ�������
 }
示例#11
0
 private void InitSample()
 {
     string b = AppDomain.CurrentDomain.BaseDirectory + "macrosample\\";
     MacroModule hello = new MacroModule(0);
     hello.Title = GApp.Strings.GetString("Caption.MacroModule.SampleTitleHelloWorld");
     hello.Path = b + "helloworld.js";
     GApp.Options.Commands.AddEntry(new Commands.MacroEntry(hello.Title, Keys.None, Keys.None, hello.Index));
     _entries.Add(hello);
     MacroModule telnet = new MacroModule(1);
     telnet.Title = GApp.Strings.GetString("Caption.MacroModule.SampleTitleAutoTelnet");
     telnet.Path = b + "telnet.js";
     GApp.Options.Commands.AddEntry(new Commands.MacroEntry(telnet.Title, Keys.None, Keys.None, telnet.Index));
     _entries.Add(telnet);
     MacroModule bashrc = new MacroModule(2);
     bashrc.Title = GApp.Strings.GetString("Caption.MacroModule.SampleTitleOpenBashrc");
     bashrc.Path = b + "bashrc.js";
     GApp.Options.Commands.AddEntry(new Commands.MacroEntry(bashrc.Title, Keys.None, Keys.None, bashrc.Index));
     _entries.Add(bashrc);
 }
示例#12
0
 public object Clone()
 {
     MacroModule m = new MacroModule(_index);
     m._type = _type;
     m._path = _path;
     m._title = _title;
     m._additionalAssemblies = _additionalAssemblies;
     m._debugMode = _debugMode;
     return m;
 }
示例#13
0
 public void RemoveModule(MacroModule mod)
 {
     _entries.Remove(mod);
 }
示例#14
0
 public void ReplaceModule(MacroModule old, MacroModule module)
 {
     int i = _entries.IndexOf(old);
     Debug.Assert(i!=-1);
     _entries[i] = module;
 }
示例#15
0
 public void InsertModule(int n, MacroModule mod)
 {
     _entries.Insert(n, mod);
 }
示例#16
0
        public void Load(ConfigNode parent)
        {
            ConfigNode node = parent.FindChildConfigNode("macro");
            if(node==null)
                SetDefault();
            else {
                ConfigNode var = node.FindChildConfigNode("variables");
                if(var!=null)
                    _environmentVariables = var.InnerHashtable;

                foreach(ConfigNode ch in node.Children) {
                    if(ch.Name=="module") {
                        MacroModule m = new MacroModule(_entries.Count);
                        m.Load(ch);
                        _entries.Add(m);
                    }
                }
            }
        }
示例#17
0
 public void AddModule(MacroModule mod)
 {
     _entries.Add(mod);
 }
示例#18
0
        public void Execute(IWin32Window parent, MacroModule mod)
        {
            if(_runningMacro!=null) {
                GUtil.Warning(parent, GApp.Strings.GetString("Message.MacroModule.AlreadyRunning"));
                return;
            }

            if(mod.Type==MacroType.Unknown) {
                GUtil.Warning(parent, GApp.Strings.GetString("Message.MacroModule.UnknownModuleType"));
                return;
            }
            else {
                try {
                    GApp.Frame.Cursor = Cursors.WaitCursor;
                    Assembly asm = MacroUtil.LoadMacroAssembly(mod);
                    MethodInfo ep = asm.EntryPoint;
                    if(ep==null)
                        throw new Exception(GApp.Strings.GetString("Message.MacroModule.NoEntryPoint"));

                    _runningMacro = new MacroExecutor(mod, ep);
                    IndicateMacroStarted();
                    _runningMacro.AsyncExec();
                }
                catch(Exception ex) {
                    GUtil.Warning(parent, ex.Message);
                }
                finally {
                    GApp.Frame.Cursor = Cursors.Default;
                }
            }
        }
示例#19
0
 public void RemoveModule(MacroModule mod)
 {
     _entries.Remove(mod);
 }
示例#20
0
 public void AdjustTitle(MacroModule mod)
 {
     this.Text = GApp.Strings.GetString("Caption.MacroTrace.Title") + mod.Title;
 }
示例#21
0
 public void InsertModule(int n, MacroModule mod)
 {
     _entries.Insert(n, mod);
 }
示例#22
0
 public void AddModule(MacroModule mod)
 {
     _entries.Add(mod);
 }
示例#23
0
 private void AddListItem(MacroModule mod, Keys shortcut)
 {
     ListViewItem li = new ListViewItem(mod.Title);
     li = _list.Items.Add(li);
     li.SubItems.Add(mod.Path);
     li.SubItems.Add(UILibUtil.KeyString(shortcut & Keys.Modifiers, shortcut & Keys.KeyCode, '+'));
     li.SubItems.Add(GetInfoString(mod));
 }
示例#24
0
 public void AdjustTitle(MacroModule mod)
 {
     this.Text = GApp.Strings.GetString("Caption.MacroTrace.Title") + mod.Title;
 }
示例#25
0
        public static Assembly LoadMacroAssembly(MacroModule mod)
        {
            if(mod.Type==MacroType.Assembly) {
                return Assembly.LoadFrom(mod.Path);
            }
            else if(mod.Type==MacroType.JavaScript) {
                ICodeCompiler compiler = new JScriptCodeProvider().CreateCompiler();
                CompilerParameters param = new CompilerParameters();
                param.CompilerOptions += "/debug";
                param.GenerateInMemory = true;
                param.GenerateExecutable = true;
                //param.ReferencedAssemblies.Add("mscorlib"); //�v��́H
                param.ReferencedAssemblies.Add("System.Drawing.dll");
                param.ReferencedAssemblies.Add(GetMyExePath());
                param.ReferencedAssemblies.Add(GetGTerminalPath());
                foreach(string x in mod.AdditionalAssemblies)
                    if(x.Length>0) param.ReferencedAssemblies.Add(x);

                CompilerResults result = compiler.CompileAssemblyFromFile(param, mod.Path);
                if(result.Errors.Count>0) {
                    StringBuilder bld = new StringBuilder();
                    bld.Append(GApp.Strings.GetString("Message.MacroExec.FailedToCompileScript"));
                    foreach(CompilerError err in result.Errors) {
                        bld.Append(String.Format("Line {0} Column {1} : {2}\n", err.Line, err.Column, err.ErrorText));
                    }
                    throw new Exception(bld.ToString());
                }

                return result.CompiledAssembly;
            }
            else
                throw new Exception("Unsupported macro module type " + mod.Type.ToString() + " is specified.");
        }