public int SendSellRequest(int price, int commodity, int amount) { SimpleHTTPClient client = new SimpleHTTPClient(); this.price = price; this.commodity = commodity; this.amount = amount; this.type = "sell"; Token x = new Token(); string token = x.createToken(); string nonce = "" + x.getNonce(); string temp = client.SendPostRequest <SellRequest>(x.getUrl(), x.getUserName(), nonce, token, this); string response = MarketClient.Utils.SimpleCtyptoLibrary.decrypt(temp, x.getPrivateKey()); int output; if (response[0] < '1' | response[0] > '9') { Console.WriteLine(response); output = -1; myLogger.Error("the sell request is failed"); } else { output = Int32.Parse(response); myLogger.Info("the sell request is done:" + " " + output); } return(output); }
public string SendQueryUserRequests() { SimpleHTTPClient client = new SimpleHTTPClient(); QueryUserRequests request = new QueryUserRequests(); request.type = "queryUserRequests"; Token x = new Token(); string token = x.createToken(); string nonce = "" + x.getNonce(); string temp = client.SendPostRequest <QueryUserRequests>(x.getUrl(), x.getUserName(), nonce, token, request); string response = MarketClient.Utils.SimpleCtyptoLibrary.decrypt(temp, x.getPrivateKey()); if (response != "[]") { string[] stringSeparators = new string[] { "}, {" }; string[] output = response.Split(stringSeparators, StringSplitOptions.None); int k = 1; string Foutput = ""; for (int i = 0; i < output.Length - 1; i = i + 1) { Foutput = Foutput + output[i] + "}" + "\n" + "{"; } Foutput = Foutput + output[output.Length - 1]; return(Foutput); } else { return(response); } }
public int SendBuyRequest(int price, int commodity, int amount) { SimpleHTTPClient client = new SimpleHTTPClient(); string token = SimpleCtyptoLibrary.CreateToken("user52", key); var item = new MarketItems.BuySellRequest(); item.type = "buy"; item.price = price; item.commodity = commodity; item.amount = amount; mainLog.Debug("buying requset send to the server. information: " + item.ToString()); string output = client.SendPostRequest <MarketItems.BuySellRequest> ("http://ise172.ise.bgu.ac.il", "user52", token, item); mainLog.Debug("return answere from the server after buing request: " + output); if (!(checkMarketResponse(output))) { throw new ApplicationException(output); } int integerOutput; int.TryParse(output, out integerOutput); return(integerOutput); }
public int SendBuyRequest(int price, int commodity, int amount) { BuyRequest item = new BuyRequest(price, commodity, amount); string response = client.SendPostRequest(Url, User, token, item); int num = -1; if (response == "No price or commodity type/amount" || response == "Bad commodity" || response == "Bad amount" || response == "No query id" || response == "No commodity" || response == "No auth key" || response == "No user or auth token" || response == "Verification failure" || response == "No type key" || response == "Bad request type" || response == "Id not found" || response == "User does not match" || response == "Insufficient funds" || response == "Insufficient commodity") { Console.WriteLine(response); } else { num = Int32.Parse(response); } return(num); }
public MarketCommodityoffer(QueryMarket item) { SimpleHTTPClient client = new SimpleHTTPClient(); MarketCommodityoffer response = client.SendPostRequest <QueryMarket, MarketCommodityoffer>( Url, User, token, item); this.ask = response.ask; this.bid = response.bid; }
public void TestSimpleHTTPPost() { // Attantion!, this code is not good practice! this was made for the sole purpose of being an example. // A real good code, should use defined classes and and not hardcoded values! SimpleHTTPClient client = new SimpleHTTPClient(); var request = new{ type = "queryUser", }; string response = client.SendPostRequest(Url, User, SimpleCtyptoLibrary.CreateToken(User, PrivateKey), request); Trace.Write($"Server response is: {response}"); }
public IMarketUserData SendQueryUserRequest() { SimpleHTTPClient client = new SimpleHTTPClient(); string token = SimpleCtyptoLibrary.CreateToken("user52", key); var item = new MarketItems.QueryUserRequest(); item.type = "queryUser"; mainLog.Info("Send Query User Request to the server. information: " + item.ToString()); MarketUserData output = client.SendPostRequest <QueryUserRequest, MarketUserData>("http://ise172.ise.bgu.ac.il", "user52", token, item); mainLog.Info("return answere from the server after Send Query User Request: " + output); return(output); }
public MarketItemQuery(QueryBuySell item) { SimpleHTTPClient client = new SimpleHTTPClient(); MarketItemQuery response = client.SendPostRequest <QueryBuySell, MarketItemQuery>( Url, User, token, item); this.price = response.price; this.amount = response.amount; this.type = response.type; }
public MarketUserData SendQueryUserRequest() { SimpleHTTPClient client = new SimpleHTTPClient(); QueryUser request = new QueryUser(); request.type = "queryUser"; Token x = new Token(); string token = x.createToken(); string nonce = "" + x.getNonce(); MarketUserData response = client.SendPostRequest <QueryUser, MarketUserData>(x.getUrl(), x.getUserName(), nonce, token, request); return(response); }
public MarketItemQuery SendQueryBuySellRequest(int id) { SimpleHTTPClient client = new SimpleHTTPClient(); QueryBuySell request = new QueryBuySell(); request.type = "queryBuySell"; request.id = id; Token x = new Token(); string token = x.createToken(); string nonce = "" + x.getNonce(); MarketItemQuery response = client.SendPostRequest <QueryBuySell, MarketItemQuery>(x.getUrl(), x.getUserName(), nonce, token, request); return(response); }
public void TestObjectBasedHTTPPost() { // This test query a diffrent site (not the MarketServer)! it's only for demostration. // this site doenst accept authentication, it only returns objects. string url = "http://ip.jsontest.com/"; SimpleHTTPClient client = new SimpleHTTPClient(); IpAddress ip = new IpAddress { Ip = "8.8.8.8" }; IpAddress response = client.SendPostRequest <IpAddress, IpAddress>(url, null, null, ip); Assert.IsNotNull(response); Assert.IsNotNull(response.Ip); Trace.Write($"Server response is: {response.Ip}"); }
public MarketCommodityOffer SendQueryMarketRequest(int commodity) { SimpleHTTPClient client = new SimpleHTTPClient(); QueryMarket request = new QueryMarket(); request.type = "queryMarket"; request.commodity = commodity; Token x = new Token(); string token = x.createToken(); string nonce = "" + x.getNonce(); MarketCommodityOffer response = client.SendPostRequest <QueryMarket, MarketCommodityOffer>(x.getUrl(), x.getUserName(), nonce, token, request); string s = response.ToStringA(); return(response); }
public List <ComInfo> SendQueryAllMarketRequest() { SimpleHTTPClient client = new SimpleHTTPClient(); QueryAllMarket request = new QueryAllMarket(); request.type = "queryAllMarket"; Token x = new Token(); string nonce = "" + x.getNonce(); string token = x.createToken(); this.lci = client.SendPostRequest <QueryAllMarket, List <ComInfo> >(x.getUrl(), x.getUserName(), nonce, token, request); myLogger.Info("the user send request about all comoddities offers"); return(this.lci); }
public bool SendCancelBuySellRequest(int id) { SimpleHTTPClient client = new SimpleHTTPClient(); string token = SimpleCtyptoLibrary.CreateToken("user52", key); var item = new MarketItems.CancelBuySellRequest(); item.type = "cancelBuySell"; item.id = id; mainLog.Info("Send Cancel Buy Sell Request to the server. information: " + item.ToString()); var output = client.SendPostRequest <CancelBuySellRequest>("http://ise172.ise.bgu.ac.il", "user52", token, item); mainLog.Info("return answere from the server afterSend Cancel Buy Sell Request: " + output); if (output == "Ok") { return(true); } throw new Exception(output); }
public bool SendCancelBuySellRequest(int id) { SimpleHTTPClient client = new SimpleHTTPClient(); this.id = id; type = "cancelBuySell"; Token x = new Token(); string token = x.createToken(); string nonce = "" + x.getNonce(); string temp = client.SendPostRequest <CancelBuySellRequest>(x.getUrl(), x.getUserName(), nonce, token, this); string response = MarketClient.Utils.SimpleCtyptoLibrary.decrypt(temp, x.getPrivateKey()); if (response == "Ok") { myLogger.Info("the cancel of the request" + id + " done"); return(true); } return(false); }
public void Builder() { SimpleHTTPClient client = new SimpleHTTPClient(); QueryUser request2 = new QueryUser(); request2.type = "queryUser"; string token = MarketClient.Utils.SimpleCtyptoLibrary.CreateToken(User, PrivateKey); MarketUserData response = client.SendPostRequest <QueryUser, MarketUserData>( Url, User, token, request2); this.commodities = response.commodities; this.funds = response.funds; this.requests = response.requests; }
/// <summary> /// Send method: send request to server with HttpClient and returned updated guid of currect message /// </summary> /// <param name="url">url of the server</param> /// <param name="msg">CommunicationMessage message content</param> /// <returns>Guid from server back to client.</returns> public static IMessage Send(string url, string gourpID, string nickName, string messageContent) { return(SimpleHTTPClient.SendPostRequest(url, new Request(new Guid(), gourpID, nickName, messageContent, 0, "1"))); }