Example #1
0
        /// <summary>
        /// Returns URL of component instance after initiating a new execution thread.
        /// </summary>
        /// <param name="componentInterface"></param>
        /// <returns></returns>
        public async Task <string> RedirectLaunchAppAsync(string componentInterfaceFullname, string returnUrl) // Potentially more params to come inc. returnTaskId, forceContextSearch, etc
        {
            // Get info about the registered component.
            var registeredComponent = await AppRegisterApiClient.GetComponentByInterfaceFullName(componentInterfaceFullname);

            if (registeredComponent == null)
            {
                throw new Exception($"Component interface '{componentInterfaceFullname}' is not registered.");
            }
            var componentInterfaceName = componentInterfaceFullname.Split('.').LastOrDefault();

            var launcher = new LuLauncher()
            {
                ClientRef = componentInterfaceFullname, ReturnUrl = returnUrl
            };

            var thread = new ExecutionThread()
            {
                ExecutingComponents = new List <ExecutingComponent>()
                {
                    new ExecutingComponent()
                    {
                        ExecutingID       = 0,                           // Starts at 0 and will later be incremented for each additional component instance executing within the thread.
                        InterfaceFullname = typeof(LuLauncher).FullName, // a system Launcher Component is always the entry point to a thread
                        TypeFullname      = typeof(LuLauncher).FullName,
                        //URL = "?", // Relevant for LuLauncher??
                        Breadcrumb        = "LuLauncher(0)", // Includes ExecutingID.
                        ParentExecutingID = 0,               // No parent for entry point launcher
                        ClientRef         = launcher.ClientRef,
                        State             = launcher.State,
                        Title             = registeredComponent.Title
                    },
                    new ExecutingComponent()   // The root component (i.e. the component launched for execution).
                    {
                        ExecutingID       = 1, // Starts at 0 and is incremented for each component executed within the thread.
                        InterfaceFullname = componentInterfaceFullname,
                        //TypeFullname = "?", unknown until instantiated.
                        URL               = $"{registeredComponent.DomainName}/{registeredComponent.PrimaryAppRoute}",
                        Breadcrumb        = $"LuLauncher(0)/{componentInterfaceName}(1)",
                        ClientRef         = componentInterfaceName,
                        ParentExecutingID = 0, // LuLauncher acts as parent to root component.
                        State             = null,
                        Title             = registeredComponent.Title
                    }
                },
                ComponentExecutingID    = 1, // Execution starts at the root component.
                ExecutingComponentTitle = registeredComponent.Title,
                ExecutionStatus         = (int)LogicalUnitStatusEnum.Initialised,
                LaunchInputs            = null,
                LockDateTime            = DateTime.Now,
                LockUserID         = Guid.NewGuid().ToString(), // TODO: Determine user ID
                LockUserName       = "******",
                RootComponentTitle = registeredComponent.Title  //JH ,
                                                                //JHPendingOutcome = null
            };

            var persistedThread = await AppExecutionApiClient.SaveNewExecutionThreadAsync(thread);

            return(await RedirectResumeExecutionThreadAsync(persistedThread.ID));
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }