Exemplo n.º 1
0
        /// <summary>
        /// Retrieves the translation instance from the inner cache if the entry exists.
        /// If not, use the ITranslationService service to retrieve it from the database (and stores it into the inner cache).
        /// </summary>
        ///
        /// <param name="translationKey">
        /// Translation key.
        /// </param>
        ///
        /// <returns>
        /// Translation object.
        /// </returns>
        public Translation Resolve(TranslationEnum translationKey)
        {
            if (translationKey == TranslationEnum.None)             // special case
            {
                return(Translation.None);
            }

            string key = translationKey.ToString();

            var translation = this.GetFromCache(key);

            if (translation == null)
            {
                lock (_innerLocker)
                {
                    translation = this.GetFromCache(key);
                    if (translation == null)
                    {
                        using (var service = new ServiceProxy <ITranslationService>())
                        {
                            translation = service.Proxy.Resolve(ClientContext.Anonymous, translationKey);
                        }

                        if (translation != null)
                        {
                            _innerCacheService.Add(new CacheItem {
                                Key = key, Data = translation
                            });
                        }
                    }
                }
            }

            return(translation);
        }
Exemplo n.º 2
0
        public OperationException(TranslationEnum translation)
            : base(ToMessage(translation))
        {
            this.Translations = new List <TranslationEnum>();

            this.Translations.Add(translation);
        }
Exemplo n.º 3
0
        private void PerformTranslationTest(string testName, string folderName, TranslationEnum translationTypeEnum, AbnfToAntlrTranslator translator)
        {
            var pathPrefix = Path.Combine(@"..\..\FileDrivenTests", folderName);

            var inputFileName  = testName + ".input.txt";
            var outputFileName = testName + ".output." + translationTypeEnum.ToString().ToLowerInvariant() + ".txt";

            var inputPath          = Path.Combine(pathPrefix, inputFileName);
            var expectedOutputPath = Path.Combine(pathPrefix, outputFileName);

            string inputText = null;

            if (File.Exists(inputPath))
            {
                // do nothing
            }
            else
            {
                File.WriteAllText(inputPath, "");
            }

            inputText = File.ReadAllText(inputPath);

            if (string.IsNullOrWhiteSpace(inputText))
            {
                TestContext.WriteLine(inputPath);
                throw new InvalidOperationException("File cannot be empty (\"" + inputPath + "\").");
            }

            var performDirectTranslation = (translationTypeEnum == TranslationEnum.Direct);

            var actualOutput = translator.Translate(inputText, performDirectTranslation);

            if (File.Exists(expectedOutputPath))
            {
                // do nothing
            }
            else
            {
                File.WriteAllText(expectedOutputPath, actualOutput);
            }

            var expectedOutput = File.ReadAllText(expectedOutputPath);

            if (actualOutput.Equals(expectedOutput, StringComparison.Ordinal))
            {
                // do nothing
            }
            else
            {
                TestContext.WriteLine(outputFileName);
                Assert.AreEqual(expectedOutput, actualOutput);
            }
        }
Exemplo n.º 4
0
        protected void AddValidationError(string propertyName, TranslationEnum error)
        {
            ICollection <TranslationEnum> validationErrors =
                (_validationErrors.ContainsKey(propertyName)) ?
                validationErrors = _validationErrors[propertyName] :
                                   new Collection <TranslationEnum>();

            if (!validationErrors.Contains(error))
            {
                validationErrors.Add(error);

                _validationErrors[propertyName] = validationErrors;

                this.RaiseErrorsChanged(propertyName);
            }
        }
        public Translation Resolve(IUserContext userContext, TranslationEnum translationKey)
        {
            if (translationKey == TranslationEnum.None)             // special case
            {
                return(Translation.None);
            }

            using (var et = new ExecutionTracerService())
            {
                string key = translationKey.ToString();

                var translation = this.GetFromCache(key);
                if (translation == null)
                {
                    lock (_innerLocker)
                    {
                        translation = this.GetFromCache(key);
                        if (translation == null)
                        {
                            var options = new SearchOptions();

                            options.Filters.Add(Translation.ColumnNames.Key, FilterOperator.Equals, key);
                            options.MaxRecords = 1;

                            using (var db = new TranslationCrud(userContext))
                            {
                                translation = db.Search(ref options).FirstOrDefault();
                            }

                            if (translation != null)
                            {
                                _innerCacheService.Add(new CacheItem {
                                    Key = key, Data = translation
                                });
                            }
                        }
                    }
                }

                return(translation);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Retrieves the message translation from the inner cache if the entry exists.
        /// If not, use the ITranslationService service to retrieve it from the database (and stores it into the inner cache).
        /// </summary>
        ///
        /// <param name="translationKey">
        /// Translation key.
        /// </param>
        ///
        /// <param name="culture">
        /// Culture (VahapYigit.Test.Core.Cultures class).
        /// </param>
        ///
        /// <param name="args">
        /// Optional arguments to format the message.
        /// </param>
        ///
        /// <returns>
        /// The message.
        /// </returns>
        public string GetMessage(TranslationEnum translationKey, string culture, params object[] args)
        {
            string message = "N.C.";

            if (!Cultures.IsSupported(culture))
            {
                culture = Cultures.Default;
            }

            var translation = this.Resolve(translationKey);

            if (translation != null)
            {
                message = translation.Value[culture];

                if (!args.IsNullOrEmpty() && message != null)
                {
                    message = string.Format(message, args);
                }
            }

            return(message);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Retrieves the message translation from the inner cache if the entry exists.
 /// If not, use the ITranslationService service to retrieve it from the database (and stores it into the inner cache).
 /// </summary>
 ///
 /// <param name="translationKey">
 /// Translation key.
 /// </param>
 ///
 /// <param name="args">
 /// Optional arguments to format the message.
 /// </param>
 ///
 /// <returns>
 /// The message.
 /// </returns>
 public string GetMessage(TranslationEnum translationKey, params object[] args)
 {
     return(this.GetMessage(translationKey, TranslationHelper.ContextualCulture, args));
 }
Exemplo n.º 8
0
 private static string ToMessage(TranslationEnum translation)
 {
     return(translation.ToString());
 }
 public string GetMessage(IUserContext userContext, TranslationEnum translationKey, params object[] args)
 {
     return(this.GetMessage(userContext, translationKey, userContext.Culture, args));
 }
Exemplo n.º 10
0
 public static bool HasTranslation(this IEnumerable <TranslationEnum> translations, TranslationEnum translation)
 {
     return(translations.Contains(translation));
 }