/// <summary> /// When overridden runs the activity's execution logic /// </summary> /// <param name="context">The context to be used.</param> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlId = dataObject.DataListID; var allErrors = new ErrorResultTO(); ErrorResultTO errors; Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); IDev2DataListUpsertPayloadBuilder <IBinaryDataListEntry> toUpsert = Dev2DataListBuilderFactory.CreateBinaryDataListUpsertBuilder(true); try { toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.AttachDebugFromExpression = false; toUpsert.RecordSetDataAsCSVToScalar = true; toUpsert.ReplaceStarWithFixedIndex = true; IBinaryDataListEntry rsEntry; // We need to break up by , for InFields ;) List <string> cols = BreakAndValidate(dlId, compiler, InFields, dataObject, true, out errors, out rsEntry); allErrors.MergeErrors(errors); // Use row data?!, nope use row indexes ;) List <string> resultFields = BreakAndValidate(dlId, compiler, ResultFields, dataObject, false, out errors, out rsEntry); allErrors.MergeErrors(errors); compiler.Evaluate(dlId, enActionType.User, ResultFields, false, out errors); allErrors.MergeErrors(errors); compiler.Evaluate(dlId, enActionType.User, InFields, false, out errors); allErrors.MergeErrors(errors); // Fetch the unique data ;) if (!allErrors.HasErrors()) { List <int> uniqueRowIndexes = rsEntry.GetDistinctRows(cols); var shadowList = new List <IBinaryDataListEntry>(); // And break and validate the target expressions ;) List <string> targetExpressions = DataListCleaningUtils.SplitIntoRegions(Result); if (!allErrors.HasErrors()) { // process each row ;) foreach (var uidx in uniqueRowIndexes) { int idx = 0; // something in here is off ;) foreach (var targetExp in targetExpressions) { string error; // clone, prep and shove into the upsert payload builder ;) var clone = rsEntry.Clone(enTranslationDepth.Data, dlId, out error); allErrors.AddError(error); clone.MakeRecordsetEvaluateReady(uidx, resultFields[idx], out error); allErrors.AddError(error); // We need to replace * with fixed index? else we will over write all data all the time ;) toUpsert.Add(targetExp, clone); shadowList.Add(clone); idx++; } toUpsert.FlushIterationFrame(); } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); // If in debug mode, we have data and there is the correct debug info balance ;) if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { int innerCount = 1; foreach (var debugOutputTo in toUpsert.DebugOutputs) { var itemToAdd = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", innerCount.ToString(CultureInfo.InvariantCulture)), itemToAdd); AddDebugItem(new DebugItemVariableParams(debugOutputTo, targetExpressions.ToList()), itemToAdd); UpdateStarNotationColumns(itemToAdd); _debugOutputs.Add(itemToAdd); innerCount++; } } } } } catch (Exception e) { Dev2Logger.Log.Error("DSFUnique", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfUniqueActivity", allErrors); compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { if (hasErrors && !String.IsNullOrEmpty(Result)) { IBinaryDataListEntry entry = compiler.Evaluate(dlId, enActionType.User, Result, false, out errors); AddDebugOutputItem(new DebugItemVariableParams(Result, "", entry, dlId)); } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); IDev2DataListUpsertPayloadBuilder <IBinaryDataListEntry> toUpsertDeferred = Dev2DataListBuilderFactory.CreateBinaryDataListUpsertBuilder(true); toUpsertDeferred.IsDebug = true; IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = true; // Process if no errors if (dataObject.IsDebugMode()) { InitializeDebug(dataObject); } if (!errors.HasErrors()) { try { //Execute the concrete action for the specified activity IList <OutputTO> outputs = ExecuteConcreteAction(context, out errors); allErrors.MergeErrors(errors); if (outputs.Count > 0) { foreach (OutputTO output in outputs) { if (output.OutputStrings.Count > 0) { foreach (string value in output.OutputStrings) { if (output.OutPutDescription == GlobalConstants.ErrorPayload) { errors.AddError(value); } else { //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result foreach (var region in DataListCleaningUtils.SplitIntoRegions(output.OutPutDescription)) { toUpsert.Add(region, value); } } } toUpsert.FlushIterationFrame(); } } compiler.Upsert(dlId, toUpsert, out errors); if (dataObject.IsDebugMode()) { if (!String.IsNullOrEmpty(Result)) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } allErrors.MergeErrors(errors); } } catch (Exception ex) { allErrors.AddError(ex.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfFileActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } } }