public UnitOfWorkManagerMiddlewareTestsFixture SetException() { Exception = new Exception(); NextTask.Setup(n => n(Context)).ThrowsAsync(Exception); return(this); }
public void Excute_TemplateWithEnAndDeStandardValues_ItemOnlyInEn_DoesntReturnDe() { //Arrange using (Db database = new Db { new DbTemplate(new ID(TemplateInferredTypeTaskFixture.StubInferred.TemplateId)) { new Sitecore.FakeDb.DbField("Title") { { "en", "Hello!" }, { "de-de", "Hej!" } } }, new Sitecore.FakeDb.DbItem("Target", ID.NewID, new ID(TemplateInferredTypeTaskFixture.StubInferred.TemplateId)) }) { var path = "/sitecore/content/Target"; var itemEn = database.GetItem(path, "en"); var itemDe = database.GetItem(path, "de-de"); // itemEn.Template.CreateStandardValues(); var nextTaskEn = new NextTask(); var taskEn = new ItemVersionCountByRevisionTask(); taskEn.SetNext(x => nextTaskEn.Execute(x)); var contextEn = new SitecoreTypeCreationContext(); contextEn.Item = itemEn; var optionsEn = new GetItemByItemOptions(itemEn); contextEn.Options = optionsEn; var argsEn = new ObjectConstructionArgs(null, contextEn, null, null); //Act EN taskEn.Execute(argsEn); //Assert EN Assert.IsTrue(nextTaskEn.WasCalled); var nextTaskDe = new NextTask(); var taskDe = new ItemVersionCountByRevisionTask(); taskDe.SetNext(x => nextTaskDe.Execute(x)); var contextDe = new SitecoreTypeCreationContext(); var optionsDe = new GetItemByItemOptions(itemDe); contextDe.Item = itemDe; contextDe.Options = optionsDe; var argsDe = new ObjectConstructionArgs(null, contextDe, null, null); //Act De taskDe.Execute(argsDe); //Assert De Assert.IsFalse(nextTaskDe.WasCalled); } }
private void OnExecute(TaskExecutionContext context, TaskResult result) { if (result.Output != null) { Type type = NextTask.GetType(); foreach (string key in TaskPipe.Keys) { PropertyInfo pi = type.GetProperty(key); pi.SetValue(NextTask, result.Output[TaskPipe[key]], (object[])null); } } }
public void Run(String fileName, String arguments, Boolean shellCommand) { if (isRunning) { // kill process and queue Run command nextTask = () => { Run(fileName, arguments, shellCommand); }; this.KillProcess(); return; } if (!shellCommand && !File.Exists(fileName)) { throw new FileNotFoundException("The program '" + fileName + "' was not found.", fileName); } isRunning = true; process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = RedirectInput; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.StandardOutputEncoding = Encoding.Default; process.StartInfo.StandardErrorEncoding = Encoding.Default; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = fileName; process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = WorkingDirectory ?? PluginBase.MainForm.WorkingDirectory; process.Start(); outputReader = process.StandardOutput; errorReader = process.StandardError; // we need to wait for all 3 threadpool operations // to finish (processexit, readoutput, readerror) tasksFinished = 0; ThreadStart waitForExitDel = new ThreadStart(process.WaitForExit); waitForExitDel.BeginInvoke(new AsyncCallback(TaskFinished), null); ThreadStart readOutputDel = new ThreadStart(ReadOutput); ThreadStart readErrorDel = new ThreadStart(ReadError); readOutputDel.BeginInvoke(new AsyncCallback(TaskFinished), null); readErrorDel.BeginInvoke(new AsyncCallback(TaskFinished), null); }
public void Run(String fileName, String arguments, Boolean shellCommand) { if (isRunning) { // kill process and queue Run command nextTask = () => { Run(fileName, arguments, shellCommand); }; this.KillProcess(); return; } if (!shellCommand && !File.Exists(fileName)) throw new FileNotFoundException("The program '" + fileName + "' was not found.", fileName); isRunning = true; process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardInput = RedirectInput; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.StandardOutputEncoding = Encoding.Default; process.StartInfo.StandardErrorEncoding = Encoding.Default; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = fileName; process.StartInfo.Arguments = arguments; process.StartInfo.WorkingDirectory = WorkingDirectory ?? PluginBase.MainForm.WorkingDirectory; process.Start(); outputReader = process.StandardOutput; errorReader = process.StandardError; // we need to wait for all 3 threadpool operations // to finish (processexit, readoutput, readerror) tasksFinished = 0; ThreadStart waitForExitDel = new ThreadStart(process.WaitForExit); waitForExitDel.BeginInvoke(new AsyncCallback(TaskFinished), null); ThreadStart readOutputDel = new ThreadStart(ReadOutput); ThreadStart readErrorDel = new ThreadStart(ReadError); readOutputDel.BeginInvoke(new AsyncCallback(TaskFinished), null); readErrorDel.BeginInvoke(new AsyncCallback(TaskFinished), null); }
private void TaskFinished(IAsyncResult result) { lock (this) { if (++tasksFinished >= 3) { isRunning = false; if (nextTask != null) { nextTask(); nextTask = null; // do not call ProcessEnd if another process was queued after the kill } else if (process != null && ProcessEnded != null) { ProcessEnded(this, process.ExitCode); } } } }
/// <summary> /// Runs the task asynchronously. /// </summary> public void RunAsync() { _tool.Callback = this; var token = _cancellationTokenSource.Token; StartTime = DateTime.Now; Status = GisTaskStatus.Running; var t = Task <bool> .Factory.StartNew(() => Run(token), token, TaskCreationOptions.LongRunning, TaskScheduler.Default).ContinueWith(task => { try { FinishTime = DateTime.Now; if (task.IsCanceled || _cancellationTokenSource.IsCancellationRequested) { Status = GisTaskStatus.Cancelled; return; } try { // exception will be observed here, so don't check IsFaulted afterwards if (!task.Result) { Status = GisTaskStatus.Failed; return; } } catch (Exception ex) { _tool.Log.Error("Error during tool execution: " + Tool.Name, ex); Status = GisTaskStatus.Failed; return; } try { Status = _tool.AfterRun() ? GisTaskStatus.Success : GisTaskStatus.Failed; } catch (Exception ex) { _tool.Log.Error("Failed to save datasource: " + Tool.Name, ex); Status = GisTaskStatus.Failed; } } finally { // running the next task if (NextTask != null) { NextTask.RunAsync(); } // stop reporting progress from datasources _tool.CleanUp(); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
/// <summary> /// Adds a next task to the list of next tasks will be used when prosessing linkers /// </summary> /// <param name="ID"></param> internal void AddNextTask(int ID) { NextTask.Add(ID); }
private void TaskFinished(IAsyncResult result) { lock (this) { if (++tasksFinished >= 3) { isRunning = false; if (nextTask != null) { nextTask(); nextTask = null; // do not call ProcessEnd if another process was queued after the kill } else if (process != null && ProcessEnded != null) ProcessEnded(this, process.ExitCode); } } }