Пример #1
0
        //public async Task<IPluginsSynchronizeContextScoped> GetSynchronizeContextScopedAsync()
        //{
        //    return await Task.FromResult<IPluginsSynchronizeContextScoped>(new FileDataSynchronizeContextScopedImp());
        //}

        private ILogger GetLogger(IPluginServiceManager pluginServiceManager)
        {
            ILogger logger = pluginServiceManager.GetService <ILogger>(typeof(ILogger));

            logger.LogDebug("Hi from raw file reader");
            return(logger);
        }
Пример #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));
        }
Пример #3
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));
 }
Пример #4
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));
        }
Пример #5
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);
        }
Пример #6
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));
        }