Esempio n. 1
0
        public async Task <object> ExecuteCommand(DataCommand dataCommand, List <ScreenDataCommandParameter> parameters, string commandText)
        {
            object retVal = null;


            try
            {
                DataCommandPreProcessorArgs preArgs = ProcessDataCommandPreProcessor(dataCommand, parameters);
                bool SkipExecution = false;

                if (preArgs != null)
                {
                    SkipExecution = preArgs.SkipExecution;

                    if (preArgs.Data != null)
                    {
                        retVal = preArgs.Data;
                    }
                }

                if (!SkipExecution)
                {
                    DataConnection connection = dataCommand.GetDataConnection();
                    if (connection == null)
                    {
                        throw new Exception(String.Format("Data Connection could not be found in configuration - {0}", dataCommand.DataConnection));
                    }
                    IDataCommandProvider dataSource = GetProvider(connection);
                    retVal = await dataSource.ExecuteCommand(
                        connection,
                        dataCommand,
                        parameters,
                        commandText,
                        success =>
                    {
                        DataCommandPostProcessorArgs postArgs = ProcessDataCommandPostProcessor(dataCommand, parameters, retVal);
                        if (postArgs != null)
                        {
                            retVal = postArgs.Data;
                        }
                    },
                        error => {
                        throw error;
                    });
                }
            }
            catch (Exception ex)
            {
                Common.LogException(ex);
                throw ex;
            }

            return(retVal);
        }
Esempio n. 2
0
        public async Task <XDocument> GetXmlData(DataCommand dataCommand, List <ScreenDataCommandParameter> parameters, string commandText)
        {
            XDocument retVal = null;

            DataCommandPreProcessorArgs preArgs = ProcessDataCommandPreProcessor(dataCommand, parameters);
            bool SkipExecution = false;

            if (preArgs != null)
            {
                SkipExecution = preArgs.SkipExecution;

                if (preArgs.Data != null)
                {
                    if (preArgs.Data is XDocument)
                    {
                        retVal = (XDocument)preArgs.Data;
                    }
                }
            }

            if (!SkipExecution)
            {
                DataConnection connection = dataCommand.GetDataConnection();
                if (connection == null)
                {
                    throw new Exception(String.Format("Data Connection could not be found in configuration - {0}", dataCommand.DataConnection));
                }
                IDataCommandProvider DataSource = GetProvider(connection);
                retVal = await DataSource.GetXmlData(
                    connection,
                    dataCommand,
                    parameters,
                    commandText,
                    success =>
                {
                    DataCommandPostProcessorArgs postArgs = ProcessDataCommandPostProcessor(dataCommand, parameters, retVal);
                    if (postArgs != null)
                    {
                        if (postArgs.Data is XDocument)
                        {
                            retVal = (XDocument)postArgs.Data;
                        }
                    }
                },
                    error => {
                    throw error;
                });
            }



            return(retVal);
        }
Esempio n. 3
0
        public DataTable GetData(DbTransaction tran, DataConnection connection, DataCommand dataCommand, List <ScreenDataCommandParameter> parameters, string commandText)
        {
            DataTable retVal = null;

            DataCommandPreProcessorArgs preArgs = ProcessDataCommandPreProcessor(tran, dataCommand, parameters);
            bool SkipExecution = false;

            if (preArgs != null)
            {
                SkipExecution = preArgs.SkipExecution;

                if (preArgs.Data != null)
                {
                    if (preArgs.Data is DataTable)
                    {
                        retVal = (DataTable)preArgs.Data;
                    }
                }
            }

            if (!SkipExecution)
            {
                if (connection == null)
                {
                    throw new Exception(String.Format("Data Connection could not be found in configuration - {0}", dataCommand.DataConnection));
                }
                IDataCommandProvider dataSource = GetProvider(connection);

                retVal = dataSource.GetData(connection, dataCommand, parameters, commandText);
            }

            DataCommandPostProcessorArgs postArgs = ProcessDataCommandPostProcessor(tran, dataCommand, parameters, retVal);

            if (postArgs != null)
            {
                if (postArgs.Data is DataTable)
                {
                    retVal = (DataTable)postArgs.Data;
                }
            }

            return(retVal);
        }
Esempio n. 4
0
        private DataCommandPostProcessorArgs ProcessDataCommandPostProcessor(DataCommand dataCommand, List <ScreenDataCommandParameter> parameters, object data)
        {
            DataCommandPostProcessorArgs args = null;

            if (!String.IsNullOrEmpty(dataCommand.PostProcessingClass))
            {
                try
                {
                    IDataCommandPostProcessor instance = Common.CreateInstance(dataCommand.PostProcessingAssembly, dataCommand.PostProcessingClass) as IDataCommandPostProcessor;


                    if (instance != null)
                    {
                        args = new DataCommandPostProcessorArgs();

                        args.DataCommand = dataCommand;
                        args.Parameters  = parameters;
                        args.Data        = data;

                        instance.Process(args);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        Common.LogException(ex, false);
                        throw ex.InnerException;
                    }
                    else
                    {
                        Common.LogException(ex);
                    }
                }
            }
            return(args);
        }
Esempio n. 5
0
        private DataCommandPostProcessorArgs ProcessDataCommandPostProcessor(DbTransaction tran, DataCommand dataCommand, List <ScreenDataCommandParameter> parameters, object data)
        {
            DataCommandPostProcessorArgs args = null;

            if (!String.IsNullOrEmpty(dataCommand.PostProcessingClass))
            {
                try
                {
                    Assembly processorAssembly = Assembly.Load(dataCommand.PostProcessingAssembly);
                    if (processorAssembly != null)
                    {
                        Type type = processorAssembly.GetType(dataCommand.PostProcessingClass, true, true);

                        if (type != null)
                        {
                            MethodInfo      method      = type.GetMethod("Process");
                            ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                            object          instance    = constructor.Invoke(null);

                            args = new DataCommandPostProcessorArgs();

                            args.Transaction = tran;
                            args.DataCommand = dataCommand;
                            args.Parameters  = parameters;
                            args.Data        = data;


                            object[] argParameter = new object[1];
                            argParameter[0] = args;


                            try
                            {
                                method.Invoke(instance, argParameter);
                            }
                            catch (CodeTorchException cex)
                            {
                                string errorFormat = "Error in PostProcessor - {0}";

                                if (cex.MoreInfo == null)
                                {
                                    cex.MoreInfo = String.Format(errorFormat, dataCommand.PreProcessingClass);;
                                }

                                Common.LogException(cex, false);
                                throw cex;
                            }
                            catch (Exception e)
                            {
                                string errorFormat = "Error in PostProcessor - {0}";

                                CodeTorchException postProcessorException;
                                if (e.InnerException != null)
                                {
                                    Common.LogException(e, false);

                                    if (e.InnerException is CodeTorchException)
                                    {
                                        postProcessorException = e.InnerException as CodeTorchException;
                                        if (postProcessorException.MoreInfo == null)
                                        {
                                            postProcessorException.MoreInfo = String.Format(errorFormat, dataCommand.PostProcessingClass);
                                        }
                                    }
                                    else
                                    {
                                        postProcessorException          = new CodeTorchException(e.InnerException.Message, e.InnerException);
                                        postProcessorException.MoreInfo = String.Format(errorFormat, dataCommand.PostProcessingClass);
                                    }

                                    throw postProcessorException;
                                }
                                else
                                {
                                    Common.LogException(e, false);
                                    postProcessorException          = new CodeTorchException(e.Message, e.InnerException);
                                    postProcessorException.MoreInfo = String.Format(errorFormat, dataCommand.PreProcessingClass);
                                    throw postProcessorException;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogException(ex);
                }
            }
            return(args);
        }
Esempio n. 6
0
        public Task <DataTable> GetData(DataCommand dataCommand, List <ScreenDataCommandParameter> parameters, string commandText)
        {
            TaskCompletionSource <DataTable> taskDT = new TaskCompletionSource <DataTable>();



            DataCommandPreProcessorArgs preArgs = ProcessDataCommandPreProcessor(dataCommand, parameters);
            bool SkipExecution = false;

            if (preArgs != null)
            {
                SkipExecution = preArgs.SkipExecution;
            }

            if (SkipExecution)
            {
                if (preArgs.Data != null)
                {
                    if (preArgs.Data is DataTable)
                    {
                        taskDT.SetResult((DataTable)preArgs.Data);
                    }
                }
            }
            else
            {
                DataConnection connection = dataCommand.GetDataConnection();
                if (connection == null)
                {
                    taskDT.SetException(new Exception(String.Format("Data Connection could not be found in configuration - {0}", dataCommand.DataConnection)));
                }
                IDataCommandProvider dataSource = GetProvider(connection);

                var result = dataSource.GetData(
                    connection,
                    dataCommand,
                    parameters,
                    commandText,
                    success =>
                {
                    DataCommandPostProcessorArgs postArgs = ProcessDataCommandPostProcessor(dataCommand, parameters, success);
                    if (postArgs != null)
                    {
                        if (postArgs.Data is DataTable)
                        {
                            taskDT.SetResult((DataTable)postArgs.Data);
                        }
                        else
                        {
                            taskDT.SetResult(success);
                        }
                    }
                    else
                    {
                        taskDT.SetResult(success);
                    }
                },
                    error => {
                    taskDT.SetException(error);
                });
            }

            return(taskDT.Task);
        }