コード例 #1
0
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            var connString       = ConnectionString.Get(context);
            var connSecureString = ConnectionSecureString.Get(context);

            if (connString == null && connSecureString == null)
            {
                throw new ArgumentNullException(Resources.ValidationError_ConnectionStringMustNotBeNull);
            }
            if (connString != null && connSecureString != null)
            {
                throw new ArgumentException(Resources.ValidationError_ConnectionStringMustBeSet);
            }
            var provName = ProviderName.Get(context);
            DatabaseConnection dbConnection = null;

            try
            {
                dbConnection = await Task.Run(() => _connectionFactory.Create(connString ?? new NetworkCredential("", connSecureString).Password, provName));
            }
            catch (Exception e)
            {
                Trace.TraceError($"{e}");
            }

            return(asyncCodeActivityContext =>
            {
                DatabaseConnection.Set(asyncCodeActivityContext, dbConnection);
            });
        }
コード例 #2
0
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            var          connString       = ConnectionString.Get(context);
            SecureString connSecureString = null;
            var          provName         = ProviderName.Get(context);

            connSecureString = ConnectionSecureString.Get(context);
            DatabaseConnection existingConnection = null;

            existingConnection = ExistingDbConnection.Get(context);
            DatabaseConnection dbConnection = null;
            var continueOnError             = ContinueOnError.Get(context);

            try
            {
                ConnectionHelper.ConnectionValidation(existingConnection, connSecureString, connString, provName);
                dbConnection = await Task.Run(() => existingConnection ?? new DatabaseConnection().Initialize(connString ?? new NetworkCredential("", connSecureString).Password, provName));

                if (UseTransaction)
                {
                    dbConnection.BeginTransaction();
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"{e}");
                HandleException(e, continueOnError);
            }
            return(asyncCodeActivityContext =>
            {
                DatabaseConnection.Set(asyncCodeActivityContext, dbConnection);
            });
        }
コード例 #3
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ProviderName.Expression != null)
            {
                targetCommand.AddParameter("ProviderName", ProviderName.Get(context));
            }

            if (WinEventId.Expression != null)
            {
                targetCommand.AddParameter("Id", WinEventId.Get(context));
            }

            if (Version.Expression != null)
            {
                targetCommand.AddParameter("Version", Version.Get(context));
            }

            if (Payload.Expression != null)
            {
                targetCommand.AddParameter("Payload", Payload.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
コード例 #4
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));
        }
コード例 #5
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);
            });
        }
コード例 #6
0
        protected override IAsyncResult BeginExecute(NativeActivityContext context, AsyncCallback callback, object state)
        {
            var connString   = ConnectionString.Get(context);
            var provName     = ProviderName.Get(context);
            var dbConnection = ExistingDbConnection.Get(context) ?? new DatabaseConnection().Initialize(connString, provName);

            ConnectionInitFunc = () => dbConnection;
            return(ConnectionInitFunc.BeginInvoke(callback, state));
        }
コード例 #7
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            var connString = ConnectionString.Get(context);
            var provName   = ProviderName.Get(context);
            Func <DatabaseConnection> action = () => _connectionFactory.Create(connString, provName);

            context.UserState = action;

            return(action.BeginInvoke(callback, state));
        }
コード例 #8
0
        protected override System.IAsyncResult BeginExecute(AsyncCodeActivityContext context, System.AsyncCallback callback, object state)
        {
            string connString     = null;
            string provName       = null;
            string sql            = string.Empty;
            int    commandTimeout = OverTime.Get(context);

            if (commandTimeout < 0)
            {
                throw new ArgumentException("TimeoutMS");
            }
            Dictionary <string, Tuple <object, ArgumentDirection> > parameters = null;

            try
            {
                sql        = SQLString.Get(context);
                DBConn     = DBConnection.Get(context);
                connString = ConnectionString.Get(context);
                provName   = ProviderName.Get(context);
                if (Parameters != null)
                {
                    parameters = new Dictionary <string, Tuple <object, ArgumentDirection> >();
                    foreach (var param in Parameters)
                    {
                        parameters.Add(param.Key, new Tuple <object, ArgumentDirection>(param.Value.Get(context), param.Value.Direction));
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }

            // create the action for doing the actual work
            Func <DBExecuteCommandResult> action = () =>
            {
                DBExecuteCommandResult executeResult = new DBExecuteCommandResult();
                if (DBConn == null)
                {
                    DBConn = new DatabaseConnection().Initialize(connString, provName);
                }
                if (DBConn == null)
                {
                    return(executeResult);
                }
                executeResult = new DBExecuteCommandResult(DBConn.Execute(sql, parameters, commandTimeout, CommandType), parameters);
                return(executeResult);
            };

            context.UserState = action;

            return(action.BeginInvoke(callback, state));
        }
コード例 #9
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            var    dataTable      = DataTable.Get(context);
            string connString     = null;
            string provName       = null;
            string sql            = string.Empty;
            int    commandTimeout = TimeoutMS.Get(context);

            if (commandTimeout < 0)
            {
                throw new ArgumentException(UiPath.Database.Activities.Properties.Resources.TimeoutMSException, "TimeoutMS");
            }
            Dictionary <string, Tuple <object, ArgumentDirection> > parameters = null;

            try
            {
                DbConnection = ExistingDbConnection.Get(context);
                connString   = ConnectionString.Get(context);
                provName     = ProviderName.Get(context);
                sql          = Sql.Get(context);
                if (Parameters != null)
                {
                    parameters = new Dictionary <string, Tuple <object, ArgumentDirection> >();
                    foreach (var param in Parameters)
                    {
                        parameters.Add(param.Key, new Tuple <object, ArgumentDirection>(param.Value.Get(context), param.Value.Direction));
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, ContinueOnError.Get(context));
            }

            // create the action for doing the actual work
            Func <DataTable> action = () =>
            {
                if (DbConnection == null)
                {
                    DbConnection = new DatabaseConnection().Initialize(connString, provName);
                }
                if (DbConnection == null)
                {
                    return(null);
                }
                return(DbConnection.ExecuteQuery(sql, parameters, commandTimeout, CommandType));
            };

            context.UserState = action;

            return(action.BeginInvoke(callback, state));
        }
コード例 #10
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;
            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);
            });
        }
コード例 #11
0
ファイル: Connect.cs プロジェクト: sunhawk2100/RPAStudio-1
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            string        connStr      = ConnectionString.Get(context);
            string        providerName = ProviderName.Get(context);
            SqlConnection sqlConn      = new SqlConnection();

            try
            {
                IDBConnectionFactory      _connectionFactory = new DBConnectionFactory();
                Func <DatabaseConnection> action             = () => _connectionFactory.Create(connStr, providerName);
                context.UserState = action;
                return(action.BeginInvoke(callback, state));
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "数据库连接失败:", e.Message);
                throw e;
            }
        }
コード例 #12
0
        protected override void Execute(NativeActivityContext context)
        {
            var connString   = ConnectionString.Get(context);
            var provName     = ProviderName.Get(context);
            var dbConnection = DBConnection.Get(context) ?? new DatabaseConnection().Initialize(connString, provName);


            if (dbConnection == null)
            {
                return;
            }
            if (UseTransaction)
            {
                dbConnection.BeginTransaction();
            }
            DBCONN.Set(context, dbConnection);

            if (Body != null)
            {
                context.ScheduleAction(Body, OnCompletedCallback, OnFaultedCallback);
            }
        }
コード例 #13
0
ファイル: ExecInsert.cs プロジェクト: wuzeqingit/RPAStudio
        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));
        }
コード例 #14
0
        protected async override Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            string                 connString       = null;
            SecureString           connSecureString = null;
            string                 provName         = null;
            string                 sql                = string.Empty;
            int                    commandTimeout     = TimeoutMS.Get(context);
            DatabaseConnection     existingConnection = null;
            DBExecuteCommandResult affectedRecords    = null;

            if (commandTimeout < 0)
            {
                throw new ArgumentException(Resources.TimeoutMSException, "TimeoutMS");
            }
            Dictionary <string, Tuple <object, ArgumentDirection> > parameters = null;
            var continueOnError = ContinueOnError.Get(context);

            try
            {
                sql = Sql.Get(context);
                existingConnection = DbConnection = ExistingDbConnection.Get(context);
                connString         = ConnectionString.Get(context);
                connSecureString   = ConnectionSecureString.Get(context);
                provName           = ProviderName.Get(context);

                if (Parameters != null)
                {
                    parameters = new Dictionary <string, Tuple <object, ArgumentDirection> >();
                    foreach (var param in Parameters)
                    {
                        parameters.Add(param.Key, new Tuple <object, ArgumentDirection>(param.Value.Get(context), param.Value.Direction));
                    }
                }
                ConnectionHelper.ConnectionValidation(existingConnection, connSecureString, connString, provName);
                // create the action for doing the actual work
                affectedRecords = await Task.Run(() =>
                {
                    DBExecuteCommandResult executeResult = new DBExecuteCommandResult();
                    if (DbConnection == null)
                    {
                        DbConnection = new DatabaseConnection().Initialize(connString ?? new NetworkCredential("", connSecureString).Password, provName);
                    }
                    if (DbConnection == null)
                    {
                        return(executeResult);
                    }
                    executeResult = new DBExecuteCommandResult(DbConnection.Execute(sql, parameters, commandTimeout, CommandType), parameters);
                    return(executeResult);
                });
            }
            catch (Exception ex)
            {
                HandleException(ex, continueOnError);
            }
            finally
            {
                if (existingConnection == null)
                {
                    DbConnection?.Dispose();
                }
            }

            return(asyncCodeActivityContext =>
            {
                AffectedRecords.Set(asyncCodeActivityContext, affectedRecords.Result);
                foreach (var param in affectedRecords.ParametersBind)
                {
                    var currentParam = Parameters[param.Key];
                    if (currentParam.Direction == ArgumentDirection.Out || currentParam.Direction == ArgumentDirection.InOut)
                    {
                        currentParam.Set(asyncCodeActivityContext, param.Value.Item1);
                    }
                }
            });
        }
コード例 #15
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (ListLog.Expression != null)
            {
                targetCommand.AddParameter("ListLog", ListLog.Get(context));
            }

            if (LogName.Expression != null)
            {
                targetCommand.AddParameter("LogName", LogName.Get(context));
            }

            if (ListProvider.Expression != null)
            {
                targetCommand.AddParameter("ListProvider", ListProvider.Get(context));
            }

            if (ProviderName.Expression != null)
            {
                targetCommand.AddParameter("ProviderName", ProviderName.Get(context));
            }

            if (Path.Expression != null)
            {
                targetCommand.AddParameter("Path", Path.Get(context));
            }

            if (MaxEvents.Expression != null)
            {
                targetCommand.AddParameter("MaxEvents", MaxEvents.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }

            if (FilterXPath.Expression != null)
            {
                targetCommand.AddParameter("FilterXPath", FilterXPath.Get(context));
            }

            if (FilterXml.Expression != null)
            {
                targetCommand.AddParameter("FilterXml", FilterXml.Get(context));
            }

            if (FilterHashtable.Expression != null)
            {
                targetCommand.AddParameter("FilterHashtable", FilterHashtable.Get(context));
            }

            if (Force.Expression != null)
            {
                targetCommand.AddParameter("Force", Force.Get(context));
            }

            if (Oldest.Expression != null)
            {
                targetCommand.AddParameter("Oldest", Oldest.Get(context));
            }

            if (GetIsComputerNameSpecified(context) && (PSRemotingBehavior.Get(context) == RemotingBehavior.Custom))
            {
                targetCommand.AddParameter("ComputerName", PSComputerName.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }