/// <summary> /// Populate the location node /// </summary> public void PopulateLocationNode(TreeNode parent) { RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); var parentId = 0; if (parent != null) { parentId = (int)parent.Tag; } else { if (String.IsNullOrEmpty(restUtil.GetCurrentUserName)) // Login { try { restUtil.Get <User>("UserManagement.svc/GetUser", new KeyValuePair <string, object>("username", ""), new KeyValuePair <String, Object>("password", "")); } catch { } } var userInfo = restUtil.Get <User>("UserManagement.svc/GetUserInfo", new KeyValuePair <string, object>("username", restUtil.GetCurrentUserName)); parentId = userInfo.HealthFacilityId; } var facilities = restUtil.Get <HealthFacility[]>("HealthFacilityManagement.svc/GetHealthFacilityByParentId", new KeyValuePair <string, object>("parentId", parentId)); if (parent == null) { foreach (var hf in facilities) { var tn = new TreeNode() { Tag = hf.Id, Text = hf.Name }; if (!hf.Leaf) { tn.Nodes.Add(String.Empty); } trvLocation.Nodes.Add(tn); } } else { parent.Nodes.Clear(); foreach (var hf in facilities) { var tn = new TreeNode() { Tag = hf.Id, Text = hf.Name }; if (!hf.Leaf) { tn.Nodes.Add(String.Empty); } parent.Nodes.Add(tn); } } }
private SendReply Send(SendOrderParam param) { var path = "/api/order?"; int tradetype = param.side == "buy" ? 1 : 0; string body = "accesskey=" + _config.Key + $"&amount={param.quantity}¤cy={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&method=order&price={param.price}&tradeType={tradetype}"; path += body; var req = BuildRequest(path, "GET", body); RestUtil.LogRestRequest(req); SetBaseUrl("trade"); var response = _restClient.Execute(req); if (response == null || response.StatusCode == 0) { Log.Debug($"Zb Send response is null or failed ..."); return(new SendReply() { code = "-1" }); } JObject j = JObject.Parse(response.Content); SendReply reply = j.ToObject <SendReply>(); return(reply); }
private TestCompany CreateTestCompany() { var restClient = new RestClient(BaseUrl); var request = new RestRequest("/system/public/users/actions/create-test-company", Method.POST); return(RestUtil.AssertOk(restClient.Execute <TestCompany>(request))); }
public IList <Quote> FetchQuotes() { try { Log.Debug($"Getting depth from {_config.Broker}..."); var path = $"data/v1/depth?market={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&size=50"; var req = RestUtil.CreateJsonRestRequest(path); SetBaseUrl("quote"); var response = _restClient.Execute(req); if (response.ErrorException != null) { throw response.ErrorException; } Log.Debug($"Received depth from {_config.Broker}."); Depth depth = new Depth() { quotesJson = response.Content, tickerJson = FetchTicker() }; var quotes = depth.ToQuotes(); return(quotes ?? new List <Quote>()); } catch (Exception ex) { Log.Error(ex.Message); Log.Debug(ex); return(new List <Quote>()); } }
private List <ExecutionReply> GetExecutions(string acceptanceId) { var path = $"/v1/me/getexecutions?child_order_acceptance_id={acceptanceId}"; var req = BuildRequest(path); return(RestUtil.ExecuteRequest <List <ExecutionReply> >(_restClient, req)); }
public Stream DownloadOVFFile() { try { Stream stream = (Stream)null; if (this.Resource.Link != null) { foreach (LinkType linkType in this.Resource.Link) { if (linkType.rel.Equals("download:default")) { stream = RestUtil.DownloadFile(this.VcloudClient, linkType.href); break; } } } if (stream == null) { throw new VCloudException(SdkUtil.GetI18nString(SdkMessage.NO_DOWNLOAD_LINK_MSG)); } return(stream); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
public BrokerBalance GetBalance() { try { Log.Debug("Hpx GetBalance Begin"); var path = "/api/v2/getAccountInfo?"; string body = "method=getAccountInfo&accesskey=" + _config.Key; path += body; var req = BuildRequest(path, "GET", body); RestUtil.LogRestRequest(req); var response = _restClient.Execute(req); if (response == null || response.StatusCode == 0) { Log.Debug($"Hpx GetBalance response is null or failed ..."); return(null); } JObject j = JObject.Parse(response.Content); j = JObject.Parse(j["data"].ToString()); j = JObject.Parse(j["balance"].ToString()); BrokerBalance bb = new BrokerBalance(); bb.Broker = Broker; bb.Leg1 = decimal.Parse(j[_config.Leg1.ToUpper()].ToString()); bb.Leg2 = decimal.Parse(j[_config.Leg2.ToUpper()].ToString()); Log.Debug("Hpx GetBalance End"); return(bb); } catch (Exception ex) { Log.Debug("Hpx GetBalance Exception:" + ex.Message); return(null); } }
/// <summary> /// /// </summary> /// <param name="tradeType"> 挂单类型 1/0[buy/sell]</param> /// <returns></returns> public string GetOrdersState(int pageIndex, int tradeType) { try { Log.Debug("Hpx GetOrdersState Begin"); var path = "/api/v2/getOrders?"; string body = "method=getOrders&accesskey=" + _config.Key + $"&tradeType={tradeType}¤cy={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&pageIndex=1&pageSize=100"; path += body; var req = BuildRequest(path, "GET", body); RestUtil.LogRestRequest(req); var response = _restClient.Execute(req); if (response == null || response.StatusCode == 0) { Log.Debug($"Hpx GetOrderState response is null or failed ..."); return(null); } Log.Debug("Hpx GetOrdersState End"); return(response.Content); } catch (Exception ex) { Log.Debug($"Hpx GetOrdersState Exception:" + ex.Message); return(null); } }
private void Start() { string url = RestUtil.JOB_SERVICE_URI; string jsonResponse = RestUtil.Instance.Get(url); jsonResponse = RestUtil.fixJson("jobs", jsonResponse); Debug.Log("Json Response: " + jsonResponse); Jobs jobsList = JsonUtility.FromJson <Jobs>(jsonResponse); jobs = jobsList.jobs; lobbyManager = GetComponent <LobbyManager>(); Debug.Log("Jobs count: " + jobs.Count); foreach (Job job in jobs) { Debug.Log("Job: " + job.jobName + " Role: " + job.roles + " description: " + job.description + " max level: " + job.maxLevel); } // get the player data username = PlayerPrefs.GetString("user"); string playerUrl = RestUtil.PLAYER_SERVICE_URI + username; string playerJsonResponse = RestUtil.Instance.Get(playerUrl); Debug.Log("Player data json response: " + playerJsonResponse); playerData = JsonUtility.FromJson <PlayerData>(playerJsonResponse); setupGamePanel.SetActive(true); gameLobbyPanel.SetActive(false); startButton.SetActive(false); }
private OrderStateReply GetOrderState(string id) { try { Log.Debug("Hpx GetOrderState Begin"); var path = "/api/v2/getOrder?"; string body = "method=getOrder&accesskey=" + _config.Key + $"&id={id}¤cy={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}"; path += body; var req = BuildRequest(path, "GET", body); RestUtil.LogRestRequest(req); var response = _restClient.Execute(req); if (response == null || response.StatusCode == 0 || response.Content.IndexOf("total_amount") < 0) { Log.Debug($"Hpx GetOrderState response is null or failed ..."); return(null); } JObject j = JObject.Parse(response.Content); j = JObject.Parse(j["data"].ToString()); OrderStateReply reply = j.ToObject <OrderStateReply>(); Log.Debug("Hpx GetOrderState End"); return(reply); } catch (Exception ex) { Log.Debug($"Hpx GetOrderState Exception:" + ex.Message); return(null); } }
public void Login(string userName, string password) { try { HttpClient httpClient = this.HttpClient; httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(userName.Trim() + ":" + password.Trim()))); HttpRequestHeaders defaultRequestHeaders = httpClient.DefaultRequestHeaders; VersionInfoType supportedVersion = this.GetSupportedVersions()[this._vcloudClientVersion.Value()]; if (supportedVersion == null) { throw new VCloudException(this._vcloudClientVersion.Value() + " " + SdkUtil.GetI18nString(SdkMessage.VERSION_NOT_SUPPORTED)); } Response response = RestUtil.Login(this, supportedVersion.LoginUrl, defaultRequestHeaders); if (!response.IsExpected(200)) { response.HandleUnExpectedResponse(); } SessionType resource = response.GetResource <SessionType>(); this.setOrgName(resource.org); this.setUserName(resource.user); } catch (Exception ex) { Logger.Log(TraceLevel.Critical, ex.Message); throw ex; } }
// Use this for initialization void Start() { //TODO: Remove hard coded game id gameId = 1; // get the player data username = PlayerPrefs.GetString("user"); string playerUrl = RestUtil.PLAYER_SERVICE_URI + username; string playerJsonResponse = RestUtil.Instance.Get(playerUrl); Debug.Log("Player data json response: " + playerJsonResponse); playerData = JsonUtility.FromJson <PlayerData>(playerJsonResponse); // get the party data string url = RestUtil.HERO_SERVICE_URI + "user/" + username; string jsonResponse = RestUtil.Instance.Get(url); jsonResponse = RestUtil.fixJson("party", jsonResponse); Debug.Log("Json Response: " + jsonResponse); Party partyObj = JsonUtility.FromJson <Party>(jsonResponse); party = partyObj.party; if (party == null) { Debug.LogError("No hero objects found for player."); } gameState = "world"; // this loop updates the hero status panels for (int i = 0; i < 4; i++) { statusPanels[i].UpdateStats(party[i]); } combatWindow.SetActive(false); GameService.startNewGame(gameId); elapsedTime = 0f; }
private BalanceReply GetBalance() { var path = "/api/accounts/balance"; var req = BuildRequest(path); return(RestUtil.ExecuteRequest <BalanceReply>(_restClient, req)); }
/// <summary> /// Sign method /// </summary> /// <param name="request"></param> /// <param name="clientConfig"></param> /// <param name="metrics"></param> /// <param name="awsAccessKeyId"></param> /// <param name="awsSecretAccessKey"></param> public override void Sign(IRequest request, IClientConfig clientConfig, RequestMetrics metrics, string awsAccessKeyId, string awsSecretAccessKey) { base.Sign(request, clientConfig, metrics, awsAccessKeyId, awsSecretAccessKey); //内容Md5 SetContentMd5(request); //移除Md5 //RemoveContentMd5(request); //设置Copy头 SetCopySource(request); //设置User-Agent SetUserAgent(request); //resourcePath var resourcePath = GetResourcePath(request); //待签名字符串 var canonicalString = RestUtil.MakeKS3CanonicalString(request.HttpMethod, resourcePath, request, null); var hmacBytes = HmacUtil.GetHmacSha1(canonicalString, awsSecretAccessKey); //签名 var signature = Convert.ToBase64String(hmacBytes); //默认头部添加 if (!request.Headers.ContainsKey(Headers.CONTENT_TYPE)) { request.Headers.Add(Headers.CONTENT_TYPE, Headers.DEFAULT_MIMETYPE); } //如果已经添加了认证,就移除 if (request.Headers.ContainsKey(Headers.AUTHORIZATION)) { request.Headers.Remove(Headers.AUTHORIZATION); } request.Headers.Add("Authorization", "KSS " + awsAccessKeyId + ":" + signature); }
public void SsoLogin(string samlAssertionXML, string orgName) { HttpClient httpClient = this.HttpClient; httpClient.DefaultRequestHeaders.Clear(); string str = this.GZipEncodeXmlToString(samlAssertionXML); if (orgName.Equals("System", StringComparison.OrdinalIgnoreCase)) { httpClient.DefaultRequestHeaders.Add("Authorization", "SIGN token=\"" + str + "\""); } else { httpClient.DefaultRequestHeaders.Add("Authorization", "SIGN token=\"" + str + "\",org=\"" + orgName + "\""); } httpClient.DefaultRequestHeaders.Add("Accept", vCloudClient.SUPPORTED_SDK_VERSIONS[this.VcloudClientVersion]); HttpRequestHeaders defaultRequestHeaders = httpClient.DefaultRequestHeaders; VersionInfoType supportedVersion = this.GetSupportedVersions()[this._vcloudClientVersion.Value()]; if (supportedVersion == null) { throw new VCloudException(this._vcloudClientVersion.Value() + " " + SdkUtil.GetI18nString(SdkMessage.VERSION_NOT_SUPPORTED)); } Response response = RestUtil.Login(this, supportedVersion.LoginUrl, defaultRequestHeaders); if (!response.IsExpected(200)) { response.HandleUnExpectedResponse(); } SessionType resource = response.GetResource <SessionType>(); this.setOrgName(resource.org); this.setUserName(resource.user); }
public ActionResult Country(string country) // the parameter needed to use string interpolation in CountryUtil { RegionInfo myRI = new RegionInfo(country); CountryUtil cu = new CountryUtil(); IndividualSpecies ind = new IndividualSpecies(); var countryspecies = cu.Country(country); //var endangeredSpecies = cu.Country(country).Where(c => c.Category == "EN"); //var extinctSpecies = cu.Country(country).Where(c => c.Category == "EX"); //var extinctWildSpecies = cu.Country(country).Where(c => c.Category == "EW"); //var criticallyEndangeredSpecies = cu.Country(country).Where(c => c.Category == "CR"); //var vulnerableSpecies = cu.Country(country).Where(c => c.Category == "VU"); var allThreatenedSpecies = cu.Country(country).Where(c => c.Category == "EN" || c.Category == "EX" || c.Category == "EW" || c.Category == "CR" || c.Category == "VU"); ViewBag.C = myRI.EnglishName; // Annukka is PROUD of this bit :) ViewBag.RI = myRI; ViewBag.Categories = string.Join("", ind.Category); RestUtil ru = new RestUtil(); //foreach (var item in allThreatenedSpecies) //{ // //string name = ru.SingleSpecies(item.ScientificName).FirstOrDefault()?.MainCommonName; // string name = ru.SingleSpecies(item.ScientificName).FirstOrDefault()?.MainCommonName; // item.CommonName = name; //} return(View(allThreatenedSpecies)); // check what we actually want here!! //return View(countryspecies); }
public Dictionary <string, VersionInfoType> GetSupportedVersions() { try { this._supportedApiVersions = new Dictionary <string, VersionInfoType>(); Response supportedVersions = RestUtil.GetSupportedVersions(this, this.VCloudApiURL + "/versions"); SupportedVersionsType supportedVersionsType = (SupportedVersionsType)null; if (supportedVersions.IsExpected(200)) { supportedVersionsType = supportedVersions.GetResource <SupportedVersionsType>(); } else { supportedVersions.HandleUnExpectedResponse(); } if (supportedVersionsType != null) { if (supportedVersionsType.VersionInfo != null) { foreach (VersionInfoType versionInfoType in supportedVersionsType.VersionInfo) { this._supportedApiVersions.Add(versionInfoType.Version, versionInfoType); } } } } catch (Exception ex) { Logger.Log(TraceLevel.Critical, ex.Message, (object)ex); throw new VCloudRuntimeException(ex.Message); } return(this._supportedApiVersions); }
private SendReply Send(SendOrderParam param) { try { Log.Debug("Hpx Send Begin"); var path = "/api/v2/order?"; int tradetype = param.side == "buy" ? 0 : 1; string body = $"method=order&accesskey=" + _config.Key + $"&amount={param.quantity}¤cy={_config.Leg1.ToLower()}_{_config.Leg2.ToLower()}&price={param.price}&tradeType={tradetype}"; path += body; var req = BuildRequest(path, "GET", body); RestUtil.LogRestRequest(req); var response = _restClient.Execute(req); if (response == null || response.StatusCode == 0) { Log.Debug($"Hpx Send response is null or failed ..."); return(new SendReply() { code = "-1" }); } JObject j = JObject.Parse(response.Content); SendReply reply = j.ToObject <SendReply>(); Log.Debug("Hpx Send End"); return(reply); } catch (Exception ex) { Log.Debug($"Hpx Send Exception:" + ex.Message); return(null); } }
private OpenOrdersReply GetOpenOrders() { var path = "/api/exchange/orders/opens"; var req = BuildRequest(path); return(RestUtil.ExecuteRequest <OpenOrdersReply>(_restClient, req)); }
private ReferenceData() { RestUtil restUtil = new RestUtil(new Uri(ConfigurationManager.AppSettings["GIIS_URL"])); if (this.Doses == null) { this.Doses = restUtil.Get <List <GIIS.DataLayer.Dose> >("DoseManagement.svc/GetDoseList"); } if (this.Vaccines == null) { this.Vaccines = restUtil.Get <List <GIIS.DataLayer.ScheduledVaccination> >("ScheduledVaccinationManagement.svc/GetScheduledVaccinationList"); } if (this.Items == null) { this.Items = restUtil.Get <List <GIIS.DataLayer.Item> >("ItemManagement.svc/GetItemList"); } if (this.ItemLots == null) { this.ItemLots = restUtil.Get <List <GIIS.DataLayer.ItemLot> >("StockManagement.svc/GetItemLots"); } if (this.Places == null) { this.Places = restUtil.Get <List <GIIS.DataLayer.Place> >("PlaceManagement.svc/GetLeafPlaces"); } }
private OrderStateReply GetOrderState(string id) { var path = $"/orders/{id}"; var req = BuildRequest(path); return(RestUtil.ExecuteRequest <OrderStateReply>(_restClient, req)); }
private static Dictionary <string, ResourcePoolType> GetResourcePools( vCloudClient client, string url) { try { Logger.Log(TraceLevel.Information, SdkUtil.GetI18nString(SdkMessage.GET_URL_MSG) + " - " + url); RestUtil.Get(client, url); ResourcePoolListType resourcePoolListType = SdkUtil.Get <ResourcePoolListType>(client, url, 200); Dictionary <string, ResourcePoolType> dictionary = new Dictionary <string, ResourcePoolType>(); if (resourcePoolListType != null && resourcePoolListType.ResourcePool != null) { foreach (ResourcePoolType resourcePoolType in resourcePoolListType.ResourcePool) { if (!dictionary.ContainsKey(resourcePoolType.name)) { dictionary.Add(resourcePoolType.name, resourcePoolType); } } } return(dictionary); } catch (Exception ex) { throw new VCloudException(ex.Message); } }
///// <summary>是否需要移除Md5 ///// </summary> //private void RemoveContentMd5(IRequest request) //{ // if (request.Headers.ContainsKey(Headers.CONTENT_MD5) && request.ContentStream == null) // { // request.Headers.Remove(Headers.CONTENT_MD5); // } //} /// <summary>获取ResourcePath /// </summary> private string GetResourcePath(IRequest request) { var sb = new StringBuilder(request.ResourcePath); //非上传才需要处理 if (RestUtil.ShouldEndWithSprit(sb.ToString())) { sb.Append("/"); } //如果包含SubResource if (request.SubResources.Count > 0) { sb.Append("?"); var sortedDict = new SortedDictionary <string, string>(request.SubResources); foreach (var item in sortedDict) { sb.Append(item.Key); if (!string.IsNullOrWhiteSpace(item.Value)) { sb.Append($"={item.Value}&"); } } } return(sb.ToString().TrimEnd('&')); }
private void Resync() { #if DIALOG_CHECK_MODS Log.Warning("Begin Dialog_CheckMods.Resync"); #endif #if TRACE && DIALOG_CHECK_MODS Log.Message(" Mods:"); #endif foreach (ModToSync mod in this.modsToSync) { #if TRACE && DIALOG_CHECK_MODS Log.Message(" " + mod.Mod.Name); #endif if (mod.Host != null) { RestUtil.GetModSyncXml(mod.Host.ModSyncXmlUri, (XmlDocument xml) => { #if TRACE && DIALOG_CHECK_MODS Log.Message("ModCheck Callback: " + mod.Mod.Name); #endif mod.RequestDone = true; ModSyncInfo info; IHost host; if (xml != null) { if (mod.Host is HugsLibVersionHost) { if (ModToSyncFactory.ReadVersion(xml, mod.Mod.Name, out info, out host)) { mod.RemoteInfo = info; } } else if (mod.Host is ManifestHost) { if (ModToSyncFactory.ReadManifest(xml, mod.Mod.Name, out info, out host)) { mod.RemoteInfo = info; } } else { if (ModToSyncFactory.ReadModSync(xml, mod.Mod.Name, out info, out host)) { mod.RemoteInfo = info; } } } }); } else { mod.RequestDone = true; } } #if DIALOG_CHECK_MODS Log.Warning("End Dialog_CheckMods.Resync"); #endif }
private void Cancel(string orderId) { var method = "PUT"; var path = $"/orders/{orderId}/cancel"; var req = BuildRequest(path, method); RestUtil.ExecuteRequest(_restClient, req); }
public static string SetDivision() { HttpRequest Request = HttpContext.Current.Request; WebRequest webRequest = RestUtil.readRequestBody(Request); WebResponse response = accountService.SetDivision(webRequest); return(StringUtil.serializeCustomModel(response)); }
public decimal GetBtcPosition() { var path = "/trading_accounts"; var req = BuildRequest(path); var accounts = RestUtil.ExecuteRequest <List <TradingAccounts> >(_restClient, req); var account = accounts.Find(b => b.CurrencyPairCode == "BTCJPY"); return(account.Position); }
private SendReply Send(SendChildOrderParam param) { var method = "POST"; var path = "/v1/me/sendchildorder"; var body = JsonConvert.SerializeObject(param); var req = BuildRequest(path, method, body); return(RestUtil.ExecuteRequest <SendReply>(_restClient, req)); }
public decimal GetBtcPosition() { var path = "/v1/me/getbalance"; var req = BuildRequest(path); var balanceList = RestUtil.ExecuteRequest <List <Balance> >(_restClient, req); var btcBalance = balanceList.Find(b => b.CurrencyCode == "BTC"); return(btcBalance.Amount); }
private CancelReply Cancel(string orderId) { var method = "DELETE"; var path = $"/api/exchange/orders/{orderId}"; var req = BuildRequest(path, method); var reply = RestUtil.ExecuteRequest <CancelReply>(_restClient, req); return(reply); }