Exemplo n.º 1
0
        private void Save_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidateSaveRequest())
                {
                    DataCommand cmd = new DataCommand();

                    cmd.Name           = CommandName.Text;
                    cmd.DataConnection = DataConnectionList.Text;
                    cmd.Type           = CommandTypeList.Text.ToString();
                    cmd.Text           = CommandText.Text;
                    cmd.ReturnType     = (DataCommandReturnType)Enum.Parse(typeof(DataCommandReturnType), CommandReturnTypeList.Text.ToString());

                    DataConnection       connection = Project.GetDataConnection(cmd);
                    IDataCommandProvider DataSource = DataCommandService.GetInstance().GetProvider(connection);
                    DataSource.RefreshSchema(connection, cmd);

                    DataCommand.Save(cmd);

                    Configuration.GetInstance().DataCommands.Add(cmd);


                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                ErrorManager.HandleError(ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Repository&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="dataCommandProvider">The data session.</param>
        /// <param name="objectFinder">The object finder.</param>
        /// <param name="repositoryStrictness">The strictness of the repository.</param>
        public Repository(
            IDataCommandProvider dataCommandProvider,
            IObjectFinder <T> objectFinder,
            RepositoryStrictness repositoryStrictness = RepositoryStrictness.Strict)
        {
            Guard.Will.ThrowException("No unit of work was available.").When(dataCommandProvider == null);

            this.DataCommandProvider  = dataCommandProvider;
            this.objectFinder         = objectFinder;
            this.repositoryStrictness = repositoryStrictness;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public IDataCommandProvider GetProvider(DataConnection connection)
        {
            IDataCommandProvider retVal = null;

            if (this.Connections.ContainsKey(connection.Name))
            {
                //get cached data command provider
                retVal = this.Connections[connection.Name];
            }
            else
            {
                //add data command provider to cache

                DataConnectionType connectionType = connection.GetConnectionType();

                if (connectionType != null)
                {
                    if (!String.IsNullOrEmpty(connectionType.Class) && !String.IsNullOrEmpty(connectionType.Assembly))
                    {
                        try
                        {
                            Assembly providerAssembly = Assembly.Load(connectionType.Assembly);
                            if (providerAssembly != null)
                            {
                                Type type = providerAssembly.GetType(connectionType.Class, true, true);

                                if (type != null)
                                {
                                    ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
                                    retVal = constructor.Invoke(null) as IDataCommandProvider;

                                    retVal.Initialize(connectionType.Settings);

                                    this.Connections.Add(connection.Name, retVal);
                                }
                            }
                        }
                        catch {
                            //silent error
                        }
                    }
                }
            }

            if (retVal == null)
            {
                throw new Exception(String.Format("No valid data command provider found for connection {0}", connection.Name));
            }

            return(retVal);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public IDataCommandProvider GetProvider(DataConnection connection)
        {
            IDataCommandProvider retVal = null;

            if (this.Connections.ContainsKey(connection.Name))
            {
                //get cached data command provider
                retVal = this.Connections[connection.Name];
            }
            else
            {
                //add data command provider to cache

                DataConnectionType connectionType = connection.GetConnectionType();

                if (connectionType != null)
                {
                    if (!String.IsNullOrEmpty(connectionType.Class) && !String.IsNullOrEmpty(connectionType.Assembly))
                    {
                        try
                        {
                            retVal = Common.CreateInstance(connectionType.Assembly, connectionType.Class) as IDataCommandProvider;
                            retVal.Initialize(connectionType.Settings);
                            this.Connections.Add(connection.Name, retVal);
                        }
                        catch {
                            //silent error
                        }
                    }
                }
            }

            if (retVal == null)
            {
                throw new Exception(String.Format("No valid data command provider found for connection {0}", connection.Name));
            }

            return(retVal);
        }
 public StrictAggregateRootTestModelRepository(IDataCommandProvider dataCommandProvider, IObjectFinder <AggregateRootTestModel> objectFinder)
     : base(dataCommandProvider, objectFinder, RepositoryStrictness.Strict)
 {
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Query{TResult}"/> class.
 /// </summary>
 /// <param name="dataCommandProvider">The data command provider.</param>
 protected Query(IDataCommandProvider dataCommandProvider)
 {
     DataCommandProvider = dataCommandProvider;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Query{TResult}"/> class.
 /// </summary>
 /// <param name="dataCommandProvider">The data command provider.</param>
 protected Query(IDataCommandProvider dataCommandProvider)
 {
     this.dataCommandProvider = (DataCommandProvider)dataCommandProvider;
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestModelsWithTestPropertiesThatStartWithABC"/> class.
 /// </summary>
 /// <param name="dataCommandProvider">The data command provider.</param>
 public TestModelsWithTestPropertiesThatStartWithABC(IDataCommandProvider dataCommandProvider)
     : base(dataCommandProvider)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestModelRepository"/> class.
 /// </summary>
 /// <param name="dataCommandProvider">The data session.</param>
 /// <param name="objectFinder">The object finder.</param>
 public TestModelRepository(IDataCommandProvider dataCommandProvider, IObjectFinder <TestModel> objectFinder)
     : base(dataCommandProvider, objectFinder, RepositoryStrictness.Open)
 {
 }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectFinder&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="dataCommandProvider">The data command provider.</param>
        public ObjectFinder(IDataCommandProvider dataCommandProvider)
        {
            Guard.Will.ProtectAgainstNullArgument(() => dataCommandProvider);

            this.dataCommandProvider = dataCommandProvider;
        }
Exemplo n.º 14
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);
        }