Esempio n. 1
0
        private static InfoPacket getInfoPacket(string Artist, string Album)
        {
            InfoPacket ip = null;

            if (albumInfo.ContainsKey(Artist + Album))
            {
                ip = albumInfo[Artist + Album];

                while (ip.IsLoading)
                {
                    System.Threading.Thread.Sleep(100);
                }

                if (ip.Info == Net.FAILED_TOKEN && StringUtil.HasParentheticalChars(Album))
                {
                    return(getInfoPacket(Artist, StringUtil.RemoveParentheticalChars(Album)));
                }
                else
                {
                    return(ip);
                }
            }

            ip           = new InfoPacket();
            ip.IsLoading = true;
            albumInfo.Add(Artist + Album, ip);
            ip.Info = Net.FAILED_TOKEN;

            string date = String.Empty;

            if (Artist.Length > 0 && Album.Length > 0)
            {
                string url = String.Format("http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key={0}&artist={1}&album={2}",
                                           API_KEY,
                                           HttpUtility.UrlEncode(Artist),
                                           HttpUtility.UrlEncode(Album));

                string ret = Net.Get(url);

                if (ret.Length > 0)
                {
                    populateInfoPacket(ip, ret);

                    if (ip.Info == Net.FAILED_TOKEN &&
                        StringUtil.HasParentheticalChars(Album))
                    {
                        ip.IsLoading = false;
                        return(getInfoPacket(Artist, StringUtil.RemoveParentheticalChars(Album)));
                    }
                }
            }
            if (ip.Info != Net.FAILED_TOKEN)
            {
                ip.Info += Environment.NewLine +
                           Environment.NewLine +
                           "Information provided courtesy of last.fm";
            }
            ip.IsLoading = false;
            return(ip);
        }
        public void GetBytesTest()
        {
            byte[]     expected = DataGenerator.GetInfoPackets()[0];
            InfoPacket packet   = new InfoPacket(expected);

            CollectionAssert.AreEqual(expected, packet.GetBytes());
        }
Esempio n. 3
0
 STANPacket DecodeInfoPacket(IByteBuffer buffer, IChannelHandlerContext context)
 {
     if (TryGetStringFromNewlineDelimiter(buffer, STANSignatures.INFO, out var infoJson))
     {
         return(InfoPacket.CreateFromJson(infoJson));
     }
     return(null);
 }
        public void GetDataTest()
        {
            byte[] expected = DataGenerator.ExtractDataBytes(
                DataGenerator.GetInfoPackets()[0], DataStartPosition);
            InfoPacket packet = new InfoPacket(DataGenerator.GetInfoPackets()[0]);

            CollectionAssert.AreEqual(expected, packet.GetData());
        }
Esempio n. 5
0
        private static void populateInfoPacket(InfoPacket IP, string Input)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(Input);

            // Images

            XmlNodeList images = xmlDoc.GetElementsByTagName("image");

            foreach (XmlNode xn in images)
            {
                if (xn.Attributes["size"].Value == "extralarge")
                {
                    IP.ImageURL = xn.InnerText;
                    break;
                }
            }

            // Content

            XmlNodeList content = xmlDoc.GetElementsByTagName("content");

            if (content.Count > 0)
            {
                IP.Info = Net.ScrubHTMLNew(content[0].InnerXml);
            }
            else
            {
                content = xmlDoc.GetElementsByTagName("summary");
                if (content.Count > 0)
                {
                    IP.Info = Net.ScrubHTMLNew(content[0].InnerText);
                }
            }

            // URL

            XmlNodeList url = xmlDoc.GetElementsByTagName("url");

            if (url.Count > 0)
            {
                IP.URL = url[0].InnerText;
            }

            // Date

            DateTime    d    = DateTime.MinValue;
            XmlNodeList date = xmlDoc.GetElementsByTagName("releasedate");

            if (date.Count > 0)
            {
                string dateString = date[0].InnerText;
                DateTime.TryParse(dateString, out d);
            }
            IP.Date = d;
        }
        public void GetDataStringTest()
        {
            string expected = Encoding.ASCII.GetString(
                DataGenerator.ExtractDataBytes(
                    DataGenerator.GetInfoPackets()[0], DataStartPosition));

            InfoPacket packet = new InfoPacket(DataGenerator.GetInfoPackets()[0]);

            Assert.AreEqual <string>(expected, packet.GetDataString());
        }
        public void GetDataTest()
        {
            List <byte[]>    rawPackets = DataGenerator.GetInfoPackets();
            InfoPacket       packet1    = new InfoPacket(rawPackets[0]);
            InfoPacket       packet2    = new InfoPacket(rawPackets[1]);
            PacketCollection packets    = new PacketCollection();

            packets.Add(packet1);
            packets.Add(packet2);


            byte[] result = packets.GetData();
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Length > 0);
            Assert.IsTrue(result.Length == packet1.GetData().Length + packet2.GetData().Length);
        }
        public void GetDataStringTest()
        {
            List <byte[]>    rawPackets = DataGenerator.GetInfoPackets();
            InfoPacket       packet1    = new InfoPacket(rawPackets[0]);
            InfoPacket       packet2    = new InfoPacket(rawPackets[1]);
            PacketCollection packets    = new PacketCollection();

            packets.Add(packet1);
            packets.Add(packet2);

            string dataString1 = packet1.GetDataString();
            string dataString2 = packet2.GetDataString();
            string result      = packets.GetDataString();

            Assert.IsTrue(!String.IsNullOrWhiteSpace(result));
            Assert.AreEqual <string>(packet1.GetDataString() + packet2.GetDataString(), result);
        }
Esempio n. 9
0
        public string OnPostUploadAsync([FromForm] InfoPacket packet)
        {
            try
            {
                if (packet.files != null)
                {
                    if (packet.files.Length > 0)
                    {
                        //Getting FileName
                        var fileName = Path.GetFileName(packet.files.FileName);
                        var Id       = Guid.NewGuid();

                        var doc = new Document()
                        {
                            Id          = Id,
                            Title       = fileName,
                            Description = packet.description,
                            TrainingId  = packet.trainingId,
                            Date        = DateTime.Now,
                            Path        = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Documents\", String.Concat(Id, Path.GetExtension(fileName)))
                        };


                        Console.WriteLine(doc.Path);

                        using (var stream = System.IO.File.Create(doc.Path))
                        {
                            packet.files.CopyToAsync(stream);
                            stream.Flush();
                        }

                        _context.Documents.Add(doc);
                        _context.SaveChanges();
                    }
                }
                return("yes");
            }
            catch (Exception ex)
            {
                return(ex.Message.ToString());
            }
        }
Esempio n. 10
0
        public static void UpdateArtistInfo(Track Track, ArtistCallback Callback)
        {
            InfoPacket ip;

            if (artistInfo.ContainsKey(Track.Artist))
            {
                ip = artistInfo[Track.Artist];
                Callback(ip.Info, ip.URL);
                return;
            }

            ip = new InfoPacket();
            artistInfo.Add(Track.Artist, ip);
            ip.Info = Net.FAILED_TOKEN;

            if (Track.Artist.Length > 0)
            {
                string url = String.Format("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key={0}&artist={1}",
                                           API_KEY,
                                           HttpUtility.UrlEncode(Track.Artist));

                string ret = Net.Get(url);

                if (ret.Length > 0)
                {
                    populateInfoPacket(ip, ret);

                    if (ip.Info != Net.FAILED_TOKEN)
                    {
                        ip.Info += Environment.NewLine + Environment.NewLine + "Information provided courtesy of last.fm";
                    }
                }
            }

            Callback(ip.Info, ip.URL);

            return;
        }
Esempio n. 11
0
 protected void InfoAsync(InfoPacket info)
 {
     _infoTaskCompletionSource.TrySetResult(info);
 }
Esempio n. 12
0
        private static void updateAlbumInfo(string Artist, string Album, AlbumCallback Callback)
        {
            InfoPacket ip = getInfoPacket(Artist, Album);

            Callback(ip.Info, ip.Date, ip.URL);
        }
Esempio n. 13
0
        public static string GetAlbumImageURL(string Artist, string Album)
        {
            InfoPacket ip = getInfoPacket(Artist, Album);

            return(ip.ImageURL);
        }
Esempio n. 14
0
 public InfoEventArgs(PacketHeader header, InfoPacket body)
     : base(header)
 {
     Info = body.Info;
     OnlineUsers = body.OnlineUsers;
 }
Esempio n. 15
0
 private void ReceiveMessage(InfoPacket packet)
 {
     Lyrics = packet.Lyrics;
     Title  = packet.Title;
 }