public async Task <T> GetFromStoreAsync <T>(T query, OptionsIn optionsIn) where T : IWitsmlQueryType, new() { try { var request = new WMLS_GetFromStoreRequest { WMLtypeIn = query.TypeName, OptionsIn = optionsIn.GetName(), QueryIn = XmlHelper.Serialize(query), CapabilitiesIn = "" }; var response = await client.WMLS_GetFromStoreAsync(request); LogQueriesSentAndReceived(request.QueryIn, response.IsSuccessful(), response.XMLout); if (response.IsSuccessful()) { return(XmlHelper.Deserialize <T>(response.XMLout)); } var errorResponse = await client.WMLS_GetBaseMsgAsync(response.Result); throw new Exception($"Error while querying store: {response.Result} - {errorResponse.Result}. {response.SuppMsgOut}"); } catch (XmlException e) { Log.Error(e, "Failed to deserialize response from Witsml server"); return(new T()); } }
public async Task <QueryResult> AddToStoreAsync <T>(T query, OptionsIn optionsIn = OptionsIn.Requested) where T : IWitsmlQueryType { try { var request = new WMLS_AddToStoreRequest { WMLtypeIn = query.TypeName, OptionsIn = optionsIn.GetName(), XMLin = XmlHelper.Serialize(query) }; var response = await client.WMLS_AddToStoreAsync(request); LogQueriesSentAndReceived(request.XMLin, response.IsSuccessful()); if (response.IsSuccessful()) { return(new QueryResult(true)); } var errorResponse = await client.WMLS_GetBaseMsgAsync(response.Result); var message = $"Error while adding to store: {response.Result} - {errorResponse.Result}. {response.SuppMsgOut}"; return(new QueryResult(false, message)); } catch (MessageSecurityException e) { const string message = "Request forbidden. Verify credentials"; Log.Error(e, message); return(new QueryResult(false, message)); } }