/// <summary> /// Main execution method for activity /// </summary> /// <param name="context"></param> protected TextEvaluationOutputModel Execute(string Text, string apiKey = "") { TextEvaluationOutputModel _contentModeratorOutput = new TextEvaluationOutputModel(); var textInput = Text; textInput = textInput.Replace(System.Environment.NewLine, " "); if (apiKey != "") { // Sets to the user's apiKey, if supplied; if not, defaults to a free key ContentModeratorHelper.ApiKey = apiKey; } try { // Screen the input text: check for profanity, classify the text into three categories // do autocorrect text, and check for personally identifying // information (PII) _contentModeratorOutput = ContentModeratorHelper.GetTextEvaluationOutput(textInput); if (_contentModeratorOutput == null) { throw new System.Exception("Null Output"); } else { return(_contentModeratorOutput); } } catch (System.Exception ex) { Debug.WriteLine(ex.InnerException); Debug.WriteLine(ex.Message); throw new System.Exception($"Actual Exception Message: {ex.Message}\n{TextModerator.GeneralException}"); } }
/// <summary> /// Main activity method /// </summary> /// <param name="context"></param> protected override void Execute(CodeActivityContext context) { var textInput = Text.Get(context); textInput = textInput.Replace(System.Environment.NewLine, " "); var apiKey = ApiKey.Get(context); if (apiKey != null) { // Sets to the user's apiKey, if supplied; if not, defaults to a free key ContentModeratorHelper.ApiKey = apiKey; } try { // Screen the input text: check for profanity, classify the text into three categories // do autocorrect text, and check for personally identifying // information (PII) _contentModeratorOutput = ContentModeratorHelper.GetTextEvaluationOutput(textInput); if (_contentModeratorOutput == null) { throw new System.Exception("Null Output"); } else { FriendlyOutput.Set(context, _contentModeratorOutput.FriendlyOutput); JsonOutput.Set(context, _contentModeratorOutput.JsonOutput); AutoCorrectedText.Set(context, _contentModeratorOutput.AutoCorrectedText); NormalizedText.Set(context, _contentModeratorOutput.NormalizedText); ProfanityCategory1Score.Set(context, _contentModeratorOutput.ProfanityCategory1Score); ProfanityCategory2Score.Set(context, _contentModeratorOutput.ProfanityCategory2Score); ProfanityCategory3Score.Set(context, _contentModeratorOutput.ProfanityCategory3Score); ReviewRecommended.Set(context, _contentModeratorOutput.ReviewRecommended); } } catch (System.Exception ex) { throw new System.Exception($"Actual Exception Message: {ex.Message}\n{GeneralException}"); } }