Ejemplo n.º 1
0
        protected virtual void ExecuteQuery <Context>(Context execContext) where Context : class, IDataLoaderContext
        {
            bool trace = execContext.CurrentNode.Trace;

            string qry = GetQuery(execContext);

            if (qry != null)
            {
                try
                {
                    var runner = Compiler.Compile(qry);
                    if (runner.ErrorText != null)
                    {
                        KraftLogger.LogError($"{execContext.LocationInfo(PLUGIN_INTERNAL_NAME)}\n{runner.ErrorText}");
                        throw new Exception(runner.ErrorText);
                    }
                    using (var host = new ActionQueryHost <Context>(execContext)
                    {
                        { "HostInfo", HostInfo }
                    }) {
                        if (trace)
                        {
                            host.Trace = true;
                        }
                        try
                        {
                            var result = runner.ExecuteScalar(host, ActionQueryHost <Context> .HardLimit(execContext));
                        }
                        catch
                        {
                            if (trace)
                            {
                                var traceInfo = host.GetTraceInfo();
                                if (traceInfo != null)
                                {
                                    KraftLogger.LogError($"{execContext.LocationInfo(PLUGIN_INTERNAL_NAME)}\n");
                                    KraftLogger.LogError(traceInfo.ToString());
                                }
                            }
                            throw;
                        }
                    }
                }
                catch (Exception ex)
                {
                    KraftLogger.LogError(ActionQueryTrace.ExceptionToString(ex));
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        protected override void ExecuteWrite(IDataLoaderWriteContext execContext)
        {
            bool   trace = execContext.CurrentNode.Trace;
            string qry   = GetQuery(execContext);

            if (qry != null)
            {
                try
                {
                    var runner = Compiler.Compile(qry);
                    if (runner.ErrorText != null)
                    {
                        KraftLogger.LogError($"{execContext.LocationInfo(PLUGIN_INTERNAL_NAME)}\n{runner.ErrorText}");
                        throw new Exception(runner.ErrorText);
                    }
                    using (var host = new ActionQueryHost <IDataLoaderWriteContext>(execContext)
                    {
                        { nameof(IsPostedFile), IsPostedFile },
                        { nameof(PostedFileSize), PostedFileSize },
                        { nameof(PostedFileName), PostedFileName },
                        { nameof(PostedFileType), PostedFileType },
                        { nameof(CombinePaths), CombinePaths },
                        { nameof(DeleteFile), DeleteFile },
                        { nameof(SaveFile), SaveFile },
                        { nameof(PrependFileName), PrependFileName },
                        { nameof(CreateDirectory), CreateDirectory },
                        { nameof(SaveFileToSpread), SaveFileToSpread },
                        { nameof(PostedFile), this.PostedFile },
                        { nameof(FileResponse), FileResponse },
                        { nameof(FileExists), FileExists }
                    })
                    {
                        host.AddLibrary(new BasicImageLib <IDataLoaderWriteContext>());
                        if (trace)
                        {
                            host.Trace = true;
                        }
                        try
                        {
                            var result = runner.ExecuteScalar(host, ActionQueryHost <IDataLoaderWriteContext> .HardLimit(execContext));
                        }
                        catch
                        {
                            if (trace)
                            {
                                var traceInfo = host.GetTraceInfo();
                                if (traceInfo != null)
                                {
                                    KraftLogger.LogError($"{execContext.LocationInfo(PLUGIN_INTERNAL_NAME)}\n");
                                    KraftLogger.LogError(traceInfo.ToString());
                                }
                                KraftLogger.LogError($"{runner.DumpProgram()}\n");
                            }
                            throw;
                        }
                    }
                }
                catch (Exception ex)
                {
                    KraftLogger.LogError(ActionQueryTrace.ExceptionToString(ex));
                    throw;
                }
            }
            // Else nothing to do.
        }