private void DisplaySelectedChannelGrabberInfo()
 {
     if (lvMapping.SelectedItems.Count == 1 && _channelMapping.ContainsKey(lvMapping.SelectedItems[0].Text))
     {
         ChannelMap channel = _channelMapping[lvMapping.SelectedItems[0].Text];
         DisplayChannelGrabberInfo(channel);
     }
     else
     {
         DisplayChannelGrabberInfo(null);
     }
 }
        private void UpdateList()
        {
            //update existing channels
            foreach (ListViewItem channel in lvMapping.Items)
            {
                if (_channelMapping.ContainsKey(channel.Text))
                {
                    ChannelMap channelDetails = _channelMapping[channel.Text];
                    string     name           = string.Empty;
                    if (channelDetails.id != null)
                    {
                        ChannelConfigInfo info = (ChannelConfigInfo)_hChannelConfigInfo[channelDetails.id];
                        if (info != null)
                        {
                            name = info.FullName;
                        }
                    }
                    else
                    {
                        if (channelDetails.merged != null)
                        {
                            name = "[Merged]";
                        }
                    }
                    channel.SubItems[1].Text = name;
                    channel.SubItems[2].Text = channelDetails.id;
                    channel.SubItems[3].Text = channelDetails.grabber;
                }
                else
                {
                    int selectedIndex = 0;
                    if (lvMapping.SelectedIndices.Count > 0)
                    {
                        selectedIndex = lvMapping.SelectedIndices[0];
                    }

                    lvMapping.Items.Remove(channel);

                    if (lvMapping.Items.Count > 0)
                    {
                        if (lvMapping.Items.Count > selectedIndex)
                        {
                            lvMapping.Items[selectedIndex].Selected = true;
                        }
                        else
                        {
                            lvMapping.Items[lvMapping.Items.Count - 1].Selected = true;
                        }
                    }
                }
            }
            lvMapping.Select();
        }
        public void OnGrabberSelected(Object source, GrabberSelectedEventArgs e)
        {
            //this.Activate(); -> form control
            GrabberSelectionInfo id = e.Selection;

            if (tcMappingDetails.SelectedIndex == 0) // single mapping
            {
                if (id != null)
                {
                    if (UpdateGrabberDetails(id.ChannelId, id.GrabberId))
                    {
                        foreach (ListViewItem channel in lvMapping.SelectedItems)
                        {
                            if (_channelMapping.ContainsKey(channel.Text))
                            {
                                ChannelMap channelMap = _channelMapping[channel.Text];
                                channelMap.id      = id.ChannelId;
                                channelMap.grabber = id.GrabberId;
                                _channelMapping.Remove(channel.Text);
                                _channelMapping.Add(channel.Text, channelMap);
                            }
                        }
                    }

                    UpdateList();
                }
            }
            else // merged mapping
            {
                DataGridViewRow row = null;
                if (dgvMerged.SelectedRows.Count == 1)
                {
                    row = dgvMerged.SelectedRows[0];
                }
                else
                {
                    row = dgvMerged.CurrentRow;
                }
                if (row != null)
                {
                    //MergedChannel channelDetails = (MergedChannel)dgvMerged.SelectedRows[0].DataBoundItem;
                    //dgvMerged.BeginEdit(false);
                    dgvMerged.CurrentCell = row.Cells["idColumn"];
                    dgvMerged.NotifyCurrentCellDirty(true);
                    dgvMerged.NotifyCurrentCellDirty(false);
                    row.Cells["idColumn"].Value      = id.ChannelId;
                    row.Cells["grabberColumn"].Value = id.GrabberId;
                    //dgvMerged.EndEdit();
                }
            }
        }
        private void bClearMapping_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem channel in lvMapping.SelectedItems)
            {
                if (_channelMapping.ContainsKey(channel.Text))
                {
                    ChannelMap channelMap = _channelMapping[channel.Text];
                    channelMap.id      = null;
                    channelMap.grabber = null;
                    channelMap.merged  = null;
                    _channelMapping.Remove(channel.Text);
                    _channelMapping.Add(channel.Text, channelMap);
                }
            }

            UpdateList();
            DisplaySelectedChannelGrabberInfo();
        }
        private void getTvServerChannels()
        {
            CBChannelGroup chGroup = (CBChannelGroup)GroupComboBox.SelectedItem;

            IList <Channel> Channels;

            if (chGroup != null && chGroup.idGroup != -1)
            {
                SqlBuilder   sb1           = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof(Channel));
                SqlStatement stmt1         = sb1.GetStatement(true);
                SqlStatement ManualJoinSQL = new SqlStatement(stmt1.StatementType, stmt1.Command,
                                                              String.Format(
                                                                  "select c.* from Channel c join {0}GroupMap g on c.idChannel=g.idChannel where c.{1} = 1 and g.idGroup = '{2}' order by g.sortOrder",
                                                                  IsTvMapping ? "" : "Radio", IsTvMapping ? "isTv" : "isRadio",
                                                                  chGroup.idGroup), typeof(Channel));
                Channels = ObjectFactory.GetCollection <Channel>(ManualJoinSQL.Execute());
            }
            else
            {
                SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof(Channel));
                sb.AddOrderByField(true, "sortOrder");
                if (IsTvMapping)
                {
                    sb.AddConstraint("isTv = 1");
                }
                else
                {
                    sb.AddConstraint("isRadio = 1");
                }
                SqlStatement stmt = sb.GetStatement(true);
                Channels = ObjectFactory.GetCollection <Channel>(stmt.Execute());
            }

            foreach (Channel chan in Channels)
            {
                if (!_channelMapping.ContainsKey(chan.DisplayName))
                {
                    ChannelMap channel = new ChannelMap();
                    channel.displayName = chan.DisplayName;
                    _channelMapping.Add(chan.DisplayName, channel);
                }
            }
        }
        private void DisplayChannelGrabberInfo(ChannelMap channel)
        {
            if (channel == null)
            {
                tcMappingDetails.SelectedIndex = 0;
                UpdateGrabberDetails(null, null);
                UpdateMergedList(null);
            }
            else
            {
                if (channel.merged != null && channel.merged.Count > 0)
                {
                    tcMappingDetails.SelectedIndex = 1;
                    UpdateMergedList(channel);
                }
                else
                {
                    tcMappingDetails.SelectedIndex = 0;
                    UpdateGrabberDetails(channel.id, channel.grabber);
                }
            }

            lvMapping.Select();
        }
Exemple #7
0
        private void LoadOldConfigFile()
        {
            Log.Info("Trying to load old config file format");

            _configFile = new WebepgConfigFile();

            Xml xmlreader = new Xml(_configFileDir + "\\WebEPG.xml");

            _configFile.Info            = new WebepgInfo();
            _configFile.Info.GrabDays   = xmlreader.GetValueAsInt("General", "MaxDays", 2);
            _configFile.Info.GrabberDir = xmlreader.GetValueAsString("General", "GrabberDir", null);

            int AuthCount = xmlreader.GetValueAsInt("AuthSites", "Count", 0);

            if (AuthCount > 0)
            {
                _configFile.Sites = new List <SiteAuth>();
                for (int i = 1; i <= AuthCount; i++)
                {
                    SiteAuth site = new SiteAuth();
                    site.id       = xmlreader.GetValueAsString("Auth" + i.ToString(), "Site", "");
                    site.username = xmlreader.GetValueAsString("Auth" + i.ToString(), "Login", "");
                    site.password = xmlreader.GetValueAsString("Auth" + i.ToString(), "Password", "");
                    _configFile.Sites.Add(site);
                }
            }

            _configFile.Channels = new List <ChannelMap>();

            int channelCount = xmlreader.GetValueAsInt("ChannelMap", "Count", 0);

            for (int i = 1; i <= channelCount; i++)
            {
                ChannelMap channel = new ChannelMap();
                channel.displayName = xmlreader.GetValueAsString(i.ToString(), "DisplayName", "");
                string grabber = xmlreader.GetValueAsString(i.ToString(), "Grabber1", "");
                ;
                //if (mergedList.ContainsKey(channel.displayName))
                //{
                //  channel.merged = mergedList[channel.displayName];
                //  foreach (MergedChannel mergedChannel in channel.merged)
                //    mergedChannel.grabber = grabber;
                //}
                //else
                //{
                channel.id      = xmlreader.GetValueAsString(i.ToString(), "ChannelID", "");
                channel.grabber = grabber;
                //}
                _configFile.Channels.Add(channel);
            }

            int mergeCount = xmlreader.GetValueAsInt("MergeChannels", "Count", 0);
            Dictionary <string, List <MergedChannel> > mergedList = new Dictionary <string, List <MergedChannel> >();

            if (mergeCount > 0)
            {
                for (int i = 1; i <= mergeCount; i++)
                {
                    int channelcount = xmlreader.GetValueAsInt("Merge" + i.ToString(), "Channels", 0);
                    if (channelcount > 0)
                    {
                        List <MergedChannel> mergedChannels = new List <MergedChannel>();
                        ChannelMap           channel        = new ChannelMap();
                        channel.displayName = xmlreader.GetValueAsString("Merge" + i.ToString(), "DisplayName", "");
                        channel.merged      = new List <MergedChannel>();
                        for (int c = 1; c <= channelcount; c++)
                        {
                            MergedChannel mergedChannel = new MergedChannel();
                            mergedChannel.id    = xmlreader.GetValueAsString("Merge" + i.ToString(), "Channel" + c.ToString(), "");
                            mergedChannel.start = xmlreader.GetValueAsString("Merge" + i.ToString(), "Start" + c.ToString(), "0:0");
                            mergedChannel.end   = xmlreader.GetValueAsString("Merge" + i.ToString(), "End" + c.ToString(), "0:0");
                            channel.merged.Add(mergedChannel);
                        }

                        _configFile.Channels.Add(channel);
                    }
                }
            }

            xmlreader.Clear();
            xmlreader.Dispose();
        }
    private void DisplayChannelGrabberInfo(ChannelMap channel)
    {
      if (channel == null)
      {
        tcMappingDetails.SelectedIndex = 0;
        UpdateGrabberDetails(null, null);
        UpdateMergedList(null);
      }
      else
      {
        if (channel.merged != null && channel.merged.Count > 0)
        {
          tcMappingDetails.SelectedIndex = 1;
          UpdateMergedList(channel);
        }
        else
        {
          tcMappingDetails.SelectedIndex = 0;
          UpdateGrabberDetails(channel.id, channel.grabber);
        }
      }

      lvMapping.Select();
    }
 private void UpdateMergedList(ChannelMap channelMap)
 {
   bsMergedChannel.DataSource = (channelMap == null) ? null : channelMap.merged;
   bsMergedChannel.ResetBindings(false);
 }
    private void getTvServerChannels()
    {
      CBChannelGroup chGroup = (CBChannelGroup)GroupComboBox.SelectedItem;

      IList<Channel> Channels;
      if (chGroup != null && chGroup.idGroup != -1)
      {
        SqlBuilder sb1 = new SqlBuilder(Gentle.Framework.StatementType.Select, typeof (Channel));
        SqlStatement stmt1 = sb1.GetStatement(true);
        SqlStatement ManualJoinSQL = new SqlStatement(stmt1.StatementType, stmt1.Command,
                                                      String.Format(
                                                        "select c.* from Channel c join {0}GroupMap g on c.idChannel=g.idChannel where c.{1} = 1 and g.idGroup = '{2}' order by g.sortOrder",
                                                        IsTvMapping ? "" : "Radio", IsTvMapping ? "isTv" : "isRadio",
                                                        chGroup.idGroup), typeof (Channel));
        Channels = ObjectFactory.GetCollection<Channel>(ManualJoinSQL.Execute());
      }
      else
      {
        SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel));
        sb.AddOrderByField(true, "sortOrder");
        if (IsTvMapping)
        {
          sb.AddConstraint("isTv = 1");
        }
        else
        {
          sb.AddConstraint("isRadio = 1");
        }
        SqlStatement stmt = sb.GetStatement(true);
        Channels = ObjectFactory.GetCollection<Channel>(stmt.Execute());
      }

      foreach (Channel chan in Channels)
      {
        if (!_channelMapping.ContainsKey(chan.DisplayName))
        {
          ChannelMap channel = new ChannelMap();
          channel.displayName = chan.DisplayName;
          _channelMapping.Add(chan.DisplayName, channel);
        }
      }
    }
    private void LoadOldConfigFile()
    {
      Log.Info("Trying to load old config file format");

      _configFile = new WebepgConfigFile();

      Xml xmlreader = new Xml(_configFileDir + "\\WebEPG.xml");

      _configFile.Info = new WebepgInfo();
      _configFile.Info.GrabDays = xmlreader.GetValueAsInt("General", "MaxDays", 2);
      _configFile.Info.GrabberDir = xmlreader.GetValueAsString("General", "GrabberDir", null);

      int AuthCount = xmlreader.GetValueAsInt("AuthSites", "Count", 0);
      if (AuthCount > 0)
      {
        _configFile.Sites = new List<SiteAuth>();
        for (int i = 1; i <= AuthCount; i++)
        {
          SiteAuth site = new SiteAuth();
          site.id = xmlreader.GetValueAsString("Auth" + i.ToString(), "Site", "");
          site.username = xmlreader.GetValueAsString("Auth" + i.ToString(), "Login", "");
          site.password = xmlreader.GetValueAsString("Auth" + i.ToString(), "Password", "");
          _configFile.Sites.Add(site);
        }
      }

      _configFile.Channels = new List<ChannelMap>();

      int channelCount = xmlreader.GetValueAsInt("ChannelMap", "Count", 0);

      for (int i = 1; i <= channelCount; i++)
      {
        ChannelMap channel = new ChannelMap();
        channel.displayName = xmlreader.GetValueAsString(i.ToString(), "DisplayName", "");
        string grabber = xmlreader.GetValueAsString(i.ToString(), "Grabber1", "");
        ;
        //if (mergedList.ContainsKey(channel.displayName))
        //{
        //  channel.merged = mergedList[channel.displayName];
        //  foreach (MergedChannel mergedChannel in channel.merged)
        //    mergedChannel.grabber = grabber;
        //}
        //else
        //{
        channel.id = xmlreader.GetValueAsString(i.ToString(), "ChannelID", "");
        channel.grabber = grabber;
        //}
        _configFile.Channels.Add(channel);
      }

      int mergeCount = xmlreader.GetValueAsInt("MergeChannels", "Count", 0);
      Dictionary<string, List<MergedChannel>> mergedList = new Dictionary<string, List<MergedChannel>>();

      if (mergeCount > 0)
      {
        for (int i = 1; i <= mergeCount; i++)
        {
          int channelcount = xmlreader.GetValueAsInt("Merge" + i.ToString(), "Channels", 0);
          if (channelcount > 0)
          {
            List<MergedChannel> mergedChannels = new List<MergedChannel>();
            ChannelMap channel = new ChannelMap();
            channel.displayName = xmlreader.GetValueAsString("Merge" + i.ToString(), "DisplayName", "");
            channel.merged = new List<MergedChannel>();
            for (int c = 1; c <= channelcount; c++)
            {
              MergedChannel mergedChannel = new MergedChannel();
              mergedChannel.id = xmlreader.GetValueAsString("Merge" + i.ToString(), "Channel" + c.ToString(), "");
              mergedChannel.start = xmlreader.GetValueAsString("Merge" + i.ToString(), "Start" + c.ToString(), "0:0");
              mergedChannel.end = xmlreader.GetValueAsString("Merge" + i.ToString(), "End" + c.ToString(), "0:0");
              channel.merged.Add(mergedChannel);
            }

            _configFile.Channels.Add(channel);
          }
        }
      }

      xmlreader.Clear();
      xmlreader.Dispose();
    }
        //private void bMergedAdd_Click(object sender, EventArgs e)
        //{
        //  lvMerged.SelectedItems.Clear();
        //  //_mergeConfig = new MergedChannelDetails(tGrabbers, null, this.bMergedOk_Click);
        //  //_mergeConfig.MinimizeBox = false;
        //  //_mergeConfig.Show();
        //}

        //private void bMergedOk_Click(object sender, EventArgs e)
        //{
        //  if (lvMapping.SelectedItems.Count == 1)
        //  {
        //    ChannelMap channelMap = _channelMapping[lvMapping.SelectedItems[0].Text];
        //    if (lvMerged.SelectedItems.Count == 1)
        //    {
        //      MergedChannel channelDetails = (MergedChannel) lvMerged.SelectedItems[0].Tag;

        //      channelDetails.id = _mergeConfig.ChannelDetails.id;
        //      channelDetails.grabber = _mergeConfig.ChannelDetails.grabber;
        //      channelDetails.start = _mergeConfig.ChannelDetails.start;
        //      channelDetails.end = _mergeConfig.ChannelDetails.end;
        //    }
        //    else
        //    {
        //      channelMap.merged.Add(_mergeConfig.ChannelDetails);
        //    }
        //    UpdateMergedList(channelMap);
        //  }
        //  _mergeConfig.Close();
        //}

        //private void bMergedRemove_Click(object sender, EventArgs e)
        //{
        //  if (lvMerged.SelectedItems.Count == 1 && lvMapping.SelectedItems.Count == 1)
        //  {
        //    ChannelMap channelMap = _channelMapping[lvMapping.SelectedItems[0].Text];
        //    channelMap.merged.Remove((MergedChannel) lvMerged.SelectedItems[0].Tag);
        //    UpdateMergedList(channelMap);
        //  }
        //}

        //private void bMergedEdit_Click(object sender, EventArgs e)
        //{
        //  if (lvMerged.SelectedItems.Count == 1 && lvMapping.SelectedItems.Count == 1)
        //  {
        //    //MergedChannel channel = (MergedChannel) lvMerged.SelectedItems[0].Tag;
        //    //_mergeConfig = new MergedChannelDetails(tGrabbers, channel, this.bMergedOk_Click);
        //    //_mergeConfig.MinimizeBox = false;
        //    //_mergeConfig.Show();
        //  }
        //}

        private void tcMappingDetails_Selecting(object sender, TabControlCancelEventArgs e)
        {
            if (tcMappingDetails.SelectedIndex == 1)
            {
                if (lvMapping.SelectedItems.Count == 1)
                {
                    if (_channelMapping.ContainsKey(lvMapping.SelectedItems[0].Text))
                    {
                        ChannelMap channelMap = _channelMapping[lvMapping.SelectedItems[0].Text];
                        if (channelMap.merged == null || channelMap.merged.Count == 0)
                        {
                            channelMap.merged = new List <MergedChannel>();
                            if (channelMap.id != null)
                            {
                                MergedChannel channel = new MergedChannel();
                                channel.id         = channelMap.id;
                                channelMap.id      = null;
                                channel.grabber    = channelMap.grabber;
                                channelMap.grabber = null;
                                channelMap.merged.Add(channel);
                            }
                            //_channelMapping.Remove(channel.Text);
                            //_channelMapping.Add(channel.Text, channelMap);
                        }
                        UpdateMergedList(channelMap);
                        UpdateList();
                    }
                }
                else
                {
                    e.Cancel = true;
                    MessageBox.Show("Only one channel can be mapped to multiple channels at a time.", "Multiple Selection Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                if (lvMapping.SelectedItems.Count == 1)
                {
                    if (_channelMapping.ContainsKey(lvMapping.SelectedItems[0].Text))
                    {
                        if (_channelMapping[lvMapping.SelectedItems[0].Text].merged == null ||
                            _channelMapping[lvMapping.SelectedItems[0].Text].merged.Count <= 1)
                        {
                            ChannelMap channelMap = _channelMapping[lvMapping.SelectedItems[0].Text];
                            if (channelMap.merged != null)
                            {
                                if (channelMap.merged.Count > 0)
                                {
                                    channelMap.id      = channelMap.merged[0].id;
                                    channelMap.grabber = channelMap.merged[0].grabber;
                                }
                                channelMap.merged = null;
                            }
                            UpdateMergedList(channelMap);
                            UpdateList();
                        }
                        else
                        {
                            e.Cancel = true;
                            MessageBox.Show("Cannot convert multiple channels to single channel. Please remove one.",
                                            "Multiple Channel Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
            }
        }
 private void UpdateMergedList(ChannelMap channelMap)
 {
     bsMergedChannel.DataSource = (channelMap == null) ? null : channelMap.merged;
     bsMergedChannel.ResetBindings(false);
 }