开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from 车江毅/NScript
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
NScript
/
FrCodeEdit.cs
NScript
/
FrCodeEdit.cs
FrCodeEdit.cs 15.52 KB
一键复制 编辑 原始数据 按行查看 历史
车江毅 提交于 2016年06月24日 10:21 +08:00 . add project
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
using BSF.BaseService.NScript.Compiler;
using BSF.BaseService.NScript.Core;
using ICSharpCode.TextEditor.Document;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BSF.BaseService.NScript
{
public partial class FrCodeEdit : Form
{
public FrCodeEdit()
{
InitializeComponent();
this.rtbCode.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("C#");
this.rtbCode.Encoding = System.Text.Encoding.Default;
}
FrDebug frdebug = new FrDebug();
public class FileInfoItem
{
public string FileName;
public string FullFileName;
public bool isMainFile;
public override string ToString()
{
return (isMainFile == true ? "[主]" : "") + FileName;
}
}
private void TryToLoadMainFile()
{
try
{
foreach (var dir in GetSearchDirs())
{
foreach (var filepath in System.IO.Directory.GetFiles(dir))
{
if (filepath.ToLower().EndsWith(".main.cs"))
{
OpenMainFile(filepath);
return;
}
}
}
}
catch (Exception exp)
{
}
}
private List<string> GetSearchDirs()
{
List<string> dirs = new List<string>(); dirs.Add(AppDomain.CurrentDomain.BaseDirectory);
string strsearchdirs = System.Configuration.ConfigurationManager.AppSettings["searchdirs"];
strsearchdirs = (strsearchdirs == null ? "" : strsearchdirs);
string[] searchdirs = strsearchdirs.Trim(';').Split(';');
foreach (var dir in searchdirs)
{
if (!dirs.Contains(dir) && System.IO.Directory.Exists(dir))
{
dirs.Add(dir);
}
}
return dirs;
}
private void OpenMainFile(string mainFilePath)
{
CompilerInfoContext.CompilerInfoCache.ClearCache();
CompilerInfo ci = new CompilerInfo().Parse(EnumSourceType.File, mainFilePath);
var mainFileInfoItem = new FileInfoItem() { FileName = ci.MainFilePath.FileName, FullFileName = ci.MainFilePath.FullFileName, isMainFile = true };
this.lbFileList.Items.Add(mainFileInfoItem);
foreach (var file in ci.CodeFilePaths)
{
this.lbFileList.Items.Add(new FileInfoItem() { FileName = file.FileName, FullFileName = file.FullFileName, isMainFile = false });
}
OpenFileCode(mainFileInfoItem);
this.lbFileList.SelectedItem = mainFileInfoItem;
}
int lastindex = -1; DateTime lastshowtime = DateTime.Now;
private void showFileToolTip()
{
Point point = this.lbFileList.PointToClient(Control.MousePosition);
int index = lbFileList.IndexFromPoint(point.X, point.Y);
if (index >= 0 && index != lastindex && (DateTime.Now - lastshowtime) > TimeSpan.FromSeconds(5))
{
lastindex = index; lastshowtime = DateTime.Now;
this.toolTip1.SetToolTip(lbFileList, (lbFileList.Items[index] as FileInfoItem).FullFileName);
}
}
private FileInfoItem GetMainFileInfoItem()
{
foreach (var item in this.lbFileList.Items)
{
if (item is FileInfoItem)
{
var fileinfoitem = (item as FileInfoItem);
if (fileinfoitem.isMainFile == true)
{
return fileinfoitem;
}
}
}
throw new Exception("找不到主编译文件");
}
private void OpenFileCode(FileInfoItem fileinfoitem)
{
SaveFileCode();
this.rtbCode.Tag = null;
this.rtbCode.ResetText();// = "";
this.rtbCode.Text = IOHelper.ReadAllText(fileinfoitem.FullFileName);
this.rtbCode.Tag = fileinfoitem;
this.rtbCode.Refresh();
}
public void SaveFileCode()
{
if (this.rtbCode.Tag != null)
{
var fileinfoitemtemp = (this.rtbCode.Tag as FileInfoItem);
IOHelper.WriteAllText(fileinfoitemtemp.FullFileName, this.rtbCode.Text);
PrintInfo(fileinfoitemtemp.FileName + " 已保存 " + DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
}
}
public string GetMainCompilerTempFile()
{
string mainFileCode = IOHelper.ReadAllText(GetMainFileInfoItem().FullFileName) + "\n//编译时间:" + DateTime.Now.ToString("yyMMddHHmmssfff") + "\n";
string compilertempMainFilePath = System.IO.Path.GetDirectoryName(GetMainFileInfoItem().FullFileName).TrimEnd('\\') + "\\" + GetMainFileInfoItem().FileName + "." + DateTime.Now.ToString("yyMMddHHmmssfff") + ".compiler";
System.IO.File.WriteAllText(compilertempMainFilePath, mainFileCode);
return compilertempMainFilePath;
}
public CompilerResult RunCompiler(EnumCompilerMode enumCompilerMode)
{
try
{
var mainFileInfoItem = GetMainFileInfoItem();
if (mainFileInfoItem == null)
{
throw new Exception("找不到主编译文件");
}
string mainFileCode = IOHelper.ReadAllText(mainFileInfoItem.FullFileName) + "\n//编译时间:" + DateTime.Now.ToString("yyMMddHHmmssfff") + "\n";
string compilertempMainFilePath = System.IO.Path.GetDirectoryName(mainFileInfoItem.FullFileName).TrimEnd('\\') + "\\" + mainFileInfoItem.FileName + ".compiler";
System.IO.File.WriteAllText(compilertempMainFilePath, mainFileCode);
return NScriptHelper.RunCompiler(new CompilerParams() { EnumSourceType = EnumSourceType.File, CodeOrFileName = compilertempMainFilePath, EnumCompilerMode = enumCompilerMode });
}
catch (Exception exp)
{
throw exp;
}
finally
{
DeleteCompilerTempFiles();
}
}
public void DeleteCompilerTempFiles()
{
try
{
var mainFileInfoItem = GetMainFileInfoItem();
if (mainFileInfoItem != null)
{
string[] files = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(mainFileInfoItem.FullFileName));
foreach (var file in files)
{
if (file.ToLower().EndsWith(".compiler") == true)
{
try
{
System.IO.File.Delete(file);
}
catch { }
}
}
}
}
catch { }
}
private void ErrorCatch(Action action)
{
try
{
action.Invoke();
}
catch (Exception exp)
{
if (exp is NScript.Compiler.NScriptException)
MessageBox.Show((exp as NScriptException).MessageDetail);
else
MessageBox.Show(exp.Message);
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
ErrorCatch(() =>
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = false;
fileDialog.Title = "请选择文件";
fileDialog.Filter = "C#.Main主文件 (*.main.cs)|*.main.cs|所有文件 (*.*)|*.*";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
this.lbFileList.Items.Clear();
string filepath = fileDialog.FileName;
OpenMainFile(filepath);
}
});
}
private void PrintInfo(string msg, bool iserror = false)
{
if (iserror == true)
{
this.lbInfo.ForeColor = Color.Red;
this.lbInfo.Text = msg;
}
else
{
this.lbInfo.ForeColor = Color.Green;
this.lbInfo.Text = msg;
}
}
private void lbFileList_MouseMove(object sender, MouseEventArgs e)
{
ErrorCatch(() =>
{
showFileToolTip();
});
}
private void lbFileList_MouseHover(object sender, EventArgs e)
{
ErrorCatch(() =>
{
showFileToolTip();
});
}
private void FrCodeEdit_Load(object sender, EventArgs e)
{
ErrorCatch(() =>
{
TryToLoadMainFile();
});
}
private void lbFileList_MouseDoubleClick(object sender, MouseEventArgs e)
{
ErrorCatch(() =>
{
if (this.lbFileList.SelectedItem != null)
{
var fileinfoitem = (this.lbFileList.SelectedItem as FileInfoItem);
OpenFileCode(fileinfoitem);
}
});
}
private void btnSave_Click(object sender, EventArgs e)
{
ErrorCatch(() =>
{
SaveFileCode();
});
}
private bool TryToLoadAssembly(string filepath)
{
Assembly assembly = null;
try
{
assembly = Assembly.Load(filepath);
}
catch { }
if (assembly != null)
return true;
else
return false;
}
private void btnCompiler_Click(object sender, EventArgs e)
{
try
{
SaveFileCode();
RunCompiler(EnumCompilerMode.Assembly);
PrintInfo("编译成功:" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
}
catch (Exception exp)
{
PrintInfo("编译失败:" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss"), true);
if (exp is NScript.Compiler.NScriptException)
MessageBox.Show("编译出错:" + (exp as NScriptException).MessageDetail);
else
MessageBox.Show("编译出错:" + exp.Message);
}
}
private void btnDebug_Click(object sender, EventArgs e)
{
ErrorCatch(() =>
{
//frdebug.MainFileInfoItem = GetMainFileInfoItem();
frdebug.FrParent = this;
frdebug.Show();
});
}
private void btnTemplate1_Click(object sender, EventArgs e)
{
new FrInfo(StringResources.CodeTemplate1).ShowDialog();
}
private void btnAuthor_Click(object sender, EventArgs e)
{
MessageBox.Show(StringResources.AuthorInfo);
}
private void btnAssemblyDll_Click(object sender, EventArgs e)
{
ErrorCatch(() =>
{
SaveFileCode();
string systemdir = System.IO.Path.GetDirectoryName(typeof(string).Assembly.Location).TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
string info = "【检查系统引用的情况,仅供参考,以实际运行为准】\n";
#region check引用
if (Config.SystemReferencedAssembliesDlls.Count > 0)
{
info += "\n*******系统编译默认添加的程序集*******" + "\n";
info += "系统目录路径:" + systemdir + "\n";
foreach (var dll in Config.SystemReferencedAssembliesDlls)
{
if (System.IO.File.Exists(systemdir + dll))
{
info += dll + " [find file]\n";
}
else
{
info += dll + " 【文件未找到】\n";
}
}
}
CompilerInfo ci = new CompilerInfo().Parse(EnumSourceType.File, GetMainFileInfoItem().FullFileName);
if (ci.DllFiles.Count > 0)
{
info += "\n*******dllfiles添加dll需要引用的程序集*******" + "\n";
foreach (var dll in ci.DllFiles)
{
Assembly assembly = null;
try
{
string fullpath = dll.FullFileName;
if (!System.IO.File.Exists(fullpath))
fullpath = systemdir + dll.FileName;
assembly = Assembly.LoadFile(fullpath);
}
catch (Exception exp)
{ }
if (assembly != null)
{ info += dll.FileName + "[load file]\n"; }
else
{ info += dll.FileName + "[加载文件失败]\n"; }
if (assembly != null)
{
string assemblydir = System.IO.Path.GetDirectoryName(assembly.Location);
foreach (var tdll in assembly.GetReferencedAssemblies())
{
var find = (from o in ci.DllFiles where o.FileName == tdll.Name + ".dll" select o).FirstOrDefault();
if (System.IO.File.Exists(systemdir + tdll.Name + ".dll") || System.IO.File.Exists(assemblydir + tdll.Name + ".dll")
|| find != null)
{
if (Config.SystemReferencedAssembliesDlls.Contains(tdll.Name + ".dll") ||
(from o in ci.DllFiles where o.FileName == tdll.Name + ".dll" select o).FirstOrDefault() != null)
{
info += "--" + tdll.Name + " [find file]\n";
}
else
{
info += "--" + tdll.Name + " [find file]【主文件中dllfiles未引用" + tdll.Name + ".dll文件】\n";
}
}
else
{
info += "--" + tdll.Name + " 【文件未找到】\n";
}
}
}
}
}
#endregion
info += "\n\n" + StringResources.ReferencedAssembliesDllsHelp + "\n\n";
new FrInfo(info, false).ShowDialog();
});
}
private void btnExeHelp_Click(object sender, EventArgs e)
{
new FrInfo(StringResources.ExeHelp, false).ShowDialog();
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

.net 动态脚本引擎, 解决.net环境windows系统下类似java中Grovvy的功能和方向。 在互联网项目可以用来做动态营销活动(营销业务解耦和剥离),规则引擎,流程引擎,windows运维脚本,源码式插件开发。
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/MuNet/NScript.git
git@gitee.com:MuNet/NScript.git
MuNet
NScript
NScript
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /