Exemple #1
0
        private static int InternalAddIconToLists(string assetTypeName, string iconFileName, Image image)
        {
            int index = 0;

            lock (mAssetTypes)
            {
                try
                {
                    // Handle any situation where we might not know the filename of the icon
                    if (iconFileName == null)
                    {
                        iconFileName = assetTypeName;
                    }

                    // Do we already have this image loaded?
                    if (mAssetTypeImages.Images.ContainsKey(iconFileName))
                    {
                        index = mAssetTypeImages.Images.IndexOfKey(iconFileName);

                        //Debug.WriteLine("Returning cached icon - " + iconFileName + " at index - " + index.ToString());

                        if (mAssetTypes.Find(iconFileName) == null)
                        {
                            mAssetTypes.Add(assetTypeName, index);
                        }

                        //Debug.WriteLine("Returned cached icon - " + iconFileName + " at index - " + index.ToString());
                    }
                    else
                    {
                        // Add the image and the type to the arrayLists
                        index = mAssetTypeImages.Images.Count;
                        //Debug.WriteLine("Addeding icon - " + assetTypeName + " as index - " + index.ToString() + " with key = " + iconFileName);

                        mAssetTypeImages.Images.Add(iconFileName, image);
                        mAssetTypes.Add(assetTypeName, index);

                        //Debug.WriteLine("Added icon - " + assetTypeName + " as index - " + index.ToString() + " with key = " + iconFileName);
                    }
                }
                catch (Exception e)
                {
                    e.ToString();
                }
            }

            return(index);
        }
Exemple #2
0
        private static void AddToRelationList <T>(string key, T relation, TstDictionaries toRelations)
            where T : RelationBase <T>
        {
            TstDictionary list = GetRelationList(key, toRelations);
            string        href = relation.HRef;

            if (href != null && !list.Contains(href))
            {
                list.Add(href, relation);
            }
        }
        static private int LoadIcon(string imageFileName, string assetClassName)
        {
            try
            {
                // Load the icon specified by the Icon= key
                string iconName = imageFileName;

                // Make sure this is a full path, if not append the tools directory to it?
                iconName = MOG_ControllerSystem.LocateTool(imageFileName);

                lock (mAssetTypes)
                {
                    // Make sure that the icon file exists
                    if (iconName.Length > 0 && DosUtils.FileExist(iconName))
                    {
                        // Get the image
                        Image myImage = new Bitmap(iconName);

                        // Add the image and the type to the arrayLists
                        mAssetTypeImages.Images.Add(myImage);
                        mAssetTypes.Add(assetClassName, mAssetTypeImages.Images.Count - 1);

                        return(mAssetTypeImages.Images.Count - 1);
                    }
                }
            }
            catch (Exception e)
            {
                MOG_Report.ReportMessage("Load Icon", e.Message, e.StackTrace, MOG_ALERT_LEVEL.CRITICAL);
            }

            return(0);
        }
Exemple #4
0
        static private void LoadRawIcon(ImageList myImages, TstDictionary myImageNames, string imageFileName, string imageName)
        {
            // Make sure that the icon file exists
            if (DosUtils.FileExist(imageFileName))
            {
                // Get the image
                Image myImage = new Bitmap(imageFileName);

                // Add the image and the type to the arrayLists
                myImages.Images.Add(myImage);
                myImageNames.Add(imageName, myImages.Images.Count - 1);
            }
        }
Exemple #5
0
    private void LoadDictionary(string path)
    {
        StreamReader reader = new StreamReader(path);

        while (!reader.EndOfStream)
        {
            string line      = reader.ReadLine();
            var    splitline = line.Split(' ');
            if (splitline.Length > 0)
            {
                words.Add(splitline[0].Trim(), null);
            }
        }
        Debug.Log("# Words in Dictionary Loaded : " + words.Count);
    }
Exemple #6
0
        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}' and c.visibleInGuide = 1 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");
                    }
                    sb.AddConstraint(" visibleInGuide = 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";
            }
        }