Example #1
0
        public async Task <IProcessingContext> ExecuteAsync(LoadedNodeSet loaderContext, IProcessingContext processingContext, IPluginServiceManager pluginServiceManager, IPluginsSynchronizeContextScoped contextScoped, INode currentNode)
        {
            if (currentNode is View view)
            {
                string          cacheKey       = processingContext.InputModel.Module + processingContext.InputModel.NodeSet + processingContext.InputModel.Nodepath + view.BindingKey + "_View";
                ICachingService cachingService = pluginServiceManager.GetService <ICachingService>(typeof(ICachingService));
                string          cachedView     = cachingService.Get <string>(cacheKey);
                if (cachedView == null)
                {
                    string directoryPath = Path.Combine(
                        processingContext.InputModel.KraftGlobalConfigurationSettings.GeneralSettings.ModulesRootFolder,
                        processingContext.InputModel.Module,
                        "Views");

                    PhysicalFileProvider fileProvider = new PhysicalFileProvider(directoryPath);
                    cachedView = File.ReadAllText(Path.Combine(directoryPath, view.Settings.Path));
                    cachingService.Insert(cacheKey, cachedView, fileProvider.Watch(view.Settings.Path));
                }
                IResourceModel resourceModel = new ResourceModel();
                resourceModel.Content = cachedView;
                resourceModel.SId     = $"node/view/{processingContext.InputModel.Module}/{processingContext.InputModel.NodeSet}/{processingContext.InputModel.Nodepath}/{view.BindingKey}";
                processingContext.ReturnModel.Views.Add(view.BindingKey, resourceModel);
            }
            else
            {
                processingContext.ReturnModel.Status.StatusResults.Add(new StatusResult {
                    StatusResultType = EStatusResult.StatusResultError, Message = "Current node is null or not OfType(View)"
                });
                throw new InvalidDataException("HtmlViewSynchronizeContextLocalImp.CurrentNode is null or not OfType(View)");
            }
            return(await Task.FromResult(processingContext));
        }
Example #2
0
        public async Task <IProcessingContext> ExecuteAsync(
            LoadedNodeSet loadedNodeSet,
            IProcessingContext processingContext,
            IPluginServiceManager pluginServiceManager,
            IPluginAccessor <IDataLoaderPlugin> externalService,
            IPluginAccessor <INodePlugin> customService
            )
        {
            _dataIteratorContext.LoadedNodeSet            = loadedNodeSet;
            _dataIteratorContext.ProcessingContext        = processingContext;
            _dataIteratorContext.PluginServiceManager     = pluginServiceManager;
            _dataIteratorContext.DataLoaderPluginAccessor = externalService;
            _dataIteratorContext.CustomPluginAccessor     = customService;
            _dataIteratorContext.CheckNulls();

            // dataIteratorContext already has a reference to processingContext.ReturrnModel.Data,
            // that's why previous implementation with assigning the retturn result from Begin(Read\Write)Operation to it is obsolete.

            if (processingContext.InputModel.IsWriteOperation == false)
            {
                BeginReadOperation(_dataIteratorContext);
            }
            else if (processingContext.InputModel.IsWriteOperation == true)
            {
                BeginWriteOperation(_dataIteratorContext);
            }

            return(await Task.FromResult(processingContext));
        }
Example #3
0
        public void Execute(IProcessingContext processingContext, ITransactionScopeContext transactionScopeContext)
        {
            KraftModule   loadedModule  = _KraftModuleCollection.GetModule(processingContext.InputModel.Module);
            LoadedNodeSet loadedNodeSet = _NodesSetService.LoadNodeSet(
                processingContext.InputModel.Module,
                processingContext.InputModel.NodeSet,
                processingContext.InputModel.Nodepath);
            StringBuilder sb;

            if (!CheckValidity(processingContext, loadedModule, loadedNodeSet, out sb))
            {
                PluginAccessorImp <IDataLoaderPlugin> externalService = new PluginAccessorImp <IDataLoaderPlugin>(transactionScopeContext, loadedModule.ModuleSettings);
                PluginAccessorImp <INodePlugin>       customService   = new PluginAccessorImp <INodePlugin>(transactionScopeContext, loadedModule.ModuleSettings);
                INodeTaskExecutor taskExecutor = new NodeTaskExecutor(transactionScopeContext, loadedModule.ModuleSettings);
                taskExecutor.Execute(loadedNodeSet, processingContext, externalService, customService);
            }
            else
            {
                processingContext.ReturnModel.Status.IsSuccessful = false;
                processingContext.ReturnModel.Status.StatusResults.Add(new StatusResult()
                {
                    Message = sb.ToString(), StatusResultType = SysPlugins.Interfaces.Packet.StatusResultEnum.EStatusResult.StatusResultError
                });
            }
        }
Example #4
0
        public void Execute(
            LoadedNodeSet loaderContextDefinition,
            IProcessingContext processingContext,
            IPluginAccessor <IDataLoaderPlugin> dataLoaderAccessor,
            IPluginAccessor <INodePlugin> pluginAccessor)
        {
            _CollectiveCall = true;
            //Check for null values
            GenericUtilities.CheckNullOrEmpty(loaderContextDefinition, true);
            GenericUtilities.CheckNullOrEmpty(processingContext, true);
            GenericUtilities.CheckNullOrEmpty(_TransactionScope.PluginServiceManager, true);

            try
            {
                if (processingContext.InputModel.LoaderType.HasFlag(ELoaderType.DataLoader))
                {
                    ExecuteNodeData(loaderContextDefinition, processingContext, dataLoaderAccessor, pluginAccessor);
                }

                if (processingContext.InputModel.LoaderType.HasFlag(ELoaderType.ViewLoader))
                {
                    ExecuteNodeView(loaderContextDefinition, processingContext);
                }

                //if (processingContext.InputModel.LoaderType.HasFlag(ELoaderType.LookupLoader))
                //{
                //    if (loaderContextDefinition.StartNode != null && loaderContextDefinition.StartNode.HasLookup())
                //    {
                //        using (KraftProfiler.Current.Step("Execution time loading lookups: "))
                //        {
                //            foreach (Lookup lookup in loaderContextDefinition.StartNode.Lookups)
                //            {
                //                ISystemPlugin systemPlugin = Utilities.GetPlugin<ISystemPlugin>(lookup.SystemPluginName, _TransactionScope.DependencyInjectionContainer, _KraftModuleConfigurationSettings, ELoaderType.LookupLoader);
                //                GenericUtilities.CheckNullOrEmpty(systemPlugin, true);
                //                IPluginsSynchronizeContextScoped synchronizeContextScoped = await _TransactionScope.GetSynchronizeContextScopedAsync(lookup.SystemPluginName, ELoaderType.LookupLoader, _KraftModuleConfigurationSettings, systemPlugin);
                //                GenericUtilities.CheckNullOrEmpty(synchronizeContextScoped, true);
                //                await systemPlugin.ExecuteAsync(loaderContextDefinition, processingContext, _TransactionScope.PluginServiceManager, synchronizeContextScoped, lookup);
                //            }
                //        }
                //    }
                //}

                _TransactionScope.CommitTransactions();
            }
            catch (Exception ex)
            {
                processingContext.ReturnModel.Status.IsSuccessful = false;
                processingContext.ReturnModel.Status.StatusResults.Add(new StatusResult {
                    StatusResultType = EStatusResult.StatusResultError, Message = ex.Message
                });
                _TransactionScope.RollbackTransactions();
                KraftLogger.LogError(ex.Message, ex);
            }
            finally
            {
                _CollectiveCall = false;
            }
        }
Example #5
0
 private void ExecuteNodeViewPrivate(LoadedNodeSet loaderContextDefinition, IProcessingContext processingContext, View view)
 {
     if (view != null)
     {
         ISystemPlugin systemPlugin = Utilities.GetPlugin <ISystemPlugin>(view.SystemPluginName, _TransactionScope.DependencyInjectionContainer, _KraftModuleConfigurationSettings, ELoaderType.ViewLoader);
         GenericUtilities.CheckNullOrEmpty(systemPlugin, true);
         IPluginsSynchronizeContextScoped synchronizeContextScoped = _TransactionScope.GetSynchronizeContextScopedAsync(view.SystemPluginName, ELoaderType.ViewLoader, _KraftModuleConfigurationSettings, systemPlugin).Result;
         GenericUtilities.CheckNullOrEmpty(synchronizeContextScoped, true);
         systemPlugin.ExecuteAsync(loaderContextDefinition, processingContext, _TransactionScope.PluginServiceManager, synchronizeContextScoped, view);
     }
 }
Example #6
0
 public async Task <IProcessingContext> ExecuteAsync(
     LoadedNodeSet loaderContext,
     IProcessingContext processingContext,
     IPluginServiceManager pluginServiceManager,
     IPluginsSynchronizeContextScoped contextScoped,
     INode currentNode)
 {
     processingContext.ReturnModel.LookupData =
         LoadLookups(loaderContext, processingContext, pluginServiceManager, contextScoped, currentNode);
     return(await Task.FromResult(processingContext));
 }
Example #7
0
        public override void Execute(IProcessingContext processingContext, ITransactionScopeContext transactionScopeContext)
        {
            KraftModule   loadedModule  = _KraftModuleCollection.GetModule(processingContext.InputModel.Module);
            LoadedNodeSet loadedNodeSet = _NodesSetService.LoadNodeSet(
                processingContext.InputModel.Module,
                processingContext.InputModel.NodeSet,
                processingContext.InputModel.Nodepath);

            if (CheckValidity(processingContext, loadedModule, loadedNodeSet))
            {
                PluginAccessorImp <IDataLoaderPlugin> externalService = new PluginAccessorImp <IDataLoaderPlugin>(transactionScopeContext, loadedModule.ModuleSettings);
                PluginAccessorImp <INodePlugin>       customService   = new PluginAccessorImp <INodePlugin>(transactionScopeContext, loadedModule.ModuleSettings);
                INodeTaskExecutor taskExecutor = new NodeTaskExecutor(transactionScopeContext, loadedModule.ModuleSettings);
                taskExecutor.Execute(loadedNodeSet, processingContext, externalService, customService);
            }
        }
Example #8
0
        public void ExecuteNodeView(
            LoadedNodeSet loaderContextDefinition,
            IProcessingContext processingContext)
        {
            if (!_CollectiveCall)
            {
                //Check for null values
                GenericUtilities.CheckNullOrEmpty(loaderContextDefinition, true);
                GenericUtilities.CheckNullOrEmpty(processingContext, true);
                GenericUtilities.CheckNullOrEmpty(_TransactionScope.PluginServiceManager, true);
            }

            try
            {
                using (KraftProfiler.Current.Step("Execution time loading views: "))
                {
                    if (!string.IsNullOrEmpty(processingContext.InputModel.BindingKey))
                    {
                        View view = loaderContextDefinition.StartNode.Views.Find(v => v.BindingKey.Equals(processingContext.InputModel.BindingKey, StringComparison.OrdinalIgnoreCase));
                        ExecuteNodeViewPrivate(loaderContextDefinition, processingContext, view);
                    }
                    else
                    {
                        foreach (View view in loaderContextDefinition.StartNode.Views)
                        {
                            ExecuteNodeViewPrivate(loaderContextDefinition, processingContext, view);
                        }
                    }
                }
                if (!_CollectiveCall)
                {
                    _TransactionScope.CommitTransactions();
                }
            }
            catch (Exception ex)
            {
                processingContext.ReturnModel.Status.IsSuccessful = false;
                processingContext.ReturnModel.Status.StatusResults.Add(new StatusResult {
                    StatusResultType = EStatusResult.StatusResultError, Message = ex.Message
                });
                if (!_CollectiveCall)
                {
                    _TransactionScope.RollbackTransactions();
                }
                KraftLogger.LogError(ex.Message, ex);
            }
        }
Example #9
0
 public void ExecuteNodeData(
     LoadedNodeSet loaderContextDefinition,
     IProcessingContext processingContext,
     IPluginAccessor <IDataLoaderPlugin> dataLoaderAccessor,
     IPluginAccessor <INodePlugin> pluginAccessor)
 {
     if (!_CollectiveCall)
     {
         //Check for null values
         GenericUtilities.CheckNullOrEmpty(loaderContextDefinition, true);
         GenericUtilities.CheckNullOrEmpty(processingContext, true);
         GenericUtilities.CheckNullOrEmpty(_TransactionScope.PluginServiceManager, true);
     }
     try
     {
         if (processingContext.InputModel.LoaderType.HasFlag(ELoaderType.DataLoader))
         {
             using (KraftProfiler.Current.Step("Execution time loading data: "))
             {
                 if (loaderContextDefinition.StartNode != null && loaderContextDefinition.StartNode.HasValidDataSection(processingContext.InputModel.IsWriteOperation))
                 {
                     IDataIteratorPlugin dataIteratorPlugin = Utilities.GetPlugin <IDataIteratorPlugin>(_KraftModuleConfigurationSettings.NodeSetSettings.SourceLoaderMapping.NodesDataIterator.NodesDataIteratorConf.Name, _TransactionScope.DependencyInjectionContainer, _KraftModuleConfigurationSettings, ELoaderType.DataLoader, true);
                     GenericUtilities.CheckNullOrEmpty(dataIteratorPlugin, true);
                     IProcessingContext r = dataIteratorPlugin.ExecuteAsync(loaderContextDefinition, processingContext, _TransactionScope.PluginServiceManager, dataLoaderAccessor, pluginAccessor).Result;
                 }
             }
         }
         if (!_CollectiveCall)
         {
             _TransactionScope.CommitTransactions();
         }
     }
     catch (Exception ex)
     {
         processingContext.ReturnModel.Status.IsSuccessful = false;
         processingContext.ReturnModel.Status.StatusResults.Add(new StatusResult {
             StatusResultType = EStatusResult.StatusResultError, Message = ex.Message
         });
         if (!_CollectiveCall)
         {
             _TransactionScope.RollbackTransactions();
         }
         KraftLogger.LogError(ex.Message, ex);
     }
 }
Example #10
0
        public LoadedNodeSet LoadNodeSet(string module, string treeNodesName, string nodeName)
        {
            LoadedNodeSet loaderContext = new LoadedNodeSet();
            //find the node definition in the directory specified
            //load the definition
            //parse the definition and populate into the models
            NodeSetModel nodeSet         = null;
            string       NODESET_DIRNAME = "NodeSets";
            string       cacheKey        = $"NodeSet_{module}_{treeNodesName}";

            nodeSet = _CachingService.Get <NodeSetModel>(cacheKey);
            if (nodeSet == null)
            {
                nodeSet = new NodeSetModel();
                string nodeSetDir  = Path.Combine(_KraftGlobalConfigurationSettings.GeneralSettings.ModulesRootFolder(module), module, NODESET_DIRNAME, treeNodesName);
                string nodeSetFile = Path.Combine(nodeSetDir, "Definition.json");

                if (!File.Exists(nodeSetFile))
                {
                    throw new FileNotFoundException($"The requested file: {nodeSetFile} was not found");
                }

                PhysicalFileProvider fileProvider = new PhysicalFileProvider(nodeSetDir);

                using (StreamReader file = File.OpenText(nodeSetFile))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    RootObject     result     = (RootObject)serializer.Deserialize(file, typeof(RootObject));
                    nodeSet = result.NodeSet;
                };

                nodeSet.Name = treeNodesName;

                ProcessNodes(nodeSet.Root, nodeSetFile, nodeSet);
                _CachingService.Insert(cacheKey, nodeSet, fileProvider.Watch("**/*.*"));
            }

            loaderContext.NodeSet   = nodeSet;
            loaderContext.StartNode =
                (!string.IsNullOrEmpty(nodeName))
                    ? FindNode(nodeSet.Root.Children, ParseNodePath(nodeName), n => n.Children, n => n.NodeKey.Trim())
                    : nodeSet.Root;

            return(loaderContext);
        }
Example #11
0
        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);
        }
Example #12
0
        public async Task <IProcessingContext> ExecuteAsync(
            LoadedNodeSet loaderContext,
            IProcessingContext processingContext,
            IPluginServiceManager pluginServiceManager,
            IPluginsSynchronizeContextScoped contextScoped,
            INode currentNode)
        {
            IHttpContextAccessor httpContextAccessor = pluginServiceManager.GetService <IHttpContextAccessor>(typeof(HttpContextAccessor));
            HttpRequest          request             = httpContextAccessor.HttpContext.Request;
            UploadFileBase       uploadFile;

            if (request.ContentLength == null && request.Headers["Transfer-Encoding"] == "chunked")
            {
                uploadFile = new UploadFileForm();
            }
            else
            {
                uploadFile = new UploadFileMultipart();
            }

            return(await uploadFile.Execute(request, processingContext));
        }
Example #13
0
        protected bool CheckValidity(IProcessingContext processingContext, KraftModule module, LoadedNodeSet loadedNodeSet)
        {
            if (processingContext.InputModel.LoaderType == ELoaderType.None)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"You have to specify a loader type.");
                return(false);
            }
            if (module == null)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested module: {processingContext.InputModel.Module} doesn't exist or not loaded.");
                return(false);
            }

            if (loadedNodeSet == null)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested nodeset: {processingContext.InputModel.NodeSet} doesn't exist or not loaded.");
                return(false);
            }
            //If authentication is required but the user is not logged in redirect to authentication
            if (loadedNodeSet.StartNode.RequireAuthentication && !processingContext.InputModel.SecurityModel.IsAuthenticated)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.Unauthorized, null);
                return(false);
            }
            return(true);
        }
Example #14
0
        protected bool CheckValidity(IProcessingContext processingContext, KraftModule module, LoadedNodeSet loadedNodeSet)
        {
            if (processingContext.InputModel.LoaderType == ELoaderType.None)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"You have to specify a loader type.");
                return(false);
            }
            if (module == null)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested module: {processingContext.InputModel.Module} doesn't exist or not loaded.");
                return(false);
            }

            if (loadedNodeSet == null)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.NotFound, $"Requested nodeset: {processingContext.InputModel.NodeSet} doesn't exist or not loaded.");
                return(false);
            }
            if (loadedNodeSet.StartNode == null)//Handle errors better and show when a node is addressed but missing.
            {
                string error = $"Node: {processingContext.InputModel.Nodepath} from module: {processingContext.InputModel.Module}, nodeset: {processingContext.InputModel.NodeSet} is missing!";
                KraftLogger.LogError(error);
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.InternalServerError, error);
                return(false);
            }
            //If authentication is required but the user is not logged in redirect to authentication
            if (loadedNodeSet.StartNode.RequireAuthentication && !processingContext.InputModel.SecurityModel.IsAuthenticated)
            {
                Utilities.ExtensionMethods.KraftResult(_HttpContext, HttpStatusCode.Unauthorized, null);
                return(false);
            }
            return(true);
        }
Example #15
0
        protected virtual Dictionary <string, object> LoadLookups(
            LoadedNodeSet loaderContext,
            IProcessingContext processingContext,
            IPluginServiceManager pluginServiceManager,
            IPluginsSynchronizeContextScoped contextScoped,
            INode currentNode)
        {
            Dictionary <string, object>         returnResult  = new Dictionary <string, object>();
            List <Dictionary <string, object> > results       = null;
            Dictionary <string, object>         currentResult = null;

            // This shouldn't happen to a dog! but I needed a hack for basket consumer.
            LookupLoaderContext.Instance.PluginServiceManager = pluginServiceManager;
            LookupLoaderContext.Instance.LoaderContext        = loaderContext;
            LookupLoaderContext.Instance.ProcessingContext    = processingContext;
            //

            Lookup lookup = (Lookup)currentNode;

            if (lookup.HasStatement())
            {
                results = new List <Dictionary <string, object> >();

                IADOTransactionScope scopedContext = contextScoped as IADOTransactionScope;
                // Check it is valid

                if (scopedContext == null)
                {
                    throw new NullReferenceException("Scoped synchronization and transaction context is not available.");
                }

                DbConnection conn = scopedContext.Connection;
                using (DbCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = lookup.Query;
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                currentResult = new Dictionary <string, object>(reader.FieldCount);
                                currentResult = new Dictionary <string, object>(reader.FieldCount);
                                for (int i = 0; i < reader.FieldCount; i++)
                                {
                                    string fldname = reader.GetName(i);
                                    if (fldname == null)
                                    {
                                        continue;
                                    }
                                    fldname = fldname.ToLower().Trim();
                                    if (fldname.Length == 0)
                                    {
                                        throw new Exception($"Empty name when reading the output of a query. The field index is {i}. The query is: {cmd.CommandText}");
                                    }
                                    if (currentResult.ContainsKey(fldname))
                                    {
                                        throw new Exception($"Duplicated field name in the output of a query. The field is:{fldname}, the query is: {cmd.CommandText}");
                                    }
                                    object o = reader.GetValue(i);
                                    currentResult.Add(fldname, (o is DBNull) ? null : o);
                                }
                                results.Add(currentResult);
                            }
                        }
                    }
                }
                returnResult.Add(lookup.BindingKey, results);
            }
            return(returnResult);
        }
Example #16
0
        private bool CheckValidity(IProcessingContext processingContext, KraftModule module, LoadedNodeSet loadedNodeSet, out StringBuilder sb)
        {
            sb = new StringBuilder();
            bool isError = false;

            if (module == null)
            {
                sb.Append($"Requested module: {processingContext.InputModel.Module} doesn't exist or not loaded.");
                isError = true;
            }

            if (loadedNodeSet == null)
            {
                sb.Append($"Requested nodeset: {processingContext.InputModel.NodeSet} doesn't exist or not loaded.");
                isError = true;
            }
            if (loadedNodeSet.StartNode == null)//Handle errors better and show when a node is addressed but missing.
            {
                sb.Append($"Node: {processingContext.InputModel.Nodepath} from module: {processingContext.InputModel.Module}, nodeset: {processingContext.InputModel.NodeSet} is missing!");
                isError = true;
            }
            return(isError);
        }