public static void Main() { #region Конфигурация StandardKernel kernel = new StandardKernel(); kernel.Bind <IStoreData>().To <StoreDataMethods>(); kernel.Bind <ICreatorJson>().To <CreatorJsonMethods>(); Bot = SimpleTBot.ConfigureBot(ConfigurationManager.AppSettings[ConstantStrings.TelegaToken]); WeatherCore.SetWeatherApi(ConfigurationManager.AppSettings[ConstantStrings.WeatherToken]); OpenWeatherCore.SetWeatherApi(ConfigurationManager.AppSettings[ConstantStrings.OpenWeatherMapToken]); jCreator = kernel.Get <ICreatorJson>(); jCreator.SetJsonPath(Environment.CurrentDirectory + "//LocalizationStrings.json"); localization = jCreator.ReadConfig <LocalizationModel>(); localization.Current = ConfigurationManager.AppSettings[ConstantStrings.Localization] == "ru" ? localization.Ru : localization.En; kernel.Get <IStoreData>().StoreData(localization, ConstantStrings.Localization); MessageCore.GetStoreDataFromKernel(kernel); WebApiCore.GetStoreDataFromKernel(kernel); KeyboardCore.GetStoreDataFromKernel(kernel); #endregion #region Запуск бота Bot.OnMessage += BotOnMessage; Bot.OnCallbackQuery += BotOnCallbackQuery; Bot.StartReceiving(); Console.WriteLine(localization.Current.BotStartingConsole); #endregion #region Остановка бота Console.ReadLine(); Bot.StopReceiving(); Console.WriteLine(localization.Current.BotStoppedConsole); Console.ReadLine(); #endregion }
public async Task EditAsync(LocalizationModel model) { if (await _context.Localizations.AnyAsync(x => x.Address == model.Address && x.City == model.City)) { throw new Exception("Já existe essa localização"); } var localizations = await _context.Localizations .FirstOrDefaultAsync(x => x.Id == model.Id); if (localizations == null) { throw new Exception("Poste de luz não encontrado"); } localizations.Address = model.Address; localizations.Neighborhood = model.Neighborhood; localizations.City = model.City; localizations.State = model.State.Value; try { _context.Localizations.Update(localizations); await _context.SaveChangesAsync(); } catch { throw new Exception("Erro. Por favor tente novamente"); } }
public LocalizationModel Read(Stream stream) { var model = new LocalizationModel { Localizations = new Dictionary <string, Dictionary <string, string> >() }; var reader = new IO.Readers.CSVReader(stream); var headers = new string[0]; var row = 0; while (reader.Peek() >= 0) { var rowValues = reader.ReadRow(); if (row == 0) { headers = rowValues; SetHeaders(model.Localizations, headers); } else { AddKeys(model.Localizations, headers, rowValues); } row++; } return(model); }
public string ToString(IFormatProvider culture, LocalizationModel model, int maxCountOfStars, bool preferAvatarOverProfileLink) { var result = new StringBuilder(); result.AppendFormat(culture, model.RestaurantAndSourceForReview, RestaurantName, Resource); if (ReviewType != null) { result.Append('\n'); result.AppendFormat(culture, model.TypeForReview, ReviewType); } var link = !preferAvatarOverProfileLink ? ProfileUrl ?? AuthorAvatar : AuthorAvatar ?? ProfileUrl; result.AppendFormat(culture, "\n{0} <i>({1})</i>", string.IsNullOrWhiteSpace(link) ? AuthorName : $"<a href=\"{link}\">{AuthorName}</a>", Date); if (Rating > 0) { result.Append('\n'); result.Append(model.RatingForReview); result.AppendJoin(string.Empty, Enumerable.Repeat("👍", Rating)); var emptyStarsCount = maxCountOfStars - Rating; if (emptyStarsCount > 0) { result.AppendJoin(string.Empty, Enumerable.Repeat("👍🏿", emptyStarsCount)); } } if (Likes > 0) { result.AppendFormat(culture, "\n{0} {1}", Likes, Dislikes <= 0 ? "❤️" : "👍"); if (Dislikes > 0) { result.AppendFormat(culture, "\n{0} 👎", Dislikes); } } if (!string.IsNullOrWhiteSpace(Text)) { result.Append('\n'); var text = new string(Text.Take(1021 - result.Length).ToArray()); if (Text.Length > text.Length) { text += "..."; } result.AppendFormat(model.TextForReview, HtmlEncoder.Default.Encode(text)); } return(result.ToString()); }
public LocalizationModel GetLocalization(string lang) { var en = File.ReadAllText($"{AppDomain.CurrentDomain.BaseDirectory}\\Data\\dic.xml"); var model = new LocalizationModel { Lang = LocalizationManager.DefaultLang, Map = new Dictionary <string, string>() }; LocalizationManager.Update(en, model); return(model); }
public void UpdateLocalization(LocalizationModel model) { if (_localizationModel.ContainsKey(model.Lang)) { _localizationModel[model.Lang] = model; } else { _localizationModel.Add(model.Lang, model); } _saverService.Save(Constants.Localization, _localizationModel); }
public static ILocalizationModel LocalizationFromJObject(JObject source) { if (source == null) { return(null); } LocalizationModel model = new LocalizationModel(); model.Author = source.ToString(nameof(model.Author)); model.Name = source.ToString(nameof(model.Name)); model.Description = source.ToString(nameof(model.Description)); model.Identity = source.ToString(nameof(model.Identity)); // symbol description localizations model.SymbolDescriptions = source.ToStringDictionary(StringComparer.OrdinalIgnoreCase, "symbols"); // post action localizations Dictionary <Guid, IPostActionLocalizationModel> postActions = new Dictionary <Guid, IPostActionLocalizationModel>(); foreach (JObject item in source.Items <JObject>(nameof(model.PostActions))) { IPostActionLocalizationModel postActionModel = PostActionLocalizationModel.FromJObject(item); postActions.Add(postActionModel.ActionId, postActionModel); } model.PostActions = postActions; // regular file localizations IReadOnlyDictionary <string, JToken> fileLocalizationJson = source.ToJTokenDictionary(StringComparer.OrdinalIgnoreCase, "localizations"); List <FileLocalizationModel> fileLocalizations = new List <FileLocalizationModel>(); if (fileLocalizationJson != null) { foreach (KeyValuePair <string, JToken> fileLocInfo in fileLocalizationJson) { string fileName = fileLocInfo.Key; JToken localizationJson = fileLocInfo.Value; FileLocalizationModel fileModel = FileLocalizationModel.FromJObject(fileName, (JObject)localizationJson); fileLocalizations.Add(fileModel); } } model.FileLocalizations = fileLocalizations; return(model); }
public LocalizationModel GetLocalization(string lang) { try { var txt = File.ReadAllText($@"Languages/{lang}/dic.xml"); if (!string.IsNullOrWhiteSpace(txt)) { var model = new LocalizationModel(); LocalizationManager.Update(txt, model); return(model); } } catch (System.Exception ex) { AppSettings.Logger.Warning(ex); } return(new LocalizationModel()); }
public void LocateIp_Always_ReturnsModelObject(string ip) { var expectedLocalization = new Localization { Ip = ip }; var expectedLocalizationModel = new LocalizationModel { Ip = expectedLocalization.Ip }; mockIpStackService.Setup(service => service.GetLocalizationByIpAsync(ip)).ReturnsAsync(expectedLocalization); mockLocalizationRepository.Setup(repository => repository.CreateAsync(expectedLocalization)).ReturnsAsync(true); mockMapper.Setup(mapper => mapper.Map <LocalizationModel>(expectedLocalization)).Returns(expectedLocalizationModel); var result = controller.LocateIp(ip).Result as ObjectResult; Assert.IsInstanceOf <LocalizationModel>(result.Value); }
public void XmlCompereTest() { var json = File.ReadAllText($"{AppDomain.CurrentDomain.BaseDirectory}\\Data\\dicOld.xml"); var lm = new LocalizationModel(); LocalizationManager.Update(json, lm); var ls = new List <string>(); foreach (var itm in lm.Map) { var t = LocalizationManager.GetText(itm.Key); if (!t.Equals(itm.Value)) { ls.Add($"{itm.Key} |> {itm.Value}"); } } Console.WriteLine(string.Join(Environment.NewLine, ls)); Assert.IsFalse(ls.Any()); }
public async Task <IActionResult> Register(LocalizationModel model) { LoadData(); if (!ModelState.IsValid) { return(View(model)); } try { await _appLocalization.RegisterAsync(model); TempData["Success"] = true; TempData["Message"] = "Localização cadastrada com sucesso"; return(RedirectToAction("Index")); } catch (Exception x) { ViewBag.Success = false; ViewBag.Message = x.Message; return(View(model)); } }
/// <summary> /// /// </summary> /// <param name="args"> /// [0] path to project directory /// [1] name of injected Localizer component /// </param> public static void Main(string[] args) { var locales = new List <string> { "it-IT" }; var matcher = new Matcher(args[0]); /*var content = matcher.SearchContentInTags(); * var contentJson = new ContentReplacementModel(content,locales).ToJson(); * File.WriteAllText("D:\\contents.json",contentJson);*/ // create localization.json with labels var matches = new List <string>(); matches.AddRange(matcher.SearchLocalizationComponentLabels(args[1])); matches.AddRange(matcher.SearchDisplayNameLabels()); matches.AddRange(matcher.SearchValidationMessageLabels()); var localizationJson = new LocalizationModel(matches, locales).ToJson(); File.WriteAllText("D:\\localization.json", localizationJson); }
public LocalizationViewModel() { _model = new LocalizationModel(); foreach (LocaleInfo localeInfo in LocaleInfos) { if (localeInfo.CultureName == Thread.CurrentThread.CurrentCulture.Name) { CurrentLocaleInfo = localeInfo; break; } } CultureManager.Current.UICultureChanged += new EventHandler <Perspective.Core.ChangedEventArgs <string> >(Current_UICultureChanged); SetCurrentLocaleInfoCommand = new SignalCommand(); SetCurrentLocaleInfoCommand.Executed += (sender, e) => { if ((e.Parameter != null) && (e.Parameter is LocaleInfo)) { CurrentLocaleInfo = e.Parameter as LocaleInfo; CultureManager.Current.UICulture = CurrentLocaleInfo.CultureName; } }; }
public LocalizationModel GetLocalization(string lang) { try { string txt; var stream = _assetManager.Open($@"Languages/{lang}/dic.xml"); using (var sr = new StreamReader(stream)) txt = sr.ReadToEnd(); stream.Dispose(); if (!string.IsNullOrWhiteSpace(txt)) { var model = new LocalizationModel(); LocalizationManager.Update(txt, model); return(model); } } catch (System.Exception ex) { AppSettings.Logger.Warning(ex); } return(new LocalizationModel()); }
public async Task RegisterAsync(LocalizationModel model) { if (await _context.Localizations.AnyAsync(x => x.Address.Trim().ToLower() == model.Address.Trim().ToLower() && x.City.Trim().ToLower() == model.City.Trim().ToLower() && x.Neighborhood.Trim().ToLower() == model.Neighborhood.Trim().ToLower() && x.State == model.State)) { throw new Exception("Localização já cadastrada"); } var localization = new Localization(model.Address, model.Neighborhood, model.City, model.State.Value); try { await _context.Localizations.AddAsync(localization); await _context.SaveChangesAsync(); } catch { throw new Exception("Erro. Por favor tente novamente"); } }
public void SetLocalization(LocalizationModel model) { TryWriteAsset($"Localization.{model.Lang}.txt", model); }
public void UpdateLocalization(LocalizationModel model) { //todo nothing }
public Localization() { InitializeComponent(); BindingContext = new LocalizationModel(); }
/// <summary> /// Метод получения кеша из биндинга /// </summary> /// <param name="kernel">Ядро нинжекта</param> public static void GetStoreDataFromKernel(IKernel kernel) { mcache = kernel.Get <IStoreData>(); localization = mcache.GetData <LocalizationModel>(ConstantStrings.Localization); }
public ActionResult Edit(Guid id, LocalizationModel model, string button) { string entityName = LocalizationProvider.Provider.GetMetaEntiryName(); if (!ModelState.IsValid) { return(View(model)); } dynamic target = null; try { if (model.Id != Guid.Empty) { target = DynamicRepository.GetByEntity( entityName, FilterCriteriaSet.And.Equal(model.Id, "Id")).FirstOrDefault(); string oldKey = target.Key; target.Key = model.Key; target.Value = model.Value; if (target == null) { throw new Exception("Запись не найдена."); } var depens = DynamicRepository.GetByEntity( entityName, FilterCriteriaSet.And.Equal(oldKey, "Key"). Merge(FilterCriteriaSet.And.Custom("Lang is not null"))); foreach (dynamic d in depens) { d.Key = target.Key; } depens.Add(target); DynamicRepository.UpdateByEntity(entityName, depens); } else { target = DynamicRepository.NewByEntity(entityName); target.Id = Guid.NewGuid(); target.Key = model.Key; target.Value = model.Value; DynamicRepository.InsertByEntity(entityName, new List <dynamic>() { target }); } } catch (Exception ex) { var sb = new StringBuilder(Resources.Resource.SaveError + ": " + ex.Message); if (ex.InnerException != null) { sb.AppendLine(ex.InnerException.Message); } ModelState.AddModelError("", sb.ToString()); return(View(model)); } if (button == "SaveAndExit") { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", new { target.Id })); } }
public static ILocalizationModel LocalizationFromJObject(JObject source) { if (source == null) { return(null); } LocalizationModel locModel = new LocalizationModel() { Author = source.ToString(nameof(locModel.Author)), Name = source.ToString(nameof(locModel.Name)), Description = source.ToString(nameof(locModel.Description)), Identity = source.ToString(nameof(locModel.Identity)), }; // symbol description & choice localizations Dictionary <string, IParameterSymbolLocalizationModel> parameterLocalizations = new Dictionary <string, IParameterSymbolLocalizationModel>(); IReadOnlyDictionary <string, JToken> symbolInfoList = source.ToJTokenDictionary(StringComparer.OrdinalIgnoreCase, "symbols"); foreach (KeyValuePair <string, JToken> symbolDetail in symbolInfoList) { string symbol = symbolDetail.Key; string description = symbolDetail.Value.ToString("description"); Dictionary <string, string> choicesAndDescriptionsForSymbol = new Dictionary <string, string>(); foreach (JObject choiceObject in symbolDetail.Value.Items <JObject>("choices")) { string choice = choiceObject.ToString("choice"); string choiceDescription = choiceObject.ToString("description"); if (!string.IsNullOrEmpty(choice) && !string.IsNullOrEmpty(choiceDescription)) { choicesAndDescriptionsForSymbol.Add(choice, choiceDescription); } } IParameterSymbolLocalizationModel symbolLocalization = new ParameterSymbolLocalizationModel(symbol, description, choicesAndDescriptionsForSymbol); parameterLocalizations.Add(symbol, symbolLocalization); } locModel.ParameterSymbols = parameterLocalizations; // post action localizations Dictionary <Guid, IPostActionLocalizationModel> postActions = new Dictionary <Guid, IPostActionLocalizationModel>(); foreach (JObject item in source.Items <JObject>(nameof(locModel.PostActions))) { IPostActionLocalizationModel postActionModel = PostActionLocalizationModel.FromJObject(item); postActions.Add(postActionModel.ActionId, postActionModel); } locModel.PostActions = postActions; // regular file localizations IReadOnlyDictionary <string, JToken> fileLocalizationJson = source.ToJTokenDictionary(StringComparer.OrdinalIgnoreCase, "localizations"); List <FileLocalizationModel> fileLocalizations = new List <FileLocalizationModel>(); if (fileLocalizationJson != null) { foreach (KeyValuePair <string, JToken> fileLocInfo in fileLocalizationJson) { string fileName = fileLocInfo.Key; JToken localizationJson = fileLocInfo.Value; FileLocalizationModel fileModel = FileLocalizationModel.FromJObject(fileName, (JObject)localizationJson); fileLocalizations.Add(fileModel); } } locModel.FileLocalizations = fileLocalizations; return(locModel); }
public FluentConfigurationLocalizationTests() { model = new LocalizationModel(); metadataConfiguration = new LocalizationModelConfiguration(); }