###前提・実現したいこと
https://github.com/chomado/xamarin-dev-doc/tree/master/hands-on
Xamarin Dev Days Tokyoのサンプルコードを実行していてわからない部分があったので質問させてください.
###発生している問題・エラーメッセージ
質問1 宿題1: Cognitive ServicesのEmotionServiceクラスのメソッドGetHappinessAsync中で, var client = new HttpClient(); と記述していますが,利用している箇所が見当たりません.これは何をしているのでしょうか? 質問2 デバッグをすると,GetHappinessAsyncメソッドからの応答がありません. Azure上を見るとData InとData Outは出ているので通信まではうまくいっていると思うのですが,どこで停止しているのかがわかりません.
###該当のソースコード
public class EmotionService { private static async Task<Emotion[]> GetHappinessAsync(string url) { var client = new HttpClient(); var emotionClient = new EmotionServiceClient("INSERT_EMOTION_SERVICE_KEY_HERE"); var emotionResults = await emotionClient.RecognizeAsync(url); if (emotionResults == null || emotionResults.Count() == 0) { throw new Exception("Can't detect face"); } return emotionResults; } //複数の被検対象が存在する場合の平均幸福度算出 public static async Task<float> GetAverageHappinessScoreAsync(string url) { Emotion[] emotionResults = await GetHappinessAsync(url); float score = 0; foreach (var emotionResult in emotionResults) { score = score + emotionResult.Scores.Happiness; } return score / emotionResults.Count(); } public static string GetHappinessMessage(float score) { score = score * 100; double result = Math.Round(score, 2); if (score >= 50) return result + " % ヽ(ヽ *゚▽゚*)ノ"; else return result + "% (;_;)"; } }
###試したこと
・HttpClientをコメントアウト=>特に変化なし
・ var emotionResults = await emotionClient.RecognizeAsync(url);をTry~Catch文で囲む=>Exceptionなし
###補足情報(言語/FW/ツール等のバージョンなど)
Windows10 Pro + VisualStudio2015Community
XamarinはStableの11/12時点の最新版です.
宜しくお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/14 13:36