public BpmtkTestCase(ITestOutputHelper output) { var loggerProvider = new XunitLoggerProvider(output); this.loggerFactory.AddProvider(loggerProvider); this.output = output; this.engine = this.BuildProcessEngine(); this.context = this.engine.CreateContext(); Context.SetCurrent(context); this.deploymentManager = context.DeploymentManager; this.runtimeManager = context.RuntimeManager; this.taskManager = context.TaskManager; this.identityManager = context.IdentityManager; this.transaction = context.DbSession.BeginTransaction(); var user = this.identityManager.FindUserById("felix"); if (user == null) { user = new User() { Id = "felix", Name = "felix" }; this.identityManager.CreateUser(user); } var group = this.identityManager.FindGroupById("tests"); if (group == null) { group = new Group() { Id = "tests", Name = "tests" }; group.Users = new List <UserGroup>(); group.Users.Add(new UserGroup() { User = user }); this.identityManager.CreateGroup(group); } this.context.SetAuthenticatedUser(user.Id); }
private void StartSynchronous(IExecutionItem[] items, IRuntimeManager manager) { using (var mre = new AutoResetEvent(false)) { foreach (IExecutionItem item in items) { if (m_abortRequested) break; if (item.State == ProjectExecutionState.Pending) { item.IsSelected = true; item.BeginExecute(manager, i => mre.Set()); mre.WaitOne(); } } } }
private void StartAsynchronous(IExecutionItem[] items, IRuntimeManager manager) { IExecutionItem[] executableItems = items.Where(i => i.State == ProjectExecutionState.Pending).ToArray(); int count = executableItems.Length; if (count > 0) { executableItems.First().IsSelected = true; } using (var mre = new ManualResetEvent(false)) { foreach (IExecutionItem item in executableItems) { if (m_abortRequested) break; item.BeginExecute(manager, i => { if (--count == 0) { mre.Set(); } }); } mre.WaitOne(); } }
private void Start(ExecutionMode mode, IExecutionItem[] items, IRuntimeManager manager) { try { if (mode == ExecutionMode.Synchronous) { StartSynchronous(items, manager); } else { StartAsynchronous(items, manager); } } finally { IsExecuting = false; } }
internal void StartWhenFullyLoaded(ExecutionMode mode, IExecutionItem[] items, IRuntimeManager manager) { IsExecuting = true; m_manager = manager; Items = items; Action a = () => SelfDisposingBackgroundWorker.RunWorkerAsync((s,e) => Start(mode, items, manager)); if (IsLoaded) { Dispatcher.BeginInvoke(a, DispatcherPriority.ContextIdle, null); } else { RoutedEventHandler handler = null; handler = (s, e) => { Loaded -= handler; Dispatcher.BeginInvoke(a, DispatcherPriority.ContextIdle, null); }; Loaded += handler; } }
/// <summary> /// Invokes those of the supplied project invocation rules that are valid and enabled. /// </summary> /// <param name="mode">The ExecutionMode to be used.</param> /// <param name="rules">The project invocation rules that are to be invoked.</param> /// <param name="manager">The IRuntimeManager with which to perform the underlying Absyntax project- /// loading and invocation activities.</param> /// <param name="coordinator">The IExecutionCoordinator needed to coordinate the execution sequence.</param> public void Run(ExecutionMode mode, ProjectInvocationRule[] rules, IRuntimeManager manager, IExecutionCoordinator coordinator) { UnloadProjectsWhereNecessary(rules, manager); ExecutionItem[] items = CreateExecutionItems(rules); coordinator.Start(mode, items, manager); lock (m_ruleState) { foreach (ExecutionItem item in items) { switch (item.State) { case ProjectExecutionState.Completed: case ProjectExecutionState.WriteDataErrors: if (!m_ruleState.ContainsKey(item.Id)) { m_ruleState[item.Id] = item.Detail; } break; case ProjectExecutionState.Ineligible: case ProjectExecutionState.Pending: // Do nothing break; default: m_ruleState.Remove(item.Id); break; } ProjectInvocationRule rule = rules.First(r => r.Id == item.Id); rule.LastExecutionResult = GetLastExecutionResult(item.State); } } }
/// <summary> /// Instructs the Absyntax runtime host to close certain project slots. /// </summary> /// <remarks> /// Project slots to be closed are: /// (a) those that are not referred to in the incoming invocation rules; /// (b) those that are associated with rules whose material details have changed; /// (c) those that are associated with rules for which the property ReloadProjectBeforeExecuting /// returns true. /// </remarks> private void UnloadProjectsWhereNecessary(IProjectInvocationRule[] rules, IRuntimeManager manager) { KeyValuePair<int, ProjectExecutionDetail>[] items; lock (m_ruleState) { items = m_ruleState.ToArray(); } var list = new List<int>(); foreach (var kvp in items) { int ruleId = kvp.Key; ProjectExecutionDetail ped = kvp.Value; IProjectInvocationRule matchingRule = rules.FirstOrDefault(r => r.Id == ruleId); if (matchingRule == null || DetailsHaveChanged(ped, matchingRule) || matchingRule.ReloadProjectBeforeExecuting) { int? key = ped.Key; if (key.HasValue) { manager.Unload(key.Value); } list.Add(ruleId); } } lock (m_ruleState) { list.ForEach(i => m_ruleState.Remove(i)); } }
/// <summary> /// Causes this WorkbookRuntimeAdapter to close all open project runtime slots. /// </summary> /// <param name="manager">The IRuntimeManager to be used to perform the unload.</param> public void UnloadAll(IRuntimeManager manager) { ProjectExecutionDetail[] items; lock (m_ruleState) { items = m_ruleState.Values.ToArray(); m_ruleState.Clear(); } foreach (var key in items.Select(i => i.Key)) { if (key.HasValue) { manager.Unload(key.Value); } } }
/// <summary> /// Begins execution of the supplied items and waits for them to complete before returning. /// </summary> /// <param name="mode">Indicates whether items are to be executed synchronously or asynchronously.</param> /// <param name="items">An array of IExecutionItem instances to be executed.</param> /// <param name="manager">The IRuntimeManager with which to perform the underlying Absyntax /// project-loading and invocation activities.</param> public void Start(ExecutionMode mode, IExecutionItem[] items, IRuntimeManager manager) { Content.StartWhenFullyLoaded(mode, items, manager); ShowDialog(); }
public void ReturnToPool(IRuntimeManager runtimeManager) { _availableRuntimes.Add(runtimeManager); }
private static void SetupForLongInvocation(out ExecutionItem i, out IRuntimeManager manager) { var args = new MockProjectInvocationRuleSetupArgs() { CanExecute = true, UsesInput = false }; int key = 1; var d = new ProjectExecutionDetail() { Key = key }; i = CreateItem(args, d); var rmMock = new Mock<IRuntimeManager>(); rmMock.Setup(m => m.Invoke(key)).Callback(() => Thread.Sleep(200)); manager = rmMock.Object; }
public ProcessInstanceController(IContext context) { this.context = context; this.runtimeManager = context.RuntimeManager; }