コード例 #1
0
        /// <summary>
        /// Check if the report was successfully generated
        /// </summary>
        /// <param name="reportOutputPath"></param>
        /// <param name="isChecked"></param>
        /// <param name="optionalInformation"></param>
        /// <param name="projects"></param>
        /// <returns></returns>
        public bool GenerateReportFile(BindingList <ProjectDetails> projects, OptionalInformation optionalInformation, string reportOutputPath, bool isChecked)
        {
            try
            {
                Directory.CreateDirectory(reportOutputPath);
                var projectsToBeExported = projects.Where(p => p.ShouldBeExported).ToList();
                var areCheckedLanguages  = projectsToBeExported.Any(p => p.ProjectLanguages.Any(l => l.Value));
                if (areCheckedLanguages || projectsToBeExported.Count > 0)
                {
                    foreach (var project in projectsToBeExported)
                    {
                        // check which languages to export
                        if (project.ProjectLanguages == null)
                        {
                            continue;
                        }
                        var checkedLanguages = project.ProjectLanguages.Where(l => l.Value).ToList();

                        foreach (var languageReport in checkedLanguages)
                        {
                            project.ReportPath = reportOutputPath;
                            WriteReportFile(project, optionalInformation, languageReport, isChecked);
                        }
                    }
                    return(true);
                }
                _messageBoxService.ShowInformationMessage(PluginResources.SelectLanguage_Export_Message, PluginResources.ExportResult_Label);
                return(false);
            }
            catch (Exception exception)
            {
                Log.Logger.Error($"GenerateReport method: {exception.Message}\n {exception.StackTrace}");
                throw;
            }
        }
コード例 #2
0
        public async Task AddTermToDictionary(Term term)
        {
            CheckConnection();

            var model        = GetCorrespondingLanguageMappingModel();
            var dictionaryId = model.SelectedDictionary.DictionaryId;

            if (string.IsNullOrWhiteSpace(dictionaryId))
            {
                _messageService.ShowWarningMessage(PluginResources.No_dictionary_has_been_selected, PluginResources.Operation_failed);
                return;
            }

            var uri     = new Uri($@"{Constants.MTCloudTranslateAPIUri}/v4/accounts/{ConnectionService.Credential.AccountId}/dictionaries/{dictionaryId}/terms");
            var request = GetRequestMessage(HttpMethod.Post, uri);

            var content = JsonConvert.SerializeObject(term);

            request.Content = new StringContent(content, new UTF8Encoding(), "application/json");

            var httpResponseMessage = await _httpClient.SendRequest(request);

            if (httpResponseMessage is not null)
            {
                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    _messageService.ShowInformationMessage(PluginResources.The_term_has_been_successfully_added_to_the_current_dictionary,
                                                           PluginResources.Operation_complete);
                }
                else
                {
                    _messageService.ShowWarningMessage(httpResponseMessage.Content.ReadAsStringAsync().Result,
                                                       PluginResources.Operation_failed);
                }
            }
        }