Пример #1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            DataTable dataTable  = null;
            string    connString = null;
            string    provName   = null;
            string    tableName  = null;

            try
            {
                DbConnection = ExistingDbConnection.Get(context);
                connString   = ConnectionString.Get(context);
                provName     = ProviderName.Get(context);
                tableName    = TableName.Get(context);
                dataTable    = DataTable.Get(context);
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }
            // create the action for doing the actual work
            Func <int> action = () =>
            {
                DbConnection = DbConnection ?? new DatabaseConnection().Initialize(connString, provName);
                if (DbConnection == null)
                {
                    return(0);
                }
                return(DbConnection.InsertDataTable(tableName, dataTable));
            };

            context.UserState = action;
            return(action.BeginInvoke(callback, state));
        }
Пример #2
0
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            DataTable    dataTable        = null;
            string       connString       = null;
            SecureString connSecureString = null;
            string       provName         = null;
            string       tableName        = null;

            string[]           columnNames        = null;
            DatabaseConnection existingConnection = null;
            long             affectedRecords      = 0;
            IExecutorRuntime executorRuntime      = null;
            var continueOnError = ContinueOnError.Get(context);

            try
            {
                existingConnection = DbConnection = ExistingDbConnection.Get(context);
                connString         = ConnectionString.Get(context);
                provName           = ProviderName.Get(context);
                tableName          = TableName.Get(context);
                dataTable          = DataTable.Get(context);
                columnNames        = ColumnNames.Get(context);
                executorRuntime    = context.GetExtension <IExecutorRuntime>();
                connSecureString   = ConnectionSecureString.Get(context);
                ConnectionHelper.ConnectionValidation(existingConnection, connSecureString, connString, provName);
                affectedRecords = await Task.Run(() =>
                {
                    DbConnection = DbConnection ?? new DatabaseConnection().Initialize(connString != null ? connString : new NetworkCredential("", connSecureString).Password, provName);
                    if (DbConnection == null)
                    {
                        return(0);
                    }
                    if (executorRuntime != null && executorRuntime.HasFeature(ExecutorFeatureKeys.LogMessage))
                    {
                        return(DbConnection.BulkUpdateDataTable(BulkUpdateFlag, tableName, dataTable, columnNames, executorRuntime));
                    }
                    else
                    {
                        return(DbConnection.BulkUpdateDataTable(BulkUpdateFlag, tableName, dataTable, columnNames));
                    }
                });
            }
            catch (Exception ex)
            {
                HandleException(ex, continueOnError);
            }
            finally
            {
                if (existingConnection == null)
                {
                    DbConnection?.Dispose();
                }
            }

            return(asyncCodeActivityContext =>
            {
                AffectedRecords.Set(asyncCodeActivityContext, affectedRecords);
            });
        }
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            DataTable          dataTable          = null;
            string             connString         = null;
            SecureString       connSecureString   = null;
            string             provName           = null;
            string             tableName          = null;
            DatabaseConnection existingConnection = null;
            int affectedRecords = 0;
            var continueOnError = ContinueOnError.Get(context);

            try
            {
                existingConnection = DbConnection = ExistingDbConnection.Get(context);
                connString         = ConnectionString.Get(context);
                provName           = ProviderName.Get(context);
                tableName          = TableName.Get(context);
                dataTable          = DataTable.Get(context);

                connSecureString = ConnectionSecureString.Get(context);
                ConnectionHelper.ConnectionValidation(existingConnection, connSecureString, connString, provName);
                // create the action for doing the actual work
                affectedRecords = await Task.Run(() =>
                {
                    DbConnection = DbConnection ?? new DatabaseConnection().Initialize(connString != null ? connString : new NetworkCredential("", connSecureString).Password, provName);
                    if (DbConnection == null)
                    {
                        return(0);
                    }
                    return(DbConnection.InsertDataTable(tableName, dataTable));
                });
            }
            catch (Exception ex)
            {
                HandleException(ex, continueOnError);
            }
            finally
            {
                if (existingConnection == null)
                {
                    DbConnection?.Dispose();
                }
            }

            return(asyncCodeActivityContext =>
            {
                AffectedRecords.Set(asyncCodeActivityContext, affectedRecords);
            });
        }
Пример #4
0
        protected override void Execute(CodeActivityContext context)
        {
            var        vars       = context.DataContext.GetProperties();
            Connection connection = null;

            foreach (dynamic v in vars)
            {
                if (v.DisplayName == "conn")
                {
                    connection = v.GetValue(context.DataContext);
                }
            }
            var tablename = TableName.Get(context);
            var datatable = DataTable.Get(context);

            var result = connection.UpdateDataTable(tablename, datatable);

            Result.Set(context, result);
        }
Пример #5
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            DataTable dataTable  = null;
            string    connString = null;
            string    provName   = null;
            string    tableName  = null;

            try
            {
                DbConn     = DBConnection.Get(context);
                connString = ConnectionString.Get(context);
                provName   = ProviderName.Get(context);
                tableName  = TableName.Get(context);
                dataTable  = DataTable.Get(context);

                Func <int> action = () =>
                {
                    DbConn = DbConn ?? new DatabaseConnection().Initialize(connString, provName);
                    if (DbConn == null)
                    {
                        return(0);
                    }
                    return(DbConn.InsertDataTable(tableName, dataTable));
                };
                context.UserState = action;
                return(action.BeginInvoke(callback, state));
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }
            //if(dataTable.Rows.Count == 0)
            //{
            //    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "dataTable为空");
            //}
            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Пример #6
0
 /// <summary> Creates a new DataTable object. </summary>
 /// <param name="context"></param>
 protected override void DoWork(CodeActivityContext context)
 {
     Result.Set(context, new DataTable(TableName.Get(context)));
 }