Exemple #1
0
        /// <summary>
        /// Retrieve all channel-mappings from TvMovieMapping table
        /// </summary>
        /// <returns></returns>
        private List <Mapping> GetMappingList()
        {
            List <Mapping> mappingList = new List <Mapping>();

            try
            {
                IList <TvMovieMapping> mappingDb = TvMovieMapping.ListAll();
                foreach (TvMovieMapping mapping in mappingDb)
                {
                    try
                    {
                        string newStart     = mapping.TimeSharingStart;
                        string newEnd       = mapping.TimeSharingEnd;
                        string newStation   = mapping.StationName;
                        string newChannel   = Channel.Retrieve(mapping.IdChannel).DisplayName;
                        int    newIdChannel = mapping.IdChannel;

                        mappingList.Add(new Mapping(newChannel, newIdChannel, newStation, newStart, newEnd));
                    }
                    catch (Exception)
                    {
                        Log.Info("TVMovie: Error loading mappings - make sure tv channel: {0} (ID: {1}) still exists!",
                                 mapping.StationName, mapping.IdChannel);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Info("TVMovie: Error in GetMappingList - {0}\n{1}", ex.Message, ex.StackTrace);
            }
            return(mappingList);
        }
        /// <summary>
        /// Save station-channel mapping to database
        /// </summary>
        private void SaveMapping()
        {
            IList <TvMovieMapping> mappingList = TvMovieMapping.ListAll();

            if (mappingList != null && mappingList.Count > 0)
            {
                foreach (TvMovieMapping mapping in mappingList)
                {
                    mapping.Remove();
                }
            }
            else
            {
                Log.Info("TvMovieSetup: SaveMapping - no mappingList items");
            }

            TvBusinessLayer layer = new TvBusinessLayer();

            foreach (TreeNode channel in treeViewMpChannels.Nodes)
            {
                //Log.Debug("TvMovieSetup: Processing channel {0}", channel.Text);
                foreach (TreeNode station in channel.Nodes)
                {
                    ChannelInfo channelInfo = (ChannelInfo)station.Tag;
                    //Log.Debug("TvMovieSetup: Processing channelInfo {0}", channelInfo.Name);
                    TvMovieMapping mapping = null;
                    try
                    {
                        mapping = new TvMovieMapping(((Channel)channel.Tag).IdChannel, channelInfo.Name, channelInfo.Start,
                                                     channelInfo.End);
                    }
                    catch (Exception exm)
                    {
                        Log.Error("TvMovieSetup: Error on new TvMovieMapping for channel {0} - {1}", channel.Text, exm.Message);
                    }
                    //Log.Write("TvMovieSetup: SaveMapping - new mapping for {0}/{1}", channel.Text, channelInfo.Name);
                    try
                    {
                        Log.Debug("TvMovieSetup: Persisting TvMovieMapping for channel {0}", channel.Text);
                        mapping.Persist();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("TvMovieSetup: Error on mapping.Persist() {0},{1}", ex.Message, ex.StackTrace);
                    }
                }
            }
        }
        /// <summary>
        /// Load station-channel mapping from database
        /// </summary>
        private void LoadMapping()
        {
            treeViewMpChannels.BeginUpdate();
            try
            {
                foreach (TreeNode treeNode in treeViewMpChannels.Nodes)
                {
                    foreach (TreeNode childNode in treeNode.Nodes)
                    {
                        childNode.Remove();
                    }
                }
                try
                {
                    IList <TvMovieMapping> mappingDb = TvMovieMapping.ListAll();
                    if (mappingDb != null && mappingDb.Count > 0)
                    {
                        foreach (TvMovieMapping mapping in mappingDb)
                        {
                            string MpChannelName = string.Empty;
                            try
                            {
                                TreeNode channelNode = FindChannel(mapping.IdChannel);
                                if (channelNode != null)
                                {
                                    string stationName = mapping.StationName;
                                    if (FindStation(stationName) != null)
                                    {
                                        TreeNode    stationNode = (TreeNode)FindStation(stationName).Clone();
                                        ChannelInfo channelInfo = new ChannelInfo();
                                        if (stationNode != null)
                                        {
                                            string start = mapping.TimeSharingStart;
                                            string end   = mapping.TimeSharingEnd;

                                            if (start != "00:00" || end != "00:00")
                                            {
                                                stationNode.Text = string.Format("{0} ({1}-{2})", stationName, start, end);
                                            }
                                            else
                                            {
                                                stationNode.Text = string.Format("{0}", stationName);
                                            }

                                            channelInfo.Start = start;
                                            channelInfo.End   = end;
                                            channelInfo.Name  = stationName;

                                            stationNode.Tag = channelInfo;

                                            channelNode.Nodes.Add(stationNode);
                                            channelNode.Expand();
                                        }
                                    }
                                    else
                                    {
                                        Log.Debug("TVMovie plugin: Channel {0} no longer present in Database - ignoring", stationName);
                                    }
                                }
                            }
                            catch (Exception exInner)
                            {
                                Log.Debug("TVMovie plugin: Mapping of station {0} failed; maybe it has been deleted / changed ({1})",
                                          MpChannelName, exInner.Message);
                            }
                        }
                    }
                    else
                    {
                        Log.Debug("TVMovie plugin: LoadMapping did not find any mapped channels");
                    }
                }
                catch (Exception ex)
                {
                    Log.Debug("TVMovie plugin: LoadMapping failed - {0},{1}", ex.Message, ex.StackTrace);
                }
                ColorTree();
            }
            finally
            {
                treeViewMpChannels.EndUpdate();
            }
        }