internal static Func <Ccf.Ck.Models.DirectCall.InputModel, Task <Ccf.Ck.Models.DirectCall.ReturnModel> > ExecutionDelegateDirect(IApplicationBuilder builder, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings) { Func <Ccf.Ck.Models.DirectCall.InputModel, Task <Ccf.Ck.Models.DirectCall.ReturnModel> > directDelegate = (inputModel) => { TransactionScopeContext transactionScope = new TransactionScopeContext(builder.ApplicationServices.GetService <IServiceCollection>()); INodeSetService nodesSetService = builder.ApplicationServices.GetService <INodeSetService>(); KraftModuleCollection kraftModuleCollection = builder.ApplicationServices.GetService <KraftModuleCollection>(); ReturnModel returnModel = null; DirectCallHandler dcHandler = new DirectCallHandler(inputModel, kraftModuleCollection, nodesSetService, kraftGlobalConfigurationSettings); IProcessingContextCollection processingContextCollection = dcHandler.GenerateProcessingContexts(null); foreach (IProcessingContext processingContext in processingContextCollection.ProcessingContexts) { dcHandler.Execute(processingContext, transactionScope); returnModel = new Models.DirectCall.ReturnModel { Data = processingContext.ReturnModel.Data, BinaryData = processingContext.ReturnModel.BinaryData, IsSuccessful = processingContext.ReturnModel.Status.IsSuccessful }; return(Task.FromResult(returnModel)); } return(Task.FromResult(returnModel)); }; return(directDelegate); }
public ProcessorNodeBase(HttpContext httpContext, KraftModuleCollection kraftModuleCollection, ESupportedContentTypes requestContentType, INodeSetService nodeSetService) : base(httpContext, kraftModuleCollection, requestContentType) { _QueryCollection = httpContext.Request.Query.Convert2Dictionary(); _HeaderCollection = httpContext.Request.Headers.Convert2Dictionary(); _FormCollection = (httpContext.Request.HasFormContentType) ? httpContext.Request?.Form?.Convert2Dictionary() : new Dictionary <string, object>(); _NodesSetService = nodeSetService; }
internal void ExecuteSignals(string module, string signal) { INodeSetService nodeSetService = _ServiceProvider.GetService <INodeSetService>(); KraftModuleCollection kraftModuleCollection = _ServiceProvider.GetService <KraftModuleCollection>(); DefaultHttpContext httpContext = new DefaultHttpContext(); httpContext.Request.Method = "GET"; RouteData routeData = new RouteData(); routeData.Values.Add(Constants.RouteSegmentConstants.RouteModule, module); routeData.Values.Add(Constants.RouteSegmentConstants.RouteModuleSignalParameter, signal); routeData.DataTokens.Add("key", Constants.RouteSegmentConstants.RouteDataTokenSignalRead); httpContext.Features[typeof(IRoutingFeature)] = new RoutingFeature() { RouteData = routeData, }; ProcessorSignal processorSignal = new ProcessorSignal(httpContext, kraftModuleCollection, ESupportedContentTypes.JSON, nodeSetService); IProcessingContextCollection processingContextCollection = processorSignal.GenerateProcessingContexts(_KraftGlobalConfigurationSettings, string.Empty, new SecurityModelMock(_KraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection)); RequestExecutor requestExecutor = new RequestExecutor(_ServiceProvider, httpContext, _KraftGlobalConfigurationSettings); foreach (IProcessingContext processingContext in processingContextCollection.ProcessingContexts) { requestExecutor.ExecuteReEntrance(processingContext); } }
public DirectCallHandler(Ccf.Ck.Models.DirectCall.InputModel inputModel, KraftModuleCollection kraftModuleCollection, INodeSetService nodeSetService, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings) { _InputModel = inputModel; _KraftModuleCollection = kraftModuleCollection; _NodesSetService = nodeSetService; _KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings; }
public ProcessorMultipartEx(HttpContext httpContext, KraftModuleCollection kraftModuleCollection, ESupportedContentTypes requestContentType, INodeSetService nodeSetService, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings) : base(httpContext, kraftModuleCollection, requestContentType, nodeSetService, kraftGlobalConfigurationSettings) { }
public RequestExecutor(IServiceProvider serviceProvider, HttpContext httpContext, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings) { _ServiceProvider = serviceProvider; _HttpContext = httpContext; _KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings; _TransactionScope = new TransactionScopeContext(_ServiceProvider.GetService <IServiceCollection>()); _NodesSetService = _ServiceProvider.GetService <INodeSetService>(); _KraftModuleCollection = _ServiceProvider.GetService <KraftModuleCollection>(); }
public ProcessorNodeBase(HttpContext httpContext, KraftModuleCollection kraftModuleCollection, ESupportedContentTypes requestContentType, INodeSetService nodeSetService, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings) : base(httpContext, kraftModuleCollection, requestContentType, kraftGlobalConfigurationSettings) { _QueryCollection = httpContext.Request.Query.Convert2Dictionary(); _HeaderCollection = httpContext.Request.Headers.Convert2Dictionary(); _FormCollection = (httpContext.Request.HasFormContentType) ? httpContext.Request?.Form?.Convert2Dictionary() : new Dictionary <string, object>(); _ServerCollection = new Dictionary <string, object>(); _ServerCollection.Add("REMOTE_ADDR", httpContext.Connection.RemoteIpAddress); _ServerCollection.Add("SERVER_HOST_KEY", kraftGlobalConfigurationSettings.GeneralSettings.ServerHostKey); _NodesSetService = nodeSetService; }
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); }
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); }
private static ModuleSignalDetails GenerateDetails(string moduleKey, KraftModuleSignal kraftModuleSignal, INodeSetService nodeSetService) { ModuleSignalDetails moduleSignalDetails = new ModuleSignalDetails(); LoadedNodeSet nodeSet = nodeSetService.LoadNodeSet(moduleKey, kraftModuleSignal.NodeSet, kraftModuleSignal.NodePath); if (nodeSet.StartNode.Read != null) { moduleSignalDetails.Read = nodeSet.StartNode.Read; moduleSignalDetails.Read.Parameters = nodeSet.StartNode.Parameters; //moduleSignalDetails.InitRead(); } if (nodeSet.StartNode.Write != null) { moduleSignalDetails.Write = nodeSet.StartNode.Write; moduleSignalDetails.Write.Parameters = nodeSet.StartNode.Parameters; //moduleSignalDetails.InitWrite(); } return(moduleSignalDetails); }
public ProcessorNodeSingle(HttpContext httpContext, KraftModuleCollection kraftModuleCollection, ESupportedContentTypes requestContentType, INodeSetService nodeSetService) : base(httpContext, kraftModuleCollection, requestContentType, nodeSetService) { }
internal abstract ProcessorBase CreateProcessor(HttpContext httpContext, KraftModuleCollection kraftModuleCollection, INodeSetService nodesSetService);
internal override ProcessorBase CreateProcessor(HttpContext httpContext, KraftModuleCollection kraftModuleCollection, INodeSetService nodesSetService) { RouteData routeData = httpContext.GetRouteData(); //see class: KraftRouteBuilder //In KraftRouteBuilder all routings are defined ESupportedContentTypes contentType = MapContentType(httpContext); if (routeData.Values != null) { string routeDataKey = routeData.DataTokens["key"]?.ToString()?.ToLower(); if (!string.IsNullOrEmpty(routeDataKey)) { switch (routeDataKey) { case Constants.RouteSegmentConstants.RouteDataTokenWarmup: { return(new ProcessorWarmup(httpContext, kraftModuleCollection, contentType)); } case Constants.RouteSegmentConstants.RouteDataTokenSignal: case Constants.RouteSegmentConstants.RouteDataTokenSignalRead: case Constants.RouteSegmentConstants.RouteDataTokenSignalWrite: { return(new ProcessorSignal(httpContext, kraftModuleCollection, contentType, nodesSetService)); } case Constants.RouteSegmentConstants.RouteDataTokenView: { return(new ProcessorView(httpContext, kraftModuleCollection, contentType, nodesSetService)); } //case Constants.RouteSegmentConstants.RouteDataTokenResource: // { // //return new ProcessorResource(httpContext, kraftModuleCollection); // break; // } case Constants.RouteSegmentConstants.RouteDataTokenBatch: { return(new ProcessorNodeBatch(httpContext, kraftModuleCollection, contentType, nodesSetService)); } default: { //Here we have the CoreKraft configured entry point switch (contentType) { case ESupportedContentTypes.JSON: case ESupportedContentTypes.FORM_URLENCODED: { return(new ProcessorNodeSingle(httpContext, kraftModuleCollection, contentType, nodesSetService)); } case ESupportedContentTypes.FORM_MULTIPART: { return(new ProcessorMultipart(httpContext, kraftModuleCollection, contentType, nodesSetService)); } default: { return(new ProcessorUnknown(httpContext, kraftModuleCollection, contentType)); } } } } } } return(new ProcessorUnknown(httpContext, kraftModuleCollection, contentType)); }
public DirectCallHandler(Ccf.Ck.Models.DirectCall.InputModel inputModel, KraftModuleCollection kraftModuleCollection, INodeSetService nodeSetService) { _InputModel = inputModel; _KraftModuleCollection = kraftModuleCollection; _NodesSetService = nodeSetService; }