예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #4
0
        private DataCommandPreProcessorArgs ProcessDataCommandPreProcessor(DataCommand dataCommand, List <ScreenDataCommandParameter> parameters)
        {
            DataCommandPreProcessorArgs args = null;

            if (!String.IsNullOrEmpty(dataCommand.PreProcessingClass))
            {
                try
                {
                    IDataCommandPreProcessor instance = Common.CreateInstance(dataCommand.PreProcessingAssembly, dataCommand.PreProcessingClass) as IDataCommandPreProcessor;



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

                        args.DataCommand   = dataCommand;
                        args.Parameters    = parameters;
                        args.SkipExecution = false;

                        instance.Process(args);
                    }
                }
                catch (Exception ex)
                {
                    Common.LogException(ex);
                    //if (ex.InnerException != null)
                    //{
                    //    Common.LogException(ex, false);
                    //    throw ex.InnerException;
                    //}
                    //else
                    //{
                    //////    Common.LogException(ex);
                    //}
                }
            }
            return(args);
        }
예제 #5
0
        private DataCommandPreProcessorArgs ProcessDataCommandPreProcessor(DbTransaction tran, DataCommand dataCommand, List <ScreenDataCommandParameter> parameters)
        {
            DataCommandPreProcessorArgs args = null;

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

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

                            args = new DataCommandPreProcessorArgs();

                            args.Transaction   = tran;
                            args.DataCommand   = dataCommand;
                            args.Parameters    = parameters;
                            args.SkipExecution = false;

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

                            try
                            {
                                method.Invoke(instance, argParameter);
                            }
                            catch (CodeTorchException cex)
                            {
                                string errorFormat = "Error in PreProcessor - {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 PreProcessor - {0}";

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

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

                                    throw preProcessorException;
                                }
                                else
                                {
                                    Common.LogException(e, false);
                                    preProcessorException          = new CodeTorchException(e.Message, e.InnerException);
                                    preProcessorException.MoreInfo = String.Format(errorFormat, dataCommand.PreProcessingClass);
                                    throw preProcessorException;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Common.LogException(ex);
                }
            }
            return(args);
        }
예제 #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);
        }