public async Task <string> ExecuteLogicalUnitAsync <T>(string txid) where T : LogicalUnit, new() { var lu = await LoadComponentFromExecutionThreadAsync <T>(txid); if (lu.executionThread.PendingOutcomeJson != null) { var outcome = JsonConvert.DeserializeObject <Outcome>(lu.executionThread.PendingOutcomeJson); Type outcomeType = null; try { outcomeType = CoreFunctions.GetType(outcome.TypeName); } catch (Exception) { } if (outcomeType != null) { outcome = (Outcome)JsonConvert.DeserializeObject(lu.executionThread.PendingOutcomeJson, outcomeType); } outcome.SourceComponent = ExtractComponentFromExecutionThread(lu.executionThread, outcome.SourceExecutionID); lu.HandleOutcome(outcome); lu.executionThread.PendingOutcomeJson = null; } var nextComponent = await lu.GetNextComponentAsync(); var executingLu = lu.executionThread.ExecutingComponents.FirstOrDefault( e => e.ExecutingID == lu.TXID.xid ); executingLu.State = lu.State; if (nextComponent == null) // lu Done? { // Determine parent launcher... var executingLauncher = lu.executionThread.ExecutingComponents.FirstOrDefault( e => e.ExecutingID == executingLu.ParentExecutingID ); var launcherTXID = new TXID(lu.executionThread.ID, executingLauncher.ExecutingID).ToString(); var launcher = await LoadComponentFromExecutionThreadAsync <LuLauncher>(launcherTXID); return(launcher.ReturnUrl); } var nextExecutingComponent = lu.executionThread.ExecutingComponents.FirstOrDefault( e => e.ExecutingID == nextComponent.TXID.xid ); nextExecutingComponent.State = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(nextComponent)); //executingComponent.State = JsonConvert.DeserializeObject<Dictionary<string, object>>(CoreFunctions.ProxyAsJson(nextComponent)); lu.executionThread = await AppExecutionApiClient.SaveExecutionThreadAsync(lu.executionThread); return(nextExecutingComponent.URL); }
public async Task <ActionResult> UxSelectCustomer_PreviewCustomer(string txid, int customerId) { var TXID = new TXID(txid); return(Redirect(await executionManager.RedirectLaunchAppAsync(txid, "GOLD.SomeDomain.Interfaces.ISomeComponent"))); // TODO: Properly launch 2ndary app //return Redirect(await executionManager.RaiseOutcomeAsync(new TXID(txid), new ComponentDoneOutcome())); }
public async Task <T> LoadComponentInterfaceFromExecutionThreadAsync <T>(string txid) where T : class { var txid2 = new TXID(txid); var executionThread = await AppExecutionApiClient.LoadExecutionThreadAsync(txid2.tid); return(ExtractComponentInterfaceFromExecutionThread <T>(executionThread, txid2.xid)); //return await LoadComponentFromExecutionThreadAsync<T>(new TXID(txid)); }
public T LoadComponentFromExecutionThread <T>(string txid) where T : Component, new() { var txid2 = new TXID(txid); var executionThread = AppExecutionApiClient.LoadExecutionThread(txid2.tid); return(ExtractComponentFromExecutionThread <T>(executionThread, txid2.xid)); //return await LoadComponentFromExecutionThreadAsync<T>(new TXID(txid)); }
//public async Task<ExecutionThread> LoadExecutionThreadAsync(int tid) //{ // return await AppExecution.LoadExecutionThreadAsync(tid); //} public async Task <IComponent> LoadComponentAsync(string txid) { var txid2 = new TXID(txid); var executionThread = await AppExecutionApiClient.LoadExecutionThreadAsync(txid2.tid); return(ExtractComponentFromExecutionThread(executionThread, txid2.xid)); //return await LoadComponentFromExecutionThreadAsync<T>(new TXID(txid)); }
public async Task <string> RedirectResumeExecutionThreadAsync(ExecutionThread executionThread) { var txid = new TXID(executionThread.ID, executionThread.ComponentExecutingID).ToString(); var componentExecuting = executionThread.ExecutingComponents.FirstOrDefault(e => e.ExecutingID == executionThread.ComponentExecutingID); componentExecuting.URL = $"{componentExecuting.URL}/{txid}"; executionThread.ExecutionStatus = (int)LogicalUnitStatusEnum.Started; executionThread = await AppExecutionApiClient.SaveExecutionThreadAsync(executionThread); return(componentExecuting.URL); }
public async Task <T> LoadComponentFromExecutionThreadAsync <T>(TXID txid) where T : Component, new() { var executionThread = await AppExecution.LoadExecutionThreadAsync(txid.tid); return(LoadComponentFromExecutionThread <T>(executionThread, txid.xid)); }
public async Task <IComponent> GetComponentInterfaceAsync <T>(Component parentComponent, string clientRef) where T : class//, IComponent { var executionThread = parentComponent.executionThread; var executingComponent = executionThread.ExecutingComponents.FirstOrDefault( e => e.ParentExecutingID == parentComponent.TXID.xid && e.ClientRef == clientRef ); var childComponentWithClientRefNotInThread = (executingComponent == null); if (childComponentWithClientRefNotInThread) { var componentInterfaceFullname = typeof(T).FullName; var registeredComponent = await AppRegisterApiClient.GetComponentByInterfaceFullName(componentInterfaceFullname); if (registeredComponent == null) { throw new Exception($"Component interface '{componentInterfaceFullname}' is not registered."); } var parentExecutingComponent = executionThread.ExecutingComponents.FirstOrDefault(e => e.ExecutingID == parentComponent.TXID.xid); if (parentExecutingComponent == null) { throw new Exception($"Exececuting component with id'{parentComponent.TXID.xid}' not found in execution thread with id'{parentComponent.TXID.tid}."); } if (registeredComponent == null) { throw new Exception($"Component interface '{componentInterfaceFullname}' is not registered."); } var componentInterfaceName = componentInterfaceFullname.Split('.').LastOrDefault(); int nextExecutingID = executionThread.ExecutingComponents.Count(); // Zero based. var nextTXID = new TXID(executionThread.ID, nextExecutingID).ToString(); executingComponent = new ExecutingComponent() { ExecutingID = nextExecutingID, InterfaceFullname = componentInterfaceFullname, TypeFullname = typeof(T).FullName, URL = $"{registeredComponent.DomainName}/{registeredComponent.PrimaryAppRoute}/{nextTXID}", Breadcrumb = $"{parentExecutingComponent.Breadcrumb}/{componentInterfaceName}({nextExecutingID})", ClientRef = clientRef, ParentExecutingID = parentExecutingComponent.ExecutingID, State = null, Title = registeredComponent.Title }; executionThread.ExecutingComponents.Add(executingComponent); executionThread.ComponentExecutingID = nextExecutingID; executionThread.ExecutingComponentTitle = registeredComponent.Title; } T proxy; IComponent component; if (childComponentWithClientRefNotInThread) { proxy = CoreFunctions.CreateProxy <T>(typeof(IComponent)); component = proxy as IComponent; component.TXID = new TXID(executionThread.ID, executingComponent.ExecutingID); } else { var stateJson = JsonConvert.SerializeObject(executingComponent.State); proxy = CoreFunctions.CreateProxy <T>(stateJson, typeof(IComponent)); component = proxy as IComponent; } return(component); }
public async Task <T> GetComponentAsync <T>(Component parentComponent, string clientRef) where T : Component, new() { var t = new T(); var component = t as Component; if (component == null) { return(null); } var executionThread = parentComponent.executionThread; var executingComponent = executionThread.ExecutingComponents.FirstOrDefault( e => e.ParentExecutingID == parentComponent.TXID.xid && e.ClientRef == clientRef ); var componentInterfaceFullname = typeof(T).GetCustomAttribute <ComponentInterfaceAttribute>()?.Type.FullName; // TODO: Cater for unregistered components! var registeredComponent = await AppRegisterApiClient.GetComponentByInterfaceFullName(componentInterfaceFullname); if (registeredComponent == null) { throw new Exception($"Component interface '{componentInterfaceFullname}' is not registered."); } if (executingComponent == null) { var parentExecutingComponent = executionThread.ExecutingComponents.FirstOrDefault(e => e.ExecutingID == parentComponent.TXID.xid); if (parentExecutingComponent == null) { throw new Exception($"Exececuting component with id'{parentComponent.TXID.xid}' not found in execution thread with id'{parentComponent.TXID.tid}."); } if (registeredComponent == null) { throw new Exception($"Component interface '{componentInterfaceFullname}' is not registered."); } var componentInterfaceName = componentInterfaceFullname.Split('.').LastOrDefault(); int nextExecutingID = executionThread.ExecutingComponents.Count(); // Zero based. var nextTXID = new TXID(executionThread.ID, nextExecutingID).ToString(); executingComponent = new ExecutingComponent() { ExecutingID = nextExecutingID, InterfaceFullname = componentInterfaceFullname, TypeFullname = t.GetType().FullName, URL = $"{registeredComponent.DomainName}/{registeredComponent.PrimaryAppRoute}/{nextTXID}", Breadcrumb = $"{parentExecutingComponent.Breadcrumb}/{componentInterfaceName}({nextExecutingID})", ClientRef = clientRef, ParentExecutingID = parentExecutingComponent.ExecutingID, State = null, Title = registeredComponent.Title }; executionThread.ExecutingComponents.Add(executingComponent); executionThread.ComponentExecutingID = nextExecutingID; executionThread.ExecutingComponentTitle = registeredComponent.Title; } component.executionThread = executionThread; component.TXID = new TXID(executionThread.ID, executingComponent.ExecutingID); component.ClientRef = executingComponent.ClientRef; component.State = executingComponent.State; return(t); }