Exemple #1
0
        /// <summary>
        /// Returns a list of relations, that are known in RelationCosmos and pointing to
        /// the relation provided.
        /// </summary>
        /// <param name="relation">The object implementing RelationBase</param>
        /// <param name="excludeRelations">List of relations,
        /// that should be excluded in that check</param>
        /// <returns>RelationList</returns>
        public IList <T> GetIncoming <T>(T relation, IList <T> excludeRelations)
            where T : RelationBase <T>
        {
            if (relation == null)
            {
                return(new List <T>());
            }

            lock (syncRoot) {
                IList <T> ret  = new List <T>(relation.OutgoingRelations.Count);
                string    hRef = relation.HRef;
                if (hRef != null && hRef.Length > 0)
                {
                    //_log.Info("GetIncoming(href):" + hRef);
                    TstDictionary list = relationsLinkTo[hRef];
                    if (list != null)
                    {
                        foreach (T linkBack in list.Values)
                        {
                            if (!excludeRelations.Contains(linkBack) && !ret.Contains(linkBack))
                            {
                                ret.Add(linkBack);
                                //_log.Info(" ^--:" + linkBack.HRef);
                            }
                        }
                    }
                }

                return(ret);
            }
        }
        /// <summary>
        /// Reset the currently loaded project icons preparatory to loading a new set
        /// </summary>
        static public void ClassIconsClear()
        {
            mAssetTypeImages = new ImageList();
            mAssetTypes      = new TstDictionary();

            mStateTypeImages = new ImageList();
            mStateTypes      = new TstDictionary();
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        private static TstDictionary GetRelationList(string key, TstDictionaries fromRelations)
        {
            TstDictionary list = fromRelations[key];

            if (list == null)
            {
                list = new TstDictionary();
                fromRelations.Add(key, list);
            }
            return(list);
        }
Exemple #5
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 #6
0
        /// <summary>
        /// Return true, if the <c>relation</c> has any incoming or outgoing relations
        /// (registered/added to RelationCosmos).
        /// </summary>
        /// <param name="relation">Relation to check</param>
        /// <param name="excludeRelations">List of strings with relation.HRef's,
        /// that should be excluded in that check</param>
        /// <returns>
        /// True, if any relation was found, else false
        /// </returns>
        public bool HasIncomingOrOutgoing <T>(T relation, IList <T> excludeRelations)
            where T : RelationBase <T>
        {
            if (relation == null)
            {
                return(false);
            }
            IList <string> excludeUrls = GetRelationUrls(excludeRelations);

            lock (syncRoot) {
                // check for outgoing:
                foreach (string hrefOut in relation.outgoingRelationships)
                {
                    if (excludeUrls.Contains(hrefOut))
                    {
                        continue;
                    }

                    if (hrefOut != relation.HRef && registeredRelations.ContainsKey(hrefOut))
                    {
                        return(true);
                    }
                }

                // check for incoming:
                string hRef = relation.HRef;
                if (hRef != null && hRef.Length > 0)
                {
                    TstDictionary list = relationsLinkTo[hRef];
                    if (list != null)
                    {
                        foreach (T linkBack in list.Values)
                        {
                            if (hRef != linkBack.HRef && !excludeRelations.Contains(linkBack))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #7
0
 private static void RemoveFromRelationList <T>(string key, T relation, TstDictionaries fromRelations)
     where T : RelationBase <T>
 {
     if (key != null)
     {
         TstDictionary list = fromRelations[key];
         if (list != null)
         {
             string href = relation.HRef;
             if (href != null && !list.Contains(href))
             {
                 list.Remove(href);
             }
             if (list.Count == 0)
             {
                 fromRelations.Remove(key);
             }
         }
     }
 }
Exemple #8
0
    // Use this for initialization
    void Start()
    {
        words = new TstDictionary();
#if UNITY_STANDALONE_WIN
        string path = Application.dataPath + @"\SpellChecker\Resources\frequency_dictionary_en_82_765.txt";
#else
        string path = Application.dataPath + @"/SpellChecker/Resources/frequency_dictionary_en_82_765.txt";
#endif


        LoadDictionary(path);
        targetkeyboard = GetComponent <KeyboardLayout>();
        if (!targetkeyboard)
        {
            Debug.LogError("Target Keyboard Empty");
        }
        else
        {
            targetkeyboard.KeyboardLayout_OnKeyPressed += WordPrediction_KeyPressedHandler;
        }
    }
Exemple #9
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";
            }
        }
        /// <summary>
        /// Procesa un PDI.
        /// </summary>
        /// <param name="elPdi">El PDI.</param>
        /// <returns>El número de problemas detectados al procesar el elemento.</returns>
        protected override int ProcesaElemento(Pdi elPdi)
        {
            int númeroDeProblemasDetectados = 0;

            // Retorna si el PDI ya ha sido identificado como duplicado.
            if (misPdisDuplicados.Contains(elPdi))
            {
                return(númeroDeProblemasDetectados);
            }

            List <Pdi> duplicados = new List <Pdi>();

            // Busca en todos los PDIs desde la posición n + 1 que
            // no estén eliminados.
            for (int i = IndiceDeElementoProcesándose + 1; i < NúmeroDeElementos; ++i)
            {
                Pdi posiblePdiDuplicado = this[i];
                if (!posiblePdiDuplicado.FuéEliminado)
                {
                    // Si el PDI es idéntico entonces se puede borrar de una.
                    if (posiblePdiDuplicado.TieneLaMismaInformación(elPdi))
                    {
                        posiblePdiDuplicado.Elimina(string.Format(Properties.Recursos.M006, elPdi.Número));
                        misPdisDuplicados.Add(posiblePdiDuplicado);
                        ++miNúmeroDeElementosEliminados;
                    }
                    else
                    {
                        // Si el PDI no es idéntico entonces puede ser duplicado si:
                        //  - El tipo principal es el mismo, y
                        //  - La distancia es cercana, y
                        //      - El nombre es igual, o
                        //      - Uno es las siglas del otro, o
                        //      - El nombre es parecido.
                        if ((elPdi.Tipo != null) &&
                            (posiblePdiDuplicado.Tipo != null) &&
                            (((Tipo)elPdi.Tipo).TipoPrincipal == ((Tipo)posiblePdiDuplicado.Tipo).TipoPrincipal))
                        {
                            double distanciaEnMetros = Coordenadas.DistanciaEnMetros(elPdi.Coordenadas, posiblePdiDuplicado.Coordenadas);
                            if (distanciaEnMetros <= miDistanciaMáxima)
                            {
                                bool esDuplicado = false;

                                // Nombre es igual?
                                if (elPdi.Nombre == posiblePdiDuplicado.Nombre)
                                {
                                    esDuplicado = true;
                                }
                                // El PDI es las siglas del posible duplicado?
                                else if (PuedeSerSiglas(elPdi.Nombre))
                                {
                                    string siglasPosibleDuplicado = ObtieneSiglas(posiblePdiDuplicado.Nombre);

                                    if (elPdi.Nombre == siglasPosibleDuplicado)
                                    {
                                        esDuplicado = true;
                                    }
                                }
                                // El posible duplicado es las siglas del PDI?
                                else if (PuedeSerSiglas(posiblePdiDuplicado.Nombre))
                                {
                                    string siglasPdi = ObtieneSiglas(elPdi.Nombre);

                                    if (siglasPdi == posiblePdiDuplicado.Nombre)
                                    {
                                        esDuplicado = true;
                                    }
                                }
                                // El nombre es parecido?
                                else
                                {
                                    TstDictionary diccionario = new TstDictionary {
                                        { elPdi.Nombre, null }
                                    };
                                    ICollection resultados = diccionario.NearNeighbors(posiblePdiDuplicado.Nombre, miDistanciaHamming);

                                    // Como solo estamos comparando el nombre del PDI con el nombre del
                                    // posible duplicado, entonces al tener un solo resultado significa
                                    // que son parecidos.
                                    if (resultados.Count > 0)
                                    {
                                        esDuplicado = true;
                                    }
                                }

                                if (esDuplicado)
                                {
                                    duplicados.Add(posiblePdiDuplicado);
                                    misPdisDuplicados.Add(posiblePdiDuplicado);
                                }
                            }
                        }
                    }
                }
            }

            if (duplicados.Count > 0)
            {
                misGruposDeDuplicados.Add(elPdi, duplicados);
                ++númeroDeProblemasDetectados;
            }

            return(númeroDeProblemasDetectados);
        }