// ---------------------------------
// <copyright file="AbstractTrados2007LanguageDirection.cs" company="SDL International">
// Copyright  2011 All Right Reserved
// </copyright>
// <author>Kostiantyn Lukianets</author>
// <email>klukianets@sdl.com</email>
// <date>2011-11-08</date>
// ---------------------------------
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace Sdl.Community.Trados2007
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using Sdl.LanguagePlatform.Core;
    using Sdl.LanguagePlatform.TranslationMemory;
    using Sdl.LanguagePlatform.TranslationMemoryApi;
    using Trados.Interop.TMAccess;
    using Action = Sdl.LanguagePlatform.TranslationMemory.Action;
    using SearchResult = Sdl.LanguagePlatform.TranslationMemory.SearchResult;
    
    using Sdl.LanguagePlatform.Lingua.TermRecognition;
    /// <summary>
    /// Abstract base class for file- and server-based Trados 2007 language directions.
    /// </summary>
    [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1623:PropertySummaryDocumentationMustMatchAccessors",
        Justification = "By original SDL API design.")]
    public abstract class AbstractTrados2007LanguageDirection : ITranslationProviderLanguageDirection
    {
        #region Fields
        protected readonly object locker = new object();
        /// <summary>
        /// Stores Trados 2007 Translation Provider that owns this particular Language Direction.
        /// </summary>
        private readonly AbstractTrados2007TranslationProvider translationProvider;
        /// <summary>
        /// Stores languages direction.
        /// </summary>
        private readonly LanguagePair languageDirection;
        #endregion // Fields
        /// <summary>
        /// Initializes a new instance of the <see cref="AbstractTrados2007LanguageDirection"/> class.
        /// </summary>
        /// <param name="translationProvider">The Trados 2007 translation provider.</param>
        protected AbstractTrados2007LanguageDirection(AbstractTrados2007TranslationProvider translationProvider)
        {
            if (translationProvider == null)
            {
                throw new ArgumentNullException("translationProvider");
            }
            // Trados 2007 TP supports only one language direction, regardless file- or -server based
            this.translationProvider = translationProvider;
            this.languageDirection = translationProvider.LanguageDirection;
        }
        #region Properties
        /// <summary>
        /// The translation provider to which this language direction belongs.
        /// </summary>
        ITranslationProvider ITranslationProviderLanguageDirection.TranslationProvider
        {
            get
            {
                return this.translationProvider;
            }
        }
        /// <summary>
        /// Gets the source language.
        /// </summary>
        public CultureInfo SourceLanguage
        {
            get
            {
                return this.languageDirection.SourceCulture;
            }
        }
        /// <summary>
        /// Gets the target language.
        /// </summary>
        public CultureInfo TargetLanguage
        {
            get
            {
                return this.languageDirection.TargetCulture;
            }
        }
        /// <summary>
        /// Gets a flag which indicates whether the translation provider supports
        /// searches in the reversed language direction.
        /// </summary>
        public bool CanReverseLanguageDirection
        {
            get
            {
                return false;
            }
        }
        /// <summary>
        /// The translation provider to which this language direction belongs.
        /// </summary>
        protected AbstractTrados2007TranslationProvider TranslationProvider
        {
            get
            {
                return this.translationProvider;
            }
        }
        #endregion // Properties
        #region Methods
        /// <summary>
        /// Adds a translation unit to the database. If the provider doesn't support adding/updating, the 
        ///             implementation should return a reasonable <see cref="T:Sdl.LanguagePlatform.TranslationMemory.ImportResult"/> but should not throw an exception.
        /// </summary>
        /// <param name="translationUnit">The translation unit.</param><param name="settings">The settings used for this operation.</param>
        /// <returns>
        /// An <see cref="T:Sdl.LanguagePlatform.TranslationMemory.ImportResult"/> which represents the status of the operation (succeeded, ignored, etc).
        /// </returns>
        [Obsolete(@"Trados 2007 Translation Provider does not support adding\editing.")]
        public virtual ImportResult AddTranslationUnit(TranslationUnit translationUnit, ImportSettings settings)
        {
            return new ImportResult { Action = Action.Add, ErrorCode = ErrorCode.InvalidOperation };
        }
        /// <summary>
        /// Adds an array of translation units to the database. If the provider doesn't support adding/updating, the 
        ///             implementation should return a reasonable <see cref="T:Sdl.LanguagePlatform.TranslationMemory.ImportResult"/> but should not throw an exception.
        /// </summary>
        /// <param name="translationUnits">An arrays of translation units to be added.</param><param name="settings">The settings used for this operation.</param>
        /// <returns>
        /// An array of <see cref="T:Sdl.LanguagePlatform.TranslationMemory.ImportResult"/> objects, which mirrors the translation unit array. It has the exact same size and contains the
        ///             status of each add operation for each particular translation unit with the same index within the array.
        /// </returns>
        [Obsolete(@"Trados 2007 Translation Provider does not support adding\editing.")]
        public virtual ImportResult[] AddTranslationUnits(TranslationUnit[] translationUnits, ImportSettings settings)
        {
            return new[] { new ImportResult() { Action = Action.Add, ErrorCode = ErrorCode.InvalidOperation } };
        }
        /// <summary>
        /// Adds an array of translation units to the database. If hash codes of the previous translations are provided, 
        ///             a found translation will be overwritten. If none is found, or the hash is 0 or the collection is <c>null</c>, 
        ///             the operation behaves identical to <see cref="M:Sdl.LanguagePlatform.TranslationMemoryApi.ITranslationProviderLanguageDirection.AddTranslationUnits(Sdl.LanguagePlatform.TranslationMemory.TranslationUnit[],Sdl.LanguagePlatform.TranslationMemory.ImportSettings)"/>.
        /// <para>
        /// If the provider doesn't support adding/updating, the 
        ///             implementation should return a reasonable <see cref="T:Sdl.LanguagePlatform.TranslationMemory.ImportResult"/> but should not throw an exception.
        /// </para>
        /// </summary>
        /// <param name="translationUnits">An arrays of translation units to be added.</param><param name="previousTranslationHashes">If provided, a corresponding array of a the hash code of a previous translation.</param><param name="settings">The settings used for this operation.</param>
        /// <returns>
        /// An array of <see cref="T:Sdl.LanguagePlatform.TranslationMemory.ImportResult"/> objects, which mirrors the translation unit array. It has the exact same size and contains the
        ///             status of each add operation for each particular translation unit with the same index within the array.
        /// </returns>
        [Obsolete(@"Trados 2007 Translation Provider does not support adding\editing.")]
        public virtual ImportResult[] AddOrUpdateTranslationUnits(TranslationUnit[] translationUnits, int[] previousTranslationHashes, ImportSettings settings)
        {
            int count = translationUnits.Length;
            var result = new ImportResult[count];
            var err = new ImportResult() { Action = Action.Add, ErrorCode = ErrorCode.InvalidOperation };
            for (int i = 0; i < count; i++)
            {
                result[i] = err;
            }
            return result;
        }
        /// <summary>
        /// Adds an array of translation units to the database, but will only add those
        ///             for which the corresponding mask field is <c>true</c>. If the provider doesn't support adding/updating, the 
        ///             implementation should return a reasonable ImportResult but should not throw an exception.
        /// </summary>
        /// <param name="translationUnits">An arrays of translation units to be added.</param><param name="settings">The settings used for this operation.</param><param name="mask">A boolean array with the same cardinality as the TU array, specifying which TUs to add.</param>
        /// <returns>
        /// An array of ImportResult objects, which mirrors the translation unit array. It has the exact same size and contains the
        ///             status of each add operation for each particular translation unit with the same index within the array.
        /// </returns>
        [Obsolete(@"Trados 2007 Translation Provider does not support adding\editing.")]
        public virtual ImportResult[] AddTranslationUnitsMasked(TranslationUnit[] translationUnits, ImportSettings settings, bool[] mask)
        {
            return new[] { new ImportResult() { Action = Action.Add, ErrorCode = ErrorCode.InvalidOperation } };
        }
        /// <summary>
        /// Adds an array of translation units to the database, but will only add those
        ///             for which the corresponding mask field is true. If the previous translation hashes are provided,
        ///             existing translations will be updated if the target segment hash changed.
        /// <para>
        /// If the provider doesn't support adding/updating, the 
        ///             implementation should return a reasonable ImportResult but should not throw an exception.
        /// </para>
        /// </summary>
        /// <param name="translationUnits">An arrays of translation units to be added.</param><param name="previousTranslationHashes">Corresponding hash codes of a previous translation (0 if unknown). The parameter may be null.</param><param name="settings">The settings used for this operation.</param><param name="mask">A boolean array with the same cardinality as the TU array, specifying which TUs to add.</param>
        /// <returns>
        /// An array of ImportResult objects, which mirrors the translation unit array. It has the exact same size and contains the
        ///             status of each add operation for each particular translation unit with the same index within the array.
        /// </returns>
        [Obsolete(@"Trados 2007 Translation Provider does not support adding\editing.")]
        public virtual ImportResult[] AddOrUpdateTranslationUnitsMasked(TranslationUnit[] translationUnits, int[] previousTranslationHashes, ImportSettings settings, bool[] mask)
        {
            return new[] { new ImportResult() { Action = Action.Add, ErrorCode = ErrorCode.InvalidOperation } };
        }
        /// <summary>
        /// Performs a search for an array of segments.
        /// </summary>
        /// <param name="settings">The settings that define the search parameters.</param><param name="segments">The array containing the segments to search for.</param>
        /// <returns>
        /// An array of <see cref="T:Sdl.LanguagePlatform.TranslationMemory.SearchResults"/> objects, which mirrors the segments array. It has the exact same size and contains the
        ///             search results for each segment with the same index within the segments array.
        /// </returns>
        public virtual SearchResults[] SearchSegments(SearchSettings settings, Segment[] segments)
        {


Answer:             var searchResultsArray = new SearchResults[segments.Length];