async Task <ApiResponse <TResponse> > PostJson <TResponse>(string relativeUrl, object req) { var jsonReq = _converter.ToJson(req); _logger.Debug(this, $"Request ({req.GetType().Name}) to '{relativeUrl}': '{jsonReq}'"); var netResponse = await _network.PostJson(relativeUrl, jsonReq); ApiResponse <TResponse> result; if (netResponse.Success) { var response = _converter.FromJson <TResponse>(netResponse.Text); result = response.AsResult(); } else { var error = ConvertToError(netResponse); _errorHandle.OnError(error); result = error.AsError <TResponse>(); } _logger.Debug(this, $"Response ({typeof(TResponse).Name}) from '{relativeUrl}': {result.Success}, '{result.Result}', {result.Error}"); if (!result.Success) { OnError(result.Error); } return(result); }
public FileStorageRepository(ConvertService convert, string path) { _convert = convert; _path = path; if (File.Exists(path)) { var contents = File.ReadAllText(path); State = _convert.FromJson <FileState>(contents); } }
public UserState Find(string login, string passwordHash = null) { var model = _users.Find(u => u.Login == login).FirstOrDefault(); if (model == null) { return(null); } var state = _convert.FromJson <UserState>(model.User.ToJson()); if ((passwordHash == null) || (state.PasswordHash == passwordHash)) { return(state); } return(null); }
public FileConfigRepository(ConvertService convert, string path) { _config = convert.FromJson <ConfigRoot>(File.ReadAllText(path)); }
GameState FromBson(BsonDocument doc) { return(_convert.FromJson <GameState>(doc.ToJson())); }
public TextConfigRepository(ConvertService convert, string text) { _config = convert.FromJson <ConfigRoot>(text); }