Example #1
0
 /// <summary>
 /// Returns a synchronized (thread-safe) wrapper for
 /// the <see cref="TstDictionary"/>.
 /// </summary>
 /// <param name="table">The <see cref="TstDictionary"/> to synchronize.</param>
 /// <returns>A synchronized (thread-safe) wrapper for the
 /// <see cref="TstDictionary"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="table"/> is a null reference.</exception>
 public static TstDictionary Synchronized(TstDictionary table)
 {
     if (table == null)
     {
         throw new ArgumentNullException("table");
     }
     return(new TstSynchronizedDictionary(table));
 }
Example #2
0
 /// <summary>
 /// Tarverses the ternary search tree nodes of <paramref name="dic"/>.
 /// </summary>
 /// <param name="dic">Tree to explore</param>
 /// <exception cref="ArgumentNullException"><paramref name="dic"/> is null.</exception>
 public void Traverse(TstDictionary dic)
 {
     if (dic == null)
     {
         throw new ArgumentNullException("dic");
     }
     Traverse(dic.Root);
 }
 /// <summary>Constructs an enumerator over <paramref name="tst"/></summary>
 /// <param name="tst">dictionary to enumerate.</param>
 /// <exception cref="ArgumentNullException">tst is null</exception>
 public TstDictionaryEnumerator(TstDictionary tst)
 {
   if (tst == null)
     throw new ArgumentNullException("tst");
   this.version = tst.Version;
   this.dictionary = tst;
   this.currentNode = null;
   this.stack = null;
 }
 /// <summary>Constructs an enumerator over <paramref name="tst"/></summary>
 /// <param name="tst">dictionary to enumerate.</param>
 /// <exception cref="ArgumentNullException">tst is null</exception>
 public TstDictionaryEnumerator(TstDictionary tst)
 {
     if (tst == null)
     {
         throw new ArgumentNullException("tst");
     }
     this.version     = tst.Version;
     this.dictionary  = tst;
     this.currentNode = null;
     this.stack       = null;
 }
 /// <summary>
 /// Creates a synchronized wrapper around the
 /// <see cref="TstDictionary"/> <paramref name="dic"/>.
 /// </summary>
 /// <param name="dic">Dictionary to synchronize</param>
 public TstSynchronizedDictionary(TstDictionary dic)
     : base()
 {
     this.wrapped = dic;
 }
    private void buttonRefresh_Click(object sender, EventArgs e)
    {
      String name = null;


      try
      {
        textBoxAction.Text = "Loading";
        this.Refresh();

        Log.Debug("Loading all channels from the tvguide[s]");
        // used for partial matches
        TstDictionary guideChannels = new TstDictionary();

        Dictionary<string, Channel> guideChannelsExternald = new Dictionary<string, Channel>();

        List<Channel> lstTvGuideChannels = readChannelsFromTVGuide();

        if (lstTvGuideChannels == null)
          return;

        // convert to Dictionary
        foreach (Channel ch in lstTvGuideChannels)
        {
          string tName = ch.DisplayName.Replace(" ", "").ToLowerInvariant();
          if (!guideChannels.ContainsKey(tName))
            guideChannels.Add(tName, ch);

          // used to make sure that the available mapping is used by default
          if (ch.ExternalId != null && !ch.ExternalId.Trim().Equals(""))
          {
            // need to check this because we can have channels with multiple display-names 
            // and they're currently handles as one channel/display-name.
            // only in the mapping procedure of course
            if (!guideChannelsExternald.ContainsKey(ch.ExternalId))
              guideChannelsExternald.Add(ch.ExternalId, ch);
          }
        }

        Log.Debug("Loading all channels from the database");

        CBChannelGroup chGroup = (CBChannelGroup)comboBoxGroup.SelectedItem;

        IList<Channel> channels;

        bool loadRadio = checkBoxLoadRadio.Checked;

        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 GroupMap g on c.idChannel=g.idChannel where " +
                                                          (loadRadio ? "" : " c.isTv = 1 and ") +
                                                          " g.idGroup = '{0}' order by g.sortOrder", chGroup.idGroup),
                                                        typeof (Channel));
          channels = ObjectFactory.GetCollection<Channel>(ManualJoinSQL.Execute());
        }
        else
        {
          SqlBuilder sb = new SqlBuilder(StatementType.Select, typeof (Channel));
          sb.AddOrderByField(true, "sortOrder");
          if (!loadRadio)
            sb.AddConstraint(" isTv = 1");
          SqlStatement stmt = sb.GetStatement(true);
          channels = ObjectFactory.GetCollection<Channel>(stmt.Execute());
        }

        progressBar1.Minimum = 0;
        progressBar1.Maximum = channels.Count;
        progressBar1.Value = 0;

        dataGridChannelMappings.Rows.Clear();

        int row = 0;

        if (channels.Count == 0)
        {
          MessageBox.Show("No tv-channels available to map");
          return;
        }
        // add as many rows in the datagrid as there are channels
        dataGridChannelMappings.Rows.Add(channels.Count);

        DataGridViewRowCollection rows = dataGridChannelMappings.Rows;

        // go through each channel and try to find a matching channel
        // 1: matching display-name (non case-sensitive)
        // 2: partial search on the first word. The first match will be selected in the dropdown

        foreach (Channel ch in channels)
        {
          Boolean alreadyMapped = false;
          DataGridViewRow gridRow = rows[row++];

          DataGridViewTextBoxCell idCell = (DataGridViewTextBoxCell)gridRow.Cells["Id"];
          DataGridViewTextBoxCell channelCell = (DataGridViewTextBoxCell)gridRow.Cells["tuningChannel"];
          DataGridViewTextBoxCell providerCell = (DataGridViewTextBoxCell)gridRow.Cells["tuningChannel"];
          DataGridViewCheckBoxCell showInGuideCell = (DataGridViewCheckBoxCell)gridRow.Cells["ShowInGuide"];

          channelCell.Value = ch.DisplayName;
          idCell.Value = ch.IdChannel;
          showInGuideCell.Value = ch.VisibleInGuide;

          DataGridViewComboBoxCell guideChannelComboBox = (DataGridViewComboBoxCell)gridRow.Cells["guideChannel"];

          // always add a empty item as the first option
          // these channels will not be updated when saving
          guideChannelComboBox.Items.Add("");

          // Start by checking if there's an available mapping for this channel
          Channel matchingGuideChannel = null;

          if (guideChannelsExternald.ContainsKey(ch.ExternalId))
          {
            matchingGuideChannel = guideChannelsExternald[ch.ExternalId];
            alreadyMapped = true;
          }
          // no externalid mapping available, try using the name
          if (matchingGuideChannel == null)
          {
            string tName = ch.DisplayName.Replace(" ", "").ToLowerInvariant();
            if (guideChannels.ContainsKey(tName))
              matchingGuideChannel = (Channel)guideChannels[tName];
          }

          Boolean exactMatch = false;
          Boolean partialMatch = false;

          if (!alreadyMapped)
          {
            if (matchingGuideChannel != null)
            {
              exactMatch = true;
            }
            else
            {
              // No name mapping found

              // do a partial search, default off
              if (checkBoxPartialMatch.Checked)
              {
                // do a search using the first word(s) (skipping the last) of the channelname
                name = ch.DisplayName.Trim();
                int spaceIdx = name.LastIndexOf(" ");
                if (spaceIdx > 0)
                {
                  name = name.Substring(0, spaceIdx).Trim();
                }
                else
                {
                  // only one word so we'll do a partial match on the first 3 letters
                  if (name.Length > 3)
                    name = name.Substring(0, 3);
                }

                try
                {
                  // Note: the partial match code doesn't work as described by the author
                  // so we'll use PrefixMatch method (created by a codeproject user)
                  ICollection partialMatches = guideChannels.PrefixMatch(name.Replace(" ", "").ToLowerInvariant());

                  if (partialMatches != null && partialMatches.Count > 0)
                  {
                    IEnumerator pmE = partialMatches.GetEnumerator();
                    pmE.MoveNext();
                    matchingGuideChannel = (Channel)guideChannels[(string)pmE.Current];
                    partialMatch = true;
                  }
                }
                catch (Exception ex)
                {
                  Log.Error("Error while searching for matching guide channel :" + ex.Message);
                }
              }
            }
          }
          // add the channels 
          // set the first matching channel in the search above as the selected

          Boolean gotMatch = false;

          string ALREADY_MAPPED = "Already mapped (got external id)";
          string EXACT_MATCH = "Exact match";
          string PARTIAL_MATCH = "Partial match";
          string NO_MATCH = "No match";

          DataGridViewCell cell = gridRow.Cells["matchType"];

          foreach (DictionaryEntry de in guideChannels)
          {
            Channel guideChannel = (Channel)de.Value;

            String itemText = guideChannel.DisplayName + " (" + guideChannel.ExternalId + ")";

            guideChannelComboBox.Items.Add(itemText);

            if (!gotMatch && matchingGuideChannel != null)
            {
              if (guideChannel.DisplayName.ToLowerInvariant().Equals(matchingGuideChannel.DisplayName.ToLowerInvariant()))
              {
                // set the matchtype row color according to the type of match(already mapped,exact, partial, none)
                if (alreadyMapped)
                {
                  cell.Style.BackColor = Color.White;
                  cell.ToolTipText = ALREADY_MAPPED;
                  // hack so that we can order the grid by mappingtype
                  cell.Value = "";
                }
                else if (exactMatch)
                {
                  cell.Style.BackColor = Color.Green;
                  cell.ToolTipText = EXACT_MATCH;
                  cell.Value = "  ";
                }
                else if (partialMatch)
                {
                  cell.Style.BackColor = Color.Yellow;
                  cell.ToolTipText = PARTIAL_MATCH;
                  cell.Value = "   ";
                }

                guideChannelComboBox.Value = itemText;
                guideChannelComboBox.Tag = ch.ExternalId;

                gotMatch = true;
              }
            }
          }
          if (!gotMatch)
          {
            cell.Style.BackColor = Color.Red;
            cell.ToolTipText = NO_MATCH;
            cell.Value = "    ";
          }
          progressBar1.Value++;
        }
        textBoxAction.Text = "Finished";
      }
      catch (Exception ex)
      {
        Log.Error("Failed loading channels/mappings : channel {0} erro {1} ", name, ex.Message);
        Log.Error(ex.StackTrace);
        textBoxAction.Text = "Error";
      }
    }
 /// <summary>
 /// Creates a synchronized wrapper around the 
 /// <see cref="TstDictionary"/> <paramref name="dic"/>.
 /// </summary>
 /// <param name="dic">Dictionary to synchronize</param>
 public TstSynchronizedDictionary(TstDictionary dic)
   : base()
 {
   this.wrapped = dic;
 }
Example #8
0
 /// <summary>
 /// Tarverses the ternary search tree nodes of <paramref name="dic"/>.
 /// </summary>
 /// <param name="dic">Tree to explore</param>
 /// <exception cref="ArgumentNullException"><paramref name="dic"/> is null.</exception>
 public void Traverse(TstDictionary dic)
 {
   if (dic == null)
     throw new ArgumentNullException("dic");
   Traverse(dic.Root);
 }
Example #9
0
 /// <summary>
 /// Returns a synchronized (thread-safe) wrapper for 
 /// the <see cref="TstDictionary"/>.
 /// </summary>
 /// <param name="table">The <see cref="TstDictionary"/> to synchronize.</param>
 /// <returns>A synchronized (thread-safe) wrapper for the 
 /// <see cref="TstDictionary"/>.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="table"/> is a null reference.</exception>
 public static TstDictionary Synchronized(TstDictionary table)
 {
   if (table == null)
     throw new ArgumentNullException("table");
   return new TstSynchronizedDictionary(table);
 }