protected override T[] Execute(CodeActivityContext context)
        {
            var dt  = InputDataTable.Get(context);
            var col = Column.Get(context);

            int index = 0;

            if (col is string colName)
            {
                try
                {
                    index = dt.Columns[colName].Ordinal;
                }
                catch (NullReferenceException e)
                {
                    throw new ArgumentException(Resources.ExtractDataColumnValues_ErrorMsg_InvalidColumnNameFormat(colName), e);
                }
            }
            else
            {
                index = (int)col;
                if (index >= dt.Columns.Count)
                {
                    throw new ArgumentException(Resources.ExtractDataColumnValues_ErrorMsg_InvalidColumnIndexFormat(index));
                }
            }

            var values = dt.AsEnumerable().Select(row => row[index]).ToArray();

            return(ConvertValues(values, DefaultValue.Get(context)));
        }
        protected override void Execute(CodeActivityContext context)
        {
            var    inputDataTable = InputDataTable.Get(context);
            var    columnIndex    = ColumnIndex.Get(context);
            double result         = Utils.ColumnActionOnDataTable(inputDataTable, columnIndex, "MAX");

            MaximumValue.Set(context, result);
        }
        protected override void Execute(CodeActivityContext context)
        {
            var inputDataTable = InputDataTable.Get(context);
            var columnName     = ColumnName.Get(context);
            var result         = inputDataTable.AsEnumerable().Select(r => r.Field <string>(columnName)).ToArray();

            ResultArray.Set(context, result);
        }
        protected override string Execute(CodeActivityContext context)
        {
            var dt = InputDataTable.Get(context);

            if (dt == null)
            {
                return(null);
            }

            return(ConvertTo(TextFormat, dt, DateTimeFormat.Get(context) ?? DATE_FORMAT));
        }
        protected override void Execute(CodeActivityContext context)
        {
            Dictionary <string, string> dict = InputColumnsRenameMapping.Get(context);
            DataTable DT = InputDataTable.Get(context);

            foreach (string key in dict.Keys)
            {
                DT.Columns[key].ColumnName = dict[key];
            }

            OutputDataTable.Set(context, DT);
        }
        protected override void Execute(CodeActivityContext context)
        {
            var inputDataTable = InputDataTable.Get(context);
            int totalColumns   = inputDataTable.Columns.Count;

            string[] result = new string[totalColumns];
            for (int i = 0; i < totalColumns; i++)
            {
                result[i] = inputDataTable.Columns[i].ColumnName.ToString();
            }
            ResultArray.Set(context, result.ToArray());
        }
        protected override DataTable Execute(CodeActivityContext context)
        {
            var names     = new Dictionary <string, int>();
            var emptyName = EmptyColumnName.Get(context);

            var inputDT = InputDataTable.Get(context);

            if (inputDT.Rows.Count == 0)
            {
                throw new InvalidOperationException(Resources.PromoteHeaders_ErrorMsg_NoData);
            }

            var outputDT = inputDT.Copy();

            var row = outputDT.Rows[0];

            string getName(string firstRowValue)
            {
                return(string.IsNullOrEmpty(firstRowValue) ? emptyName : firstRowValue);
            }

            if (AutoRename)
            {
                foreach (DataColumn col in outputDT.Columns)
                {
                    var name = getName(row[col.ColumnName].ToString());
                    if (names.ContainsKey(name))
                    {
                        names[name]++;
                        name += names[name].ToString();
                    }
                    else
                    {
                        names.Add(name, 0);
                    }

                    col.ColumnName = name;
                }
            }
            else
            {
                foreach (DataColumn col in outputDT.Columns)
                {
                    col.ColumnName = getName(row[col.ColumnName].ToString());
                }
            }

            outputDT.Rows.Remove(row);
            return(outputDT);
        }
Esempio n. 8
0
        protected override object[] Execute(CodeActivityContext context)
        {
            var dt      = InputDataTable.Get(context);
            var columns = Columns?.Get(context);

            var columnIndexes = DataTableUtil.IdentifyDataColumns(dt, columns);

            var result = new object[dt.Columns.Count];

            if (dt.Rows.Count > 0)
            {
                AggregateTo(result, GetConvertibleColumns(dt, columnIndexes), dt.AsEnumerable());
            }

            return(result);
        }
Esempio n. 9
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            var names = new Dictionary <string, int>();

            // Inputs
            var inputDT = InputDataTable.Get(context);

            if (inputDT.Rows.Count == 0)
            {
                throw new InvalidOperationException(Resources.PromoteHeaders_EmptyRows_Error);
            }

            var outputDT = inputDT.Copy();

            var row = outputDT.Rows[0];

            if (AutoRename)
            {
                foreach (DataColumn col in outputDT.Columns)
                {
                    var name = row[col.ColumnName].ToString();
                    if (names.ContainsKey(name))
                    {
                        names[name]++;
                        name += names[name].ToString();
                    }
                    else
                    {
                        names.Add(name, 0);
                    }

                    col.ColumnName = name;
                }
            }
            else
            {
                foreach (DataColumn col in outputDT.Columns)
                {
                    col.ColumnName = row[col.ColumnName].ToString();
                }
            }

            outputDT.Rows.Remove(row);

            // Outputs
            return((ctx) => OutputDataTable.Set(ctx, outputDT));
        }
        protected override DataTable Execute(CodeActivityContext context)
        {
            var inputDt = InputDataTable.Get(context) ?? throw new ArgumentException(nameof(InputDataTable));
            var columns = DataTableUtil.IdentifyDataColumns(inputDt, Columns?.Get(context));

            DataTable outputDt;

            if (columns.Any())
            {
                outputDt = inputDt.Clone();
                var colIndexes = columns.ToArray();
                foreach (DataRow inRow in inputDt.Rows)
                {
                    var skip = false;
                    foreach (DataRow outRow in outputDt.Rows)
                    {
                        if (RowExist(inRow.ItemArray, outRow.ItemArray, colIndexes))
                        {
                            skip = true;
                            break;
                        }
                    }

                    if (skip)
                    {
                        continue;
                    }

                    outputDt.ImportRow(inRow);
                }
            }
            else
            {
                outputDt = inputDt.AsDataView().ToTable(true);
            }

            return(outputDt);
        }
        protected override DataTable Execute(CodeActivityContext context)
        {
            var inputDt = InputDataTable.Get(context);

            bool predicate(object value) => value != null && value != DBNull.Value && !string.IsNullOrWhiteSpace(value.ToString());

            // default handler
            Func <DataRow, bool> handler = dr => dr.ItemArray.Any(predicate);

            if (Mode == DataRowEvaluationMode.Any)
            {
                handler = dr => dr.ItemArray.All(predicate);
            }
            else if (Mode == DataRowEvaluationMode.Custom)
            {
                handler = GetCustomModeHandler(context, inputDt, predicate);
            }

            var rows     = inputDt.AsEnumerable().Where(handler);
            var dtResult = rows.Any() ? rows.CopyToDataTable() : inputDt.Clone();

            return(dtResult);
        }