public async Task <DownloadTask> GetLatestAICoreDownloadTask(DownloadSource source, string downloadTo) { string apiBase = string.Empty; switch (source) { case DownloadSource.Mojang: apiBase = "https://authlib-injector.yushi.moe/artifact/latest.json"; break; case DownloadSource.BMCLAPI: apiBase = "https://bmclapi2.bangbang93.com/mirrors/authlib-injector/artifact/latest.json"; break; default: apiBase = "https://authlib-injector.yushi.moe/artifact/latest.json"; break; } var jobj = JObject.Parse(await APIRequester.HttpGetStringAsync(apiBase)); string downloadURL = jobj.Value <string>("download_url"); string sha256 = jobj["checksums"].Value <string>("sha256"); return(new DownloadTask("AuthlibInjector核心", downloadURL, downloadTo) { Checker = new Util.Checker.SHA256Checker() { CheckSum = sha256, FilePath = downloadTo } }); }
public async Task <NsisoLauncherVersionResponse> GetLatestLauncherVersion() { try { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("app_key", App_key); //表模型 args.Add("model_name", "VersionList"); //order args.Add("order", "[\"id DESC\"]"); //查询规则(ID>0) args.Add("where", "[[\"id\", \">\", \"0\"]]"); //仅返回一条(即ID最高的最新版本) args.Add("perpage", "1"); string result = await APIRequester.HttpPostReadAsStringForString(APIUrl + "?s=App.Table.FreeQuery", args); PhalApiClientResponse desObj = JsonConvert.DeserializeObject <PhalApiClientResponse>(result); JObject listJobj = desObj.Data; NsisoLauncherVersionListResponse list = listJobj.ToObject <NsisoLauncherVersionListResponse>(); return(list.List.FirstOrDefault()); } catch { return(null); } }
public async Task <ImageSource> GetHeadSculSource(string uuid) { string arg = "?size=60"; if (overlay) { arg += "&overlay"; } string url = APIUrl + uuid + arg; var res = await APIRequester.HttpGetAsync(url); //var stream = await res.Content.ReadAsStreamAsync(); if (res.IsSuccessStatusCode) { using (Stream stream = await res.Content.ReadAsStreamAsync()) { var bImage = new BitmapImage(); bImage.BeginInit(); bImage.StreamSource = stream; bImage.EndInit(); return(bImage); } } else { return(new BitmapImage(new Uri("/MineRealmsLauncher;component/Resource/Steve.jpg"))); } }
public async Task ThrowIfConnectionParamEmpty(string connection) { var httpWrapper = new Mock <IHttpWrapper>(); var apiRequester = new APIRequester(httpWrapper.Object); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => apiRequester.Request(connection)); }
/// <summary> /// 联网获取指定版本所有的FORGE /// </summary> /// <param name="version">要搜索的版本</param> /// <returns>Forge列表</returns> public async Task <List <JWForge> > GetForgeList(Version version) { string json = await APIRequester.HttpGetStringAsync(string.Format("{0}/{1}", ForgeListURL, version.ID)); var e = JsonConvert.DeserializeObject <List <JWForge> >(json); return(e); }
/// <summary> /// 联网获取指定版本所有的Liteloader /// </summary> /// <param name="version">要搜索的版本</param> /// <returns>Liteloader列表</returns> public async Task <JWLiteloader> GetLiteloaderList(Version version) { string json = await APIRequester.HttpGetStringAsync(string.Format("{0}/?mcversion={1}", LiteloaderListURL, version.ID)); var e = JsonConvert.DeserializeObject <JWLiteloader>(json); return(e); }
/// <summary> /// 联网获取新闻列表 /// </summary> /// <returns>新闻列表</returns> public async Task <List <JWNews> > GetNewList() { string json = await APIRequester.HttpGetStringAsync(NewListURL); var e = JsonConvert.DeserializeObject <List <JWNews> >(json); return(e); }
/// <summary> /// 联网获取版本列表 /// </summary> /// <returns>版本列表</returns> public async Task <List <JWVersion> > GetVersionList() { string json = await APIRequester.HttpGetStringAsync(VersionListURL); var e = JsonConvert.DeserializeObject <JWVersions>(json); return(e.Versions); }
public async Task <APIModules> GetInfoAsync() { string json = await APIRequester.HttpGetStringAsync(string.Format("https://auth2.nide8.com:233/{0}", Nide8ID)); return(await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject <APIModules>(json); })); }
public async Task <APIModules> GetInfoAsync() { string json = await APIRequester.HttpGetStringAsync(BaseURL); return(await Task.Factory.StartNew(() => { return JsonConvert.DeserializeObject <APIModules>(json); })); }
public async Task ThrowIfReponseIsEmpty(string response) { var httpWrapper = new Mock <IHttpWrapper>(); httpWrapper.Setup(hw => hw.GetStringAsync("connection")) .ReturnsAsync(response); var apiRequester = new APIRequester(httpWrapper.Object); await Assert.ThrowsExceptionAsync <ArgumentNullException>(() => apiRequester.Request("connection")); }
public Task UpdateBaseURL() { return(Task.Factory.StartNew(async() => { APIModules module = JsonConvert.DeserializeObject <APIModules>(await APIRequester.HttpGetStringAsync(BaseURL)); if (!string.IsNullOrWhiteSpace(module.APIRoot)) { this.BaseURL = module.APIRoot; } })); }
/// <summary> /// 异步报告日志 /// </summary> /// <param name="level">日志等级</param> /// <param name="log">日志内容</param> /// <returns></returns> public async Task PostLogAsync(Modules.LogLevel level, string log) { var escapeLog = Uri.EscapeDataString(log); Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("app_key", App_key); args.Add("super_type", level.ToString()); args.Add("super_message", log); var result = await APIRequester.HttpPostReadAsStringForString(APIUrl + "?s=App.Market_SuperLogger.Record", args); Console.WriteLine(result); }
public void getCurrencyList() { APIRequester currencyListRequest = new APIRequester("https://free.currconv.com/api/v7/currencies?apiKey=8a6251713f19f409c37d"); CurrencyList currencyList = CurrencyList.Deserialize(currencyListRequest.SendAndGetResponse()); CurrencyData[] datas = currencyList.ToArray(); foreach (CurrencyData currency in datas) { comboBox1.Items.Add(currency.id); comboBox2.Items.Add(currency.id); } }
public async Task ReturnReponseIfEverythingIsValid() { var httpWrapper = new Mock <IHttpWrapper>(); httpWrapper.Setup(hw => hw.GetStringAsync("connection")) .ReturnsAsync("response"); var apiRequester = new APIRequester(httpWrapper.Object); var result = await apiRequester.Request("connection"); Assert.AreEqual("response", result); }
//作者觉得使用这个方法判断是否丢失文件不如直接根据GetLostDependDownloadTask方法返回的列表的Count数来判断 //毕竟这种方法大部分用在启动前判断是否丢失文件,但是如果丢失还是要获取一次列表,效率并没怎样优化 //public static bool IsLostAnyDependent(LaunchHandler core, Version version) //{ // return IsLostJarCore(core, version) || IsLostAnyLibs(core, version) || IsLostAnyNatives(core, version); //} /// <summary> /// 获取全部丢失的文件下载任务 /// </summary> /// <param name="source">下载源</param> /// <param name="core">使用的核心</param> /// <param name="version">检查的版本</param> /// <returns></returns> public async static Task <List <DownloadTask> > GetLostDependDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version version) { var lostLibs = GetLostLibs(core, version); var lostNatives = GetLostNatives(core, version); List <DownloadTask> tasks = new List <DownloadTask>(); if (IsLostJarCore(core, version)) { if (version.Jar == null) { tasks.Add(GetDownloadUrl.GetCoreJarDownloadTask(source, version, core)); } } if (version.InheritsVersion != null) { string innerJsonPath = core.GetJsonPath(version.InheritsVersion); string innerJsonStr; if (!File.Exists(innerJsonPath)) { innerJsonStr = await APIRequester.HttpGetStringAsync(GetDownloadUrl.GetCoreJsonDownloadURL(source, version.InheritsVersion)); string jsonFolder = Path.GetDirectoryName(innerJsonPath); if (!Directory.Exists(jsonFolder)) { Directory.CreateDirectory(jsonFolder); } File.WriteAllText(innerJsonPath, innerJsonStr); } else { innerJsonStr = File.ReadAllText(innerJsonPath); } Version innerVer = core.JsonToVersion(innerJsonStr); if (innerVer != null) { tasks.AddRange(await GetLostDependDownloadTaskAsync(source, core, innerVer)); } } foreach (var item in lostLibs) { tasks.Add(GetDownloadUrl.GetLibDownloadTask(source, item)); } foreach (var item in lostNatives) { tasks.Add(GetDownloadUrl.GetNativeDownloadTask(source, item)); } return(tasks); }
/// <summary> /// 刷新使用次数计数器(统计) /// </summary> /// <returns></returns> public async Task RefreshUsingTimesCounter() { if (!NoTracking) { try { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("app_key", App_key); args.Add("type", "forever"); args.Add("name", "NsisoLauncherUsingTimes"); args.Add("value", "1"); await APIRequester.HttpPostAsync(APIUrl + "?s=App.Main_Counter.SmartRefresh", args); } catch { } } }
private async Task AppendVersionsDownloadTask(IList list) { try { foreach (JWVersion item in list) { string json = await APIRequester.HttpGetStringAsync(apiHandler.DoURLReplace(item.Url)); NsisoLauncherCore.Modules.Version ver = App.handler.JsonToVersion(json); string jsonPath = App.handler.GetJsonPath(ver.ID); string dir = Path.GetDirectoryName(jsonPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } File.WriteAllText(jsonPath, json); List <DownloadTask> tasks = new List <DownloadTask>(); tasks.Add(new DownloadTask("资源引导", apiHandler.DoURLReplace(ver.AssetIndex.URL), App.handler.GetAssetsIndexPath(ver.Assets))); tasks.AddRange(await NsisoLauncherCore.Util.FileHelper.GetLostDependDownloadTaskAsync(App.config.MainConfig.Download.DownloadSource, App.handler, ver)); App.downloader.SetDownloadTasks(tasks); App.downloader.StartDownload(); } } catch (WebException ex) { this.Dispatcher.Invoke(new Action(() => { this.ShowMessageAsync("获取版本信息失败", "请检查您的网络是否正常或更改下载源/n原因:" + ex.Message); })); } catch (Exception ex) { AggregateExceptionArgs args = new AggregateExceptionArgs() { AggregateException = new AggregateException(ex) }; App.CatchAggregateException(this, args); } }
static void Main(string[] args) { APIRequester _apirequester = new APIRequester(); string userName, password, token = ""; while (string.IsNullOrEmpty(token)) { Console.WriteLine("User name:"); userName = Console.ReadLine(); Console.WriteLine("Password:"******"http://dataapi.bazhuayu.com/token")); Console.WriteLine("Getting Token:"); token = _apirequester.user.GetToken(); if (string.IsNullOrEmpty(token)) { Console.WriteLine("Wrong user name or password!"); } else { Console.WriteLine(token); } } Console.WriteLine("{0}", token); Console.WriteLine("Getting task group(s)"); _apirequester.GetTaskGroups(token, _apirequester.taskGroupUrl); foreach (TaskGroup tg in _apirequester.user.taskGroups) { Console.WriteLine("->Task group: {0}[{1}]", tg.taskGroupName, tg.taskGroupID); Console.WriteLine("->Requiring task(s)"); List <Task> tasks = _apirequester.GetTasks(token, tg.taskGroupID, _apirequester.taskUrl); if (null != tasks) { foreach (var item in tasks) { Console.WriteLine("-->Requiring data: {0}[{1}]", item.taskName, item.taskID); Console.WriteLine("--->Required data: {0}", _apirequester.GetDataByTask(token, 0, item.taskID, 1, 10)); System.Threading.Thread.Sleep(1000); } } } Console.ReadKey(); }
public async void TestCanRequestObjectDetectionAndReceiveResultsInCallback() { var responseReceived = new AutoResetEvent(false); var mockResponseListener = new Mock <IResponseListener <ImageObjects> >(); mockResponseListener.Setup( m => m.ResponseReceived( It.IsNotNull <string>(), It.IsNotNull <ImageObjects>())). Callback <string, ImageObjects>((id, objects) => { //Signaling that the result was called back responseReceived.Set(); //Check if all attributes are not empty and not null Assert.InRange(objects.Objects.Count, 1, 101); foreach (var obj in objects.Objects) { Assert.False(string.IsNullOrEmpty(obj.Name)); Assert.InRange(obj.Score, 0.00001, 1); } }).Verifiable(); //Wait 60 times 1 seconds each var apiRequester = new APIRequester(new AuthorizedHttpRequester(TestResources.bBridgeAPIBaseURI, userPasswordAuthorizer)) { ResponseWaitNumAttempts = 60, ResponseWaitTime = TimeSpan.FromSeconds(1) }; apiRequester.ReceiveResponseAsync((await apiRequester.RequestAsync( new ObjectDetectionData("https://pbs.twimg.com/media/C6ij4CLUwAAxu9r.jpg", 0.5), bBridgeAPIURLSuffixes.ObjectDetectionSuffix)).Id, mockResponseListener.Object); //Waiting for response for 1 minute Assert.True(responseReceived.WaitOne(TimeSpan.FromMinutes(1))); }
/// <summary> /// 获取丢失的资源文件下载任务 /// </summary> /// <param name="source"></param> /// <param name="core"></param> /// <param name="version"></param> /// <returns></returns> public async static Task <List <DownloadTask> > GetLostAssetsDownloadTaskAsync(DownloadSource source, LaunchHandler core, Version ver) { List <DownloadTask> tasks = new List <DownloadTask>(); JAssets assets = null; string assetsPath = core.GetAssetsIndexPath(ver.Assets); if (!File.Exists(assetsPath)) { if (ver.AssetIndex != null) { string jsonUrl = GetDownloadUrl.DoURLReplace(source, ver.AssetIndex.URL); string assetsJson = await APIRequester.HttpGetStringAsync(jsonUrl); assets = core.GetAssetsByJson(assetsJson); tasks.Add(new DownloadTask("资源文件引导", jsonUrl, assetsPath)); } else { return(tasks); } } else { assets = core.GetAssets(ver); } var lostAssets = GetLostAssets(core, assets); foreach (var item in lostAssets) { DownloadTask task = GetDownloadUrl.GetAssetsDownloadTask(source, item.Value, core); if (!tasks.Contains(task)) { tasks.Add(task); } } return(tasks); }
public Response Query() { String url = String.Format("http://api.zeit.de/client?api_key={0}", this.API.APIKey); return(APIRequester.Request <Response>(url, this.API)); }