public async Task <(bool success, string message, DirectoryObject)> GetDirectoryInfo(string relativePath) { try { var result = await HttpClient.GetAsync( string.Format("{0}api/explorer?splitChar={1}&relativePath={2}", Host, Uri.EscapeDataString(Path.DirectorySeparatorChar.ToString()), Uri.EscapeDataString(relativePath)) ); if (GetUnhandledMessage(result, out var message)) { return(false, message, null); } var respJson = await result.Content.ReadAsStringAsync(); if (result.StatusCode == HttpStatusCode.OK && ResponseBase.GetCode(respJson) == "200") { var obj = JsonConvert.DeserializeObject <ResponseDataBase <DirectoryObject> >(respJson); return(true, obj.Message, obj.Data); } return(false, GetJsonMessage(respJson), null); } catch (Exception ex) { return(false, ex.Message, null); } }
public async Task <string> AuthenticationAsync(string user, string pass) { try { var reqJson = JsonConvert.SerializeObject(new AuthenticateModel(user, pass)); var result = await HttpClient.PostAsync( $"{Host}api/authenticate", GetJsonContent(reqJson) ); if (GetUnhandledMessage(result, out var message)) { return(message); } var respJson = await result.Content.ReadAsStringAsync(); if (result.StatusCode == HttpStatusCode.OK && ResponseBase.GetCode(respJson) == "200") { Initialize(user, pass, !_initialized); return(null); } return(GetJsonMessage(respJson)); } catch (Exception ex) { return(ex.Message); } }
public async Task <(bool success, string message, NavObj)> GetNavigatorInfo() { try { var result = await HttpClient.GetAsync( $"{Host}api/navigator" ); if (GetUnhandledMessage(result, out var message)) { return(false, message, null); } var respJson = await result.Content.ReadAsStringAsync(); if (result.StatusCode == HttpStatusCode.OK && ResponseBase.GetCode(respJson) == "200") { var obj = JsonConvert.DeserializeObject <ResponseDataBase <NavObj> >(respJson); return(true, obj.Message, obj.Data); } return(false, GetJsonMessage(respJson), null); } catch (Exception ex) { return(false, ex.Message, null); } }
private static string GetJsonMessage(string json) { var jsonCode = ResponseBase.GetCode(json); var jsonMessage = ResponseBase.GetMessage(json); if (jsonCode != "400.1") { return(jsonMessage); } var kvp = JsonConvert.DeserializeObject <ResponseDataBase <Dictionary <string, string> > >(json); return(jsonMessage + ":" + Environment.NewLine + string.Join(Environment.NewLine, kvp.Data.Select(k => k.Key + ": " + k.Value))); }