private void LoadPresetFileButton_Click(object sender, RoutedEventArgs e) { PresetFile presetData = new PresetFile(); OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Filter = "Helix Preset File (*.hlx)|*.hlx"; fileDialog.Multiselect = false; if (fileDialog.ShowDialog() == true) { using (FileStream fs = new FileStream(fileDialog.FileName, FileMode.Open)) { presetData = JsonConvert.DeserializeObject <PresetFile>(new StreamReader(fs).ReadToEnd()); } // Saving. //using (FileStream fs = new FileStream("C:\\Temp\\U All Delay.hlx", FileMode.Create)) //{ // string jsonString = JsonConvert.SerializeObject(presetData, Formatting.Indented); // byte[] jsonArray = Encoding.ASCII.GetBytes(jsonString); // fs.Write(jsonArray, 0, jsonArray.Length); // fs.Flush(); //} } }
public void Delete(Guid presetId, Guid regionId) { var regions = GetAllRegions(presetId).ToList(); var region = regions.RemoveAll(x => x.Id == regionId); File.WriteAllText(PresetFile.ResolvePresetFilePath(presetId), JsonConvert.SerializeObject(regions)); }
public async Task UpdateAsync(Guid presetId, RegionViewModel regionViewModel) { var regions = (await GetAllRegionsAsync(presetId)).ToList(); var index = regions.IndexOf(regions.First(x => x.Id == regionViewModel.Id)); regions[index] = _mapper.Map <RegionConfig>(regionViewModel); await File.WriteAllTextAsync(PresetFile.ResolvePresetFilePath(presetId), JsonConvert.SerializeObject(regions)); }
public void Update(Guid presetId, RegionViewModel regionViewModel) { var regions = GetAllRegions(presetId).ToList(); var region = regions.FirstOrDefault(x => x.Id == regionViewModel.Id); region = _mapper.Map <RegionConfig>(regionViewModel); File.WriteAllText(PresetFile.ResolvePresetFilePath(presetId), JsonConvert.SerializeObject(regions)); }
public RegionViewModel Create(Guid presetId, string regionName) { var newRegion = new RegionConfig { Id = Guid.NewGuid(), Name = regionName }; var regions = GetAllRegions(presetId).ToList(); regions.Add(newRegion); File.WriteAllText(PresetFile.ResolvePresetFilePath(presetId), JsonConvert.SerializeObject(regions)); return(_mapper.Map <RegionViewModel>(newRegion)); }
public async Task <IEnumerable <RegionConfig> > GetAllRegionsAsync(Guid presetId) { var contents = await File.ReadAllTextAsync(PresetFile.ResolvePresetFilePath(presetId)); return(JsonConvert.DeserializeObject <IEnumerable <RegionConfig> >(contents)); }
public IEnumerable <RegionConfig> GetAllRegions(Guid presetId) { return(JsonConvert.DeserializeObject <IEnumerable <RegionConfig> >(File.ReadAllText(PresetFile.ResolvePresetFilePath(presetId)))); }