Ejemplo n.º 1
0
        private void LoadConfigurable(Type configurable)
        {
            string            path                      = null;
            ConfigurationList configurations            = null;
            Dictionary <Type, IConfigurable> dictionary = null;
            IConfigurable cfg = (IConfigurable)Activator.CreateInstance(configurable);

            path           = cfg.ConfigurationDirectory;
            configurations = cfg.Configurations;
            dictionary     = cfg.ConfigurationDictionary;
            if (dictionary != null)
            {
                dictionary.Add(configurable, cfg);
            }

            UniversalData UniData;

            if (_SavedConfigs.ContainsKey(cfg))
            {
                UniData = _SavedConfigs[cfg];
            }
            else
            {
                UniData = new UniversalData(PointBlankServer.ConfigurationsPath + "/" + (string.IsNullOrEmpty(path) ? "" : path + "/") + configurable.Name);
            }
            JsonData JSON = UniData.GetData(EDataType.JSON) as JsonData;

            if (!_SavedConfigs.ContainsKey(cfg))
            {
                _SavedConfigs.Add(cfg, UniData);
            }
            if (UniData.CreatedNew)
            {
                foreach (KeyValuePair <string, object> kvp in configurations)
                {
                    if (JSON.CheckKey(kvp.Key))
                    {
                        JSON.Document[kvp.Key] = JToken.FromObject(kvp.Value);
                    }
                    else
                    {
                        JSON.Document.Add(kvp.Key, JToken.FromObject(kvp.Value));
                    }
                }
            }
            else
            {
                foreach (JProperty property in JSON.Document.Properties())
                {
                    if (configurations[property.Name] == null)
                    {
                        continue;
                    }

                    configurations[property.Name] = property.Value.ToObject(configurations[property.Name].GetType());
                }
            }
            UniData.Save();
        }
Ejemplo n.º 2
0
        private void LoadTranslatable(Type translatable)
        {
            string          path         = null;
            TranslationList translations = null;
            Dictionary <Type, ITranslatable> dictionary = null;
            ITranslatable translater = (ITranslatable)Activator.CreateInstance(translatable);

            path         = translater.TranslationDirectory;
            translations = translater.Translations;
            dictionary   = translater.TranslationDictionary;
            if (dictionary != null)
            {
                dictionary.Add(translatable, translater);
            }

            UniversalData UniData;

            if (_SavedTranslations.ContainsKey(translater))
            {
                UniData = _SavedTranslations[translater];
            }
            else
            {
                UniData = new UniversalData(PointBlankServer.TranslationsPath + "/" + (string.IsNullOrEmpty(path) ? "" : path + "/") + translatable.Name);
            }
            JsonData JSON = UniData.GetData(EDataType.JSON) as JsonData;

            if (!_SavedTranslations.ContainsKey(translater))
            {
                _SavedTranslations.Add(translater, UniData);
            }
            if (UniData.CreatedNew)
            {
                foreach (KeyValuePair <string, string> kvp in translations)
                {
                    if (JSON.CheckKey(kvp.Key))
                    {
                        JSON.Document[kvp.Key] = kvp.Value;
                    }
                    else
                    {
                        JSON.Document.Add(kvp.Key, kvp.Value);
                    }
                }
            }
            else
            {
                foreach (JProperty property in JSON.Document.Properties())
                {
                    if (translations[property.Name] == null)
                    {
                        continue;
                    }

                    translations[property.Name] = (string)property.Value;
                }
            }
            UniData.Save();
        }