public void AddTranslation(ITranslation translation) { EnsureOnlyOneDefaultLanguage(translation); EnsureTranslationIsNotADuplicate(translation); _translations.Add(translation.IsoCode, translation); }
public WebSocketInterface(int port, ITranslation translations) { _server = new WebSocketServer(); var setupComplete = _server.Setup(new ServerConfig { Name = "NecroWebSocket", Ip = "Any", Port = port, Mode = SocketMode.Tcp, Security = "tls", Certificate = new CertificateConfig { FilePath = @"cert.pfx", Password = "******" } }); if (setupComplete == false) { Logger.Write(translations.GetTranslation(TranslationString.WebSocketFailStart, port), LogLevel.Error); return; } _server.NewMessageReceived += HandleMessage; _server.NewSessionConnected += HandleSession; _server.Start(); }
public HomeController(IHomeZoneService homeZoneService, IMenuService menuService, ITranslation translation) { //_userManager = userManager; _homeZoneService = homeZoneService; _menuService = menuService; _translation = translation; }
private void EnsureTranslationIsNotADuplicate(ITranslation translationToAdd) { if (_translations.ContainsKey(translationToAdd.IsoCode)) { throw new Exception(String.Format("{0} has already been added as a translation", translationToAdd.IsoCode)); } }
public ArticleDetailPage(ITranslation translation, IArticleDetailPageViewModel viewModel) { _translation = translation; _viewModel = viewModel; BindingContext = _viewModel; CreateUI(); }
public TEditor(ListBox lb, ISong song, GUI owner, ITranslation trans) { // // Erforderlich für die Windows Form-Designerunterstützung // InitializeComponent(); this.AcceptButton = this.button1; this.song = song; this.trans = trans; this.lb = lb; this.owner = owner; this.textBox2.Text = this.song.Number.ToString(); this.textBox2.Enabled = false; tEditor = this; TEditorOpen = true; if (this.trans != null) { this.textBox1.Text = this.trans.Title; this.richTextBox1.Text = this.trans.Text; this.checkBox1.Checked = this.trans.Unformatted; this.panel1.Enabled = !this.trans.Unformatted; } else { this.textBox1.Text = ""; this.richTextBox1.Text = ""; } }
public static void AddTranslationItemsFromFields(string category, object obj, ITranslation translation) { if (obj == null) return; AddTranslationItemsFromList(category, translation, GetObjProperties(obj, "$this")); }
public MenuService(IMenuHolder holder, IAccountPermissionsManager userPermissionsManager, ITranslation translation) { _holder = holder; _userPermissionsManager = userPermissionsManager; _translation = translation; }
private void EnsureOnlyOneDefaultLanguage(ITranslation translationToAdd) { if ((translationToAdd.IsDefault) && (_translations.Any(t => t.Value.IsDefault))) { throw new Exception("Only one default langauge is allowed."); } }
public LoginPage(ILoginPageViewModel viewModel, ITranslation translation, IViewLocator viewLocator) { _viewModel = viewModel; _viewModel.NavigateToMainPageCommand = new Command(async () => await NavigateToMainPage()); BindingContext = _viewModel; _translation = translation; _viewLocator = viewLocator; }
public IList<ITranslation> GetSimilarTranslations( ITranslation sourceTranslation, IList<ITranslation> targetTranslations) { return targetTranslations .Where(translation => translation.Source.Id == sourceTranslation.Source.Id || translation.Target.Id == sourceTranslation.Target.Id) .ToList(); }
/// <summary> /// Creates a new map message. /// </summary> /// <param name="text">The message.</param> /// <param name="boundary">The boundary object.</param> /// <param name="translation">The map translation.</param> public MapInfoAnnotation(string text, IAnchor boundary, ITranslation translation) : base(text, null, translation) { // Validate the parameters. if (null == boundary) throw new ArgumentNullException("boundary"); if (null == translation) throw new ArgumentNullException("translation"); // Set the annotation defaults. this.BackgroundColor = Color.White; this.Visible = false; // Set the boundary anchor. this.boundary = boundary; }
public static void AddTranslationItemsFromList(string category, ITranslation translation, IEnumerable<Tuple<string, object>> items) { Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo) { var value = (string)propertyInfo.GetValue(itemObj, null); if (AllowTranslateProperty(value)) { translation.AddTranslationItem(category, item, propertyInfo.Name, value); } }; ForEachItem(items, action); }
public static ITranslation GetTranslation(string translationName) { if (string.IsNullOrEmpty(translationName)) { _translation = null; } else if (!translationName.Equals(_name)) { _translation = TranslationSerializer.Deserialize(Path.Combine(GetTranslationDir(), translationName + ".xlf")); } _name = translationName; return _translation; }
public ArticleMasterPage(ITranslation translation, IArticleMasterPageViewModel viewModel, IArticlesHubProxy articlesHub, IViewLocator viewLocator) { _translation = translation; _viewModel = viewModel; _articlesHub = articlesHub; _viewLocator = viewLocator; BindingContext = _viewModel; CreateUI(); this.SetDefaultPadding(); }
private static void SetupConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartDefaultLocationPrompt, "Y", "N"))) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationSet)); return; } Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocation), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongPrompt)); while (true) { try { var strInput = Console.ReadLine(); var strSplit = strInput.Split(','); if (strSplit.Length > 1) { var dblLat = double.Parse(strSplit[0].Trim(' ')); var dblLong = double.Parse(strSplit[1].Trim(' ')); settings.LocationConfig.DefaultLatitude = dblLat; settings.LocationConfig.DefaultLongitude = dblLong; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongConfirm, $"{dblLat}, {dblLong}")); } else { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.LocationConfig.DefaultLatitude}, {settings.LocationConfig.DefaultLongitude}", LogLevel.Error)); continue; } break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.LocationConfig.DefaultLatitude}, {settings.LocationConfig.DefaultLongitude}", LogLevel.Error)); } } }
public RoleController(IRoleService roleService, IModuleManager moduleManager, IPermissionManager permissionManager, IMenuService menuService, IRoleBelongsSystemService belongsSystemService, IAuthorizer authorizer, ITranslation translation, IRolePermissionsService rolePermissionsService) { _roleService = roleService; _moduleManager = moduleManager; _permissionManager = permissionManager; _menuService = menuService; _belongsSystemService = belongsSystemService; _authorizer = authorizer; _translation = translation; _rolePermissionsService = rolePermissionsService; }
public ThrowTranslation(UnaryExpression throwExpression, ITranslationContext context) { Type = throwExpression.Type; TranslationSize = _throw.Length; FormattingSize = context.GetKeywordFormattingSize(); // ReSharper disable once ConditionIsAlwaysTrueOrFalse // unary.Operand is null when using Expression.Rethrow(): if ((throwExpression.Operand == null) || context.IsCatchBlockVariable(throwExpression.Operand)) { return; } _thrownItemTranslation = context.GetTranslationFor(throwExpression.Operand); TranslationSize = _thrownItemTranslation.TranslationSize; FormattingSize += _thrownItemTranslation.FormattingSize; }
private void SetPredicate(ITranslation translation) { if (!string.IsNullOrWhiteSpace(translation.Id)) { _predicate = _predicate.And(x => x.Id == translation.Id); return; } if (translation.Key == null) { throw new ArgumentException("Key cannot be null"); } if (translation.Environment != null) { _predicate = _predicate.And(x => x.Branch == translation.Branch); } _predicate = _predicate.And(x => x.Key == translation.Key); }
public static ITranslation GetTranslation(string translationName) { if (string.IsNullOrEmpty(translationName)) { _translation = null; } else if (!translationName.Equals(_name)) { _translation = TranslationSerializer.Deserialize(Path.Combine(GetTranslationDir(), translationName + ".xlf")); if (_translation == null) { _translation = new Translation(); } } _name = translationName; return(_translation); }
public Session(GlobalSettings globalSettings, ISettings settings, ILogicSettings logicSettings, IElevationService elevationService, ITranslation translation) { this.GlobalSettings = globalSettings; this.CancellationTokenSource = new CancellationTokenSource(); this.Forts = new List <FortData>(); this.VisibleForts = new List <FortData>(); this.Cache = new MemoryCache("Necrobot2"); this.accounts = new List <AuthConfig>(); this.EventDispatcher = new EventDispatcher(); this.LogicSettings = logicSettings; this.RuntimeStatistics = new Statistics(); this.ElevationService = elevationService; this.Settings = settings; this.Translation = translation; this.Reset(settings, LogicSettings); this.Stats = new SessionStats(this); this.accounts.AddRange(logicSettings.Bots); if (!this.accounts.Any(x => x.AuthType == settings.AuthType && x.Username == settings.Username)) { this.accounts.Add(new AuthConfig() { AuthType = settings.AuthType, Password = settings.Password, Username = settings.Username }); } if (File.Exists("runtime.log")) { var lines = File.ReadAllLines("runtime.log"); foreach (var item in lines) { var arr = item.Split(';'); var acc = this.accounts.FirstOrDefault(p => p.Username == arr[0]); if (acc != null) { acc.RuntimeTotal = Convert.ToDouble(arr[1]); } } } GymState = new GymTeamState(); }
/// <summary> /// Build a mockup for a static text used by the food waste domain. /// </summary> /// <param name="staticTextType">Type of the static text.</param> /// <returns>Mockup for a static text used by the food waste domain.</returns> public static IStaticText BuildStaticTextMock(StaticTextType staticTextType = StaticTextType.WelcomeLetter) { Guid subjectTranslationIdentifier = Guid.NewGuid(); ITranslation subjectTranslation = BuildTranslationMock(subjectTranslationIdentifier); Guid bodyTranslationIdentifier = Guid.NewGuid(); ITranslation bodyTranslation = BuildTranslationMock(bodyTranslationIdentifier); IStaticText staticTextMock = MockRepository.GenerateMock <IStaticText>(); staticTextMock.Stub(m => m.Identifier) .Return(Guid.NewGuid()) .Repeat.Any(); staticTextMock.Stub(m => m.Type) .Return(staticTextType) .Repeat.Any(); staticTextMock.Stub(m => m.Translation) .Return(null) .Repeat.Any(); staticTextMock.Stub(m => m.Translations) .Return(new List <ITranslation> { subjectTranslation, bodyTranslation }) .Repeat.Any(); staticTextMock.Stub(m => m.SubjectTranslationIdentifier) .Return(subjectTranslationIdentifier) .Repeat.Any(); staticTextMock.Stub(m => m.SubjectTranslation) .Return(subjectTranslation) .Repeat.Any(); staticTextMock.Stub(m => m.SubjectTranslations) .Return(new List <ITranslation> { subjectTranslation }) .Repeat.Any(); staticTextMock.Stub(m => m.BodyTranslationIdentifier) .Return(bodyTranslationIdentifier) .Repeat.Any(); staticTextMock.Stub(m => m.BodyTranslation) .Return(bodyTranslation) .Repeat.Any(); staticTextMock.Stub(m => m.BodyTranslations) .Return(new List <ITranslation> { bodyTranslation }) .Repeat.Any(); return(staticTextMock); }
public WebSocketInterface(string ipAddress, int port, Session session) { _session = session; _server = new WebSocketServer(); _websocketHandler = WebSocketEventManager.CreateInstance(); // Add custom seriaizer to convert ulong to string (ulong shoud not appear to json according to json specs) _jsonSerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; _jsonSerializerSettings.Converters.Add(new LongToStringJsonConverter()); ITranslation translations = session.Translation; ServerConfig config = new ServerConfig { Name = "NecroWebSocket", Mode = SocketMode.Tcp, Certificate = new CertificateConfig { FilePath = @"cert.pfx", Password = "******" }, Listeners = new List <ListenerConfig> { new ListenerConfig { Ip = ipAddress, Port = port, Security = "tls" }, new ListenerConfig { Ip = ipAddress, Port = port + 1, Security = "none" } }, }; bool setupComplete = _server.Setup(config); if (setupComplete == false) { Logger.Write(translations.GetTranslation(TranslationString.WebSocketFailStart, port), LogLevel.Error); return; } _server.NewMessageReceived += HandleMessage; _server.NewSessionConnected += HandleSession; _server.Start(); }
/// <summary> /// Build a mockup for a translation. /// </summary> /// <param name="cultureName">Name for the culture which are used for translation.</param> /// <param name="translationOfIdentifier">Identifier for the domain object which are translated by the translation.</param> /// <returns>Mockup for a translation.</returns> public static ITranslation BuildTranslationMock(string cultureName, Guid translationOfIdentifier) { ITranslation translationMock = MockRepository.GenerateMock <ITranslation>(); translationMock.Stub(m => m.Identifier) .Return(Guid.NewGuid()) .Repeat.Any(); translationMock.Stub(m => m.TranslationOfIdentifier) .Return(translationOfIdentifier) .Repeat.Any(); translationMock.Stub(m => m.TranslationInfo) .Return(BuildTranslationInfoMock(cultureName)) .Repeat.Any(); translationMock.Stub(m => m.Value) .Return(Fixture.Create <string>()) .Repeat.Any(); return(translationMock); }
/// <summary> /// Execute functionality which deletes a translation. /// </summary> /// <param name="translation">Translation to delete.</param> /// <returns>Identifier for the deleted translation.</returns> public virtual Guid TranslationDelete(ITranslation translation) { if (translation == null) { throw new ArgumentNullException("translation"); } if (translation.Identifier.HasValue == false) { throw new IntranetSystemException(Resource.GetExceptionMessage(ExceptionMessage.IllegalValue, translation.Identifier, "Identifier")); } var command = new TranslationDeleteCommand { TranslationIdentifier = translation.Identifier.Value }; var serviceReceipt = Execute <TranslationDeleteCommand, ServiceReceiptResponse>(command); return(serviceReceipt.Identifier.HasValue ? serviceReceipt.Identifier.Value : default(Guid)); }
public static bool TryGetTranslation(DynamicTranslationArgs args, out ITranslation translation) { if (!args.IsMatch(_matcher, out var match)) { translation = null; return(false); } var targetTranslation = DynamicMemberAccessTranslation.GetTranslation(args, match); translation = new AssignmentTranslation( ExpressionType.Assign, targetTranslation, args.LastArgument, args.Context); return(true); }
public static void AddTranslationItem(string category, object obj, string propName, ITranslation translation) { if (obj == null) return; var propertyInfo = obj.GetType().GetProperty(propName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.SetProperty); if (propertyInfo == null) { return; } var value = propertyInfo.GetValue(obj, null) as string; if (value != null && AllowTranslateProperty(value)) { translation.AddTranslationItem(category, propName, "Text", value); } }
private static void SetupTelegramConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupTelegramPrompt, "Y", "N"))) { return; } settings.TelegramConfig.UseTelegramAPI = true; string strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodePrompt)); settings.TelegramConfig.TelegramAPIKey = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodeConfirm, strInput)); strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordPrompt)); settings.TelegramConfig.TelegramPassword = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordConfirm, strInput)); }
public TypeOfTranslation( ITranslation operandTranslation, ITranslation typeNameTranslation, ITranslationContext context) { _operandTranslation = operandTranslation; _typeNameTranslation = typeNameTranslation; TranslationSize = operandTranslation.TranslationSize + typeNameTranslation.TranslationSize + _typeOf.Length + "()".Length; FormattingSize = operandTranslation.FormattingSize + typeNameTranslation.FormattingSize + context.GetKeywordFormattingSize(); }
public void CheckProxy(ITranslation translator) { string unproxiedIp; using (HttpClient client = new HttpClient()) { var responseContent = client.GetAsync("https://api.ipify.org/?format=text").Result; unproxiedIp = responseContent.Content.ReadAsStringAsync().Result; } if (ProxyConfig.UseProxy) { var httpClientHandler = new HttpClientHandler { Proxy = InitProxy(), UseProxy = true }; using (HttpClient client = new HttpClient(httpClientHandler)) { var responseContent = client.GetAsync("https://api.ipify.org/?format=text").Result; var proxiedIPres = responseContent.Content.ReadAsStringAsync().Result; var proxiedIp = proxiedIPres == null ? "INVALID PROXY" : proxiedIPres; Logger.Write(translator.GetTranslation(TranslationString.Proxied, unproxiedIp, proxiedIp), LogLevel.Info, unproxiedIp == proxiedIp ? ConsoleColor.Red : ConsoleColor.Green); if (unproxiedIp != proxiedIp && proxiedIPres != null) { return; } Logger.Write(translator.GetTranslation(TranslationString.FixProxySettings), LogLevel.Info, ConsoleColor.Red); Console.ReadKey(); Environment.Exit(0); } } else { Logger.Write(translator.GetTranslation(TranslationString.Unproxied, unproxiedIp), LogLevel.Info, ConsoleColor.Red); } }
public void TestTranslateAsync() { BingLocanTranslator translator = this.GetNewBingLocanTranslator(); List <string> stringsToTranslate = new List <string> { @"What is your name?", @"How old are you?", @"My name is Sayed." }; List <string> expectedTranslations = new List <string> { @"Qual é seu nome?", @"São velhos ou não é?", @"Meu nome é Sayed.", }; ILanguage sourceLanguage = new BaseLanguage("en"); ILanguage destLangage = new BaseLanguage("pt"); int currentIndex = 0; translator .Translate(stringsToTranslate, destLangage, sourceLanguage) .OnTranslationComplete((payload, translationValues) => { Assert.AreEqual(stringsToTranslate.Count, translationValues.Count()); for (int i = 0; i < stringsToTranslate.Count; i++) { string stringToTranslate = stringsToTranslate[i]; string expectedTranslation = expectedTranslations[i]; ITranslation translation = translationValues.ElementAt(i); Assert.AreEqual(stringToTranslate, translation.StringToTranslate); Assert.AreEqual(expectedTranslation, translation.TrnaslatedString); currentIndex++; } }); // must give the service time to perform the translations Thread.Sleep(10000); Assert.IsTrue(currentIndex == stringsToTranslate.Count); }
private static void SetupAccountType(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAccount), LogLevel.Info); string accountType = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupTypePrompt, "google", "ptc"), new string[] { "google", "ptc" }, translator.GetTranslation(TranslationString.FirstStartSetupTypePromptError, "google", "ptc"), false); switch (accountType) { case "google": settings.Auth.AuthConfig.AuthType = AuthType.Google; break; case "ptc": settings.Auth.AuthConfig.AuthType = AuthType.Ptc; break; } Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, accountType.ToUpper())); }
public Session(ISettings settings, ILogicSettings logicSettings, ITranslation translation) { this.Forts = new List <FortData>(); this.VisibleForts = new List <FortData>(); EventDispatcher = new EventDispatcher(); LogicSettings = logicSettings; ElevationService = new ElevationService(this); // Update current altitude before assigning settings. settings.DefaultAltitude = ElevationService.GetElevation(settings.DefaultLatitude, settings.DefaultLongitude); Settings = settings; Translation = translation; Reset(settings, LogicSettings); Stats = new SessionStats(); }
private static void SetupAutoCompleteTutConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutPrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } settings.PlayerConfig.AutoCompleteTutorial = true; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknamePrompt)); strInput = Console.ReadLine(); settings.PlayerConfig.DesiredNickname = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknameConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutGenderPrompt)); strInput = Console.ReadLine(); settings.PlayerConfig.DesiredGender = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutGenderConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutStarterPrompt)); strInput = Console.ReadLine(); settings.PlayerConfig.DesiredStarter = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutStarterConfirm, strInput)); }
public static bool TryCreate( ConstantExpression constant, ITranslationContext context, out ITranslation timeSpanTranslation) { if (constant.Type != typeof(TimeSpan)) { timeSpanTranslation = null; return(false); } if (TryTranslateDefault <TimeSpan>(constant, context, out timeSpanTranslation)) { return(true); } timeSpanTranslation = new TimeSpanConstantTranslation(constant, context); return(true); }
public bool LoadTranslations(string sourceDirectory) { //Load each of the translation's DLL files if (!Directory.Exists(sourceDirectory)) { return(false); } Translations.Clear(); foreach (FileInfo file in new DirectoryInfo(sourceDirectory).GetFiles("*.dll")) { Assembly assembly = Assembly.LoadFile(file.FullName); if (assembly != null) { Type[] pluginTypes = assembly.GetTypes(); foreach (Type t in pluginTypes) { if (typeof(ITranslation).IsAssignableFrom(t)) { if (!t.IsAbstract && t.IsPublic) { //Load this plugin try { ITranslation newTranslation = (ITranslation)assembly.CreateInstance(t.FullName); Translations.Add(newTranslation); } catch { } } } } } } RefreshCurrentTranslation(); return(true); }
public StandardMethodCallTranslation( ExpressionType nodeType, ITranslation subjectTranslation, IMethod method, ParameterSetTranslation parameters, ITranslationContext context) { _context = context; NodeType = nodeType; _subjectTranslation = subjectTranslation; _methodInvocationTranslation = new MethodInvocationTranslation(method, parameters, context); TranslationSize = _subjectTranslation.TranslationSize + ".".Length + _methodInvocationTranslation.TranslationSize; FormattingSize = _subjectTranslation.FormattingSize + _methodInvocationTranslation.FormattingSize; }
public AccountController(ISsoSetting ssoSetting, IAuthenticationService svcAuthentication, IAuthService svcAuth, IAuthorizationCodeManager authorizationCodeManager, IClientVerifier clientVerifier, ITranslation translation, IAccountRegisterManager accountRegisterManager, IClientManager clientManager, IValidateCodeBuilder validateCodeBuilder, IAuthorizationCodeHolder authorizationCodeHolder) { _svcAuthentication = svcAuthentication; _svcAuth = svcAuth; _authorizationCodeManager = authorizationCodeManager; _clientVerifier = clientVerifier; _translation = translation; _accountRegisterManager = accountRegisterManager; _clientManager = clientManager; _validateCodeBuilder = validateCodeBuilder; _authorizationCodeHolder = authorizationCodeHolder; _ssoSetting = ssoSetting; Logger =NullLogger.Instance; }
public static void AddTranslationItemsFromList(string category, ITranslation translation, IEnumerable <Tuple <string, object> > items) { foreach (var item in items) { var itemName = item.Item1; var itemObj = item.Item2; foreach (var property in GetItemPropertiesEnumerator(item)) { var value = property.GetValue(itemObj, null); if (value == null) { continue; } var valueStr = value as string; if (valueStr != null) { if (AllowTranslateProperty(valueStr)) { translation.AddTranslationItem(category, itemName, property.Name, valueStr); } continue; } var listItems = value as IList; if (listItems != null) { for (int index = 0; index < listItems.Count; index++) { var listItem = listItems[index] as string; if (AllowTranslateProperty(listItem)) { translation.AddTranslationItem(category, itemName, "Item" + index, listItem); } } } } } }
public IManyToManyRelationship SaveTranslation( ITranslation translation, out ServiceOperationAction action) { action = ServiceOperationAction.Update; if (!translationValidator.Validate(translation).Status) { throw new ValidationFailedException(); } using (var context = ContextFactory.Build()) { var targetTranslation = GetTranslation(translation.Id) ?? GetTranslation(translation.Source.Id, translation.Target.Id); if (targetTranslation == null) { targetTranslation = context.Translations.CreateObject<Translation>(); context.Translations.AddObject(targetTranslation); action = ServiceOperationAction.Create; } else { context.Attach(targetTranslation); action = ServiceOperationAction.Update; } targetTranslation.Source = context.Words.Single(item => item.Id == translation.Source.Id); targetTranslation.Target = context.Words.Single(item => item.Id == translation.Target.Id); context.SaveChanges(); // TODO: to factory return new ManyToManyRelationship { Id = targetTranslation.Id, SourceId = targetTranslation.SourceId, TargetId = targetTranslation.TargetId }; } }
public static string PromptForString(ITranslation translator, string initialPrompt, string[] validStrings = null, string errorPrompt = null, bool caseSensitive = true) { while (true) { Logger.Write(initialPrompt, LogLevel.Info); // For now this just reads from the console, but in the future, we may change this to read from the GUI. string strInput = Console.ReadLine(); if (!caseSensitive) { strInput = strInput.ToLower(); } // If no valid strings to validate, then return immediately. if (validStrings == null) { return(strInput); } // Validate string foreach (string validString in validStrings) { if (String.Equals(strInput, validString, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)) { return(strInput); } } // If we got here, no valid strings. if (string.IsNullOrEmpty(errorPrompt)) { errorPrompt = translator.GetTranslation( TranslationString.PromptErrorString, string.Join(",", validStrings) ); } Logger.Write(errorPrompt, LogLevel.Error); } }
public static bool TryCreate( ConstantExpression constant, ITranslationContext context, out ITranslation lambdaTranslation) { #if NET35 if (constant.Value is LinqLambda linqLambda) { var convertedLambda = LinqExpressionToDlrExpressionConverter.Convert(linqLambda); lambdaTranslation = new LambdaConstantTranslation(convertedLambda, context); return(true); } #endif if (constant.Value is LambdaExpression lambda) { lambdaTranslation = new LambdaConstantTranslation(lambda, context); return(true); } lambdaTranslation = null; return(false); }
public DayProcessor( IPreparedGiasRepository preparedGiasRepository, IPreparedUkrlpRepository preparedUkrlpRepository, IPreparedRegistryRepository preparedRegistryRepository, ITranslation translation, IStatisticsRepository statisticsRepository, ILogger logger) { _giasChangeProcessor = new GiasChangeProcessor(preparedGiasRepository, logger); _ukrlpChangeProcessor = new UkrlpChangeProcessor(preparedUkrlpRepository, logger); _registryChangeProcessor = new RegistryChangeProcessor( preparedRegistryRepository, preparedGiasRepository, preparedUkrlpRepository, translation, logger); _preparedGiasRepository = preparedGiasRepository; _preparedUkrlpRepository = preparedUkrlpRepository; _preparedRegistryRepository = preparedRegistryRepository; _statisticsRepository = statisticsRepository; _logger = logger; }
public TypeTestedTranslation( ExpressionType nodeType, ITranslation testedValueTranslation, string test, Type testedType, ITranslationContext context) { NodeType = nodeType; _testedValueTranslation = testedValueTranslation; _test = test; _testedTypeNameTranslation = context.GetTranslationFor(testedType); TranslationSize = _testedValueTranslation.TranslationSize + _test.Length + _testedTypeNameTranslation.TranslationSize; FormattingSize = _testedValueTranslation.FormattingSize + context.GetKeywordFormattingSize() + _testedTypeNameTranslation.FormattingSize; }
private static void SetupTelegramConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPrompt, "Y", "N"), LogLevel.None); string strInput; var boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } settings.TelegramConfig.UseTelegramAPI = true; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodePrompt)); strInput = Console.ReadLine(); settings.TelegramConfig.TelegramAPIKey = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramCodeConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordPrompt)); strInput = Console.ReadLine(); settings.TelegramConfig.TelegramPassword = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTelegramPasswordConfirm, strInput)); }
public Domain(string inputFolderName, IFormCollection <IArea> areas, IFormCollection <IDesign> designs, IFormCollection <ILayout> layouts, IFormCollection <IObject> objects, IFormCollection <IPage> pages, IFormCollection <IResource> resources, IFormCollection <IBackground> backgrounds, IFormCollection <IColorTheme> colorThemes, IFormCollection <IFont> fonts, IFormCollection <IDynamic> dynamics, IFormCollection <IUnitTest> unitTests, ITranslation translation, IPreprocessorDefine preprocessorDefine, IPage homePage, IColorTheme selectedColorTheme, IUnitTest selectedUnitTest) { InputFolderName = inputFolderName; Areas = areas; Designs = designs; Layouts = layouts; Objects = objects; Pages = pages; Resources = resources; Backgrounds = backgrounds; ColorThemes = colorThemes; Fonts = fonts; Dynamics = dynamics; UnitTests = unitTests; Translation = translation; PreprocessorDefine = preprocessorDefine; HomePage = homePage; SelectedColorTheme = selectedColorTheme; SelectedUnitTest = selectedUnitTest; HomePage.SetIsReachable(); }
public static int PromptForInteger(ITranslation translator, string initialPrompt, string errorPrompt = null) { while (true) { Logger.Write(initialPrompt, LogLevel.Info); var strInput = Console.ReadLine(); int intVal; if (int.TryParse(strInput, out intVal)) { return(intVal); } else { if (string.IsNullOrEmpty(errorPrompt)) { errorPrompt = translator.GetTranslation(TranslationString.PromptErrorInteger); } Logger.Write(errorPrompt, LogLevel.Error); } } }
public StandardCastTranslation( ExpressionType nodeType, ITranslation castTypeNameTranslation, ITranslation castValueTranslation) { NodeType = nodeType; _castTypeNameTranslation = castTypeNameTranslation; _castValueTranslation = castValueTranslation; if (_castValueTranslation.ShouldWriteInParentheses()) { _castValueTranslation = _castValueTranslation.WithParentheses(); } TranslationSize = _castTypeNameTranslation.TranslationSize + 2 + // <- for () _castValueTranslation.TranslationSize; FormattingSize = _castTypeNameTranslation.FormattingSize + _castValueTranslation.FormattingSize; }
public static bool PromptForSetup(ITranslation translator) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartPrompt, "Y", "N"), LogLevel.Warning); while (true) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": return(true); case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartAutoGenSettings)); return(false); default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "Y", "N"), LogLevel.Error); continue; } } }
public static void TranslateItemsFromList(string category, ITranslation translation, IEnumerable<Tuple<string, object>> items) { Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo) { Func<string> provideDefaultValue = () => (string)propertyInfo.GetValue(itemObj, null); string value = translation.TranslateItem(category, item, propertyInfo.Name, provideDefaultValue); if (!String.IsNullOrEmpty(value)) { if (propertyInfo.CanWrite) propertyInfo.SetValue(itemObj, value, null); } else if (propertyInfo.Name == "ToolTipText" && !String.IsNullOrEmpty((string)propertyInfo.GetValue(itemObj, null))) { value = translation.TranslateItem(category, item, "Text", provideDefaultValue); if (!String.IsNullOrEmpty(value)) { if (propertyInfo.CanWrite) propertyInfo.SetValue(itemObj, value, null); } } }; ForEachItem(items, action); }
public static void AddTranslationItemsFromList(string category, ITranslation translation, IEnumerable<Tuple<string, object>> items) { foreach (var item in items) { var itemName = item.Item1; var itemObj = item.Item2; foreach (var property in GetItemPropertiesEnumerator(item)) { var value = property.GetValue(itemObj, null); if (value == null) continue; var valueStr = value as string; if (valueStr != null) { if (AllowTranslateProperty(valueStr)) { translation.AddTranslationItem(category, itemName, property.Name, valueStr); } continue; } var listItems = value as IList; if (listItems != null) { for (int index = 0; index < listItems.Count; index++) { var listItem = listItems[index] as string; if (AllowTranslateProperty(listItem)) { translation.AddTranslationItem(category, itemName, "Item" + index, listItem); } } } } } }
public void checkProxy(ITranslation translator) { using (var tempWebClient = new NecroWebClient()) { string unproxiedIP = WebClientExtensions.DownloadString(tempWebClient, new Uri("https://api.ipify.org/?format=text")); if (UseProxy) { tempWebClient.Proxy = this.InitProxy(); string proxiedIPres = WebClientExtensions.DownloadString(tempWebClient, new Uri("https://api.ipify.org/?format=text")); string proxiedIP = proxiedIPres == null?"INVALID PROXY": proxiedIPres; Logger.Write(translator.GetTranslation(TranslationString.Proxied, unproxiedIP, proxiedIP), LogLevel.Info, (unproxiedIP == proxiedIP) ? ConsoleColor.Red : ConsoleColor.Green); if (unproxiedIP == proxiedIP || proxiedIPres == null) { Logger.Write(translator.GetTranslation(TranslationString.FixProxySettings), LogLevel.Info, ConsoleColor.Red); Console.ReadKey(); Environment.Exit(0); } } else { Logger.Write(translator.GetTranslation(TranslationString.Unproxied, unproxiedIP), LogLevel.Info, ConsoleColor.Red); } } }
private static void SetupUserAccount(ITranslation translator, GlobalSettings settings) { Console.WriteLine(""); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupUsernamePrompt), LogLevel.None); string strInput = Console.ReadLine(); if (settings.Auth.AuthType == AuthType.Google) settings.Auth.GoogleUsername = strInput; else settings.Auth.PtcUsername = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupUsernameConfirm, strInput)); Console.WriteLine(""); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupPasswordPrompt), LogLevel.None); strInput = Console.ReadLine(); if (settings.Auth.AuthType == AuthType.Google) settings.Auth.GooglePassword = strInput; else settings.Auth.PtcPassword = strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupPasswordConfirm, strInput)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartAccountCompleted), LogLevel.None); }
private static Session SetupTranslationCode(Session session, ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguagePrompt, "Y", "N"), LogLevel.None); string strInput; bool boolBreak = false; while (!boolBreak) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": return session; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageCodePrompt)); strInput = Console.ReadLine(); settings.TranslationLanguageCode = strInput; session = new Session(new ClientSettings(settings), new LogicSettings(settings)); translator = session.Translation; Logger.Write(translator.GetTranslation(TranslationString.FirstStartLanguageConfirm, strInput)); return session; }
private static void SetupConfig(ITranslation translator, GlobalSettings settings) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationPrompt, "Y", "N"), LogLevel.None); bool boolBreak = false; while (!boolBreak) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": boolBreak = true; break; case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocationSet)); return; default: // PROMPT ERROR \\ Logger.Write(translator.GetTranslation(TranslationString.PromptError, "y", "n"), LogLevel.Error); continue; } } Logger.Write(translator.GetTranslation(TranslationString.FirstStartDefaultLocation), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLatLongPrompt)); while (true) { try { string strInput = Console.ReadLine(); string[] strSplit = strInput.Split( ',' ); if( strSplit.Length > 1 ) { double dblLat = double.Parse( strSplit[ 0 ].Trim( ' ' ) ); double dblLong = double.Parse( strSplit[ 1 ].Trim( ' ' ) ); settings.DefaultLatitude = dblLat; settings.DefaultLongitude = dblLong; Logger.Write( translator.GetTranslation( TranslationString.FirstStartSetupDefaultLatLongConfirm, $"{dblLat}, {dblLong}" ) ); } else { Logger.Write( translator.GetTranslation( TranslationString.FirstStartSetupDefaultLocationError, $"{settings.DefaultLatitude}, {settings.DefaultLongitude}", LogLevel.Error ) ); continue; } break; } catch (FormatException) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupDefaultLocationError, $"{settings.DefaultLatitude}, {settings.DefaultLongitude}", LogLevel.Error)); continue; } } }
private static void SetupAccountType(ITranslation translator, GlobalSettings settings) { string strInput; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAccount), LogLevel.None); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypePrompt, "google", "ptc")); while (true) { strInput = Console.ReadLine().ToLower(); switch (strInput) { case "google": settings.Auth.AuthType = AuthType.Google; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, "GOOGLE")); return; case "ptc": settings.Auth.AuthType = AuthType.Ptc; Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypeConfirm, "PTC")); return; default: Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupTypePromptError, "google", "ptc"), LogLevel.Error); break; } } }
public void checkProxy(ITranslation translator) { Auth.checkProxy(translator); }
public static bool PromptForSetup(ITranslation translator) { Logger.Write(translator.GetTranslation(TranslationString.FirstStartPrompt, "Y", "N"), LogLevel.Warning); while (true) { string strInput = Console.ReadLine().ToLower(); switch (strInput) { case "y": return true; case "n": Logger.Write(translator.GetTranslation(TranslationString.FirstStartAutoGenSettings)); return false; default: Logger.Write(translator.GetTranslation(TranslationString.PromptError, "Y", "N"), LogLevel.Error); continue; } } }
public override void TranslateItems(ITranslation translation) { base.TranslateItems(translation); TranslationUtils.TranslateItemsFromFields(Name, _filterRevisionsHelper, translation); TranslationUtils.TranslateItemsFromFields(Name, _filterBranchHelper, translation); }
private void TestTranslationResult(ITranslation translation) { Assert.NotNull(translation); Assert.Equal("ru", translation.FromLanguage); Assert.Equal("en", translation.ToLanguage); Assert.Equal("Hello world", translation.Text); }