Esempio n. 1
0
        public async void Download()
        {
            StatusMessage        = "ダウンロードを開始します";
            ProgressMaxValue     = TranslationFiles.Count();
            ProgressCurrentValue = 0;
            IsProgress           = true;
            try
            {
                if (!Directory.Exists(DownloadDirectoryName))
                {
                    Directory.CreateDirectory(DownloadDirectoryName);
                }

                foreach (var translationFile in TranslationFiles)
                {
                    StatusMessage = $"{translationFile.Name}をダウンロード中...";
                    var uri = new Uri(translationFile.Url);
                    await Downloader.DownloadAsync(uri,
                                                   $@"{DownloadDirectoryName}\{translationFile.Name}.csv");

                    translationFile.UpdateLastModifyTime();
                    ProgressCurrentValue += 1;
                }

                StatusMessage = "全てのダウンロードが完了しました";
            }
            finally
            {
                IsProgress = false;
            }
        }
        public void RefreshScores()
        {
            //get unique translation keys of all files
            Dictionary <string, Tuple <string, string> > uniqueTranslationKeys = new Dictionary <string, Tuple <string, string> >();

            foreach (TranslationFile translationFile in TranslationFiles)
            {
                foreach (TranslationPair translationPair in translationFile.TranslationPairs)
                {
                    if (!uniqueTranslationKeys.ContainsKey(translationPair.Key))
                    {
                        uniqueTranslationKeys.Add(translationPair.Key, new Tuple <string, string>(translationFile.Name, translationPair.Value));
                    }
                }
            }

            //determine score for every key and add missing keys to respective files
            foreach (KeyValuePair <string, Tuple <string, string> > uniqueTranslationPair in uniqueTranslationKeys)
            {
                double score = (double)TranslationFiles.Count(tf => tf.TranslationPairs.Any(tp => tp.Key == uniqueTranslationPair.Key && !string.IsNullOrWhiteSpace(tp.Value))) / TranslationFiles.Count();
                foreach (TranslationFile translationFile in TranslationFiles)
                {
                    TranslationPair translationPair = translationFile.TranslationPairs.FirstOrDefault(tp => tp.Key == uniqueTranslationPair.Key);
                    if (translationPair == null)
                    {
                        //_languageServiceClient.GetAppIdToken(APP_ID, );
                        //string autoTranslateValue = _languageServiceClient.Translate(
                        //	"Bearer" + " " + APP_ID,
                        //	uniqueTranslationPair.Value.Item2,
                        //	uniqueTranslationPair.Value.Item1,
                        //	translationFile.Name,
                        //	"text/plain",
                        //	"general"
                        //	);
                        translationFile.TranslationPairs.Add(new TranslationPair {
                            Key = uniqueTranslationPair.Key, Value = "", Score = 0
                        });
                    }
                    else if (string.IsNullOrWhiteSpace(translationPair.Value))
                    {
                        translationPair.Score = 0;
                        //translationPair.Value = _languageServiceClient.Translate(
                        //	"Bearer" + " " + APP_ID,
                        //	uniqueTranslationPair.Value.Item2,
                        //	uniqueTranslationPair.Value.Item1,
                        //	translationFile.Name,
                        //	"text/plain",
                        //	"general"
                        //	);
                    }
                    else
                    {
                        translationPair.Score = score;
                    }
                }
            }

            foreach (TranslationFile translationFile in TranslationFiles)
            {
                translationFile.TranslationPairs = new ObservableCollection <TranslationPair>(translationFile.TranslationPairs.OrderBy(tp => tp.Score).ThenBy(tp => tp.Key));
            }
        }