コード例 #1
0
        /// <summary>
        /// Load collection of groups of playlists
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public PlaylistGroup Load(string fileName)
        {
            PlaylistGroup plg;

            // Open file containing all playlistGroups "playlistGroup.xml"
            try
            {
                using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    XmlSerializer xml = new XmlSerializer(typeof(PlaylistGroup));
                    if (fs.Length > 0)
                    {
                        plg = (PlaylistGroup)xml.Deserialize(fs);
                    }
                    else
                    {
                        plg = new PlaylistGroup();
                    }
                }
                return(plg);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while loading playlist file:\n" + ex.Message, "Karaboss", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(new PlaylistGroup());
            }
        }
コード例 #2
0
 public PlaylistGroupItem Find(PlaylistGroup plg, string Key)
 {
     foreach (PlaylistGroupItem plgi in plg.plGroupItems)
     {
         if (plgi.Key == Key)
         {
             return(plgi);
         }
     }
     return(null);
 }
コード例 #3
0
        public Playlist getPlaylistByName(PlaylistGroup plg, string plName, string Key)
        {
            PlaylistGroupItem plgi = this.Find(plg, Key);

            if (plgi != null)
            {
                Playlist pltarget = plgi.Playlists.Where(z => z.Name == plName).FirstOrDefault();
                return(pltarget == null ? null : pltarget);
            }

            return(null);
        }
コード例 #4
0
 /// <summary>
 /// Save all groups of playlists in a xml file
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="plg"></param>
 public void Save(string fileName, PlaylistGroup plg)
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(PlaylistGroup));
         TextWriter    textWriter = new StreamWriter(@fileName);
         serializer.Serialize(textWriter, plg);
         textWriter.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error while saving playlist file:\n" + ex.Message, "Karaboss", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
コード例 #5
0
 /// <summary>
 /// Load existing playlists
 /// </summary>
 private void LoadPlaylists()
 {
     // not executed in DesignMode
     if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
     {
         return;
     }
     try
     {
         string fileName = Karaclass.GetPlaylistGroupFile(PlGroupHelper.File);
         PlGroupHelper.File = fileName;
         PlGroup            = PlGroupHelper.Load(fileName);
     }
     catch (Exception ex)
     {
         Console.Write(ex.Message);
     }
 }
コード例 #6
0
        /// <summary>
        /// Search recursively the most deeper child key
        /// </summary>
        /// <param name="plg"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public string SearchLastChildKey(PlaylistGroup plg, string Key)
        {
            foreach (PlaylistGroupItem plgi in plg.plGroupItems)
            {
                if (plgi.ParentKey == Key)
                {
                    // plgi is a child,
                    string newkey = plgi.Key;

                    // Search childs of plgi
                    string nextkey = SearchLastChildKey(plg, newkey);
                    if (nextkey != null)
                    {
                        return(nextkey);
                    }
                    else
                    {
                        return(newkey);
                    }
                }
            }
            return(null);
        }
コード例 #7
0
        /// <summary>
        /// Populate Treeview (list of Playlists)
        /// </summary>
        /// <param name="plg"></param>
        /// <param name="selectedKey"></param>
        private void PopulatetvPlaylistGroup(PlaylistGroup plg, string selectedKey = null)
        {
            TreeNode tnPl;

            tvPlaylistGroup.Nodes.Clear();
            tvPlaylistGroup.BeginUpdate();

            for (int i = 0; i < plg.Count; i++)
            {
                PlaylistGroupItem item = plg.plGroupItems[i];

                // 1 - Create folder node named item.Name
                TreeNode tnFolder = new TreeNode(item.Name)
                {
                    Name       = item.Name,
                    ImageIndex = 0,
                    Tag        = item.Key,
                };

                // Position new node under item.Parent;
                TreeNode tnParent = null;
                if (item.ParentKey != null && tvPlaylistGroup.Nodes.Count > 0)
                {
                    // Search for a treenode aving a tag equal to ParentKey
                    foreach (TreeNode node in tvPlaylistGroup.Nodes)
                    {
                        var result = FindString(item.ParentKey, node);
                        if (result != null)
                        {
                            tnParent = result;
                            break;
                        }
                    }
                }

                // 2 - Add folder node to root or to an existing folder node
                if (tnParent != null)
                {
                    tnParent.Nodes.Add(tnFolder);
                }
                else
                {
                    tvPlaylistGroup.Nodes.Add(tnFolder);
                }

                // 3 - Add child nodes (playlists)
                for (int j = 0; j < item.Playlists.Count; j++)
                {
                    Playlist pl = item.Playlists[j];
                    tnPl = new TreeNode(pl.Name)
                    {
                        Tag = "playlist",
                    };

                    // image for treenode not selected
                    tnPl.ImageIndex = 1;
                    // image for selected treenode
                    tnPl.SelectedImageIndex = 2;

                    tnFolder.Nodes.Add(tnPl);
                }
            }

            tvPlaylistGroup.EndUpdate();
            tvPlaylistGroup.ExpandAll();

            // Set focus to selected node
            TreeNode tns = null;

            if (selectedKey != null)
            {
                if (tvPlaylistGroup.Nodes.Count > 0)
                {
                    foreach (TreeNode node in tvPlaylistGroup.Nodes)
                    {
                        var result = FindString(selectedKey, node);
                        if (result != null)
                        {
                            tns = result;
                            break;
                        }
                    }
                }
            }
            if (tns != null)
            {
                tvPlaylistGroup.SelectedNode = tns;
                if (tns.LastNode != null)
                {
                    tns.LastNode.EnsureVisible();
                }
                else
                {
                    tns.EnsureVisible();
                }
            }
            else if (tvPlaylistGroup.Nodes.Count > 0)
            {
                tvPlaylistGroup.SelectedNode = tvPlaylistGroup.Nodes[0];
            }
        }