Пример #1
0
        public void InitialiseResource()
        {
            ResourcePayload payload = new ResourcePayload(this._ResourceName);

            DirectoryInfo DI = new DirectoryInfo(this._JSONFolderPath);


            IEnumerable <FileInfo> JSON_Files = DI.GetFiles().Where(i => i.Extension == ".JSON" || i.Extension == ".json");

            List <T> data = new List <T>();

            if (JSON_Files.Count() == 1)
            {
                if (JSON_Files.ElementAt(0).Name == "Settings.JSON")
                {
                    payload.Data = JsonConvert.DeserializeObject <T>(File.ReadAllText(JSON_Files.ElementAt(0).FullName));
                }
                else
                {
                    data.Add(JsonConvert.DeserializeObject <T>(File.ReadAllText(JSON_Files.ElementAt(0).FullName)));
                    payload.Data = data;
                }
            }
            else
            {
                foreach (FileInfo item in JSON_Files)
                {
                    data.Add(JsonConvert.DeserializeObject <T>(File.ReadAllText(item.FullName)));
                }

                payload.Data = data;
            }

            this._manager.SetResource(payload);
        }
Пример #2
0
        public void UpdateSettings(string Name, string newValue)
        {
            ResourcePayload getPayload = (from res in this._Resources
                                          where res.Name == ResourceName.Mapping_Settings
                                          select res).FirstOrDefault();

            if (getPayload == null)
            {
                throw new Exception("Couldn't remove payload Named Mapping_Settings");
            }
            this._Resources.Remove(getPayload);


            Settings settings = (Settings)getPayload.Data;

            Setting setting = (from set in settings.ListOfSettings
                               where set.Name == Name
                               select set).FirstOrDefault();

            settings.ListOfSettings.Remove(setting);
            setting.Data = newValue;
            settings.ListOfSettings.Add(setting);

            File.WriteAllText(FileLocations.CONFIG_FOLDER_PATH + "\\Settings.JSON", JsonConvert.SerializeObject(settings, Formatting.Indented));

            this._Resources.Add(new ResourcePayload(ResourceName.Mapping_Settings)
            {
                Data = JsonConvert.DeserializeObject <Settings>(File.ReadAllText(FileLocations.CONFIG_FOLDER_PATH + "\\Settings.JSON"))
            });
        }
Пример #3
0
 public void SetResource(ResourcePayload Resource)
 {
     this._Resources.Add(Resource);
 }