protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _dataObject = dataObject; ErrorResultTO allErrors = new ErrorResultTO(); int indexToUpsertTo = 0; InitializeDebug(dataObject); try { IExchange runtimeSource = ResourceCatalog.GetResource <ExchangeSource>(dataObject.WorkspaceID, SavedSource.ResourceID); if (runtimeSource == null) { dataObject.Environment.Errors.Add(ErrorResource.InvalidEmailSource); return; } if (IsDebug) { AddDebugInputItem(new DebugEvalResult(To, "To", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Subject, "Subject", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Body, "Body", dataObject.Environment, update)); } var colItr = new WarewolfListIterator(); var toItr = new WarewolfIterator(dataObject.Environment.Eval(To, update)); colItr.AddVariableToIterateOn(toItr); var ccItr = new WarewolfIterator(dataObject.Environment.Eval(Cc, update)); colItr.AddVariableToIterateOn(ccItr); var bccItr = new WarewolfIterator(dataObject.Environment.Eval(Bcc, update)); colItr.AddVariableToIterateOn(bccItr); var subjectItr = new WarewolfIterator(dataObject.Environment.Eval(Subject, update)); colItr.AddVariableToIterateOn(subjectItr); var bodyItr = new WarewolfIterator(dataObject.Environment.Eval(Body, update)); colItr.AddVariableToIterateOn(bodyItr); var attachmentsItr = new WarewolfIterator(dataObject.Environment.Eval(Attachments ?? string.Empty, update)); colItr.AddVariableToIterateOn(attachmentsItr); if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { ErrorResultTO errors; var result = _emailSender.SendEmail(runtimeSource, colItr, toItr, ccItr, bccItr, subjectItr, bodyItr, attachmentsItr, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { indexToUpsertTo = UpsertResult(indexToUpsertTo, dataObject.Environment, result, update); } } if (IsDebug && !allErrors.HasErrors()) { if (!string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } } else { if (IsDebug) { AddDebugInputItem(To, "To"); AddDebugInputItem(Subject, "Subject"); AddDebugInputItem(Body, "Body"); } } } catch (Exception e) { Dev2Logger.Error("DSFEmail", e); allErrors.AddError(e.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { foreach (var err in allErrors.FetchErrors()) { dataObject.Environment.Errors.Add(err); } UpsertResult(indexToUpsertTo, dataObject.Environment, null, update); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfSendEmailActivity", allErrors); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
private int TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, int indexToUpsertTo, IExchange runtimeSource) { if (IsDebug) { AddDebugInputItem(new DebugEvalResult(To, "To", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Subject, "Subject", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Body, "Body", dataObject.Environment, update)); } var colItr = new WarewolfListIterator(); var toItr = new WarewolfIterator(dataObject.Environment.Eval(To, update)); colItr.AddVariableToIterateOn(toItr); var ccItr = new WarewolfIterator(dataObject.Environment.Eval(Cc, update)); colItr.AddVariableToIterateOn(ccItr); var bccItr = new WarewolfIterator(dataObject.Environment.Eval(Bcc, update)); colItr.AddVariableToIterateOn(bccItr); var subjectItr = new WarewolfIterator(dataObject.Environment.Eval(Subject, update)); colItr.AddVariableToIterateOn(subjectItr); var bodyItr = new WarewolfIterator(dataObject.Environment.Eval(Body, update)); colItr.AddVariableToIterateOn(bodyItr); var attachmentsItr = new WarewolfIterator(dataObject.Environment.Eval(Attachments ?? string.Empty, update)); colItr.AddVariableToIterateOn(attachmentsItr); if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { var result = _emailSender.SendEmail(runtimeSource, colItr, toItr, ccItr, bccItr, subjectItr, bodyItr, attachmentsItr, out ErrorResultTO errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { indexToUpsertTo = UpsertResult(indexToUpsertTo, dataObject.Environment, result, update); } } if (IsDebug && !allErrors.HasErrors() && !string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } else { if (IsDebug) { AddDebugInputItem(To, "To"); AddDebugInputItem(Subject, "Subject"); AddDebugInputItem(Body, "Body"); } } return(indexToUpsertTo); }