/// <summary> /// Main activity method /// </summary> /// <param name="context"></param> protected override void Execute(CodeActivityContext context) { var textToTranslate = Text.Get(context); var targetLanguageCode = TargetLanguageCode.Get(context); var apiKey = ApiKey.Get(context); if (apiKey != null) { // Sets to the user's apiKey, if supplied; if not, defaults to a free key MicrosoftTranslationClient.ApiKey = apiKey; } try { var translatedText = MicrosoftTranslationClient.TranslateText(textToTranslate, targetLanguageCode); var detectedSourceLanguage = MicrosoftTranslationClient.Detect(textToTranslate); TranslatedText.Set(context, translatedText); DetectedSourceLanguage.Set(context, detectedSourceLanguage); } catch (System.Exception ex) { throw new System.Exception($"Actual Error: {ex.Message}\n{MicrosoftTranslationClient.InvalidApiKeyResolution}"); } }