Ejemplo n.º 1
0
        private static async Task <WFApi> GetTranslateApi()
        {
            var api = new WFApi();
            // var source = "https://raw.githubusercontent.com/Richasy/WFA_Lexicon/WFA5/";
            var source = "https://cdn.jsdelivr.net/gh/Richasy/WFA_Lexicon@WFA5/";
            var tasks  = new List <Task>();

            AddTask(ref api.RDict, "WF_Dict.json");
            AddTask(ref api.RInvasion, "WF_Invasion.json");
            AddTask(ref api.RSale, "WF_Sale.json");
            AddTask(ref api.RRiven, "WF_Riven.json");
            AddTask(ref api.RAllriven, "WF_AllRiven.json");
            AddTask(ref api.RLib, "WF_Lib.json");
            AddTask(ref api.RNightWave, "WF_NightWave.json");

            await Task.WhenAll(tasks.ToArray());

            void AddTask <T>(ref WFResource <T> obj, string name) where T : class
            {
                var path     = $"{source}{name}";
                var resource = WFResource <T> .Create(path, category : nameof(WFTranslator));

                obj = resource;
                tasks.Add(resource.WaitForInited());
            }

            //Messenger.SendDebugInfo($"翻译 API 加载完成. 用时 {sw.Elapsed.TotalSeconds:N1}s.");
            // 嘿,如果你在看这个方法怎么用,让2019年3月14日23:59:23的trks来告诉你吧,这个api是本地缓存的api(在本地有的情况下),但是不久后将会被第三方线程操成最新的,我在这里浪费了好久,希望你不会.
            // 呃, 还好我当时写了这局注释 不然我可能之后会拉不出屎憋死 来自2020年2月20日15:34:49的trks
            // 天哪. 这api真是野蛮不堪 我当时为什么要这么写
            // 我的上帝, 我居然需要再次修改这个野蛮的api 简直不敢相信
            // 已经不会这么干了
            return(api);
        }
Ejemplo n.º 2
0
        private static async Task SetWFContentApi()
        {
            var          result = new WFContentApi();
            const string source = "http://content.warframe.com/PublicExport/Manifest/";

            var resource = WFResource <ExportRelicArcane[]> .Create(
                resourceLoader : async s =>
            {
                var r = await ResourceLoaders <ExportRelicArcaneZh> .JsonDotNetLoader(s);
                return(r.ExportRelicArcane);
            },
                fileName : "ExportRelicArcane_zh.json",
                requester : async _ =>
            {
                List <string> urls;
                try
                {
                    urls = await GetWFOriginUrls();
                }
                catch (Exception e)
                {
                    Trace.WriteLine("WFOriginUrls 获取失败, 下面是异常:");
                    Trace.WriteLine(e);
                    throw;
                }
                var link = source + urls.First(u => u.Contains("ExportRelicArcane_zh.json"));
                return(await new HttpClient(new RetryHandler(new HttpClientHandler())).GetStreamAsync(link));
            });

            result.RExportRelicArcanes = resource;

            WFContent = result;
            await resource.WaitForInited();
        }
Ejemplo n.º 3
0
        public static async Task UpdateOnline()
        {
            if (SlangResource == null)
            {
                SlangResource = WFResource <List <SlangItem> > .Create(
                    "http://github.cdn.therealkamisama.top/https://github.com/TRKS-Team/WFBotSlang/blob/main/slang.json",
                    category : nameof(WFTranslator),
                    resourceLoader : s =>
                {
                    try
                    {
                        using var sr = new StreamReader(s);
                        var str      = sr.ReadToEnd();
                        return(Task.FromResult(JsonConvert.DeserializeObject <List <SlangItem> >(str)));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("黑话辞典加载出错.");
                        Console.WriteLine(e);
                        return(Task.FromResult(new List <SlangItem>()));
                    }
                });

                await SlangResource.WaitForInited();

                return;
            }

            await SlangResource.Reload();
        }
Ejemplo n.º 4
0
        public static WFResource <T> Create(string url = null, string category = null, string fileName = null, WebHeaderCollection header = null, WFResourceLoader <T> resourceLoader = null, WFResourceRequester requester = null)
        {
            var result = new WFResource <T>(url, category, fileName, header, resourceLoader, requester);

            result.initTask = result.Reload(true);
            return(result);
        }
Ejemplo n.º 5
0
        private static Task SetWFCDResources()
        {
            var header = new WebHeaderCollection
            {
                { "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0" }
            };

            var resource = WFResource <WFCD_All[]> .Create("https://api.warframestat.us/items",
                                                           header : header,
                                                           resourceLoader : ResourceLoaders <WFCD_All[]> .SystemTextJsonLoader);

            RWFCDAll = resource;
            return(resource.WaitForInited());
        }
Ejemplo n.º 6
0
        private static Task SetWFCDResources()
        {
            var header = new WebHeaderCollection
            {
                //{"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"},
                { "Accept-Encoding", "br" }
            };

            var resource = WFResource <WFCD_All[]> .Create(url : "https://wfcd-all.therealkamisama.top/",
                                                           header : header,
                                                           resourceLoader : ResourceLoaders <WFCD_All[]> .JsonDotNetLoader, // todo .NET 5 再换
                                                           fileName : "All.json");

            RWFCDAll = resource;
            return(resource.WaitForInited());
        }