Coded UI很是好,我开始还在想,怎么样能让一个经过SharePoint Designer建立的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Designer里那个publish按钮调用的是什么方法,想来想去仍是用Coded UI尝试了一下,发现也挺好,在资源容许的状况下,就这样完成了SPD Workflow的自动化建立:web
1. 首先,你得有个SPD Workflow浏览器
2. 经过我第一次录制的脚本发现,SharePoint自己有个bug,就是若是你在Publish完这个Reusable Workflow以后若是不去SharePoint List的Workflow Settings页面刷新一下的话,这个Publish的版本根本就没有建立成功,因而我第二次录制的脚本中有多了一步,就是在Publish Workflow以后要去往Workflow Settings页面刷新一下,这样就能确保Workflow每次Publish都是成功的:学习
具体的脚本流程以下(Coded UI具体用法详见我以前发表的一篇文章里有介绍),其实和你操做SharePoint Designer Publish Workflow的步骤是同样的,只不过在最后两步——Publish Workflow和刷新Workflow Settings页面这里我加了一个循环,以达到自动化建立欲达到的次数,就是这样(过程详见我注释行括号中加的汉语):this
public void RecordedMethod() { #region Variable Declarations WinButton uIItem30828CI1Button = this.UIHttpmgluca10000sitesWindow.UIItem30828CI1ListItem.UIItem30828CI1Button; WinButton uIWorkflowsButton = this.UIHttpmgluca10000sitesWindow.UIWorkflowsListItem.UIWorkflowsButton; WinListItem uIRe10ListItem = this.UIHttpmgluca10000sitesWindow.UIItemWindow1.UIItemList.UIRe10ListItem; WinButton uIPublishButton = this.UIHttpmgluca10000sitesWindow.UIItemWindow.UISaveToolBar.UIPublishButton; WinEdit uIAddressEdit = this.UIMsnWindowsInternetExWindow.UIItemWindow.UIAddressBarClient.UIAddressEdit; BrowserWindow uIMsnWindowsInternetExWindow = this.UIMsnWindowsInternetExWindow; HtmlHyperlink uIShareHyperlink = this.UIMsnWindowsInternetExWindow.UIWorkflowSettingsDocument.UIShareHyperlink; HtmlDocument uIWorkflowSettingsDocument = this.UIMsnWindowsInternetExWindow.UIWorkflowSettingsDocument; #endregion // Launch '%ProgramW6432%\Microsoft Office\Office15\SPDESIGN.EXE'(打开SPD) ApplicationUnderTest sPDESIGNApplication = ApplicationUnderTest.Launch(this.RecordedMethod4Params.ExePath, this.RecordedMethod4Params.AlternateExePath); // Click '30828CI1' button(点击相应的站点) Mouse.Click(uIItem30828CI1Button, new Point(48, 10)); // Click 'Workflows' button(点击Workflows) Mouse.Click(uIWorkflowsButton, new Point(54, 7)); // Click 're10' list item(点击相应的Workflow) Mouse.Click(uIRe10ListItem, new Point(35, 13)); // Click 'Publish' button(点击Publish按钮) Mouse.Click(uIPublishButton, new Point(13, 31)); // Go to web page 'http://go.microsoft.com/fwlink/p/?LinkId=255141' using new browser instance(打开浏览器) this.UIMsnWindowsInternetExWindow.LaunchUrl(new System.Uri(this.RecordedMethod4Params.UIMsnWindowsInternetExWindowUrl)); // Click 'Address' text box(点击浏览器地址栏) Mouse.Click(uIAddressEdit, new Point(216, 2)); // Go to web page 'http://mglu-ca:10000/sites/30828CI1/_layouts/15/WrkSetng.aspx?List={C9B1EDD4-8B24-4115-9753-3113D02BE3C1}'(输入Workflow Settings页面的地址) uIMsnWindowsInternetExWindow.NavigateToUrl(new System.Uri(this.RecordedMethod4Params.UIMsnWindowsInternetExWindowUrl1)); // Set flag to allow play back to continue if non-essential actions fail. (For example, if a mouse hover action fails.) Playback.PlaybackSettings.ContinueOnError = true; // Mouse hover 'Share' link at (8, 3) Mouse.Hover(uIShareHyperlink, new Point(8, 3)); // Reset flag to ensure that play back stops if there is an error. Playback.PlaybackSettings.ContinueOnError = false; int i=0; while (i < 350) { // Click 'Publish' button(点击Publish按钮) Mouse.Click(uIPublishButton, new Point(23, 31)); // Type '{F5}' in 'Workflow Settings' document(刷新Workflow Settings页面) Keyboard.SendKeys(uIWorkflowSettingsDocument, this.RecordedMethod4Params.UIWorkflowSettingsDocumentSendKeys, ModifierKeys.None); } }
就这样,一个自动化建立SPD Workflow的任务就完成了,还挺快的,一分钟差很少建立10个SPD Workflow左右,半个小时左右弄完。spa
不过这是经过最接近用户操做的方法实现的,却不是经过直接调用相关API实现的。code
还但愿有大神能给出直接调用相关API实现Publish SPD Workflow的方法,共同窗习,共同进步。blog