- General Information
- Connecting Third-party Systems
- crossConnect for content systems
- crossConnect for External Editing
- Purpose and usage
- Requirements
- Implementation
- Across XLIFF format
- Across-specific Extensions
- <xliff> Element Attributes
- <file> Element Extensions
- <trans-unit> Element Extension
- Paragraph States
- Paragraph State Flags
- <source> and <target> Element Content
- <bpt> Element Attributes
- <ph> Element Attributes
- <x> Element Attributes
- Across-specific Properties
- Analysis Results
- Sample Files
- Across XLIFF - import, export and segmentation
- Context information
- Exporting best matches in Across XLIFF
- Hyperlinks to XLIFF
- Secure file handling with C#
- Secure file handling with JAVA
- Workflow and vendor configuration
- Sample code - Integrated solution
- Across XLIFF format
- Generic File Connector
- Display Texts
- APIs
- APIs - Technology
- crossTank API v1
- crossTank API v2
- crossTerm API v1
- crossTerm API v2
- crossAPI SI
- Requirements
- Function Return Types
- crossAPI SI and Java
- List of Objects in crossAPI SI
- Sample - transferring checkout files via FileManager
- Sample - VBS
- Text Preprocessing API
Used Functions
Search
This app illustrates the wildcard search mode with parameters.
public async Task<(IEnumerable<Term> Terms, long TotalCount)> SearchTermsAsync(string query, int? lcid, int top, int skip) { var dataContext = await _dataContextFactory.CreateAsync().ConfigureAwait(false); var searchQuery = new CrossTerm.WildcardSearchTermQuery { Query = query, Parameters = new CrossTerm.TermsSearchParameters { SourceLanguage = lcid.GetValueOrDefault() } }; var terms = await dataContext.Terms .Expand("Properties($expand=Values,DataCategory)") .Expand("Entry($expand=Definitions)") .AddQueryOption("$skip", skip) .AddQueryOption("$top", top) .IncludeTotalCount() .WildcardSearch(searchQuery) .ExecuteAsync() .ConfigureAwait(false) as QueryOperationResponse<CrossTerm.Term>; return (terms.Select(_mapper.Map), terms.TotalCount); }
Get by ID
Simply get term by ID.
public async Task<Term> GetTermAsync(int id) { var dataContext = await _dataContextFactory.CreateAsync().ConfigureAwait(false); Term result = null; var term = await CrossTerm.ExtensionMethods.ByKey(dataContext.Terms, id) .Expand("Properties($expand=Values,DataCategory)") .Expand("Entry($expand=Definitions)") .GetValueAsync() .ConfigureAwait(false); if (term != null) { result = _mapper.Map(term); } return result; }
Create New Term
The new term can only exist under the root of the entry. There are ways to create a new term within an existing entry or to create a completely new entry.
public async Task<Term> CreateTermAsync(Term term) { if (term == null) { throw new ArgumentNullException(nameof(term)); } var dataContext = await _dataContextFactory.CreateAsync().ConfigureAwait(false); CrossTerm.Entry entry; if (term.EntryId.HasValue) { // Get existing entry to add term to. entry = await CrossTerm.ExtensionMethods .ByKey(dataContext.Entries, term.EntryId.Value) .GetValueAsync() .ConfigureAwait(false); } else { // Otherwise create new entry. entry = new CrossTerm.Entry { InstanceId = term.InstanceId, }; dataContext.AddToEntries(entry); } ...
Then consistently add term to the entry, add entry definitions, term properties and values.
... // Add new definitions to entry. foreach (var definition in term.Definitions) { var newDefinition = new CrossTerm.EntryDefinition { Definition = definition.Value, LanguageId = _mapper.Map(definition.Lcid.Value), }; dataContext.AddRelatedObject(entry, "Definitions", newDefinition); } // Create new term. var newTerm = new CrossTerm.Term { Name = term.Name, LanguageId = _mapper.Map(term.Lcid.Value) }; dataContext.AddRelatedObject(entry, "Terms", newTerm); // Add related properties. foreach (var property in term.Properties) { var newProperty = new CrossTerm.TermProperty { DataCategoryId = property.DataCategoryId }; dataContext.AddRelatedObject(newTerm, "Properties", newProperty); foreach (var value in property.Values) { var newValue = new CrossTerm.TextPropertyValue { Value = value.Value }; dataContext.AddRelatedObject(property, "Values", value); } } var response = await dataContext.SaveChangesAsync().ConfigureAwait(false); term.Id = newTerm.Id; return term; }
Update Term
Retrieve every entity instance to update using OData context. Then apply changes consistently and save them.
As an example for term:
private async Task UpdateTermInfoAsync(Term model, CrossTermDataContext dataContext) { var term = await CrossTerm.ExtensionMethods .ByKey(dataContext.Terms, model.Id.Value) .GetValueAsync() .ConfigureAwait(false); if (term == null) { throw new InvalidOperationException($"There is no term with Id = {model.Id.Value}."); } term.Name = model.Name; term.LanguageId = _mapper.Map(model.Lcid.Value); dataContext.UpdateObject(term); }
Term properties:
private async Task UpdateTermPropertiesAsync(Term model, CrossTermDataContext dataContext) { var values = model.Properties .Where(p => p.Type != PropertyType.Undefined) .SelectMany(p => p.Values); foreach (var value in values) { var propertyValue = await CrossTerm.ExtensionMethods .ByKey(dataContext.PropertyValues, value.Id.Value) .GetValueAsync() .ConfigureAwait(false); if (propertyValue == null) { throw new InvalidOperationException(); } switch (propertyValue) { case CrossTerm.TextPropertyValue textValue: textValue.Value = value.Value; break; case CrossTerm.AttachmentPropertyValue _: case CrossTerm.ExternalPropertyValue _: case CrossTerm.IndexPropertyValue _: case CrossTerm.PicklistPropertyValue _: throw new NotImplementedException(); default: throw new InvalidOperationException("Unknown property value type."); } dataContext.UpdateObject(propertyValue); } }
Then await dataContext.SaveChangesAsync();
Delete Term
See previous description.
public async Task<Term> DeleteTermAsync(int id) { var dataContext = await _dataContextFactory.CreateAsync().ConfigureAwait(false); var term = await CrossTerm.ExtensionMethods .ByKey(dataContext.Terms, id) .GetValueAsync() .ConfigureAwait(false); if (term == null) { throw new InvalidOperationException($"There is no term with Id = {id}."); } dataContext.DeleteObject(term); await dataContext.SaveChangesAsync().ConfigureAwait(false); var deleted = _mapper.Map(term); return deleted; }