public async Task AddOrUpdateEntry(int entryId, ExcelTerm excelEntry) { if (!string.IsNullOrWhiteSpace(excelEntry.Source) && !string.IsNullOrWhiteSpace(excelEntry.Target)) { await _excelTermLoaderService.AddOrUpdateTerm(entryId, excelEntry); } }
public async Task <Dictionary <int, ExcelTerm> > GetTermsFromExcel(ExcelWorksheet worksheet) { var result = new Dictionary <int, ExcelTerm>(); try { if (worksheet == null) { return(result); } await Task.Run(() => { foreach (var cell in worksheet.Cells[worksheet.Dimension.Address]) { var excellCellAddress = new ExcelCellAddress(cell.Address); if (_providerSettings.HasHeader && excellCellAddress.Row == 1) { continue; } var id = excellCellAddress.Row; if (!result.ContainsKey(id)) { result[id] = new ExcelTerm(); } SetCellValue(result[id], cell, excellCellAddress.Column); } }); }catch (Exception ex) { TelemetryService.Instance.AddException(ex); } return(result); }
public IList <IEntryLanguage> CreateEntryLanguages(ExcelTerm excelTerm) { var result = new List <IEntryLanguage>(); var sourceEntryLanguage = new ExcelEntryLanguage { Locale = excelTerm.SourceCulture, Name = excelTerm.SourceCulture.EnglishName, Terms = CreateEntryTerms(excelTerm.Source), Fields = new List <IEntryField>(), IsSource = true }; result.Add(sourceEntryLanguage); if (excelTerm.Target != null) { var targetEntryLanguage = new ExcelEntryLanguage { Locale = excelTerm.TargetCulture, Name = excelTerm.TargetCulture.EnglishName, Terms = CreateEntryTerms(excelTerm.Target, excelTerm.Approved), Fields = new List <IEntryField>(), IsSource = false }; result.Add(targetEntryLanguage); } return(result); }
public async Task <Dictionary <int, ExcelTerm> > GetTermsFromExcel(ExcelWorksheet worksheet) { var result = new Dictionary <int, ExcelTerm>(); try { if (worksheet == null) { return(result); } await Task.Run(() => { foreach (var cell in worksheet.Cells[worksheet.Dimension.Address]) { var excellCellAddress = new ExcelCellAddress(cell.Address); if (_providerSettings.HasHeader && excellCellAddress.Row == 1) { continue; } var id = excellCellAddress.Row; if (!result.ContainsKey(id)) { result[id] = new ExcelTerm(); } SetCellValue(result[id], cell, excellCellAddress.Column); } }); } catch (Exception ex) { Log.Logger.Error($"GetTermsFromExcel method: {ex.Message}\n {ex.StackTrace}"); throw ex; } return(result); }
private async Task Save() { try { if (sourceListView.SelectedObject == null) { return; } var entry = new ExcelTerm(); var terms = sourceListView.Objects.Cast <ExcelEntry>().ToList(); var source = (ExcelEntry)sourceListView.SelectedObject; if (source.Id == 0) { var maxId = terms.Max(x => x.Id); source.Id = maxId + 1; } var entryId = source.Id; entry.Source = source.SearchText; foreach (var cultureCast in source.Languages.Cast <ExcelEntryLanguage>()) { if (cultureCast.IsSource) { entry.SourceCulture = cultureCast.Locale; } else { entry.TargetCulture = cultureCast.Locale; } } var targetTerms = bsTarget.DataSource as List <ExcelDataGrid>; if (targetTerms != null) { var termValue = string.Join(_providerSettings.Separator.ToString(), targetTerms.Select(x => x.Term)); var approvedValue = string.Join(_providerSettings.Separator.ToString(), targetTerms.Select(x => x.Approved)); entry.Target = termValue; entry.Approved = approvedValue; } var entryLanguage = _transformerService.CreateEntryLanguages(entry); var entryToUpdate = terms.Find(item => item.Id == entryId); if (entryToUpdate != null) { entryToUpdate.Languages = entryLanguage; } await _excelTermProviderService.AddOrUpdateEntry(entryId, entry); source.IsDirty = false; _terminologyProviderExcel.Terms.Add(source); } catch (Exception ex) { Log.Logger.Error($"Save method: {ex.Message}\n {ex.StackTrace}"); throw ex; } }
private void AddTermInternal(string source, string target) { var excelTerm = new ExcelTerm { SourceCulture = _providerSettings.SourceLanguage, TargetCulture = _providerSettings.TargetLanguage, Source = source, Target = target }; AddTermInternal(excelTerm); }
private void AddTermToWorksheet(int entryId, ExcelTerm excelTerm, ExcelWorksheet workSheet) { var sourceColumnAddress = $"{_providerSettings.SourceColumn}{entryId}"; var targetColumnAddress = $"{_providerSettings.TargetColumn}{entryId}"; workSheet.SetValue(sourceColumnAddress, excelTerm.Source); workSheet.SetValue(targetColumnAddress, excelTerm.Target); if (!string.IsNullOrEmpty(_providerSettings.ApprovedColumn)) { var approvedColumnAddress = $"{_providerSettings.ApprovedColumn}{entryId}"; workSheet.Cells[approvedColumnAddress].Value = excelTerm.Approved; } }
public async Task AddOrUpdateTerm(int entryId, ExcelTerm excelTerm) { using (var excelPackage = new ExcelPackage(new FileInfo(_providerSettings.TermFilePath))) { var workSheet = await GetTerminologyWorksheet(excelPackage); if (workSheet == null) { return; } AddTermToWorksheet(entryId, excelTerm, workSheet); excelPackage.Save(); } }
private void AddTermInternal(string source, string target) { if (!string.IsNullOrWhiteSpace(target)) { var excelTerm = new ExcelTerm { SourceCulture = _providerSettings.SourceLanguage, TargetCulture = _providerSettings.TargetLanguage, Source = source, Target = target }; AddTermInternal(excelTerm); } else { MessageBox.Show(@"Taget selection cannot be empty", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void SetCellValue(ExcelTerm excelTerm, ExcelRangeBase cell, int columnIndex) { var columnLetter = ExcelCellAddress.GetColumnLetter(columnIndex); if (columnLetter == _providerSettings.SourceColumn) { excelTerm.Source = cell.Text; excelTerm.SourceCulture = _providerSettings.SourceLanguage; } if (columnLetter == _providerSettings.TargetColumn.ToUpper()) { excelTerm.Target = cell.Text; excelTerm.TargetCulture = _providerSettings.TargetLanguage; } if (columnLetter == _providerSettings.ApprovedColumn?.ToUpper()) { excelTerm.Approved = cell.Text; } }
public static ExcelTerm ToExcelTerm(this ExcelEntry excelEntry) { var result = new ExcelTerm(); foreach (var entryLanguages in excelEntry.Languages.Cast <ExcelEntryLanguage>()) { if (entryLanguages.IsSource) { result.SourceCulture = entryLanguages.Locale; result.Source = string.Join("|", entryLanguages.Terms.Select(x => x.Value)); } else { result.TargetCulture = entryLanguages.Locale; result.Target = string.Join("|", entryLanguages.Terms.Select(x => x.Value)); result.Approved = string.Join("|", entryLanguages.GetTermCustomFields()); } } return(result); }
private void AddTermInternal(ExcelTerm excelTerm) { try { if (_providerSettings.IsReadOnly) { MessageBox.Show(@"Terminology Provider is configured as read only!", @"Read Only", MessageBoxButtons.OK); return; } if (!_providerSettings.IsFileReady()) { MessageBox.Show( @"The excel file configured as a terminology provider appears to be also opened in the Excel application. Please close the file!", @"Excel file is used by another process", MessageBoxButtons.OK); return; } var entryLanguages = _transformerService.CreateEntryLanguages(excelTerm); var excelEntry = new ExcelEntry { Id = 0, Fields = new List <IEntryField>(), Languages = entryLanguages, SearchText = excelTerm.Source, IsDirty = true }; sourceListView.AddObject(excelEntry); JumpToTerm(excelEntry); } catch (Exception ex) { Log.Logger.Error($"AddTermInternal method: {ex.Message}\n {ex.StackTrace}"); throw ex; } }
public void AddAndEdit(IEntry entry, ExcelDataGrid excelDataGrid) { try { if (_providerSettings.IsReadOnly) { MessageBox.Show("Terminology Provider is configured as read only!", "Read Only", MessageBoxButtons.OK); return; } if (!_providerSettings.IsFileReady()) { MessageBox.Show( @"The excel file configured as a terminology provider appears to be also opened in the Excel application. Please close the file!", @"Excel file is used by another process", MessageBoxButtons.OK); return; } var terms = sourceListView.Objects.Cast <ExcelEntry>().ToList(); var selectedTerm = terms.FirstOrDefault(item => item.Id == entry.Id); var excelTerm = new ExcelTerm { SourceCulture = _providerSettings.SourceLanguage, TargetCulture = _providerSettings.TargetLanguage, Target = excelDataGrid.Term }; var source = (ExcelEntry)entry; source.IsDirty = true; excelTerm.Source = source.SearchText; var exist = false; var targetlanguage = selectedTerm?.Languages.Cast <ExcelEntryLanguage>() .FirstOrDefault(x => !x.IsSource); if (targetlanguage != null) { foreach (var term in targetlanguage.Terms) { if (term.Value == excelDataGrid.Term) { exist = true; } } if (exist == false) { var termToAdd = new EntryTerm { Value = excelDataGrid.Term }; targetlanguage.Terms.Add(termToAdd); terms[entry.Id].Languages = selectedTerm.Languages; } } JumpToTerm(entry); Task.Run(Save); } catch (Exception ex) { throw ex; } }
public Task AddOrUpdateTerm(int entryId, ExcelTerm excelTerm) { throw new NotImplementedException(); }