Exemplo n.º 1
0
        public ModuleProperty(MacroList p, MacroModule mod) {
            _parent = p;
            //_prevShortCut = shortcut;
            _module = mod == null ? new MacroModule(0, "", "") : (MacroModule)mod.Clone();
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();

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

            _shortcutLabel.Visible = false;
            //_shortcut.Visible = false;

            if (mod != null) {
                _title.Text = _module.Title;
                _path.Text = _module.Path;
                _additionalAssembly.Text = Concat(_module.AdditionalAssemblies);
                _debugOption.Checked = _module.DebugMode;
                //_shortcut.Key = shortcut;
            }
        }
Exemplo n.º 2
0
        internal MacroExecutor RunMacroModule(MacroModule module, ISession sessionToBind, IMacroEventListener listener)
        {
            try {
                Assembly      asm       = MacroUtil.LoadMacroAssembly(module);
                MacroExecutor macroExec = new MacroExecutor(module, asm);

                if (sessionToBind != null)
                {
                    bool bound = _sessionBinder.Bind(macroExec, sessionToBind);
                    if (!bound)
                    {
                        GUtil.Warning(null, Strings.GetString("Message.MacroPlugin.AnotherMacroIsRunningInThisSession"));
                        return(null);
                    }
                }

                if (listener != null)
                {
                    listener.IndicateMacroStarted();
                }
                macroExec.AsyncExec(listener);
                return(macroExec);
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
                return(null);
            }
        }
Exemplo n.º 3
0
        public void ReplaceModule(MacroModule old, MacroModule module)
        {
            int i = _entries.IndexOf(old);

            Debug.Assert(i != -1);
            _entries[i] = module;
        }
Exemplo n.º 4
0
        private void ShowProp(int index)
        {
            MacroManager mm  = MacroPlugin.Instance.MacroManager;
            MacroModule  mod = mm.GetModule(index);

            /*
             *          Keys key = Keys.None;
             *          IDictionaryEnumerator ie = _keyToModule.GetEnumerator();
             *          while(ie.MoveNext()) {
             *                  if(ie.Value==mod) {
             *                          key = (Keys)(ie.Key);
             *                          break;
             *                  }
             *          }
             */
            ModuleProperty dlg = new ModuleProperty(this, mod);

            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                mm.ReplaceModule(mm.GetModule(index), dlg.Module);
                ListViewItem li = _list.Items[index];
                li.Text             = dlg.Module.Title;
                li.SubItems[1].Text = dlg.Module.Path;
                //li.SubItems[2].Text = UILibUtil.KeyString(dlg.ShortCut);
                li.SubItems[2].Text = GetInfoString(dlg.Module);

                AdjustUI();
            }
        }
        public ModuleProperty(MacroList p, MacroModule mod)
        {
            _parent = p;
            //_prevShortCut = shortcut;
            _module = mod == null? new MacroModule(0, "", "") : (MacroModule)mod.Clone();
            //
            // Windows フォーム デザイナ サポートに必要です。
            //
            InitializeComponent();

            StringResource sr = MacroPlugin.Instance.Strings;

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

            _shortcutLabel.Visible = false;
            //_shortcut.Visible = false;

            if (mod != null)
            {
                _title.Text = _module.Title;
                _path.Text  = _module.Path;
                _additionalAssembly.Text = Concat(_module.AdditionalAssemblies);
                _debugOption.Checked     = _module.DebugMode;
                //_shortcut.Key = shortcut;
            }
        }
Exemplo n.º 6
0
 public object Clone() {
     MacroModule m = new MacroModule(_index, _path, _title);
     m._type = _type;
     m._additionalAssemblies = _additionalAssemblies;
     m._debugMode = _debugMode;
     return m;
 }
Exemplo n.º 7
0
 public void RunMacro(string path, ISession session)
 {
     if (path != null && File.Exists(path))
     {
         string      name   = Path.GetFileNameWithoutExtension(path);
         MacroModule module = new MacroModule(0, path, name);
         RunMacroModule(module, session, null);
     }
 }
Exemplo n.º 8
0
        public object Clone()
        {
            MacroModule m = new MacroModule(_index, _path, _title);

            m._type = _type;
            m._additionalAssemblies = _additionalAssemblies;
            m._debugMode            = _debugMode;
            return(m);
        }
Exemplo n.º 9
0
        private void AddListItem(MacroModule mod)
        {
            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));
        }
Exemplo n.º 10
0
 public MacroExecutor(MacroModule mod, Assembly asm)
 {
     _module = mod;
     _assembly = asm;
     _receptionDataPool = new List<ReceptionDataPool>();
     if (mod.DebugMode) {
         ShowTraceWindow();
     }
 }
Exemplo n.º 11
0
        private void OnDeleteButtonClicked(object sender, EventArgs args)
        {
            MacroManager mm  = MacroPlugin.Instance.MacroManager;
            MacroModule  mod = mm.GetModule(_list.SelectedItems[0].Index);

            mm.RemoveModule(mod);
            _list.Items.Remove(_list.SelectedItems[0]);
            //_macroOrderUpdated = true;
            AdjustUI();
        }
Exemplo n.º 12
0
 public MacroExecutor(MacroModule mod, Assembly asm)
 {
     _module            = mod;
     _assembly          = asm;
     _receptionDataPool = new List <ReceptionDataPool>();
     if (mod.DebugMode)
     {
         ShowTraceWindow();
     }
 }
Exemplo n.º 13
0
        private void InitSample()
        {
            StringResource sr = MacroPlugin.Instance.Strings;
            string         b  = MacroPlugin.Instance.PoderosaApplication.HomeDirectory + "Macro\\Sample\\";

            _entries.Clear();

            MacroModule hello = new MacroModule(0, b + "helloworld.js", sr.GetString("Caption.MacroModule.SampleTitleHelloWorld"));

            _entries.Add(hello);

            MacroModule telnet = new MacroModule(1, b + "telnet.js", sr.GetString("Caption.MacroModule.SampleTitleAutoTelnet"));

            _entries.Add(telnet);

            MacroModule bashrc = new MacroModule(2, b + "bashrc.js", sr.GetString("Caption.MacroModule.SampleTitleOpenBashrc"));

            _entries.Add(bashrc);
        }
Exemplo n.º 14
0
        public void Execute(Form parent, MacroModule mod)
        {
            StringResource sr = MacroPlugin.Instance.Strings;

            if (_runningMacro != null)
            {
                GUtil.Warning(parent, sr.GetString("Message.MacroModule.AlreadyRunning"));
                return;
            }

            if (mod.Type == MacroType.Unknown)
            {
                GUtil.Warning(parent, sr.GetString("Message.MacroModule.UnknownModuleType"));
                return;
            }
            else
            {
                _runningMacro = MacroPlugin.Instance.RunMacroModule(mod, null, this);
            }
        }
Exemplo n.º 15
0
        private void OnUpButtonClicked(object sender, EventArgs args)
        {
            int n = _list.SelectedItems[0].Index;

            if (n == 0)
            {
                return;
            }

            MacroManager mm = MacroPlugin.Instance.MacroManager;
            ListViewItem li = _list.Items[n];

            _list.Items.RemoveAt(n);
            _list.Items.Insert(n - 1, li);
            MacroModule mod = mm.GetModule(n);

            mm.RemoveAt(n);
            mm.InsertModule(n - 1, mod);
            //_macroOrderUpdated = true;
        }
Exemplo n.º 16
0
        public void LoadFromPreference()
        {
            IPreferenceFolderArray ma = _rootPreference.FindChildFolderArray(_moduleDefinitionTemplate.Id);

            if (ma == null || ma.Folders.Length == 0)
            {
                InitSample();
            }
            else
            {
                _entries.Clear();
                foreach (IPreferenceFolder f in ma.Folders)
                {
                    MacroModule m = new MacroModule(_entries.Count,
                                                    ma.ConvertItem(f, _pathPreferenceTemplate).AsString().Value,
                                                    ma.ConvertItem(f, _titlePreferenceTemplate).AsString().Value);
                    m.AdditionalAssemblies = ma.ConvertItem(f, _additionalAssembliesPreferenceTemplate).AsString().Value.Split(';');
                    m.DebugMode            = ma.ConvertItem(f, _tracePreferenceTemplate).AsBool().Value;
                    _entries.Add(m);
                }
            }

            _touchedPreference = true;
        }
Exemplo n.º 17
0
 private string GetInfoString(MacroModule mod)
 {
     return(mod.DebugMode? MacroPlugin.Instance.Strings.GetString("Caption.MacroList.Trace") : "");            //とりあえずはデバッグかどうかだけ
 }
Exemplo n.º 18
0
 public void InsertModule(int n, MacroModule mod)
 {
     _entries.Insert(n, mod);
 }
Exemplo n.º 19
0
 public void InsertModule(int n, MacroModule mod)
 {
     _entries.Insert(n, mod);
 }
Exemplo n.º 20
0
 public void AddModule(MacroModule mod)
 {
     _entries.Add(mod);
 }
Exemplo n.º 21
0
 public void RemoveModule(MacroModule mod)
 {
     _entries.Remove(mod);
 }
Exemplo n.º 22
0
 public void RunMacro(string path, ISession session) {
     if (path != null && File.Exists(path)) {
         string name = Path.GetFileNameWithoutExtension(path);
         MacroModule module = new MacroModule(0, path, name);
         RunMacroModule(module, session, null);
     }
 }
Exemplo n.º 23
0
        internal MacroExecutor RunMacroModule(MacroModule module, ISession sessionToBind, IMacroEventListener listener) {
            try {
                Assembly asm = MacroUtil.LoadMacroAssembly(module);
                MacroExecutor macroExec = new MacroExecutor(module, asm);

                if (sessionToBind != null) {
                    bool bound = _sessionBinder.Bind(macroExec, sessionToBind);
                    if (!bound) {
                        GUtil.Warning(null, Strings.GetString("Message.MacroPlugin.AnotherMacroIsRunningInThisSession"));
                        return null;
                    }
                }

                if (listener != null)
                    listener.IndicateMacroStarted();
                macroExec.AsyncExec(listener);
                return macroExec;
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
                return null;
            }
        }
Exemplo n.º 24
0
 private string GetInfoString(MacroModule mod)
 {
     return mod.DebugMode ? MacroPlugin.Instance.Strings.GetString("Caption.MacroList.Trace") : ""; //�Ƃ肠�����̓f�o�b�O���ǂ�������
 }
Exemplo n.º 25
0
 public MacroExecCommand(MacroModule module) {
     _module = module;
 }
Exemplo n.º 26
0
        public void LoadFromPreference()
        {
            IPreferenceFolderArray ma = _rootPreference.FindChildFolderArray(_moduleDefinitionTemplate.Id);
            if (ma == null || ma.Folders.Length == 0)
                InitSample();
            else {
                _entries.Clear();
                foreach (IPreferenceFolder f in ma.Folders) {
                    MacroModule m = new MacroModule(_entries.Count,
                        ma.ConvertItem(f, _pathPreferenceTemplate).AsString().Value,
                        ma.ConvertItem(f, _titlePreferenceTemplate).AsString().Value);
                    m.AdditionalAssemblies = ma.ConvertItem(f, _additionalAssembliesPreferenceTemplate).AsString().Value.Split(';');
                    m.DebugMode = ma.ConvertItem(f, _tracePreferenceTemplate).AsBool().Value;
                    _entries.Add(m);
                }
            }

            _touchedPreference = true;
        }
Exemplo n.º 27
0
 private void AddListItem(MacroModule mod)
 {
     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));
 }
Exemplo n.º 28
0
 private string GetInfoString(MacroModule mod)
 {
     return mod.DebugMode ? MacroPlugin.Instance.Strings.GetString("Caption.MacroList.Trace") : ""; //とりあえずはデバッグかどうかだけ
 }
Exemplo n.º 29
0
 public void RemoveModule(MacroModule mod)
 {
     _entries.Remove(mod);
 }
Exemplo n.º 30
0
 public void ReplaceModule(MacroModule old, MacroModule module)
 {
     int i = _entries.IndexOf(old);
     Debug.Assert(i != -1);
     _entries[i] = module;
 }
Exemplo n.º 31
0
 public void AddModule(MacroModule mod)
 {
     _entries.Add(mod);
 }
Exemplo n.º 32
0
 public void AdjustTitle(MacroModule mod)
 {
     this.Text = MacroPlugin.Instance.Strings.GetString("Caption.MacroTrace.Title") + mod.Title;
 }
Exemplo n.º 33
0
        public void Execute(Form parent, MacroModule mod)
        {
            StringResource sr = MacroPlugin.Instance.Strings;
            if (_runningMacro != null) {
                GUtil.Warning(parent, sr.GetString("Message.MacroModule.AlreadyRunning"));
                return;
            }

            if (mod.Type == MacroType.Unknown) {
                GUtil.Warning(parent, sr.GetString("Message.MacroModule.UnknownModuleType"));
                return;
            }
            else {
                _runningMacro = MacroPlugin.Instance.RunMacroModule(mod, null, this);
            }
        }
Exemplo n.º 34
0
        public static Assembly LoadMacroAssembly(MacroModule mod)
        {
            if (mod.Type == MacroType.Assembly) {
                return Assembly.LoadFrom(mod.Path);
            }
            else if (mod.Type == MacroType.JavaScript) {
                JScriptCodeProvider compiler = new JScriptCodeProvider();
                CompilerParameters param = new CompilerParameters();
                param.IncludeDebugInformation = true;
                param.GenerateInMemory = false; //これがプラグインをロードできるかどうかの決め手になった。周辺をすべて理解したわけではないが、とりあえずこれでよしとする。深入りしている時間はあまりないし
                param.GenerateExecutable = true;

                StringCollection sc = param.ReferencedAssemblies;

                bool[] assyAdded = new bool[9];
                foreach (Assembly assy in AppDomain.CurrentDomain.GetAssemblies()) {
                    try {
                        string assyFilePath = new Uri(assy.CodeBase).LocalPath;
                        string assyFileName = Path.GetFileName(assyFilePath).ToLower(CultureInfo.InvariantCulture);
                        switch (assyFileName) {
                            case "system.drawing.dll":
                                assyAdded[0] = true;
                                break;
                            case "system.windows.forms.dll":
                                assyAdded[1] = true;
                                break;
                            case "poderosa.plugin.dll":
                                assyAdded[2] = true;
                                break;
                            case "poderosa.core.dll":
                                assyAdded[3] = true;
                                break;
                            case "granados.dll":
                                assyAdded[4] = true;
                                break;
                            case "poderosa.protocols.dll":
                                assyAdded[5] = true;
                                break;
                            case "poderosa.terminalemulator.dll":
                                assyAdded[6] = true;
                                break;
                            case "poderosa.terminalsession.dll":
                                assyAdded[7] = true;
                                break;
                            case "poderosa.macro.dll":
                                assyAdded[8] = true;
                                break;
                            case "poderosa.monolithic.exe":
                                // FIXME: it is better to use the name of the entry assembly.
                                //        but how can we know the entry assembly is the monolithic type ?
                                assyAdded[2] =
                                assyAdded[3] =
                                assyAdded[4] =
                                assyAdded[5] =
                                assyAdded[6] =
                                assyAdded[7] =
                                assyAdded[8] = true;
                                break;
                            default:
                                continue;
                        }
                        Debug.WriteLine("(LoadMacroAssembly) add to ReferencedAssemblies: " + assyFilePath);
                        sc.Add(assyFilePath);
                    }
                    catch (Exception) {
                    }
                }

                foreach (bool flag in assyAdded) {
                    if (!flag) {
                        throw new Exception(MacroPlugin.Instance.Strings.GetString("Message.MacroExec.MissingAssemblies"));
                    }
                }

                foreach (string x in mod.AdditionalAssemblies)
                    if (x.Length > 0)
                        sc.Add(x);

                CompilerResults result = compiler.CompileAssemblyFromFile(param, mod.Path);
                if (result.Errors.Count > 0) {
                    StringBuilder bld = new StringBuilder();
                    bld.Append(MacroPlugin.Instance.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());
                }

                Debug.WriteLineIf(DebugOpt.Macro, "Compiled:" + result.PathToAssembly + " FullName:" + result.CompiledAssembly.FullName);
                //AppDomain.CurrentDomain.Load(result.CompiledAssembly.FullName, result.Evidence);

                return result.CompiledAssembly;
            }
            else
                throw new Exception("Unsupported macro module type " + mod.Type.ToString() + " is specified.");
        }
Exemplo n.º 35
0
        public static Assembly LoadMacroAssembly(MacroModule mod)
        {
            if (mod.Type == MacroType.Assembly)
            {
                return(Assembly.LoadFrom(mod.Path));
            }
            else if (mod.Type == MacroType.JavaScript)
            {
                JScriptCodeProvider compiler = new JScriptCodeProvider();
                CompilerParameters  param    = new CompilerParameters();
                param.IncludeDebugInformation = true;
                param.GenerateInMemory        = false; //これがプラグインをロードできるかどうかの決め手になった。周辺をすべて理解したわけではないが、とりあえずこれでよしとする。深入りしている時間はあまりないし
                param.GenerateExecutable      = true;

                StringCollection sc = param.ReferencedAssemblies;

                bool[] assyAdded = new bool[9];
                foreach (Assembly assy in AppDomain.CurrentDomain.GetAssemblies())
                {
                    try {
                        string assyFilePath = new Uri(assy.CodeBase).LocalPath;
                        string assyFileName = Path.GetFileName(assyFilePath).ToLower(CultureInfo.InvariantCulture);
                        switch (assyFileName)
                        {
                        case "system.drawing.dll":
                            assyAdded[0] = true;
                            break;

                        case "system.windows.forms.dll":
                            assyAdded[1] = true;
                            break;

                        case "poderosa.plugin.dll":
                            assyAdded[2] = true;
                            break;

                        case "poderosa.core.dll":
                            assyAdded[3] = true;
                            break;

                        case "granados.dll":
                            assyAdded[4] = true;
                            break;

                        case "poderosa.protocols.dll":
                            assyAdded[5] = true;
                            break;

                        case "poderosa.terminalemulator.dll":
                            assyAdded[6] = true;
                            break;

                        case "poderosa.terminalsession.dll":
                            assyAdded[7] = true;
                            break;

                        case "poderosa.macro.dll":
                            assyAdded[8] = true;
                            break;

                        case "poderosa.monolithic.exe":
                            // FIXME: it is better to use the name of the entry assembly.
                            //        but how can we know the entry assembly is the monolithic type ?
                            assyAdded[2]                         =
                                assyAdded[3]                     =
                                    assyAdded[4]                 =
                                        assyAdded[5]             =
                                            assyAdded[6]         =
                                                assyAdded[7]     =
                                                    assyAdded[8] = true;
                            break;

                        default:
                            continue;
                        }
                        Debug.WriteLine("(LoadMacroAssembly) add to ReferencedAssemblies: " + assyFilePath);
                        sc.Add(assyFilePath);
                    }
                    catch (Exception) {
                    }
                }

                foreach (bool flag in assyAdded)
                {
                    if (!flag)
                    {
                        throw new Exception(MacroPlugin.Instance.Strings.GetString("Message.MacroExec.MissingAssemblies"));
                    }
                }

                foreach (string x in mod.AdditionalAssemblies)
                {
                    if (x.Length > 0)
                    {
                        sc.Add(x);
                    }
                }

                CompilerResults result = compiler.CompileAssemblyFromFile(param, mod.Path);
                if (result.Errors.Count > 0)
                {
                    StringBuilder bld = new StringBuilder();
                    bld.Append(MacroPlugin.Instance.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());
                }

                Debug.WriteLineIf(DebugOpt.Macro, "Compiled:" + result.PathToAssembly + " FullName:" + result.CompiledAssembly.FullName);
                //AppDomain.CurrentDomain.Load(result.CompiledAssembly.FullName, result.Evidence);

                return(result.CompiledAssembly);
            }
            else
            {
                throw new Exception("Unsupported macro module type " + mod.Type.ToString() + " is specified.");
            }
        }
Exemplo n.º 36
0
        private void InitSample()
        {
            StringResource sr = MacroPlugin.Instance.Strings;
            string b = MacroPlugin.Instance.PoderosaApplication.HomeDirectory + "Macro\\Sample\\";

            _entries.Clear();

            MacroModule hello = new MacroModule(0, b + "helloworld.js", sr.GetString("Caption.MacroModule.SampleTitleHelloWorld"));
            _entries.Add(hello);

            MacroModule telnet = new MacroModule(1, b + "telnet.js", sr.GetString("Caption.MacroModule.SampleTitleAutoTelnet"));
            _entries.Add(telnet);

            MacroModule bashrc = new MacroModule(2, b + "bashrc.js", sr.GetString("Caption.MacroModule.SampleTitleOpenBashrc"));
            _entries.Add(bashrc);
        }
Exemplo n.º 37
0
 public MacroExecCommand(MacroModule module)
 {
     _module = module;
 }
Exemplo n.º 38
0
 public void AdjustTitle(MacroModule mod)
 {
     this.Text = MacroPlugin.Instance.Strings.GetString("Caption.MacroTrace.Title") + mod.Title;
 }