大连网站建设要多少钱3d网站建设方案
news/
2025/9/23 2:16:16/
文章来源:
大连网站建设要多少钱,3d网站建设方案,广州互联网广告推广,空投网站建设对于Script.NET,我已经写了三篇文章来介绍它#xff0c;文章汇总如下 .NET 动态脚本语言Script.NET 入门指南 Quick Start .NET 动态脚本语言Script.NET 开发指南 .NET 动态脚本语言Script.NET 应用举例 希望这三篇文章能帮助你了解Script.NET。 下面的例子#xff0c;继续讲…对于Script.NET,我已经写了三篇文章来介绍它文章汇总如下 .NET 动态脚本语言Script.NET 入门指南 Quick Start .NET 动态脚本语言Script.NET 开发指南 .NET 动态脚本语言Script.NET 应用举例 希望这三篇文章能帮助你了解Script.NET。 下面的例子继续讲解它的应用。 发送邮件 Send Email mailObj new MailMessage(lsh2011163.com, JamesLi2015hotmail.com,From Script.NET, Body);
SMTPServer new SmtpClient(smtp.163.com);
NTLMAuthentication new System.Net.NetworkCredential(lsh2011163.com, password);
SMTPServer.UseDefaultCredentials false;
SMTPServer.Credentials NTLMAuthentication;
try
{SMTPServer.Send(mailObj);
}
catch (ex)
{ Console.WriteLine(ex.Message);
}
finally
{
} 生成PDF文档 Generate PDF Document 对于PDF文件的操作选择开源的iText library类库。脚本代码如下所示 //Create document at given location
BeginDocument(“c:\\output.pdf”);//Change title in documentв’s meta dataВ
ActiveDocument.AddTitle(‘Sample document’);
//Create paragraphs with different alignment and color options
Paragraph(‘Hello World’, ALIGN_CENTER);
Paragraph(‘This is demo’, ALIGN_RIGHT, BLUE);
Paragraph(‘This pdf was generated by S#’, GREEN);
//Create a list of string items
BeginList();ListItem(‘One’);ListItem(‘Two’);ListItem(‘Three’);
EndList();
//Create a table with tree columns
BeginTable(3);
//Create cells for the first row
Cell(’1′);
Cell(‘One’);
Cell(Paragraph(‘Description of One’, RED));
//Create cells for second row
Cell(’2′);
Cell(‘Two’);
Cell(‘Description of Two’);
EndTable();
//Flush and close document
EndDocument(); 生成PDF的应用它的原文是《Using S# to generate PDF documents》请找到这篇文章并下载代码体会。 通过这个例子你也可以用它来生成Word/Excel文件。也许一个动态生成文件的系统的方案产生于你的脑海中根据用户选择的文件类型(PDF,DOC,XLS)动态调用这个脚本来生成相应类型的文件。这里的动态生成是有好处的你可以不用编译程序而只改变这里的脚本代码来适应客户对文件内容格式(比如layout)的更改。 外壳命令 Shell Command 来实现一个拷贝文件的copy命令代码如下 class Program{static void Main(string[] args){ RuntimeHost.Initialize(); Script script Script.Compile(return Copy(a.xls,d:\Document); );script.Context.SetItem(Copy, new CopyFunction());object result script.Execute();Console.WriteLine(result);Console.ReadLine();}}public class CopyFunction : IInvokable{ public bool CanInvoke(){return true;}public object Invoke(IScriptContext context, object[] args){string sourceFile Convert.ToString(args[0]);string destintionFolderConvert.ToString(args[1]);if(!Directory.Exists(destintionFolder))Directory.CreateDirectory(destintionFolder);string targetFilePath.Combine(destintionFolder,Path.GetFileNameWithoutExtension( sourceFile)Path.GetExtension( sourceFile));File.Copy(sourceFile,targetFile);return targetFile;} } 有了这个做基础你可以实现这样的功能:每日构建 Daily Build请参考文章《图解持续集成--纯命令行实现.Net项目每日构建》 也可以做到这样的功能 原文作者使用的bat/cmd的Windows外壳命令而这里使用的是Script.NET脚本可以嵌入到其它应用程序中被应用程序启动并执行。 访问SQL Server数据库 sql DbProviderFactories.GetFactory(System.Data.SqlClient);
connection sql.CreateConnection();
connection.ConnectionString Data Source(local);Initial CatalogNorthwind;Integrated SecurityTrue;
connection.Open();command sql.CreateCommand();
command.Connection connection;
command.CommandText select * from Customers;reader command.ExecuteReader();
while (reader.Read())
{Console.WriteLine(reader[CompanyName]. reader[ContactName]);}
connection.Dispose(); 这个例子在前面已经举例过它可以引深为对其他数据源的操作(MySQL,Oracel…) 工作流系统中的自定义代码活动 这个应用是我在思考工作流的规则编辑器时想到的请看下图 我们知道在自定义的工作流系统中CodeActivity是最有价值的活动可以做任何想做的事情但也非常不好用。因为工作流的用户不是做编程的不懂C#.NET所以你不能指望他会改变这一点。Script.NET则弥补了这个缺陷可以让工作流设计人员在我的脚本编辑环境中编辑脚本给工作流添加灵活的脚本代码在执行时由Script.NET解析引擎执行。只要脚本编辑环境足够智能灵活提供的Script Sample足够多这个CodeActivity(应该改名叫ScriptActivity)为增加自定义的工作流系统的灵活性发挥极大的作用。 自动化操作 Windows Automation 要达到这个功能要参考Windows Automation API请参考这里this article。 先来看一下应用的脚本是什么样子的再来看实现原理 // Close existing instances of Notepad
Kill(“notepad”);
// Launch a new Notepad instance and get main window
window Launch(“notepad”);
// Wait 1 second
Wait(1000);
// Get main editor region
edit FindByClassName(window, “Edit”);
// focus main editor
FocusEditor(edit);
// Send sample text to the editor region
SendKeys.SendWait(“Automating Notepad using Windows UI Automation and S#”);
Wait(3000);
// Find [File] menu
mnuFile FindById(window, “Item 1″);
// Expand [File] menu
Expand(mnuFile);
Wait(1000);
// Invoke [Save As] menu item
InvokeById(window, “Item 4″);
Wait(1000);
// Get [Save As] dialog
saveAsDialog FindByName(window, “Save As”);
// Get access to [FileName] textbox
saveAsName FindById(saveAsDialog, “1001″);
// Focus filename editor
FocusEditor(saveAsName);
// Write down file name
SendKeys.SendWait(“D:\\MyTextFile”);
// Send [Enter] keypress
SendKeys.SendWait(“{ENTER}”);
Wait(1000); // Check whether Overwrite Dialog appeared
confirmSaveAs FindByName(saveAsDialog, “Confirm Save As”);
if (confirmSaveAs ! null)
{ // Click [OK] button InvokeById(confirmSaveAs, “CommandButton_6″); Wait(1000);
} // Expand [File] menu
Expand(mnuFile);
Wait(1000);
// Click [Exit] item
InvokeById(window, “Item 7″); 这是在做什么打开Notepad,在里面输入文字最后保存文件全部的实现都是用脚本来做的。这令我想到了自动化测试UI自动化测试。确实是这样的自动化的脚本代替了人工操作完全不需要人为干预。 这个应用的原文是《Windows Automation: Automating Windows 7 Notepad within S# Script》。 动态窗体 Dynamic Silverlight Forms. Embedding S# Scripts into Xaml 对于Silverlight技术不熟悉请用文章原文查看具体内容。我能理解到意思是可以把以脚本的方式创建窗体这样的窗体是动态的而不编译时就写死的自然是非常灵活的方法。 推荐一个小技巧我想把Script.NET的脚本像对待外壳命令一样双击执行或是右键点击执行如下面的效果所示 先把Script.NET的原代码中的RunTests程序改造成可以接受一个文件参数的可执行文件像这样 它的原来的用法是这样Usage: RunTests.exe folderPath 改成这样的用法 Usage: RunTests.exe scriptFile 这样的用意是让它接受一个Script.NET脚本文件名并能执行它。 再到外壳中注册文件关联比如我把Script.NET的文件扩展名定义为spt文件并添加这样的注册表项 Windows Registry Editor Version 5.00 [-HKEY_CLASSES_ROOT\SystemFileAssociations\.spt\shell\RunTests] 这样就在外壳命令中关联了Script.NET的脚本文件spt和它的执行程序RunTests达到可以像bat文件一样双击执行。 总结本质上Script.NET的脚本运行还是解析为DotNet代码的执行所以不必怀疑它能做什么.NET能实现的功能都能做到。问题是我们是否需要这样的动态脚本来增强程序的可扩展性灵活性这取决于你it is up to you。 转载于:https://www.cnblogs.com/JamesLi2015/archive/2011/09/21/2183072.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/911093.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!