public void IsSelfClosing_ShouldBeFalse_ByDefault()
        {
            IHtmlString tagHtml1 = SimpleTag.Tag("div");
            IHtmlString tagHtml2 = SimpleTag.Tag("div", new {});

            Assert.True(tagHtml1.ToString().Contains("</div>"));
            Assert.True(tagHtml2.ToString().Contains("</div>"));
        }
        public void ShouldBeAbleToSet_IsSelfClosing()
        {
            IHtmlString tagHtml1 = SimpleTag.Tag("input", true);
            IHtmlString tagHtml2 = SimpleTag.Tag("input", new { type = "text" }, true);

            Assert.True(tagHtml1.ToString().Contains(" />"));
            Assert.True(tagHtml2.ToString().Contains(" />"));
        }
Esempio n. 3
0
 public SimpleTag(string html_tag, string attributes, SimpleTag nested_tag)
 {
     this.HtmlTag = html_tag;
     this.attributes = attributes ?? "";
     if ((nested_tag != null) && (nested_tag.HtmlTag != null) && (nested_tag.HtmlTag.Length > 0)) {
         this.nested_tag = nested_tag;
     }
 }
        public void ShouldBeAbleToDefine_CusomHtmlAttributes()
        {
            IHtmlString tagHtml1 = SimpleTag.Tag("input", new { type = "submit", value = "GO!" }, true);
            IHtmlString tagHtml2 = SimpleTag.Tag("input", new { type = "text", disabled = "disabled" }, true);

            string expected1 = "<input type=\"submit\" value=\"GO!\" />";
            string expected2 = "<input type=\"text\" disabled=\"disabled\" />";

            Assert.Equal(expected1, tagHtml1.ToString());
            Assert.Equal(expected2, tagHtml2.ToString());
        }
Esempio n. 5
0
        private static bool TryGet(Tags tags, string key, out string value)
        {
            value = null;
            SimpleTag tag = tags.Tag.Find(t => t.Name == key);

            if (tag == null || tag.Value == null)
            {
                return(false);
            }

            value = tag.Value.Trim();
            return(!string.IsNullOrEmpty(value));
        }
Esempio n. 6
0
        private List <Mp3Info> GetFileList(string folder)
        {
            List <Mp3Info> list = new List <Mp3Info>();

            try
            {
                foreach (string filename in Directory.EnumerateFiles(folder, "*.mp3"))
                {
                    try
                    {
                        Log($"Found: {filename}", false);

                        var mp3Info = new Mp3Info
                        {
                            Filename    = Path.GetFileName(filename),
                            NewFilename = NormalizeFilename(filename),
                            SongName    = Path.GetFileNameWithoutExtension(filename).Replace('_', ' '),
                            TrackNumber = 0,
                            Duration    = 0
                        };
                        try
                        {
                            SimpleTag simpleTag = SimpleTag.FromFile(filename);
                            if (simpleTag != null)
                            {
                                if (!string.IsNullOrWhiteSpace(simpleTag.Artist) && !string.IsNullOrWhiteSpace(simpleTag.Title))
                                {
                                    mp3Info.SongName = $"{simpleTag.Artist} - {simpleTag.Title}";
                                }
                                mp3Info.TrackNumber = simpleTag.TrackNumber;
                                mp3Info.Duration    = simpleTag.Length / 1000;
                            }
                        }
                        catch (Exception e)
                        {
                            Log("Error: " + e);
                        }
                        list.Add(mp3Info);
                    }
                    catch (Exception e)
                    {
                        Log("Error: " + e);
                    }
                }
            }
            catch (Exception e)
            {
                Log("Error: " + e);
            }
            return(list.OrderBy(f => f.TrackNumber).ThenBy(f => f.SongName).ToList());
        }
        public void ShouldReturnType_AddinableFrom_IHtmlString()
        {
            IHtmlString tagHtml = SimpleTag.Tag("a");

            Assert.IsAssignableFrom <IHtmlString>(tagHtml);
        }
        public void ShouldBeAbleTo_CreateTagWithJust_TagNameArgument()
        {
            IHtmlString tagHtml = SimpleTag.Tag("a");

            Assert.Equal("<a></a>", tagHtml.ToString());
        }
Esempio n. 9
0
 public SimpleTag(string html_tag, SimpleTag nested_tag)
     : this(html_tag, "", nested_tag)
 {
 }
Esempio n. 10
0
        public static SimpleTag FromFile(string fileName)
        {
            SimpleTag result = new SimpleTag();
            TagBase   tag    = new TagBase();

            tag.ReadFromFile(fileName, new ID3Utils.Frames.Parsers.FrameParserFactory());
            foreach (Frames.Frame frame in tag.Frames)
            {
                if (frame is Frames.ArtistTextFrame)
                {
                    result.Artist = ((Frames.ArtistTextFrame)frame).Text;
                }
                else if (frame is Frames.AlbumTextFrame)
                {
                    result.Album = ((Frames.AlbumTextFrame)frame).Text;
                }
                else if (frame is Frames.CommentExtendedTextFrame)
                {
                    result.Comment = ((Frames.CommentExtendedTextFrame)frame).Text;
                }
                else if (frame is Frames.ComposerTextFrame)
                {
                    result.Composer = ((Frames.ComposerTextFrame)frame).Text;
                }
                else if (frame is Frames.CopyrightTextFrame)
                {
                    result.Copyright = ((Frames.CopyrightTextFrame)frame).Text;
                }
                else if (frame is Frames.EncodedByTextFrame)
                {
                    result.EncodedBy = ((Frames.EncodedByTextFrame)frame).Text;
                }
                else if (frame is Frames.GenreTextFrame)
                {
                    StandardGenreManager manager = new StandardGenreManager();
                    result.Genre = manager.TranslateToUserFriendly(((Frames.GenreTextFrame)frame).Text);
                }
                else if (frame is Frames.GroupingTextFrame)
                {
                    result.Grouping = ((Frames.GroupingTextFrame)frame).Text;
                }
                else if (frame is Frames.LyricsExtendedTextFrame)
                {
                    result.Lyrics = ((Frames.LyricsExtendedTextFrame)frame).Text;
                }
                else if (frame is Frames.OriginalArtistTextFrame)
                {
                    result.OriginalArtist = ((Frames.OriginalArtistTextFrame)frame).Text;
                }
                else if (frame is Frames.TitleTextFrame)
                {
                    result.Title = ((Frames.TitleTextFrame)frame).Text;
                }
                else if (frame is Frames.CustomUserUrlFrame)
                {
                    result.UserUrl = ((Frames.CustomUserUrlFrame)frame).Url;
                }
                else if (frame is Frames.OfficialArtistUrlFrame)
                {
                    result.ArtistUrl = ((Frames.OfficialArtistUrlFrame)frame).Url;
                }
                else if (frame is Frames.TrackTextFrame)
                {
                    result.TrackNumber = ((Frames.TrackTextFrame)frame).TrackNumber;
                    result.TotalTracks = ((Frames.TrackTextFrame)frame).TotalTracks;
                }
                else if (frame is Frames.PartOfSetTextFrame)
                {
                    result.PartNumber = ((Frames.PartOfSetTextFrame)frame).PartNumber;
                    result.TotalParts = ((Frames.PartOfSetTextFrame)frame).TotalParts;
                }
                else if (frame is Frames.YearTextFrame)
                {
                    string year = ((Frames.YearTextFrame)frame).Text;
                    if (year != "")
                    {
                        result.Year = year.Substring(0, 4);
                    }
                }
                else if (frame is Frames.ReleaseTimeTextFrame)
                {
                    string year = ((Frames.ReleaseTimeTextFrame)frame).Text;
                    if (year != "")
                    {
                        result.Year = year.Substring(0, 4);
                    }
                }
                else if (frame is Frames.BeatsPerMinuteTextFrame)
                {
                    result.BPM = int.Parse((((Frames.BeatsPerMinuteTextFrame)frame).Text));
                }
                else if (frame is Frames.LengthTextFrame)
                {
                    result.Length = int.Parse((((Frames.LengthTextFrame)frame).Text));
                }
            }

            return(result);
        }