Ejemplo n.º 1
0
        /// <summary>
        /// Given a string dictionary, parse the .config file for entries matching a prefix and midfix (located after the prefix), and add to the dictionary
        /// </summary>
        /// <param name="Coll">Your dictionary</param>
        /// <param name="Prefix">Your prefix</param>
        /// <param name="Midfix">Your "midfix"</param>
        public static void BuildCollectionFromConfig(StringDictionary Coll, string Prefix, string Midfix)
        {
            if (Coll == null)
            {
                Coll = new StringDictionary();
            }

            if (Midfix == null)
            {
                Midfix = string.Empty;
            }

            if (string.IsNullOrEmpty(Prefix))
            {
                throw new ApplicationException("SetupCollectionFromConfig requires a prefix and optional midfix to lookup values.");
            }

            string[] Keys = ServerDependentSection.AllKeys;
            foreach (string Key in Keys)
            {
                if (Key.StartsWith(Prefix + Midfix) && !Coll.ContainsKey(Key))
                {
                    Coll.Add(Key.Remove(0, Prefix.Length), ServerDependentSection[Key]);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add Frame information to where it must store
        /// </summary>
        /// <param name="Data">FileStream contain Frame</param>
        /// <param name="FrameID">FrameID of frame</param>
        /// <param name="Length">Maximum available length to read</param>
        /// <param name="Flags">Flags of frame</param>
        private bool AddFrame(string FrameID, int Length, FrameFlags Flags, Stream FS)
        {
            // NOTE: All FrameIDs must be capital letters
            if (!FramesInfo.IsValidFrameID(FrameID))
            {
                AddError(new ID3Exception("nonValid Frame found and dropped", FrameID, ExceptionLevels.Repaired));
                return(false);
            }

            int IsText = FramesInfo.IsTextFrame(FrameID, _Version.Minor);

            if (IsText == 1)
            {
                TextFrame TempTextFrame = new TextFrame(FrameID, Flags, Length, FS);
                if (TempTextFrame.IsValid && !TextFrames.ContainsKey(FrameID))
                {
                    TextFrames.Add(FrameID, TempTextFrame);
                    return(true);
                }
                return(false);
            }
            else if (IsText == 2)
            {
                UserTextFrame TempUserTextFrame = new UserTextFrame(FrameID, Flags, Length, FS);
                if (TempUserTextFrame.IsValid && FrameID != "TXXX" && !UserTextFrames.ContainsKey(FrameID))
                {
                    UserTextFrames.Add(FrameID, TempUserTextFrame);
                    return(true);
                }
                return(false);
            }
            else if (FrameID == "LINK")
            {
                LinkFrame LF = new LinkFrame(FrameID, Flags, Length, FS);
                if (LF.IsValid && !LinkFrames.ContainsKey(FrameID))
                {
                    LinkFrames.Add(FrameID, LF);
                    if (_LoadLinkedFrames)
                    {
                        LoadFrameFromFile(LF.FrameIdentifier, LF.URL); return(true);
                    }
                }
                else
                {
                    AddError(LF.Exception);
                }
            }

            Frame F = null;

            if (!FramesInfo.ExcludedList.Any(t => t == FrameID))
            {
                FrameInfo Info = FramesInfo.GetFrame(FrameID);

                if (Info == null || Info.ClassType == null)
                {
                    AddError(new ID3Exception("Unknown Frame found and dropped according to setting", FrameID, ExceptionLevels.Warning));
                    return(true);
                }

                try
                {
                    F = Info.Constuctor(FrameID, Flags, Length, TStream.FS);
                }
                catch { }
                try
                {
                    if (Info.IsSingle)
                    {
                        if (_SingleFrames.Contains(FrameID))
                        {
                            _SingleFrames.Remove(FrameID);
                        }

                        _SingleFrames.Add(FrameID, F);
                        return(true);
                    }
                    else
                    {
                        foreach (FrameCollectionBase Coll in _CollectionFrames.Values)
                        {
                            if (Coll.CollectionType == Info.ClassType)
                            {
                                Coll.Remove(F.FrameID);
                                Coll.Add(F.FrameID, F);
                                return(true);
                            }
                        }
                    }
                    AddError(new ID3Exception("ClassType not found in Collection list", FrameID, ExceptionLevels.Error));
                }
                catch {}
            }

            return(false);
        }