Beispiel #1
0
        public void UriEncode()
        {
            Assert.AreEqual("hello", TagBase.UriEncode("hello"));

            Assert.AreEqual("hell%C3%B6", TagBase.UriEncode("hellö"),
                            "check umlauts");

            Assert.AreEqual("hello/there.aspx", TagBase.UriEncode("hello/there.aspx"),
                            "check path parts");

            Assert.AreEqual("hello?parameter=7", TagBase.UriEncode("hello?parameter=7"),
                            "check params");

            Assert.AreEqual("http://azing.org", TagBase.UriEncode("http://azing.org"),
                            "check domains");

            Assert.AreEqual("http://azing.org/homepage?name=m", "http://azing.org/homepage?name=m",
                            "check full url");

            Assert.AreEqual("http://azing.org/home%20page?name=m", TagBase.UriEncode("http://azing.org/home page?name=m"),
                            "check spaces");

            Assert.AreEqual("something#hashed", TagBase.UriEncode("something#hashed"),
                            "check hash");

            Assert.AreEqual("url+plus", TagBase.UriEncode("url+plus"),
                            "check plus in url = it's a space, and shouldn't be re-encode");
        }
Beispiel #2
0
        public void DontDoubleEncode()
        {
            Assert.AreEqual("%20", TagBase.UriEncode("%20"),
                            "check don't re-encode");

            Assert.AreEqual("hello%20there", TagBase.UriEncode(TagBase.UriEncode("hello there")));
        }
        private void TagContainer_TagClick(TagBase arg1, RoutedEventArgs arg2)
        {
            RealtimePlayWindow realPlayWindow = new RealtimePlayWindow(400, 300);

            realPlayWindow.Loaded += (s, e) =>
            {
                VideoPlayModel playModel = new VideoPlayModel
                {
                    Ip         = "192.168.28.136",
                    Port       = 8000,
                    Channel    = 1,
                    UserName   = "******",
                    Password   = "******",
                    StreamType = 0
                };

                realPlayWindow.RealPlayer.PlayHelper = new VideoPlayHelper();
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(1000);
                    Dispatcher.Invoke(() =>
                    {
                        realPlayWindow.RealPlayer.StartPlay(playModel);
                    });
                });
            };

            realPlayWindow.Show();
        }
        /// <summary>
        /// Reads an NBT tag of a given tag type.
        /// </summary>
        public TagBase ReadTag(TagType type)
        {
            var tag = TagBase.CreateTagFromType(type);

            tag.ReadPayload(this);
            return(tag);
        }
Beispiel #5
0
        public TagBase Create(ITagModel tagModel)
        {
            TagBase tag = null;

            switch (tagModel.Type)
            {
            case TagType.Text:
                tag = CreateTextTag(tagModel);
                break;

            case TagType.Icon:
                tag = CreateIconTag(tagModel);
                break;

            case TagType.Area:
                tag = CreateAreaTag(tagModel);
                break;

            case TagType.Vector:
                tag = CreateVectorTag(tagModel);
                break;
            }

            if (tag != null)
            {
                tag.Id          = tagModel.Id;
                tag.DataContext = tagModel;
            }

            return(tag);
        }
Beispiel #6
0
        /// <summary>
        /// タグを再帰的に読み込んでTreeViewへ追加する
        /// </summary>
        /// <param name="tag">TagCompound</param>
        /// <param name="node">TreeNode</param>
        /// <returns></returns>
        public static TreeNode AddTag(TagBase tag, TreeNode node)
        {
            var addnode = new TreeNode()
            {
                Tag = tag
            };

            switch (tag.TagType)
            {
            case TagType.Compound:
                var compund = (TagCompound)tag;
                foreach (var child in compund)
                {
                    addnode = AddTag(child, addnode);
                }
                break;

            case TagType.List:
                var list = (TagList)tag;
                foreach (TagBase child in list)
                {
                    addnode = AddTag(child, addnode);
                }
                break;
            }

            var getnode = GetNBTNode(tag);

            addnode.Text              += getnode.Text;
            addnode.ImageIndex         = getnode.ImageIndex;
            addnode.SelectedImageIndex = getnode.ImageIndex;

            node.Nodes.Add(addnode);
            return(node);
        }
Beispiel #7
0
        /// <summary>
        /// NBTを再帰的に読み込み、ツリーを生成
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public static TreeNode AddTag(TagBase tag, TreeNode node = null)
        {
            var addnode = new TreeNode();

            addnode.NBT.Value = tag;

            switch (tag.TagType)
            {
            case TagType.Compound:
                var compound = (TagCompound)tag;
                foreach (var child in compound)
                {
                    addnode = AddTag(child, addnode);
                }
                break;

            case TagType.List:
                var list = (TagList)tag;
                foreach (TagBase child in list)
                {
                    addnode = AddTag(child, addnode);
                }
                break;
            }

            if (node == null)
            {
                return(addnode);
            }

            node.Add(addnode);
            return(node);
        }
Beispiel #8
0
        private T[] CatchArrayItems <T>(TagType arrayedTagType, TagType targetTagType, Func <TagBase, T> func) where T : IConvertible
        {
            List <T> list = new List <T>();

            while (true)
            {
                if (JsonAt() != ']')
                {
                    TagBase TagBase    = ExtractValue();
                    TagType targetType = TagBase.TagType;

                    if (targetType != targetTagType)
                    {
                        throw GenerateException("Unable to insert " + targetType.ToString() + " into " + arrayedTagType.ToString());
                    }

                    list.Add(func(TagBase));
                    if (HasArrayNext())
                    {
                        if (!InTextLength())
                        {
                            throw GenerateException("Expected value");
                        }

                        continue;
                    }
                }

                CheckCharacter(']');
                return(list.ToArray());
            }
        }
Beispiel #9
0
        /// <summary>
        /// NBTタグから値を文字列で取得します
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public static string GetValue(TagBase tag)
        {
            var value = "";

            switch (tag.TagType)
            {
            case TagType.Compound:
                var compund = (TagCompound)tag;
                value = compund.Count + " entries";
                break;

            case TagType.List:
                var list = (TagList)tag;
                value = list.Count + " entries";
                break;

            case TagType.Byte:
                value = ((TagByte)tag).Value.ToString();
                break;

            case TagType.ByteArray:
                value = ((TagByteArray)tag).Value.Length + "bytes";
                break;

            case TagType.Double:
                value = ((TagDouble)tag).Value.ToString();
                break;

            case TagType.Float:
                value = ((TagFloat)tag).Value.ToString();
                break;

            case TagType.Int:
                value = ((TagInt)tag).Value.ToString();
                break;

            case TagType.IntArray:
                value = ((TagIntArray)tag).Value.Length + "integers";
                break;

            case TagType.Long:
                value = ((TagLong)tag).Value.ToString();
                break;

            case TagType.LongArray:
                value = ((TagLongArray)tag).Value.Length + "longs";
                break;

            case TagType.Short:
                value = ((TagShort)tag).Value.ToString();
                break;

            case TagType.String:
                value = ((TagString)tag).Value.ToString();
                break;
            }

            return(value);
        }
Beispiel #10
0
 public static void ToStream(Stream stream, TagCompound tag, bool compressing)
 {
     using (NBTBinaryWriter bw = new NBTBinaryWriter(compressing ? new GZipStream(stream, CompressionMode.Compress) : stream))
     {
         TagBase.WriteNamedTag(tag, bw);
         bw.Dispose();
     }
 }
Beispiel #11
0
        /// <summary>
        /// タグ追加のFormを呼び出し、追加します
        /// </summary>
        /// <param name="selectedNodeType">TagBase</param>
        /// <returns></returns>
        public void AddTag(TagBase selectedNodeType)
        {
            var CreateTag = new OrangeNBTEditor.Forms.AddTagByte();

            CreateTag.NodeName = selectedNodeType;
            if (CreateTag.ShowDialog() == DialogResult.OK)
            {
                if (selectedNodeType.TagType == TagType.Compound)
                {
                    var tag = (TagCompound)treeView1.SelectedNode.Tag;
                    tag.Add(new TagCompound(CreateTag.AddName));

                    return;
                }
            }

            if (CreateTag.ShowDialog() == DialogResult.OK)
            {
                switch (CreateTag.NodeName.TagType)
                {
                case TagType.ByteArray:
                    break;

                case TagType.IntArray:
                    break;

                case TagType.LongArray:
                    break;

                case TagType.Byte:
                    break;

                case TagType.Short:
                    break;

                case TagType.Int:
                    break;

                case TagType.Long:
                    break;

                case TagType.Float:
                    break;

                case TagType.Double:
                    break;

                case TagType.String:
                    break;

                case TagType.List:
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #12
0
        private new static TagViewModelBase CreateFromData(TagBase tag)
        {
            if (!(tag is IntValueTag intValueTag))
            {
                return(null);
            }

            return(new IntValueTagViewModel(intValueTag.Value, intValueTag.Key, intValueTag.Duration));
        }
Beispiel #13
0
        /// <summary>
        /// NBTTagからImageListのIndexを取得する
        /// </summary>
        /// <param name="tag">NBT</param>
        /// <returns></returns>
        private static int GetImageIndex(TagBase tag)
        {
            var index = 0;

            switch (tag.TagType)
            {
            case TagType.Compound:
                index = 11;
                break;

            case TagType.List:
                index = 10;
                break;

            case TagType.Byte:
                index = 0;
                break;

            case TagType.ByteArray:
                index = 6;
                break;

            case TagType.Double:
                index = 5;
                break;

            case TagType.Float:
                index = 4;
                break;

            case TagType.Int:
                index = 2;
                break;

            case TagType.IntArray:
                index = 7;
                break;

            case TagType.Long:
                index = 3;
                break;

            case TagType.LongArray:
                index = 8;
                break;

            case TagType.Short:
                index = 1;
                break;

            case TagType.String:
                index = 9;
                break;
            }

            return(index);
        }
Beispiel #14
0
        private new static TagViewModelBase CreateFromData(TagBase tag)
        {
            if (!(tag is StringValueTag stringValueTag))
            {
                return(null);
            }

            return(new StringValueTagViewModel(stringValueTag.Value, stringValueTag.Key, stringValueTag.Duration));
        }
        private static TagBase ValueExtract(string sentence, bool isArray)
        {
            string  _key  = DivideKey(sentence, isArray);
            string  _json = DevideValues(sentence, isArray);
            TagBase _tag  = ValueExtract(_key, _json);

            _tag._name = _key;
            return(_tag);
        }
Beispiel #16
0
        private new static TagViewModelBase CreateFromData(TagBase tag)
        {
            if (!(tag is SimpleTag simpleTag))
            {
                return(null);
            }

            return(new SimpleTagViewModel(simpleTag.Key, simpleTag.Duration));
        }
Beispiel #17
0
        private void SetAreaTagPropertyBindings(TagBase tag)
        {
            Binding bindAreaPoints = new Binding("ExtraData.AreaPoints");

            tag.SetBinding(AreaTag.AreaPointsProperty, bindAreaPoints);

            Binding bindAreaColor = new Binding("ExtraData.AreaColor");

            tag.SetBinding(AreaTag.AreaColorProperty, bindAreaColor);
        }
Beispiel #18
0
        private void SetVectorTagPropertyBindings(TagBase tag)
        {
            Binding bindAreaPoints = new Binding("ExtraData.AreaPoints");

            tag.SetBinding(VectorTag.AreaPointsProperty, bindAreaPoints);

            Binding bindArrowBrush = new Binding("ExtraData.ArrowBrush");

            tag.SetBinding(VectorTag.ArrowBrushProperty, bindArrowBrush);
        }
 public void DeleteTag(TagBase tag)
 {
     Requires.NotNull(tag);
     Requires.PropertyNotNegative(tag, "TagId");
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <TagBase>();
         rep.Delete(tag);
     }
 }
        void WriteValueArray <T>(TextWriter writer, TagBase tag, string curIndent)
        {
            var array = (T[])tag.Value;
            // (Only Pretty + Multiline:)
            // If array has enough elements, put them in multiple lines.
            // Otherwise just put them all on the same line.
            var elementsPerLine = ((array.Length >= MultilineArrayMinElements)
                                ? MultilineArrayElementsPerLine : -1);

            WriteArray(writer, array, elementsPerLine, curIndent, val => writer.Write(val));
        }
Beispiel #21
0
        private new static TagViewModelBase CreateFromData(TagBase tag)
        {
            if (!(tag is ConditionTag conditionTag))
            {
                return(null);
            }

            var condition = ConditionViewModelBase.CreateFromData(conditionTag.Condition);

            return(new ConditionTagViewModel(condition, conditionTag.Key, conditionTag.Duration));
        }
 public static TagViewModelBase CreateFromData(TagBase tag)
 {
     foreach (var factory in s_factories)
     {
         var viewModel = factory(tag);
         if (viewModel != null)
         {
             return(viewModel);
         }
     }
     throw new NotImplementedException($"No Tag view model has been registered for '{tag.GetType().Name}'.");
 }
Beispiel #23
0
        private new static TagViewModelBase CreateFromData(TagBase tag)
        {
            if (!(tag is ConditionalTagsTag conditionalTagsTag))
            {
                return(null);
            }

            var tags      = conditionalTagsTag.Tags.Select(TagViewModelBase.CreateFromData);
            var condition = ConditionViewModelBase.CreateFromData(conditionalTagsTag.Condition);

            return(new ConditionalTagsTagViewModel(tags, condition, conditionalTagsTag.Key, conditionalTagsTag.Duration));
        }
 internal static string ToJson(TagBase tag, JsonOptions ops)
 {
     if (tag.TagType == TagType.Compound)
     {
         return(GetFromCompound((TagCompound)tag, ops));
     }
     else if (tag.TagType == TagType.List)
     {
         return(GetFromList((TagList)tag, ops));
     }
     return(string.Empty);
 }
Beispiel #25
0
        public static ID3v1Tag FromV2Tag(TagBase tag, IGenreManager genreManager)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag", "Argument 'tag' can not be null.");
            }

            ID3v1Tag information = new ID3v1Tag();

            Frames.AlbumTextFrame           album       = tag.SearchForFrame(typeof(Frames.AlbumTextFrame)) as Frames.AlbumTextFrame;
            Frames.ArtistTextFrame          artist      = tag.SearchForFrame(typeof(Frames.ArtistTextFrame)) as Frames.ArtistTextFrame;
            Frames.CommentExtendedTextFrame comment     = tag.SearchForFrame(typeof(Frames.CommentExtendedTextFrame)) as Frames.CommentExtendedTextFrame;
            Frames.GenreTextFrame           genre       = tag.SearchForFrame(typeof(Frames.GenreTextFrame)) as Frames.GenreTextFrame;
            Frames.ReleaseTimeTextFrame     releaseTime = tag.SearchForFrame(typeof(Frames.ReleaseTimeTextFrame)) as Frames.ReleaseTimeTextFrame;
            Frames.TitleTextFrame           title       = tag.SearchForFrame(typeof(Frames.TitleTextFrame)) as Frames.TitleTextFrame;
            Frames.TrackTextFrame           track       = tag.SearchForFrame(typeof(Frames.TrackTextFrame)) as Frames.TrackTextFrame;
            Frames.YearTextFrame            year        = tag.SearchForFrame(typeof(Frames.YearTextFrame)) as Frames.YearTextFrame;

            if (album != null)
            {
                information.Album = album.Text;
            }
            if (artist != null)
            {
                information.Artist = album.Text;
            }
            if (comment != null)
            {
                information.Comment = album.Text;
            }
            if (genre != null)
            {
                information.GenreCode = genreManager.GetGenreCode(genre.Text);
            }
            if (releaseTime != null)
            {
                information.Year = releaseTime.Text.Substring(0, 4);
            }
            else if (year != null)
            {
                information.Year = year.Text;
            }
            if (track != null)
            {
                information.TrackNumber = (byte)track.TrackNumber;
            }
            if (title != null)
            {
                information.Title = title.Text;
            }

            return(information);
        }
 public void UpdateTag(TagBase tag, int userId)
 {
     Requires.NotNull(tag);
     Requires.PropertyNotNegative(tag, "TagId");
     tag.LastModifiedByUserID = userId;
     tag.LastModifiedOnDate   = DateTime.Now;
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <TagBase>();
         rep.Update(tag);
     }
 }
Beispiel #27
0
        public TagBase ToTagBase()
        {
            var tag = new TagBase
            {
                Name = Name
            };

            if (_id != Guid.Empty)
            {
                tag.TagBaseId = _id;
            }
            return(tag);
        }
Beispiel #28
0
        public static void Main(string[] args)
        {
            TagBase tag = new TagBase();

            tag.Frames.Add(new LastPlayedOnFrame(DateTime.Now, 1, "Test!"));
            tag.WriteToFile("C:/Test.mp3", ID3v2MajorVersion.Version3, EncodingScheme.UnicodeWithBOM);

            TagBase tag2 = new TagBase();

            tag2.ReadFromFile("C:/Test.mp3", new MyFrameParserFactory());
            System.Diagnostics.Debug.Assert(tag2.Frames.Count == 1);
            System.Diagnostics.Debug.Assert(tag2.Frames[0] is LastPlayedOnFrame);
        }
        void WriteTagInternal(TextWriter writer, TagBase tag, string name, int depth, string curIndent)
        {
            writer.Write(curIndent);

            writer.Write(TypeToString(tag.Type));
            if (name != null)
            {
                writer.Write("(\"");
                writer.Write(name);
                writer.Write("\")");
            }
            writer.Write(": ");
            WriteTagLookup(writer, tag);

            if (!(tag is TagList) && !(tag is TagCompound) || (tag.Count <= 0))
            {
                return;
            }

            if (depth > 0)
            {
                writer.WriteLine();
                writer.Write(curIndent);
                writer.WriteLine("{");

                var newIndent = curIndent + Indent;
                if (tag is TagList)
                {
                    foreach (var childTag in (TagList)tag)
                    {
                        WriteTagInternal(writer, childTag, null, depth - 1, newIndent);
                        writer.WriteLine();
                    }
                }
                else
                {
                    foreach (var nameTagPair in (TagCompound)tag)
                    {
                        WriteTagInternal(writer, nameTagPair.Value, nameTagPair.Key, depth - 1, newIndent);
                        writer.WriteLine();
                    }
                }

                writer.Write(curIndent);
                writer.Write("}");
            }
            else
            {
                writer.Write(" { ... }");
            }
        }
 public int AddTag(ref TagBase tag, int userId)
 {
     Requires.NotNull(tag);
     tag.CreatedByUserID      = userId;
     tag.CreatedOnDate        = DateTime.Now;
     tag.LastModifiedByUserID = userId;
     tag.LastModifiedOnDate   = DateTime.Now;
     using (var context = DataContext.Instance())
     {
         var rep = context.GetRepository <TagBase>();
         rep.Insert(tag);
     }
     return(tag.TagId);
 }
Beispiel #31
0
        public static ID3v1Tag FromV2Tag(TagBase tag, IGenreManager genreManager)
        {
            if(tag==null)
            {
                throw new ArgumentNullException("tag", "Argument 'tag' can not be null.");
            }

            ID3v1Tag information=new ID3v1Tag();
            Frames.AlbumTextFrame album=tag.SearchForFrame(typeof(Frames.AlbumTextFrame)) as Frames.AlbumTextFrame;
            Frames.ArtistTextFrame artist=tag.SearchForFrame(typeof(Frames.ArtistTextFrame)) as Frames.ArtistTextFrame;
            Frames.CommentExtendedTextFrame comment=tag.SearchForFrame(typeof(Frames.CommentExtendedTextFrame)) as Frames.CommentExtendedTextFrame;
            Frames.GenreTextFrame genre=tag.SearchForFrame(typeof(Frames.GenreTextFrame)) as Frames.GenreTextFrame;
            Frames.ReleaseTimeTextFrame releaseTime=tag.SearchForFrame(typeof(Frames.ReleaseTimeTextFrame)) as Frames.ReleaseTimeTextFrame;
            Frames.TitleTextFrame title=tag.SearchForFrame(typeof(Frames.TitleTextFrame)) as Frames.TitleTextFrame;
            Frames.TrackTextFrame track=tag.SearchForFrame(typeof(Frames.TrackTextFrame)) as Frames.TrackTextFrame;
            Frames.YearTextFrame year=tag.SearchForFrame(typeof(Frames.YearTextFrame)) as Frames.YearTextFrame;

            if(album!=null)
                information.Album=album.Text;
            if(artist!=null)
                information.Artist=album.Text;
            if(comment!=null)
                information.Comment=album.Text;
            if(genre!=null)
                information.GenreCode=genreManager.GetGenreCode(genre.Text);
            if(releaseTime!=null)
                information.Year=releaseTime.Text.Substring(0, 4);
            else if(year!=null)
                information.Year=year.Text;
            if(track!=null)
                information.TrackNumber=(byte)track.TrackNumber;
            if (title != null)
                information.Title=title.Text;

            return information;
        }