public void SetActiveProgramGroupItem(ProgramGroupItemViewControl programGroupItem) { if (IsMediaPlaying) { return; } // set all group items to inactive foreach (Control control in pnlProgramGroupItems.Controls) { if (control is ProgramGroupItemViewControl) { ((ProgramGroupItemViewControl)control).Active = false; } } programGroupItem.Active = true; currentItem = programGroupItem.ProgramGroupItem; grpCurrentItem.Text = currentItem.Title; rtxtInfo.Text = currentItem.Info; // populate the program items of the current item to the list view PopulateProgramItems(currentItem.ProgramItems); }
public bool LoadProgramFile(string filePath) { pnlProgramGroupItems.Controls.Clear(); pnlRecurringItems.Controls.Clear(); if (File.Exists(filePath)) { try { JObject jsonFile = JObject.Parse(File.ReadAllText(filePath)); programGroupItems = new List <ProgramGroupItem>(); recurringItems = jsonFile["recurringItems"].Select(p => p.ToObject <ProgramItem>()).ToList(); foreach (JToken token in jsonFile["programGroupItems"]) { List <ProgramItem> programItems = token["programItems"].Select(p => p.ToObject <ProgramItem>()).ToList(); string info = token["info"] == null ? "" : token["info"].ToString(); programGroupItems.Add(new ProgramGroupItem(token["title"].ToString(), info, Convert.ToBoolean(token["auto"]), programItems)); } } catch (Exception) { MessageBox.Show("Fehler beim Lesen der JSON Datei"); } // create controls for all program items foreach (ProgramGroupItem item in programGroupItems) { ProgramGroupItemViewControl control = new ProgramGroupItemViewControl(item); pnlProgramGroupItems.Controls.Add(control); } foreach (ProgramItem item in recurringItems) { Button button = new Button(); button.Text = item.Name; button.Height = 40; button.Click += (_, __) => { // maintain the currently selected item after playing the recurring item restoreLastItem = true; InitializeMediaPlayer(item, true); }; pnlRecurringItems.Controls.Add(button); } string baseDir = new DirectoryInfo(filePath).Parent.FullName; ResolveFilePaths(recurringItems, baseDir); foreach (ProgramGroupItem item in programGroupItems) { ResolveFilePaths(item.ProgramItems, baseDir); } // set first program item to active SetActiveProgramGroupItem((ProgramGroupItemViewControl)pnlProgramGroupItems.Controls[0]); return(true); } return(false); }