Пример #1
0
        public plcserver(int loopTime, string applicationName)
        {
            ApplicationName = applicationName;

            _appRegister = new AppRegister(applicationName, "127.0.0.1", 10905);

            _appRegister.RegisterApp();


            // Create MDSClient object to connect to DotNetMQ
            // Name of this application: PLCServer
            mdsClient = new MDSClient(ApplicationName);

            // Connect to DotNetMQ server
            try
            {
                mdsClient.Connect();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                // esco
                this.Exit();
            }
            // Register to MessageReceived event to get messages.
            mdsClient.MessageReceived += PLCServer_MessageReceived;

            LoopTime       = loopTime;
            timer.Elapsed += timer_Elapsed;
            timer.Enabled  = true;

            Logger.InfoFormat("{0} Application ready", ApplicationName);
        }
Пример #2
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 AppRegister.GetComponentByInterfaceFullName(componentInterfaceFullname);

            // TODO: What if requested component interface is not registered?
            var componentInterfaceName = componentInterfaceFullname.Split('.').LastOrDefault();
            var componentUrl           = $"{registeredComponent.DomainName}/{registeredComponent.PrimaryAppRoute}";

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

            var thread = new ExecutionThread()
            {
                ExecutingComponents = new List <ExecutingComponent>()
                {
                    new ExecutingComponent()
                    {
                        ExecutingID       = 1,                           // Starts at 1 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
                        //URL = "?", // Relevant for LuLauncher??
                        Breadcrumb        = "LuLauncher(1)",             // 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       = 2, // Starts at 1 and is incremented for each component executed within the thread.
                        InterfaceFullname = componentInterfaceFullname,
                        URL               = componentUrl,
                        Breadcrumb        = $"LuLauncher(1)/{componentInterfaceName}(2)",
                        ClientRef         = "LuLauncher(1)",
                        ParentExecutingID = 1, // LuLauncher acts as parent to root component.
                        State             = null,
                        Title             = registeredComponent.Title
                    }
                },
                ComponentExecutingID    = 2, // Execution starts at the root component.
                ExecutingComponentTitle = registeredComponent.Title,
                ExecutionStatus         = LogicalUnitStatusEnum.Initialised,
                LaunchInputs            = null,
                LockDateTime            = DateTime.Now,
                LockUserID         = Guid.NewGuid().ToString(), // TODO: Determine user ID
                LockUserName       = "******",
                RootComponentTitle = registeredComponent.Title,
                PendingOutcome     = null
            };

            var persistedThread = await AppExecution.SaveNewExecutionThreadAsync(thread);

            return(await RedirectResumeExecutionThreadAsync(persistedThread.ID));
        }