예제 #1
0
 private bool Reset(LocalizationModel model)
 {
     try
     {
         var changed = false;
         if (Model.Lang.Equals(model.Lang) && model.Version > Model.Version)
         {
             changed = true;
             foreach (var item in model.Map)
             {
                 if (Model.Map.ContainsKey(item.Key))
                 {
                     Model.Map[item.Key] = item.Value;
                 }
                 else
                 {
                     Model.Map.Add(item.Key, item.Value);
                 }
             }
             Model.Version = model.Version;
         }
         return(changed);
     }
     catch
     {
         //to do nothing
     }
     return(false);
 }
예제 #2
0
        public LocalizationManager(ISaverService saverService, IAssetsHelper assetsHelper)
        {
            _saverService      = saverService;
            _localizationModel = _saverService.Get <Dictionary <string, LocalizationModel> >(Localization);

            Model = _localizationModel.ContainsKey(DefaultLang)
                ? _localizationModel[DefaultLang]
                : assetsHelper.GetLocalization(DefaultLang);
        }
 public LocalizationManager(LocalizationModel model)
 {
     Model = model;
 }
예제 #4
0
        public static bool Update(string xml, LocalizationModel model)
        {
            XmlTextReader reader  = null;
            StringReader  sReader = null;

            try
            {
                sReader = new StringReader(xml);
                reader  = new XmlTextReader(sReader);

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("resources") && reader.AttributeCount == 1)
                    {
                        var version = reader.GetAttribute("version");
                        if (version == null || int.Parse(version) <= model.Version)
                        {
                            return(false);
                        }

                        model.Version = int.Parse(version);
                        break;
                    }
                }

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("string") && reader.HasAttributes)
                    {
                        var json = reader.GetAttribute("name");
                        if (json == null)
                        {
                            continue;
                        }

                        var names = json.StartsWith("[")
                            ? JsonConvert.DeserializeObject <string[]>(json)
                            : json.Split(Separator, StringSplitOptions.None);

                        reader.Read();
                        var value = reader.Value;

                        foreach (var name in names)
                        {
                            value = value.Replace("\\\"", "\"");
                            if (model.Map.ContainsKey(name))
                            {
                                model.Map[name] = value;
                            }
                            else
                            {
                                model.Map.Add(name, value);
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                AppSettings.Logger.Warning(ex);
            }
            finally
            {
                sReader?.Close();
                reader?.Close();
            }
            return(false);
        }