private void Save() { if (lbMethodName.SelectedItem != null) { if (Valide(false) == false) { return; } ItemBind ib = lbMethodName.SelectedItem as ItemBind; ib.Name = tbName.Text; ib.Value = rtbContext.Text; BehindCodeItem bci = ib.Tag as BehindCodeItem; bci.FuncName = tbName.Text; bci.FuncContext = rtbContext.Text; bci.ThridDBAlias = cbxDBAlias.Text; bci.VerNo = bci.VerNo + 1; bci.IsBGCompile = chkBGCompile.Checked; txtVer.Text = Convert.ToString(bci.VerNo); } _codeDesign.BehindCodes.Clear(); foreach (ItemBind ib in lbMethodName.Items) { BehindCodeItem bci = (ib.Tag as BehindCodeItem).Clone(); _codeDesign.BehindCodes.Add(bci); } _isOk = true; }
private void tsbUpdate_Click(object sender, EventArgs e) { try { if (lbMethodName.SelectedItem == null) { MessageBox.Show("尚未选择需要更新的方法。", "提示"); return; } if (Valide(false) == false) { return; } ItemBind ib = lbMethodName.SelectedItem as ItemBind; ib.Name = tbName.Text; ib.Value = rtbContext.Text; BehindCodeItem bci = ib.Tag as BehindCodeItem; bci.FuncName = tbName.Text; bci.FuncContext = rtbContext.Text; bci.ThridDBAlias = cbxDBAlias.Text; bci.VerNo = bci.VerNo + 1; bci.IsBGCompile = chkBGCompile.Checked; txtVer.Text = Convert.ToString(bci.VerNo); } catch (Exception ex) { MsgBox.ShowException(ex, this); } }
private void tsbDebug_Click(object sender, EventArgs e) { try { IBizDataItems bizDatas = null; Runner run = new Runner(); run.Init("DEBUG", "0", null, null, null, null, null, null); BehindCodeItem bci = new BehindCodeItem(); bci.FuncName = tbName.Text; bci.FuncContext = rtbContext.Text; bci.ThridDBAlias = cbxDBAlias.Text; bci.VerNo = string.IsNullOrEmpty(txtVer.Text) ? 0 : Convert.ToInt32(txtVer.Text); bci.IsBGCompile = false; run.Run(bci, "", null, sender, e, "验证", null, null, out bizDatas, false); MessageBox.Show("验证成功。", "提示"); } catch (Exception ex) { MsgBox.ShowException(ex, this); } }
private void lbMethodName_SelectedIndexChanged(object sender, EventArgs e) { try { rtbContext.Text = ""; if (lbMethodName.SelectedItem == null) { return; } ItemBind ib = lbMethodName.SelectedItem as ItemBind; BehindCodeItem bci = ib.Tag as BehindCodeItem; tbName.Text = bci.FuncName; rtbContext.Text = bci.FuncContext; cbxDBAlias.Text = bci.ThridDBAlias; txtVer.Text = Convert.ToString(bci.VerNo); chkBGCompile.Checked = bci.IsBGCompile; } catch (Exception ex) { MsgBox.ShowException(ex); } }
private void tsbNew_Click(object sender, EventArgs e) { try { if (Valide(true) == false) { return; } ItemBind ib = new ItemBind(); ib.Name = tbName.Text; ib.Value = rtbContext.Text; BehindCodeItem bci = new BehindCodeItem(); bci.FuncName = tbName.Text; bci.FuncContext = rtbContext.Text; bci.ThridDBAlias = cbxDBAlias.Text; bci.VerNo = 1; bci.IsBGCompile = chkBGCompile.Checked; ib.Tag = bci; int newindex = lbMethodName.Items.Add(ib); lbMethodName.SelectedIndex = newindex; } catch (Exception ex) { MsgBox.ShowException(ex, this); } }
public bool Run(BehindCodeItem compileCode, string callModuleName, ISysDesign callModule, object sender, object eventArgs, string actName, string actTag, IBizDataItems sourceBizDatas, out IBizDataItems processBizDatas, bool isBuffer = true) { processBizDatas = null; if (_compilerObj == null) { _compilerObj = new Dictionary <string, IRunner>(); } if (_isAllowDebug) { _compilerObj.Remove(compileCode.FuncName); } IRunner runner = null; if (_compilerObj.ContainsKey(compileCode.FuncName)) { runner = _compilerObj[compileCode.FuncName]; } else { runner = CompilerCode(compileCode); if (isBuffer && _isAllowDebug == false) { //缓存编译对象 //调试状态不缓存编译对象 _compilerObj.Add(compileCode.FuncName, runner); } } if (runner != null) { IDBQuery thridDb = null; if (string.IsNullOrEmpty(compileCode.ThridDBAlias) == false) { string strErr = ""; thridDb = SqlHelper.GetThridDBHelper(compileCode.ThridDBAlias, _dbHelper, ref strErr); if (thridDb == null) { MessageBox.Show("动态方法 [" + compileCode.FuncName + "] 对应的数据源 [" + compileCode.ThridDBAlias + "] 链接对象创建失败," + strErr, "提示"); return(false); } } runner.Init(_winRelateModules, _dbHelper, thridDb, _userData, _stationInfo, _dataTransCenter, _owiner); return(runner.Run(callModuleName, callModule, sender, eventArgs, actName, actTag, sourceBizDatas, out processBizDatas)); } return(false); }
public BehindCodeItem Clone() { BehindCodeItem result = new BehindCodeItem(); result.FuncName = FuncName; result.FuncContext = FuncContext; result.ThridDBAlias = ThridDBAlias; result.VerNo = VerNo; result.IsBGCompile = IsBGCompile; return(result); }
/// <summary> /// 后台编译 /// </summary> /// <param name="compileCode"></param> public void BGCompiler(BehindCodeItem compileCode) { //非调试模式下才能进行后台编译 if (compileCode.IsBGCompile && _isAllowDebug == false) { IRunner runner = CompilerCode(compileCode); if (runner != null) { if (_compilerObj == null) { _compilerObj = new Dictionary <string, IRunner>(); } _compilerObj.Remove(compileCode.FuncName); _compilerObj.Add(compileCode.FuncName, runner); } } }
/// <summary> /// 编译代码 /// </summary> /// <param name="codeKey"></param> /// <param name="thridDbAlias"></param> /// <param name="codeSource"></param> private IRunner CompilerCode(BehindCodeItem compileCode) { IRunner StartCompile(string compilePath, string assemblyName) { var providerOptions = new Dictionary <string, string>(); providerOptions.Add("CompilerVersion", "v4.0"); CSharpCodeProvider codeProvider = new CSharpCodeProvider(providerOptions); CompilerParameters compilerParameters = new CompilerParameters(); compilerParameters.IncludeDebugInformation = false; compilerParameters.TreatWarningsAsErrors = false; compilerParameters.GenerateExecutable = false; compilerParameters.GenerateInMemory = !compileCode.IsBGCompile; compilerParameters.CompilerOptions = "/optimize";//优化 if (_isAllowDebug) { compilerParameters.CompilerOptions = ""; compilerParameters.IncludeDebugInformation = true; compilerParameters.GenerateInMemory = true; } compilerParameters.ReferencedAssemblies.Add("mscorlib.dll"); compilerParameters.ReferencedAssemblies.Add("Microsoft.CSharp.dll"); compilerParameters.ReferencedAssemblies.Add("System.dll"); compilerParameters.ReferencedAssemblies.Add("System.Core.dll"); compilerParameters.ReferencedAssemblies.Add("System.Data.dll"); compilerParameters.ReferencedAssemblies.Add("System.Data.DataSetExtensions.dll"); compilerParameters.ReferencedAssemblies.Add("System.Xml.dll"); compilerParameters.ReferencedAssemblies.Add("System.Xml.Linq.dll"); compilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll"); compilerParameters.ReferencedAssemblies.Add("System.Drawing.dll"); compilerParameters.ReferencedAssemblies.Add("System.Transactions.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.Data.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.Utils.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraEditors.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraGrid.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraBars.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraLayout.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraNavBar.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraReports.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraScheduler.v15.1.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\DevExpress.XtraScheduler.v15.1.Core.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\zlMedimgSystem.Interface.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\zlMedimgSystem.Services.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\zlMedimgSystem.Design.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\zlMedimgSystem.Layout.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\zlMedimgSystem.DataModel.dll"); compilerParameters.ReferencedAssemblies.Add(AppDomain.CurrentDomain.BaseDirectory + @"\zlMedimgSystem.BusinessBase.dll"); compilerParameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location); string[] source = new string[1]; source[0] = compileCode.FuncContext; if (_isAllowDebug) { compilerParameters.TempFiles = new TempFileCollection(Dir.GetAppDebugDir()); //compilerParameters.OutputAssembly = Dir.GetAppDebugDir() + @"\" + assemblyName; } else { if (compileCode.IsBGCompile) { compilerParameters.TempFiles = new TempFileCollection(compilePath); compilerParameters.OutputAssembly = compilePath + @"\" + assemblyName; } } CompilerResults compilerResults = codeProvider.CompileAssemblyFromSource(compilerParameters, source); if (_isAllowDebug) { string debugFile = compilerParameters.OutputAssembly.Replace(".dll", ".0.cs"); using (StreamWriter swcs = new StreamWriter(debugFile)) { swcs.Write(source[0]); } } StringWriter sw = new StringWriter(); foreach (CompilerError ce in compilerResults.Errors) { if (ce.IsWarning) { continue; } sw.WriteLine("{0}({1},{2}: error {3}: {4}", ce.FileName, ce.Line, ce.Column, ce.ErrorNumber, ce.ErrorText); } string errorText = sw.ToString(); if (errorText.Length > 0) { throw new ApplicationException(errorText); } Assembly ass = compilerResults.CompiledAssembly; var obj = ass.GetTypes().FirstOrDefault(); return(Activator.CreateInstance(obj) as IRunner); } IRunner runner = null; string curAssemblyName = _winKey + "_" + _moduleName + "_" + compileCode.FuncName + "_V" + Convert.ToString(compileCode.VerNo) + ".dll"; string assemblyFullName = Dir.GetAppCompileDir() + @"\" + curAssemblyName; if (compileCode.IsBGCompile && _isAllowDebug == false) { if (File.Exists(assemblyFullName)) { Assembly ass = Assembly.LoadFile(assemblyFullName); var obj = ass.GetTypes().FirstOrDefault(); runner = Activator.CreateInstance(obj) as IRunner; } else { runner = StartCompile(Dir.GetAppCompileDir(), curAssemblyName); } } else { runner = StartCompile(Dir.GetAppCompileDir(), curAssemblyName); } return(runner); }
public override bool ExecuteAction(string callModuleName, ISysDesign callModule, object sender, string actName, string tag, IBizDataItems bizDatas, object eventArgs = null) { try { _curSourceData = bizDatas; switch (actName) { case BehindCodeActionDefine.BehindRun: bool runResult = false; if (string.IsNullOrEmpty(tag)) { if (_runner == null) { _runner = new Runner(); _runner.Init(_winKey, _moduleName, _relateBizModules, _dbQuery, _userData, _stationInfo, _dataTransCenter, this); } foreach (BehindCodeItem bci in _codeDesign.BehindCodes) { if (DoActions(bci.FuncName + "执行前", sender, eventArgs) == false) { continue; } if (string.IsNullOrEmpty(bci.FuncContext)) { continue; } bool curResult = _runner.Run(bci, callModuleName, callModule, sender, eventArgs, actName, tag, bizDatas, out _curProcessData); //执行成功才需要执行后续的调用 if (curResult) { runResult = curResult; DoActions(bci.FuncName + "执行后", sender, eventArgs); } } } else { int mIndex = _codeDesign.BehindCodes.FindIndex(T => T.FuncName == tag); if (mIndex >= 0) { BehindCodeItem bci = _codeDesign.BehindCodes[mIndex]; if (DoActions(bci.FuncName + "执行前", sender, eventArgs) == false) { return(false); } if (string.IsNullOrEmpty(bci.FuncContext)) { return(false); } if (_runner == null) { _runner = new Runner(); _runner.Init(_winKey, _moduleName, _relateBizModules, _dbQuery, _userData, _stationInfo, _dataTransCenter, this); } runResult = _runner.Run(bci, callModuleName, callModule, sender, eventArgs, actName, tag, bizDatas, out _curProcessData); //执行成功才需要执行后续的调用 if (runResult) { DoActions(bci.FuncName + "执行后", sender, eventArgs); } } } return(runResult); default: return(false); } } catch (Exception ex) { MsgBox.ShowException(ex, this); return(false); } }