예제 #1
0
        public void OnNext(EventPattern <WhenClipboardContainsTextEventArgs> value)
        {
            Task.Run(async() =>
            {
                try
                {
                    string currentString = value.EventArgs.CurrentString;

                    if (_previousString == currentString)
                    {
                        return;
                    }

                    _previousString = currentString;
                    Maybe <string> failedResults;

                    string fromLanguageExtension = await _languageDetector.DetectLanguage(currentString);
                    TranslateResult[] results    = await GetMeansFromCache(currentString, fromLanguageExtension);
                    Maybe <string> findedMeans   = await _resultOrganizer.OrganizeResult(results, currentString, out failedResults).ConfigureAwait(false);

                    await Notify(currentString, findedMeans);
                    await Notify(currentString, failedResults);
                    await Trace(currentString, fromLanguageExtension);
                }
                catch (Exception ex)
                {
                    await Notify("Error", new Maybe <string>(ex.Message));
                }
            });
        }
예제 #2
0
        public async void OnNext(EventPattern <WhenClipboardContainsTextEventArgs> value)
        {
            await Task.Run(async() =>
            {
                var currentString = value.EventArgs.CurrentString;

                if (previousString == currentString)
                {
                    return;
                }

                previousString = currentString;

                var fromLanguageExtension = await languageDetector.DetectLanguage(currentString);

                var results = await cache.GetAsync(currentString,
                                                   async() => await Task.WhenAll(meanFinderFactory.GetFinders().Select(t => t.Find(new TranslateRequest(currentString, fromLanguageExtension)))))
                              .ConfigureAwait(false);

                var findedMeans = await resultOrganizer.OrganizeResult(results, currentString).ConfigureAwait(false);

                await notifier.AddNotificationAsync(currentString, ImageUrls.NotificationUrl, findedMeans.DefaultIfEmpty(string.Empty).First()).ConfigureAwait(false);

                await googleAnalytics.TrackEventAsync("DynamicTranslator", "Translate", currentString, null).ConfigureAwait(false);

                await googleAnalytics.TrackAppScreenAsync("DynamicTranslator",
                                                          ApplicationVersion.GetCurrentVersion(),
                                                          "dynamictranslator",
                                                          "dynamictranslator",
                                                          "notification").ConfigureAwait(false);
            });
        }