示例#1
0
        internal static RequestDelegate ExecutionDelegate(IApplicationBuilder app, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
        {
            INodeSetService       nodeSetService    = app.ApplicationServices.GetService <INodeSetService>();
            KraftModuleCollection modulesCollection = app.ApplicationServices.GetService <KraftModuleCollection>();
            SignalsResponse       signalsResponse   = GenerateSignalResponse(kraftGlobalConfigurationSettings, modulesCollection, nodeSetService);
            string message = JsonSerializer.Serialize <SignalsResponse>(signalsResponse);

            if (!string.IsNullOrEmpty(message))
            {
                message = message.Replace(@"\u0027", "'");
            }
            RequestDelegate requestDelegate = async httpContext =>
            {
                const string contentType = "application/json";
                int          statusCode  = 200;
                httpContext.Response.StatusCode  = statusCode;
                httpContext.Response.ContentType = contentType;
                await httpContext.Response.WriteAsync(message);
            };

            return(requestDelegate);
        }
示例#2
0
        private static SignalsResponse GenerateSignalResponse(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, KraftModuleCollection modulesCollection, INodeSetService nodeSetService)
        {
            SignalsResponse signalsResponse = new SignalsResponse
            {
                HostingServiceSettings = kraftGlobalConfigurationSettings.GeneralSettings.HostingServiceSettings,
                SignalSettings         = kraftGlobalConfigurationSettings.GeneralSettings.SignalSettings
            };

            List <SignalWithType> signalsWithTypes = new List <SignalWithType>();

            foreach (HostingServiceSetting hostingServiceSetting in signalsResponse.HostingServiceSettings)
            {
                //Collect signals
                foreach (string signal in hostingServiceSetting.Signals ?? new List <string>())
                {
                    SignalWithType signalWithType = new SignalWithType
                    {
                        SignalType = HOSTINGSERVICESTARTTYPE,
                        SignalName = signal,
                        Interval   = hostingServiceSetting.IntervalInMinutes
                    };
                    signalsWithTypes.Add(signalWithType);
                }
            }

            //Collect signals
            foreach (string signal in signalsResponse.SignalSettings.OnSystemStartup ?? new List <string>())
            {
                SignalWithType signalWithType = new SignalWithType
                {
                    SignalType = ONSYSTEMSTARTUPTYPE,
                    SignalName = signal
                };
                signalsWithTypes.Add(signalWithType);
            }

            //Collect signals
            foreach (string signal in signalsResponse.SignalSettings.OnSystemShutdown ?? new List <string>())
            {
                SignalWithType signalWithType = new SignalWithType
                {
                    SignalType = ONSYSTEMSHUTDOWNTYPE,
                    SignalName = signal
                };
                signalsWithTypes.Add(signalWithType);
            }

            //Find all signals in the nodesets
            signalsResponse.ModuleSignals = new List <ModuleSignal>();
            foreach (KraftModule module in modulesCollection.GetSortedModules())
            {
                foreach (KraftModuleSignal kraftModuleSignal in module.KraftModuleRootConf.Signals ?? new List <KraftModuleSignal>())
                {
                    ModuleSignal moduleSignal = new ModuleSignal
                    {
                        ModuleName  = module.Key,
                        NodeKey     = kraftModuleSignal.Key,
                        NodePath    = kraftModuleSignal.NodePath,
                        NodeSet     = kraftModuleSignal.NodeSet,
                        Maintenance = kraftModuleSignal.Maintenance,
                        Details     = GenerateDetails(module.Key, kraftModuleSignal, nodeSetService)
                    };
                    //(www)myserver.com/node/<read/write>/signal/board/nodekey?sysrequestcontent=ffff
                    moduleSignal.Url         = $"/{kraftGlobalConfigurationSettings.GeneralSettings.KraftUrlSegment}/{moduleSignal.Details.OperationReadWrite()}/signal/{module.Key}/{kraftModuleSignal.Key}?sysrequestcontent=ffff";
                    moduleSignal.ExecuteWhen = CalcExecuteWhen(signalsWithTypes, kraftModuleSignal.Key);
                    signalsResponse.ModuleSignals.Add(moduleSignal);
                }
            }
            return(signalsResponse);
        }