示例#1
0
        static void Main(string[] args)
        {
            string s = System.IO.File.ReadAllText(@"example.json");
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            for (int i = 0; i < 10000; i++)
                Fairytale.JsonDeserializer.Deserialize(s);
            
            sw.Stop();
            Console.WriteLine(sw.Elapsed);

            sw.Reset();

            sw.Start();

            for (int i = 0; i < 10000; i++)
                Newtonsoft.Json.JsonConvert.DeserializeObject(s);

            sw.Stop();
            Console.WriteLine(sw.Elapsed);

            sw.Reset();

            sw.Start();

            var parser = new System.Text.Json.JsonParser();
            for (int i = 0; i < 10000; i++)
                parser.Parse(s);

            sw.Stop();
            Console.WriteLine(sw.Elapsed);
            Console.ReadLine();
        }
示例#2
0
 public void TestSystemTextJson()
 {
     var parser = new System.Text.Json.JsonParser();
     var result = parser.Parse<Dictionary<string, object>>(testJson);
 }
示例#3
0
文件: Emotes.cs 项目: lyx0/chatterino
        public static void LoadGlobalEmotes()
        {
            // twitchemotes

            /*
             * Task.Run(() =>
             * {
             *  try
             *  {
             *      Directory.CreateDirectory("./Cache");
             *
             *      System.Text.Json.JsonParser parser = new System.Text.Json.JsonParser();
             *
             *      // twitchemotes api global emotes
             *      if (!File.Exists(twitchemotesGlobalCache) || DateTime.Now - new FileInfo(twitchemotesGlobalCache).LastWriteTime > TimeSpan.FromHours(24))
             *      {
             *          try
             *          {
             *              if (Util.IsLinux)
             *              {
             *                  Util.LinuxDownloadFile("https://twitchemotes.com/api_cache/v2/global.json", twitchemotesGlobalCache);
             *              }
             *              else
             *              {
             *                  using (var webClient = new WebClient())
             *                  using (var readStream = webClient.OpenRead("https://twitchemotes.com/api_cache/v2/global.json"))
             *                  using (var writeStream = File.OpenWrite(twitchemotesGlobalCache))
             *                  {
             *                      readStream.CopyTo(writeStream);
             *                  }
             *              }
             *          }
             *          catch (Exception e)
             *          {
             *              e.Message.Log("emotes");
             *          }
             *      }
             *
             *      using (var stream = File.OpenRead(twitchemotesGlobalCache))
             *      {
             *          dynamic json = parser.Parse(stream);
             *          dynamic templates = json["template"];
             *          string template112 = templates["large"];
             *
             *          foreach (KeyValuePair<string, object> e in json["emotes"])
             *          {
             *              string code = e.Key;
             *
             *              TwitchGlobalEmotes[code.ToUpper()] = code;
             *          }
             *      }
             *      EmotesLoaded?.Invoke(null, EventArgs.Empty);
             *  }
             *  catch { }
             * });
             */

            // bttv emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    // better twitch tv emotes
                    //if (!File.Exists(bttvEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.betterttv.net/2/emotes", bttvEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient())
                                    using (var readStream = webClient.OpenRead("https://api.betterttv.net/2/emotes"))
                                        using (var writeStream = File.OpenWrite(bttvEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(bttvEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);
                        var template = "https:" + json["urlTemplate"]; //{{id}} {{image}}

                        foreach (var e in json["emotes"])
                        {
                            string id        = e["id"];
                            string code      = e["code"];
                            string imageType = e["imageType"];
                            string url       = template.Replace("{{id}}", id);

                            double scale;
                            url = GetBttvEmoteLink(url, out scale);

                            BttvGlobalEmotes[code] = new LazyLoadedImage {
                                Name = code, Url = url, IsHat = IsBttvEmoteAHat(code), Scale = scale, Tooltip = code + "\nBetterTTV Global Emote", IsEmote = true
                            };
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    //if (!File.Exists(ffzEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.frankerfacez.com/v1/set/global", ffzEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient())
                                    using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/global"))
                                        using (var writeStream = File.OpenWrite(ffzEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(ffzEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);

                        foreach (var set in json["sets"])
                        {
                            var val = set.Value;

                            foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(val["emoticons"], true))
                            {
                                FfzGlobalEmotes[emote.Name] = emote;
                            }
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz event emotes
            Task.Run(() =>
            {
                try
                {
                    var set = 0;

                    var parser = new System.Text.Json.JsonParser();
                    using (var webClient = new WebClient())
                        using (var readStream = webClient.OpenRead("https://cdn.frankerfacez.com/script/event.json"))
                        {
                            dynamic json = parser.Parse(readStream);

                            string _set = json["set"];

                            int.TryParse(_set, out set);
                        }

                    if (set != 0)
                    {
                        using (var webClient = new WebClient())
                            using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/" + set))
                            {
                                dynamic json = parser.Parse(readStream);
                                dynamic _set = json["set"];

                                dynamic emoticons = _set["emoticons"];

                                foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(emoticons, true))
                                {
                                    FfzGlobalEmotes[emote.Name] = emote;
                                }
                            }
                    }
                }
                catch (Exception e)
                {
                    e.Message.Log("emotes");
                }
            });
        }
示例#4
0
 public void TestSystemTextJson()
 {
     var parser = new System.Text.Json.JsonParser();
     var result = parser.Parse <Dictionary <string, object> >(testJson);
 }
示例#5
0
        private static void ParsingAccess3MBBreakdown(string str, bool timeResults)
        {
            int strLength  = str.Length;
            int byteLength = strLength * 2;
            var buffer     = new byte[byteLength];

            for (var j = 0; j < strLength; j++)
            {
                buffer[j] = (byte)str[j];
            }

            int iter = 10;

            var json        = new JsonParser(buffer, strLength);
            var parseObject = json.Parse();

            var xElement = parseObject[1500];

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                xElement = parseObject[1500];
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var email = xElement["email"];

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                email = xElement["email"];
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var emailString = (Utf8String)email;

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                emailString = (Utf8String)email;
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var about = xElement["about"];

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                about = xElement["about"];
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var aboutString = (Utf8String)about;

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                aboutString = (Utf8String)about;
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var age = xElement["age"];

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                age = xElement["age"];
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var ageInt = (int)age;

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                ageInt = (int)age;
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var latitude = xElement["latitude"];

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                latitude = xElement["latitude"];
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var latitudeDouble = (double)latitude;

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                latitudeDouble = (double)latitude;
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var isActive = xElement["isActive"];

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                isActive = xElement["isActive"];
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
            if (timeResults)
            {
                Timer.Restart();
            }

            var isActiveBool = (bool)isActive;

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < iter; i++)
            {
                isActiveBool = (bool)isActive;
            }
            if (timeResults)
            {
                Console.WriteLine(Timer.ElapsedTicks);
            }
        }
示例#6
0
        private static void SystemTextParserHelper(byte[] buffer, int strLength, int numElements, bool timeResults)
        {
            if (timeResults)
            {
                Timer.Restart();
            }
            var json        = new JsonParser(buffer, strLength);
            var parseObject = json.Parse();

            if (timeResults)
            {
                Console.WriteLine("Parse: " + Timer.ElapsedTicks);
            }

            if (timeResults)
            {
                Timer.Restart();
            }
            for (int i = 0; i < numElements; i++)
            {
                var xElement      = parseObject[i];
                var id            = (Utf8String)xElement["_id"];
                var index         = (int)xElement["index"];
                var guid          = (Utf8String)xElement["guid"];
                var isActive      = (bool)xElement["isActive"];
                var balance       = (Utf8String)xElement["balance"];
                var picture       = (Utf8String)xElement["picture"];
                var age           = (int)xElement["age"];
                var eyeColor      = (Utf8String)xElement["eyeColor"];
                var name          = (Utf8String)xElement["name"];
                var gender        = (Utf8String)xElement["gender"];
                var company       = (Utf8String)xElement["company"];
                var email         = (Utf8String)xElement["email"];
                var phone         = (Utf8String)xElement["phone"];
                var address       = (Utf8String)xElement["address"];
                var about         = (Utf8String)xElement["about"];
                var registered    = (Utf8String)xElement["registered"];
                var latitude      = (double)xElement["latitude"];
                var longitude     = (double)xElement["longitude"];
                var tags          = xElement["tags"];
                var tags1         = (Utf8String)tags[0];
                var tags2         = (Utf8String)tags[1];
                var tags3         = (Utf8String)tags[2];
                var tags4         = (Utf8String)tags[3];
                var tags5         = (Utf8String)tags[4];
                var tags6         = (Utf8String)tags[5];
                var tags7         = (Utf8String)tags[6];
                var friends       = xElement["friends"];
                var friend1       = friends[0];
                var friend2       = friends[1];
                var friend3       = friends[2];
                var id1           = (int)friend1["id"];
                var friendName1   = (Utf8String)friend1["name"];
                var id2           = (int)friend2["id"];
                var friendName2   = (Utf8String)friend2["name"];
                var id3           = (int)friend3["id"];
                var friendName3   = (Utf8String)friend3["name"];
                var greeting      = (Utf8String)xElement["greeting"];
                var favoriteFruit = (Utf8String)xElement["favoriteFruit"];
            }
            if (timeResults)
            {
                Console.WriteLine("Access: " + Timer.ElapsedTicks);
            }
        }
示例#7
0
        private static void ParsingAccess3MBBreakdown(string str, bool timeResults)
        {
            int strLength = str.Length;
            int byteLength = strLength * 2;
            var buffer = new byte[byteLength];
            for (var j = 0; j < strLength; j++)
            {
                buffer[j] = (byte)str[j];
            }

            int iter = 10;

            var json = new JsonParser(buffer, strLength);
            var parseObject = json.Parse();

            var xElement = parseObject[1500];
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                xElement = parseObject[1500];
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var email = xElement["email"];
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                email = xElement["email"];
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var emailString = (Utf8String)email;
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                emailString = (Utf8String)email;
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var about = xElement["about"];
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                about = xElement["about"];
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var aboutString = (Utf8String)about;
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                aboutString = (Utf8String)about;
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var age = xElement["age"];
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                age = xElement["age"];
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var ageInt = (int)age;
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                ageInt = (int)age;
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var latitude = xElement["latitude"];
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                latitude = xElement["latitude"];
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var latitudeDouble = (double)latitude;
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                latitudeDouble = (double)latitude;
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var isActive = xElement["isActive"];
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                isActive = xElement["isActive"];
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
            if (timeResults) Timer.Restart();

            var isActiveBool = (bool)isActive;
            if (timeResults) Timer.Restart();
            for (int i = 0; i < iter; i++)
            {
                isActiveBool = (bool)isActive;
            }
            if (timeResults) Console.WriteLine(Timer.ElapsedTicks);
        }
示例#8
0
        private static void SystemTextParserHelper(byte[] buffer, int strLength, int numElements, bool timeResults)
        {
            if (timeResults) Timer.Restart();
            var json = new JsonParser(buffer, strLength);
            var parseObject = json.Parse();
            if (timeResults) Console.WriteLine("Parse: " + Timer.ElapsedTicks);

            if (timeResults) Timer.Restart();
            for (int i = 0; i < numElements; i++)
            {
                var xElement = parseObject[i];
                var id = (Utf8String)xElement["_id"];
                var index = (int)xElement["index"];
                var guid = (Utf8String)xElement["guid"];
                var isActive = (bool)xElement["isActive"];
                var balance = (Utf8String)xElement["balance"];
                var picture = (Utf8String)xElement["picture"];
                var age = (int)xElement["age"];
                var eyeColor = (Utf8String)xElement["eyeColor"];
                var name = (Utf8String)xElement["name"];
                var gender = (Utf8String)xElement["gender"];
                var company = (Utf8String)xElement["company"];
                var email = (Utf8String)xElement["email"];
                var phone = (Utf8String)xElement["phone"];
                var address = (Utf8String)xElement["address"];
                var about = (Utf8String)xElement["about"];
                var registered = (Utf8String)xElement["registered"];
                var latitude = (double)xElement["latitude"];
                var longitude = (double)xElement["longitude"];
                var tags = xElement["tags"];
                var tags1 = (Utf8String)tags[0];
                var tags2 = (Utf8String)tags[1];
                var tags3 = (Utf8String)tags[2];
                var tags4 = (Utf8String)tags[3];
                var tags5 = (Utf8String)tags[4];
                var tags6 = (Utf8String)tags[5];
                var tags7 = (Utf8String)tags[6];
                var friends = xElement["friends"];
                var friend1 = friends[0];
                var friend2 = friends[1];
                var friend3 = friends[2];
                var id1 = (int)friend1["id"];
                var friendName1 = (Utf8String)friend1["name"];
                var id2 = (int)friend2["id"];
                var friendName2 = (Utf8String)friend2["name"];
                var id3 = (int)friend3["id"];
                var friendName3 = (Utf8String)friend3["name"];
                var greeting = (Utf8String)xElement["greeting"];
                var favoriteFruit = (Utf8String)xElement["favoriteFruit"];
            }
            if (timeResults) Console.WriteLine("Access: " + Timer.ElapsedTicks);
        }
示例#9
0
        public static void LoadGlobalEmotes()
        {
            // bttv emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    // better twitch tv emotes
                    //if (!File.Exists(bttvEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.betterttv.net/3/cached/emotes/global", bttvEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient()) {
                                    using (var readStream = webClient.OpenRead("https://api.betterttv.net/3/cached/emotes/global")) {
                                        if (File.Exists(bttvEmotesGlobalCache))
                                        {
                                            File.Delete(bttvEmotesGlobalCache);
                                        }
                                        using (var writeStream = File.OpenWrite(bttvEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                                        readStream.Close();
                                    }
                                    webClient.Dispose();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(bttvEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);
                        //var template = "https:" + json["urlTemplate"]; // urlTemplate is outdated, came from bttv v2 api, returned: //cdn.betterttv.net/emote/{{id}}/{{image}}
                        var template = "https://cdn.betterttv.net/emote/{{id}}/{{image}}";

                        foreach (var e in json)
                        {
                            string id        = e["id"];
                            string code      = e["code"];
                            string imageType = e["imageType"];
                            string url       = template.Replace("{{id}}", id);
                            double fake;
                            string tooltipurl = GetBttvEmoteLink(url, true, out fake);

                            double scale;
                            url = GetBttvEmoteLink(url, false, out scale);

                            BttvGlobalEmotes[code] = new LazyLoadedImage {
                                Name = code, Url = url, TooltipImageUrl = tooltipurl, IsHat = IsBttvEmoteAHat(code), Scale = scale, Tooltip = code + "\nBetterTTV Global Emote", IsEmote = true
                            };
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    //if (!File.Exists(ffzEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.frankerfacez.com/v1/set/global", ffzEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient()) {
                                    using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/global")) {
                                        if (File.Exists(ffzEmotesGlobalCache))
                                        {
                                            File.Delete(ffzEmotesGlobalCache);
                                        }
                                        using (var writeStream = File.OpenWrite(ffzEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                                        readStream.Close();
                                    }
                                    webClient.Dispose();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(ffzEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);

                        foreach (var set in json["sets"])
                        {
                            var val = set.Value;

                            foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(val["emoticons"], true))
                            {
                                FfzGlobalEmotes[emote.Name] = emote;
                            }
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });

            // ffz event emotes
            Task.Run(() =>
            {
                try
                {
                    var set = 0;

                    var parser = new System.Text.Json.JsonParser();
                    using (var webClient = new WebClient()) {
                        using (var readStream = webClient.OpenRead("https://cdn.frankerfacez.com/script/event.json"))
                        {
                            dynamic json = parser.Parse(readStream);

                            string _set = json["set"];

                            int.TryParse(_set, out set);
                            readStream.Close();
                        }
                        webClient.Dispose();
                    }

                    if (set != 0)
                    {
                        using (var webClient = new WebClient()) {
                            using (var readStream = webClient.OpenRead("https://api.frankerfacez.com/v1/set/" + set))
                            {
                                dynamic json = parser.Parse(readStream);
                                dynamic _set = json["set"];

                                dynamic emoticons = _set["emoticons"];

                                foreach (LazyLoadedImage emote in GetFfzEmoteFromDynamic(emoticons, true))
                                {
                                    FfzGlobalEmotes[emote.Name] = emote;
                                }
                                readStream.Close();
                            }
                            webClient.Dispose();
                        }
                    }
                }
                catch (Exception e)
                {
                    e.Message.Log("emotes");
                }
            });

            //7tv global emotes
            Task.Run(() =>
            {
                try
                {
                    var parser = new System.Text.Json.JsonParser();

                    //if (!File.Exists(ffzEmotesGlobalCache))
                    {
                        try
                        {
                            if (Util.IsLinux)
                            {
                                Util.LinuxDownloadFile("https://api.7tv.app/v2/emotes/global", seventvEmotesGlobalCache);
                            }
                            else
                            {
                                using (var webClient = new WebClient()) {
                                    using (var readStream = webClient.OpenRead("https://api.7tv.app/v2/emotes/global")) {
                                        if (File.Exists(seventvEmotesGlobalCache))
                                        {
                                            File.Delete(seventvEmotesGlobalCache);
                                        }
                                        using (var writeStream = File.OpenWrite(seventvEmotesGlobalCache))
                                        {
                                            readStream.CopyTo(writeStream);
                                        }
                                        readStream.Close();
                                    }
                                    webClient.Dispose();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            e.Message.Log("emotes");
                        }
                    }

                    using (var stream = File.OpenRead(seventvEmotesGlobalCache))
                    {
                        dynamic json = parser.Parse(stream);
                        string emotename;
                        string emoteid;
                        dynamic owner;
                        string ownername;
                        string template = "https://cdn.7tv.app/emote/{{id}}/{{image}}";
                        bool getemote;
                        double fake;
                        double scale;
                        string tooltipurl;
                        string url;
                        int visibilityFlags;
                        string visibility;
                        const int zeroWidthFlag = 0x80;
                        bool zeroWidth          = false;

                        LazyLoadedImage emote;
                        foreach (var e in json)
                        {
                            emotename  = e["name"];
                            emoteid    = e["id"];
                            url        = template.Replace("{{id}}", emoteid);
                            tooltipurl = GetBttvEmoteLink(url, true, out fake);
                            url        = GetBttvEmoteLink(url, false, out scale);
                            owner      = e["owner"];
                            visibility = e["visibility"];
                            if (!string.IsNullOrEmpty(visibility) && int.TryParse(visibility, out visibilityFlags))
                            {
                                zeroWidth = (visibilityFlags & zeroWidthFlag) > 0;
                            }
                            ownername = "";
                            if (owner != null)
                            {
                                ownername = owner["display_name"];
                                if (!string.IsNullOrEmpty(ownername))
                                {
                                    ownername = owner["login"];
                                }
                                else if (string.Compare(ownername.ToUpper(), owner["login"].ToUpper()))
                                {
                                    ownername = ownername + "(" + owner["login"] + ")";
                                }
                            }
                            emote = new LazyLoadedImage
                            {
                                Name            = emotename,
                                Url             = url,
                                Tooltip         = emotename + "\n7TV Channel Emote\nChannel: " + ownername,
                                TooltipImageUrl = tooltipurl,
                                Scale           = scale,
                                IsHat           = zeroWidth,
                                IsEmote         = true
                            };
                            SeventvGlobalEmotes[emote.Name] = emote;
                        }
                    }
                    EmotesLoaded?.Invoke(null, EventArgs.Empty);
                }
                catch (Exception exc)
                {
                    Console.WriteLine("error loading emotes: " + exc.Message);
                }
            });
        }
示例#10
0
 public Spotify()
 {
     JParse     = new System.Text.Json.JsonParser();
     _TempTotal = new Dictionary <string, int>();
     _TempTag   = new Dictionary <String, List <ITag> >();
 }