private static bool IsValide(ServiceAuthorization serviceAuthorizationExtended) { if (serviceAuthorizationExtended is null) { return(false); } return(true); //TODO (true) TO IMPLEMENTED TEST. Move to the class itself????!!! !!!!NecessaryDataException to throw! }
public MultiLanguageString GetTranslations(ServiceAuthorization APIKey, Tuple <Language, string> TupleToTranslate) { //CHECKS APIKey.IsWellFormed($"API Key is necessary for the translation service to work. {nameof(APIKey)} @ OnlineServicesSystem.IsCorrectTranslation"); TupleToTranslate.IsValidWithThrow(); var TranslationTask = Translator.TranslateAsync(TupleToTranslate); TranslationTask.Wait(); var Translated = TranslationTask.Result.ToList(); //Cleaning the re-traduction of the posted string to avoid loosing the original serquence. Translated = Translated.Where(x => x.Item1 != TupleToTranslate.Item1).ToList(); Translated.Add(TupleToTranslate); //LOGIC HERE return(new MultiLanguageString(Translated.ToArray())); }
public bool IsCorrectTranslation(ServiceAuthorization APIKey, MultiLanguageString MLSToCheck, Language SourceLanguage) { //CHECKS APIKey.IsWellFormed($"API Key is necessary for the translation service to work. {nameof(APIKey)} @ OnlineServicesSystem.IsCorrectTranslation"); if (!Enum.IsDefined(typeof(Language), SourceLanguage)) { throw new LoggedException(new ArgumentOutOfRangeException($"IsCorrectTranslation(...) ArgumentOutOfRangeException({nameof(SourceLanguage)}). Value={(int)SourceLanguage} @ OnlineServicesSystem.IsCorrectTranslation")); } if (MLSToCheck is null) { throw new LoggedException(new ArgumentNullException($"MLSToCorrect should not be null. {nameof(SourceLanguage)}is null @ OnlineServicesSystem.IsCorrectTranslation")); } MLSToCheck.ToTupleLanguage(SourceLanguage).IsValidWithThrow(); //LOGIC HERE var IsCorrect = true; var newTranslatorTask = Translator.TranslateAsync(MLSToCheck.ToTupleLanguage(SourceLanguage)); newTranslatorTask.Wait(); var newTranslator = newTranslatorTask.Result; foreach (var item in Enum.GetValues(typeof(Language))) { if ((Language)item != SourceLanguage) { if (MLSToCheck.ToString((Language)item) != newTranslator.First(x => x.Item1 == (Language)item).Item2) { IsCorrect = false; break; } } } return(IsCorrect); }
public static bool IsWellFormed(this ServiceAuthorization serviceAuthorizationExtended, string ExceptionMessage) { return(IsValide(serviceAuthorizationExtended) ? true : throw new NecessaryDataException(ExceptionMessage)); }
public static bool IsWellFormed(this ServiceAuthorization serviceAuthorizationExtended, bool ThrowException = false) { return(!ThrowException?IsValide(serviceAuthorizationExtended) : serviceAuthorizationExtended.IsWellFormed("IsWellFormed(false) @ ServiceAuthorizationExtensions")); }