public override void Lock()
 {
     if (m_IsReady)
     {
         m_Parent.Lock();
     }
     base.Lock();
 }
Ejemplo n.º 2
0
            public void AddSource(byte[] id, string fileName, RIndexedHashtable <string, string> metaData, string comment, byte rating)
            {
                if (id == null)
                {
                    throw new ArgumentNullException("id");
                }
                if (id.Length != 48)
                {
                    throw new ArgumentException();
                }
                if (fileName == null)
                {
                    throw new ArgumentNullException("fileName");
                }
                if (metaData == null)
                {
                    throw new ArgumentNullException("metaData");
                }
                if (comment == null)
                {
                    throw new ArgumentNullException("comment");
                }
                if (rating > 3)
                {
                    throw new ArgumentOutOfRangeException("rating");
                }

                try
                {
                    m_Sources.Lock();
                    string idString = Core.ByteArrayToString(id);
                    if (!m_Sources.ContainsKey(idString))
                    {
                        m_Sources.Add(idString, new Source(m_Sources, id, fileName, metaData, comment, rating));
                    }
                    else
                    {
                        m_Sources[idString].ReportReceived(fileName, comment, rating);
                    }
                    RIndexedHashtable <string, int> fileNames1 = new RIndexedHashtable <string, int>();
                    RIndexedHashtable <byte, int>   ratings1   = new RIndexedHashtable <byte, int>();
                    foreach (Source source in m_Sources.Values)
                    {
                        if (!fileNames1.ContainsKey(source.FileName))
                        {
                            fileNames1.Add(source.FileName, 1);
                        }
                        else
                        {
                            fileNames1[source.FileName]++;
                        }
                        if (!ratings1.ContainsKey(source.Rating))
                        {
                            ratings1.Add(source.Rating, 1);
                        }
                        else
                        {
                            ratings1[source.Rating]++;
                        }
                    }
                    RList <string> fileNames2 = new RList <string>(fileNames1.Keys);
                    for (int n = 1; n <= fileNames2.Count - 1; n++)
                    {
                        for (int m = 0; m < fileNames2.Count - n; m++)
                        {
                            if (fileNames1[fileNames2[m]] < fileNames1[fileNames2[m + 1]])
                            {
                                string temp;
                                temp              = fileNames2[m];
                                fileNames2[m]     = fileNames2[m + 1];
                                fileNames2[m + 1] = temp;
                            }
                        }
                    }
                    m_FileName = fileNames2[0];
                    RList <byte> ratings2 = new RList <byte>(ratings1.Keys);
                    for (int n = 1; n <= ratings2.Count - 1; n++)
                    {
                        for (int m = 0; m < ratings2.Count - n; m++)
                        {
                            if (ratings1[ratings2[m]] < ratings1[ratings2[m + 1]])
                            {
                                byte temp;
                                temp            = ratings2[m];
                                ratings2[m]     = ratings2[m + 1];
                                ratings2[m + 1] = temp;
                            }
                        }
                    }
                    ratings2.Remove(0);
                    if (!ratings2.IsEmpty)
                    {
                        m_Rating = ratings2[0];
                    }
                    else
                    {
                        m_Rating = 0;
                    }
                    foreach (KeyValuePair <string, string> metaDataItem in metaData)
                    {
                        if (!m_MetaData.ContainsKey(metaDataItem.Key))
                        {
                            m_MetaData.Add(metaDataItem.Key, metaDataItem.Value);
                        }
                    }
                    Core.ParseMetaData(m_MetaData, out m_Album, out m_Artist, out m_Title);
                }
                finally
                {
                    m_Sources.Unlock();
                }
            }