Beispiel #1
0
 public static void Init(IApplicationBuilder app, ILogger logger)
 {
     _Logger         = logger;
     _CachingService = app.ApplicationServices.GetService <ICachingService>();
     _KraftGlobalConfigurationSettings = app.ApplicationServices.GetService <KraftGlobalConfigurationSettings>();
     _ModulesCollection = app.ApplicationServices.GetService <KraftModuleCollection>();
 }
Beispiel #2
0
            internal WriteCustomSettings(IDataLoaderContext execContext, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings) : base(execContext, kraftGlobalConfigurationSettings)
            {
                long?  maxFilesSpacePerDashboardInMB = null;
                double?previewHeight = null;
                double?previewWidth  = null;

                if (execContext.DataLoaderContextScoped.CustomSettings.TryGetValue(MAXFILESPACEPERDASHBOARDINMB, out string maxFilesLengthAsString))
                {
                    if (long.TryParse(maxFilesLengthAsString, out long maxFilesLength))
                    {
                        if (maxFilesLength < 0L)
                        {
                            throw new Exception($"{MAXFILESPACEPERDASHBOARDINMB} cannot be less than zero.");
                        }

                        maxFilesSpacePerDashboardInMB = maxFilesLength;
                    }
                }

                MaxFilesSpacePerDashboardInMB = maxFilesSpacePerDashboardInMB;

                if (execContext.DataLoaderContextScoped.CustomSettings.TryGetValue(PREVIEWHEIGHT, out string previewHeightAsString))
                {
                    previewHeight = ParseDouble(previewHeightAsString);
                }

                PreviewHeight = previewHeight;

                if (execContext.DataLoaderContextScoped.CustomSettings.TryGetValue(PREVIEWWIDTHT, out string previewWidthAsString))
                {
                    previewWidth = ParseDouble(previewWidthAsString);
                }

                PreviewWidth = previewWidth;
            }
        protected override List <Dictionary <string, object> > Read(IDataLoaderReadContext execContext)
        {
            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            if (!string.IsNullOrEmpty(execContext.CurrentNode.Read.Select?.Query) && execContext.CurrentNode.Read.Select.Query.Equals("bearer", System.StringComparison.OrdinalIgnoreCase))
            {
                if (execContext.ProcessingContext.InputModel.SecurityModel.IsAuthenticated)//Try to get bearer token only when user is logged in
                {
                    string accessToken = GetAuthAccessToken(execContext);
                    KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings = execContext.PluginServiceManager.GetService <KraftGlobalConfigurationSettings>(typeof(KraftGlobalConfigurationSettings));
                    string authority = kraftGlobalConfigurationSettings.GeneralSettings.Authority;
                    authority = authority.TrimEnd('/');
                    Dictionary <string, object> resultAuth = new Dictionary <string, object>();
                    resultAuth.Add("key", $"{authority}/api/avatar");
                    resultAuth.Add("token", accessToken);
                    resultAuth.Add("servicename", "avatarimage");
                    result.Add(resultAuth);
                    resultAuth = new Dictionary <string, object>();
                    resultAuth.Add("key", $"{authority}");
                    resultAuth.Add("token", accessToken);
                    resultAuth.Add("servicename", "authorizationserver");
                    result.Add(resultAuth);
                    resultAuth = new Dictionary <string, object>();
                    resultAuth.Add("key", $"{authority}/api/user");
                    resultAuth.Add("token", accessToken);
                    resultAuth.Add("servicename", "user");
                    result.Add(resultAuth);
                }
            }

            return(result);
        }
Beispiel #4
0
        internal KraftModule(string directoryName, string moduleName,
                             DependencyInjectionContainer dependencyInjectionContainer,
                             KraftModuleCollection moduleCollection,
                             ICachingService cachingService,
                             KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, ILogger logger)
        {
            _DependencyInjectionContainer = dependencyInjectionContainer;
            _ModuleCollection             = moduleCollection;
            _Logger       = logger;
            DirectoryName = directoryName;
            _KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;

            //dependencies
            Dependencies = new Dictionary <string, IDependable <KraftModule> >();

            //Bundles initialize
            StyleKraftBundle    = null;
            ScriptKraftBundle   = null;
            TemplateKraftBundle = null;

            _ModulePath = Path.Combine(DirectoryName, moduleName);
            if (!Directory.Exists(_ModulePath))
            {
                throw new DirectoryNotFoundException($"The {_ModulePath} path was not found!");
            }

            //read configs and dependencies
            IsInitialized = ReadModuleMetaConfiguration(Path.Combine(_ModulePath, DEPENDENCY_FILE_NAME), _ModulePath);
            if (IsInitialized)
            {
                InitConfiguredPlugins(Key, Path.Combine(_ModulePath, CONFIGURATION_FILE_NAME), cachingService);
            }
        }
Beispiel #5
0
        private void Construct(ICachingService cachingService, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
        {
            string modulePath = Path.Combine(kraftGlobalConfigurationSettings.GeneralSettings.ModulesRootFolder, DirectoryName);

            if (!Directory.Exists(modulePath))
            {
                throw new DirectoryNotFoundException($"The {modulePath} path was not found!");
            }

            //read configs and dependencies
            IsInitialized = ReadModuleMetaConfiguration(Path.Combine(modulePath, DEPENDENCY_FILE_NAME), modulePath);
            if (IsInitialized)
            {
                InitConfiguredPlugins(Key, Path.Combine(modulePath, CONFIGURATION_FILE_NAME), cachingService);

                //process CSS folder
                StyleKraftBundle = ConstructStyleBundle(kraftGlobalConfigurationSettings, Path.Combine(modulePath, CSS_FOLDER_NAME), RESOURCEDEPENDENCY_FILE_NAME);

                //process Scripts folder
                ScriptKraftBundle = ConstructScriptsBundle(kraftGlobalConfigurationSettings, Path.Combine(modulePath, JS_FOLDER_NAME), RESOURCEDEPENDENCY_FILE_NAME);

                //process Template folder
                TemplateKraftBundle = ConstructTmplResBundle(kraftGlobalConfigurationSettings, Path.Combine(modulePath, TEMPLATES_FOLDER_NAME));
            }
        }
Beispiel #6
0
 public KraftModuleCollection(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, DependencyInjectionContainer dependencyInjectionContainer, ILogger logger)
 {
     _KraftModulesCollection          = new Dictionary <string, IDependable <KraftModule> >();
     KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
     _DependencyInjectionContainer    = dependencyInjectionContainer;
     _Logger = logger;
 }
Beispiel #7
0
        internal KraftModule(string directoryName, string moduleName,
                             DependencyInjectionContainer dependencyInjectionContainer,
                             KraftModuleCollection moduleCollection,
                             ICachingService cachingService,
                             KraftDependableModule kraftDependableModule,
                             KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
        {
            _DependencyInjectionContainer = dependencyInjectionContainer;
            DirectoryName = directoryName;
            _KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
            Key = moduleName;
            //dependencies
            Dependencies = new Dictionary <string, KraftModule>();
            foreach (KeyValuePair <string, IDependable <KraftDependableModule> > item in kraftDependableModule.Dependencies)
            {
                Dependencies.Add(item.Key, moduleCollection.GetModule(item.Key));
            }

            DependencyOrderIndex = kraftDependableModule.DependencyOrderIndex;
            KraftModuleRootConf  = kraftDependableModule.KraftModuleRootConf;

            //Bundles initialize
            StyleKraftBundle    = null;
            ScriptKraftBundle   = null;
            TemplateKraftBundle = null;

            ModulePath = Path.Combine(DirectoryName, moduleName);

            //read configs and dependencies
            InitConfiguredPlugins(Key, Path.Combine(ModulePath, CONFIGURATION_FILE_NAME), cachingService);
        }
Beispiel #8
0
 public DirectCallHandler(Ccf.Ck.Models.DirectCall.InputModel inputModel, KraftModuleCollection kraftModuleCollection, INodeSetService nodeSetService, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
 {
     _InputModel                       = inputModel;
     _KraftModuleCollection            = kraftModuleCollection;
     _NodesSetService                  = nodeSetService;
     _KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
 }
Beispiel #9
0
        public void ConfigureServices(IServiceCollection services)
        {
            IServiceProvider serviceProvider = services.UseBindKraft(_Configuration);

            _KraftGlobalConfiguration = serviceProvider.GetService <KraftGlobalConfigurationSettings>();
            EmailSettings emailSettings = new EmailSettings();

            _Configuration.GetSection("EmailSettings").Bind(emailSettings);
            services.AddSingleton(emailSettings);
            if (_KraftGlobalConfiguration.GeneralSettings.RazorAreaAssembly.IsConfigured)
            {
                services.Configure <CookiePolicyOptions>(options =>
                {
                    // This lambda determines whether user consent for non-essential
                    // cookies is needed for a given request.
                    options.CheckConsentNeeded = context => true;
                    // requires using Microsoft.AspNetCore.Http;
                    options.MinimumSameSitePolicy = SameSiteMode.None;
                });
                services.AddControllersWithViews(options =>
                {
                    options.Filters.Add(typeof(CultureActionFilter));
                }).ConfigureApplicationPartManager(ConfigureApplicationParts).AddTagHelpersAsServices();
                services.AddSingleton <DynamicHostRouteTransformer>();
            }
            else
            {
                services.AddControllersWithViews(options =>
                {
                    options.Filters.Add(typeof(CultureActionFilter));
                });
            }
            services.AddHttpClient();
        }
Beispiel #10
0
 public ProcessorMultipartEx(HttpContext httpContext,
                             KraftModuleCollection kraftModuleCollection,
                             ESupportedContentTypes requestContentType,
                             INodeSetService nodeSetService,
                             KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
     : base(httpContext, kraftModuleCollection, requestContentType, nodeSetService, kraftGlobalConfigurationSettings)
 {
 }
        private IIntroContentProvider GetContentProvider(INodePluginContext pluginContext)
        {
            KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings = pluginContext.PluginServiceManager.GetService <KraftGlobalConfigurationSettings>(typeof(KraftGlobalConfigurationSettings));
            string moduleRoot       = Path.Combine(kraftGlobalConfigurationSettings.GeneralSettings.ModulesRootFolder(pluginContext.ProcessingContext.InputModel.Module), pluginContext.ProcessingContext.InputModel.Module);
            string connectionString = pluginContext.OwnContextScoped.CustomSettings["ConnectionString"].Replace("@moduleroot@", moduleRoot);

            return(new BindKraftIntroDbManager(connectionString));
        }
Beispiel #12
0
 public KraftModuleConfigurationSettings(DependencyInjectionContainer dependencyInjectionContainer, ICachingService cachingService,
                                         KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
 {
     _DependencyInjectionContainer = dependencyInjectionContainer;
     _CachingService = cachingService;
     NodeSetSettings = new NodeSetSettings();
     KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
 }
Beispiel #13
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            IProcessingContext        processingContext  = new ProcessingContext(this);
            List <IProcessingContext> processingContexts = new List <IProcessingContext>();

            processingContexts.Add(processingContext);
            _ProcessingContextCollection = new ProcessingContextCollection(processingContexts);
            return(_ProcessingContextCollection);
        }
Beispiel #14
0
 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>();
 }
Beispiel #15
0
 public static ToolSettings GetTool(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kind)
 {
     foreach (ToolSettings tool in kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.Tools)
     {
         if (tool.Kind.Equals(kind, StringComparison.OrdinalIgnoreCase))
         {
             return(tool);
         }
     }
     return(null);
 }
        protected InputModelParameters CreateBaseInputModelParameters(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, ISecurityModel securityModel)
        {
            InputModelParameters inputModelParameters = new InputModelParameters();

            inputModelParameters.QueryCollection  = _QueryCollection;
            inputModelParameters.HeaderCollection = _HeaderCollection;
            inputModelParameters.FormCollection   = _FormCollection;
            inputModelParameters.KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
            inputModelParameters.SecurityModel = securityModel;
            return(inputModelParameters);
        }
        private InputModel CreateInputModel(BatchRequest request, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            if (securityModel == null)
            {
                if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);
            //we expect the routing to be like this:
            //domain.com/startnode/<read|write>/module/nodeset/<nodepath>?lang=de
            string decodedUrl = WebUtility.UrlDecode(request.Url);
            string pattern    = @"(?:http:\/\/.+?\/|https:\/\/.+?\/|www.+?\/)(?:.+?)\/(read|write)*(?:\/)*(.+?)\/(.+?)($|\/.+?)($|\?.+)";
            Regex  regex      = new Regex(pattern);
            var    match      = regex.Match(decodedUrl);

            if (match.Groups[1] != null)
            {
                inputModelParameters.IsWriteOperation = match.Groups[1].Value == "write";
            }
            inputModelParameters.Module   = match.Groups[2].Value;
            inputModelParameters.Nodeset  = match.Groups[3].Value;
            inputModelParameters.Nodepath = string.IsNullOrEmpty(match.Groups[4].Value) ? string.Empty : match.Groups[4].Value.Substring(1);
            string paramsStr = string.IsNullOrEmpty(match.Groups[5].Value) ? string.Empty : match.Groups[5].Value.Substring(1);

            if (!string.IsNullOrEmpty(paramsStr))
            {
                string[] parameters = paramsStr.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var parameter in parameters)
                {
                    string[] kvp   = parameter.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    string   key   = kvp[0];
                    string   value = kvp[1];

                    if (key.Equals(kraftRequestFlagsKey, StringComparison.CurrentCultureIgnoreCase))
                    {
                        inputModelParameters.LoaderType = GetLoaderContent(value);
                    }
                    else
                    {
                        inputModelParameters.QueryCollection.Add(key, value);
                    }
                }
            }
            return(new InputModel(inputModelParameters));
        }
Beispiel #18
0
        internal static void MakeRouters(IApplicationBuilder app, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
        {
            RouteHandler routesHandler;
            ToolSettings tool = GetTool(kraftGlobalConfigurationSettings, "recorder"); //////////////////////////////Recorder/////////////////////////////

            if (tool != null && tool.Enabled)                                          //Recorder enabled from configuration
            {
                kraftGlobalConfigurationSettings.GeneralSettings.ToolsSettings.RequestRecorder.IsEnabled = tool.Enabled;
                routesHandler = new RouteHandler(RecorderDelegate.ExecutionDelegate(app, kraftGlobalConfigurationSettings));

                RouteBuilder routesBuilder = new RouteBuilder(app, routesHandler);

                //we expect the routing to be like this:
                //domain.com/recorder/0|1|2?lang=de
                routesBuilder.MapRoute(
                    name: "recorder",
                    template: tool.Url,
                    defaults: null,
                    constraints: null,
                    dataTokens: new { key = "recorder" }
                    );
                app.UseRouter(routesBuilder.Build());
            }
            tool = GetTool(kraftGlobalConfigurationSettings, "signals"); //////////////////////////////Signals/////////////////////////////
            if (tool != null && tool.Enabled)                            //Signals enabled from configuration
            {
                routesHandler = new RouteHandler(SignalDelegate.ExecutionDelegate(app, kraftGlobalConfigurationSettings));

                RouteBuilder routesBuilder = new RouteBuilder(app, routesHandler);

                //we expect the routing to be like this:
                //domain.com/signals/0|1|2?lang=de
                routesBuilder.MapRoute(
                    name: "signals",
                    template: tool.Url,
                    defaults: null,
                    constraints: null,
                    dataTokens: new { key = "signals" }
                    );
                app.UseRouter(routesBuilder.Build());
            }
            //tool = GetTool(kraftGlobalConfigurationSettings, "errors");//////////////////////////////Errors/////////////////////////////
            //if (tool != null && tool.Enabled)//Errors enabled from configuration
            //{
            //}
            tool = GetTool(kraftGlobalConfigurationSettings, "profiler"); //////////////////////////////Profiler/////////////////////////////
            if (tool != null && tool.Enabled)                             //Profiler enabled from configuration
            {
                app.UseBindKraftProfiler();
            }
        }
Beispiel #19
0
        public ParameterResolverValue GSetting(HostInterface _ctx, ParameterResolverValue[] args)
        {
            KraftGlobalConfigurationSettings kgcf = null;
            var ctx = _ctx as IDataLoaderContext;

            if (ctx != null)
            {
                kgcf = ctx.PluginServiceManager.GetService <KraftGlobalConfigurationSettings>(typeof(KraftGlobalConfigurationSettings));
            }
            else
            {
                var nctx = _ctx as INodePluginContext;
                if (nctx != null)
                {
                    kgcf = nctx.PluginServiceManager.GetService <KraftGlobalConfigurationSettings>(typeof(KraftGlobalConfigurationSettings));
                }
            }
            if (kgcf == null)
            {
                throw new Exception("Cannot obtain Kraft global settings");
            }
            if (args.Length != 1)
            {
                throw new ArgumentException($"GSetting accepts one argument, but {args.Length} were given.");
            }
            var name = args[0].Value as string;

            if (name == null)
            {
                throw new ArgumentException($"GSetting argument must be string - the name of the global kraft setting to obtain.");
            }
            switch (name)
            {
            case "EnvironmentName":
                return(new ParameterResolverValue(kgcf.EnvironmentSettings.EnvironmentName));

            case "ContentRootPath":
                return(new ParameterResolverValue(kgcf.EnvironmentSettings.ContentRootPath));

            case "ApplicationName":
                return(new ParameterResolverValue(kgcf.EnvironmentSettings.ApplicationName));

            case "StartModule":
                return(new ParameterResolverValue(kgcf.GeneralSettings.DefaultStartModule));

            case "ClientId":
                return(new ParameterResolverValue(kgcf.GeneralSettings.ClientId));
            }
            throw new ArgumentException($"The setting {name} is not supported");
        }
 public ProcessorBase(HttpContext httpContext, KraftModuleCollection kraftModuleCollection, ESupportedContentTypes requestContentType, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings)
 {
     _KraftModuleCollection            = kraftModuleCollection;
     _HttpContext                      = httpContext;
     _RequestMethod                    = (ERequestMethod)Enum.Parse(typeof(ERequestMethod), httpContext.Request.Method);
     _RequestContentType               = requestContentType;
     _ProcessingContextCollection      = new ProcessingContextCollection(new List <IProcessingContext>());
     _KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
     //AntiforgeryService
     //KeyValuePair<string, string> cookie = httpContext.Request.Cookies.FirstOrDefault(c => c.Key.Contains("XSRF-TOKEN"));
     //if (cookie.Value != null)
     //{
     //    httpContext.Request.Headers.Add("RequestVerificationToken", new StringValues(cookie.Value));
     //}
 }
Beispiel #21
0
            internal WriteCustomSettings(IDataLoaderContext execContext, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings) : base(execContext, kraftGlobalConfigurationSettings)
            {
                Dictionary <string, long> fileRestrictions = new Dictionary <string, long>();
                double?previewHeight = null;
                double?previewWidth  = null;

                if (execContext.DataLoaderContextScoped.CustomSettings.TryGetValue(MAXFILESPACEPERDASHBOARDINMB, out string parameters))
                {
                    long            value;
                    Regex           keyValueRegex   = new Regex(@"{(\s*(?<key>[a-zA-Z]+)\s*:\s*(?<value>[0-9]+)\s*)}");
                    MatchCollection matchCollection = keyValueRegex.Matches(parameters);

                    foreach (Match match in matchCollection)
                    {
                        if (long.TryParse(match.Groups["value"].ToString(), out value))
                        {
                            if (value < 0L)
                            {
                                throw new Exception("Invalid configuration for uploading files. Restriction cannot be less than zero.");
                            }

                            fileRestrictions.Add(match.Groups["key"].ToString(), value);
                        }
                        else
                        {
                            throw new Exception("Invalid configuration for uploading files.");
                        }
                    }
                }

                FileRestrictions = fileRestrictions;

                if (execContext.DataLoaderContextScoped.CustomSettings.TryGetValue(PREVIEWHEIGHT, out string previewHeightAsString))
                {
                    previewHeight = ParseDouble(previewHeightAsString);
                }

                PreviewHeight = previewHeight;

                if (execContext.DataLoaderContextScoped.CustomSettings.TryGetValue(PREVIEWWIDTHT, out string previewWidthAsString))
                {
                    previewWidth = ParseDouble(previewWidthAsString);
                }

                PreviewWidth = previewWidth;
            }
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            List <InputModel>   inputModels   = new List <InputModel>();
            List <BatchRequest> batchRequests = new List <BatchRequest>();

            if (_RequestContentType == ESupportedContentTypes.JSON)
            {
                batchRequests = GetBodyJson <List <BatchRequest> >(_HttpContext.Request);
            }
            foreach (BatchRequest batchRequest in batchRequests)
            {
                InputModel inputModel = CreateInputModel(batchRequest, kraftGlobalConfigurationSettings, kraftRequestFlagsKey, securityModel);
                inputModels.Add(inputModel);
            }
            _ProcessingContextCollection = new ProcessingContextCollection(CreateProcessingContexts(inputModels));
            return(_ProcessingContextCollection);
        }
Beispiel #23
0
        public void ConstructResources(ICachingService cachingService, KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string startDepFile, bool isScript)
        {
            if (IsInitialized)//This is not a module with proper configuration files
            {
                if (isScript)
                {
                    //process Scripts folder
                    ScriptKraftBundle = ConstructScriptsBundle(kraftGlobalConfigurationSettings, Path.Combine(_ModulePath, JS_FOLDER_NAME), startDepFile);

                    //process Template folder
                    TemplateKraftBundle = ConstructTmplResBundle(kraftGlobalConfigurationSettings, Path.Combine(_ModulePath, TEMPLATES_FOLDER_NAME));
                }
                else
                {
                    //process CSS folder
                    StyleKraftBundle = ConstructStyleBundle(kraftGlobalConfigurationSettings, Path.Combine(_ModulePath, CSS_FOLDER_NAME), startDepFile);
                }
            }
        }
Beispiel #24
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            if (securityModel == null)
            {
                if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);

            inputModelParameters = ExtendInputModelParameters(inputModelParameters);
            if (_RequestContentType == ESupportedContentTypes.JSON)
            {
                inputModelParameters.Data = GetBodyJson <Dictionary <string, object> >(_HttpContext.Request);
            }
            else
            {
                inputModelParameters.Data = _FormCollection;
            }
            inputModelParameters.FormCollection = _FormCollection;
            inputModelParameters.LoaderType     = GetLoaderType(kraftRequestFlagsKey);

            RouteData routeData = _HttpContext.GetRouteData();

            if (routeData != null)
            {
                string routeDataKey = routeData.DataTokens["key"]?.ToString()?.ToLower();
                if (!string.IsNullOrEmpty(routeDataKey))
                {
                    string signal           = routeData.Values[Constants.RouteSegmentConstants.RouteModuleSignalParameter]?.ToString();
                    bool   isWriteOperation = routeDataKey.Equals(Constants.RouteSegmentConstants.RouteDataTokenSignalWrite);
                    return(PrepareSignals(inputModelParameters.Module, signal, isWriteOperation, inputModelParameters));
                }
            }
            //Return only empty collection
            return(new ProcessingContextCollection(new List <IProcessingContext>()));
        }
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            Dictionary <string, object> files       = ResolveMultipartAsJson();
            List <InputModel>           inputModels = new List <InputModel>();

            if (files != null)
            {
                foreach (string key in files.Keys)
                {
                    if (files[key] is IPostedFile postedFile)
                    {
                        if (securityModel == null)
                        {
                            if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                            {
                                securityModel = new SecurityModel(_HttpContext);
                            }
                            else
                            {
                                securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                            }
                        }
                        InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);
                        inputModelParameters             = ExtendInputModelParameters(inputModelParameters);
                        inputModelParameters.LoaderType |= ELoaderType.DataLoader; //TODO Not override passed in flags

                        foreach (string metaInfoKey in postedFile.MetaInfo.Keys)
                        {
                            inputModelParameters.Data.Add(metaInfoKey, postedFile.MetaInfo[metaInfoKey]);
                        }
                        inputModelParameters.Data.Add(key, postedFile);

                        inputModels.Add(new InputModel(inputModelParameters));
                    }
                }
            }
            _ProcessingContextCollection = new ProcessingContextCollection(CreateProcessingContexts(inputModels));
            return(_ProcessingContextCollection);
        }
        public IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            InputModelParameters inputModelParameters = new InputModelParameters();

            inputModelParameters.KraftGlobalConfigurationSettings = kraftGlobalConfigurationSettings;
            inputModelParameters.SecurityModel    = securityModel;
            inputModelParameters.Module           = _InputModel.Module;
            inputModelParameters.Nodeset          = _InputModel.Nodeset;
            inputModelParameters.Nodepath         = _InputModel.Nodepath;
            inputModelParameters.IsWriteOperation = _InputModel.IsWriteOperation;
            inputModelParameters.QueryCollection  = _InputModel.QueryCollection;
            inputModelParameters.Data             = _InputModel.Data;
            inputModelParameters.LoaderType       = ELoaderType.DataLoader;

            IProcessingContext processingContext = new ProcessingContext(this);

            processingContext.InputModel = new InputModel(inputModelParameters);
            List <IProcessingContext> processingContexts = new List <IProcessingContext>(1);

            processingContexts.Add(processingContext);
            return(new ProcessingContextCollection(processingContexts));
        }
Beispiel #27
0
        private StyleKraftBundle ConstructStyleBundle(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string resFolderPath, string resProfileFileName)
        {
            string resProfilePhysFileName = Path.Combine(resFolderPath, resProfileFileName);

            if (Directory.Exists(resFolderPath) && File.Exists(resProfilePhysFileName))
            {
                StyleKraftBundle resBundle = new StyleKraftBundle();
                resBundle.ContentRootPath = kraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath;
                //KraftBundle resBundle = new StyleKraftBundle() { ContentRootPath = _KraftEnvironmentSettings.ContentRootPath };
                KraftBundleProfiles resBundleProfile = resBundle as KraftBundleProfiles;
                resBundleProfile.ContentRootPath = kraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath;
                if (resBundleProfile != null)
                {
                    resBundleProfile.StartDirPath = resFolderPath;
                    resBundleProfile.ProfileFiles = new List <string> {
                        resProfileFileName, RESOURCEDEPENDENCY_FILE_NAME
                    };                                                                                                     //The default should be last
                    return(resBundle);
                }
            }
            return(null);
        }
Beispiel #28
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);
        }
Beispiel #29
0
        private ScriptKraftBundle ConstructScriptsBundle(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string resFolderPath, string resProfileFileName)
        {
            string resProfilePhysFileName = Path.Combine(resFolderPath, resProfileFileName);

            if (Directory.Exists(resFolderPath) && File.Exists(resProfilePhysFileName))
            {
                ScriptKraftBundle resBundle = new ScriptKraftBundle();
                resBundle.ContentRootPath = kraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath;
                //KraftBundle resBundle = new StyleKraftBundle() { ContentRootPath = _KraftEnvironmentSettings.ContentRootPath };
                KraftBundleProfiles resBundleProfile = resBundle as KraftBundleProfiles;
                resBundleProfile.ContentRootPath = kraftGlobalConfigurationSettings.EnvironmentSettings.ContentRootPath;
                if (resBundleProfile != null)
                {
                    resBundleProfile.StartDirPath = resFolderPath;
                    resBundleProfile.ProfileFiles = new List <string> {
                        resProfileFileName
                    };
                    return(resBundle);
                }
            }
            return(null);
        }
Beispiel #30
0
        public override IProcessingContextCollection GenerateProcessingContexts(KraftGlobalConfigurationSettings kraftGlobalConfigurationSettings, string kraftRequestFlagsKey, ISecurityModel securityModel = null)
        {
            if (securityModel == null)
            {
                if (kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection.RequireAuthorization)
                {
                    securityModel = new SecurityModel(_HttpContext);
                }
                else
                {
                    securityModel = new SecurityModelMock(kraftGlobalConfigurationSettings.GeneralSettings.AuthorizationSection);
                }
            }
            InputModelParameters inputModelParameters = CreateBaseInputModelParameters(kraftGlobalConfigurationSettings, securityModel);

            inputModelParameters                = ExtendInputModelParameters(inputModelParameters);
            inputModelParameters.Data           = GetBodyJson <Dictionary <string, object> >(_HttpContext.Request);
            inputModelParameters.FormCollection = _FormCollection;
            inputModelParameters.LoaderType     = GetLoaderType(kraftRequestFlagsKey);
            if (inputModelParameters.LoaderType == ELoaderType.None)
            {
                inputModelParameters.LoaderType = ELoaderType.ViewLoader;
            }
            RouteData routeData = _HttpContext.GetRouteData();

            if (routeData != null)
            {
                inputModelParameters.BindingKey = routeData.Values[Constants.RouteSegmentConstants.RouteBindingkey] as string;
            }
            IProcessingContext processingContext = new ProcessingContext(this);

            processingContext.InputModel = new InputModel(inputModelParameters);
            List <IProcessingContext> processingContexts = new List <IProcessingContext>(1);

            processingContexts.Add(processingContext);
            _ProcessingContextCollection = new ProcessingContextCollection(processingContexts);
            return(_ProcessingContextCollection);
        }