Пример #1
0
        public static void StartService()
        {
            Task.Run(() =>
            {
                StickerLoader loader = new StickerLoader();

                List <StickerCategory> raw = loader.LoadCategory();
                foreach (StickerCategory cate in raw)
                {
                    LoadedCategories.TryAdd(cate.ID, cate);

                    //Directory.CreateDirectory("Stickers/" + cate.ID + "/Icons");
                    //Directory.CreateDirectory("Stickers/" + cate.ID + "/Sprites");
                    //try
                    //{

                    //    WebClient webClient = new WebClient();
                    //    webClient.DownloadFile(cate.ThumbImg, String.Format("Stickers/{0}/ThumbImg.png", cate.ID));
                    //    webClient.DownloadFile(cate.IconURL, String.Format("Stickers/{0}/Icon.png", cate.ID));
                    //    webClient.DownloadFile(cate.IconPreview, String.Format("Stickers/{0}/IconPreview.png", cate.ID));
                    //    webClient.Dispose();
                    //}
                    //catch
                    //{
                    //    Console.WriteLine("Category error: {0}",cate.ID);
                    //}
                }

                List <List <Sticker> > stickers = loader.LoadSticker();
                int total = 0;
                foreach (List <Sticker> cate in stickers)
                {
                    foreach (Sticker sticker in cate)
                    {
                        LoadedStickers.TryAdd(sticker.ID, sticker);

                        if (LoadedCategories.ContainsKey(sticker.CategoryID))
                        {
                            LoadedCategories[sticker.CategoryID].Stickers.Add(sticker);
                        }

                        //try
                        //{
                        //    WebClient webClient = new WebClient();
                        //    webClient.DownloadFile(sticker.StickerURL, String.Format("Stickers/{0}/Icons/{1}.png", sticker.CategoryID, sticker.ID));
                        //    webClient.DownloadFile(sticker.SpriteURL, String.Format("Stickers/{0}/Sprites/{1}.png", sticker.CategoryID, sticker.ID));
                        //    webClient.Dispose();
                        //} catch
                        //{
                        //    Console.WriteLine("Sticker error: {0}", sticker.ID);
                        //}

                        total++;
                    }
                }

                PacChatServer.GetServer().Logger.Info(String.Format("Loaded {0} categories, {1} stickers", LoadedCategories.Count, total));
            });
        }
Пример #2
0
 public static void Load(LoadedHandler loadedHandler)
 {
     new Task(() =>
     {
         List <StickerCategory> categories = StickerAPI.GetCategories();
         foreach (StickerCategory cate in categories)
         {
             LoadedCategories.TryAdd(cate.ID, cate);
             List <Sticker> stickers = StickerAPI.GetStickerCategory(cate.ID);
             foreach (Sticker sticker in stickers)
             {
                 LoadedStickers.TryAdd(sticker.ID, sticker);
                 cate.Stickers.Add(sticker);
             }
         }
         if (loadedHandler != null)
         {
             Application.Current.Dispatcher.Invoke(() => loadedHandler());
         }
     }).Start();
 }