|
1 | | -using DtmCommon; |
| 1 | +using System; |
| 2 | +using DtmCommon; |
2 | 3 | using Microsoft.Extensions.Options; |
3 | 4 | using System.Collections.Generic; |
4 | 5 | using System.Net.Http; |
@@ -46,7 +47,7 @@ public HttpClient GetHttpClient(string name) |
46 | 47 | { |
47 | 48 | return _httpClientFactory.CreateClient(name); |
48 | 49 | } |
49 | | - |
| 50 | + |
50 | 51 | public async Task<HttpResponseMessage> PrepareWorkflow(TransBase tb, CancellationToken cancellationToken) |
51 | 52 | { |
52 | 53 | var url = string.Concat(_dtmOptions.DtmUrl.TrimEnd(Slash), Constant.Request.URLBASE_PREFIX, "prepareWorkflow"); |
@@ -133,6 +134,46 @@ public TransBase TransBaseFromQuery(Microsoft.AspNetCore.Http.IQueryCollection q |
133 | 134 | } |
134 | 135 | #endif |
135 | 136 |
|
| 137 | + /// <summary> |
| 138 | + /// Query single global transaction |
| 139 | + /// </summary> |
| 140 | + /// <param name="gid">global id</param> |
| 141 | + /// <param name="cancellationToken"></param> |
| 142 | + /// <returns></returns> |
| 143 | + public async Task<TransGlobal> Query(string gid, CancellationToken cancellationToken) |
| 144 | + { |
| 145 | + if (string.IsNullOrEmpty(gid)) throw new ArgumentNullException(nameof(gid)); |
| 146 | + |
| 147 | + var url = string.Concat(_dtmOptions.DtmUrl.TrimEnd(Slash), Constant.Request.URL_Query, $"?gid={gid}"); |
| 148 | + var client = _httpClientFactory.CreateClient(Constant.DtmClientHttpName); |
| 149 | + var response = await client.GetAsync(url, cancellationToken).ConfigureAwait(false); |
| 150 | + var dtmContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 151 | + DtmImp.Utils.CheckStatus(response.StatusCode, dtmContent); |
| 152 | + return JsonSerializer.Deserialize<TransGlobal>(dtmContent, _jsonOptions); |
| 153 | + } |
| 154 | + |
| 155 | + /// <summary> |
| 156 | + /// Query single global transaction status |
| 157 | + /// </summary> |
| 158 | + /// <param name="gid"></param> |
| 159 | + /// <param name="cancellationToken"></param> |
| 160 | + /// <returns></returns> |
| 161 | + /// <exception cref="NotImplementedException"></exception> |
| 162 | + public async Task<string> QueryStatus(string gid, CancellationToken cancellationToken) |
| 163 | + { |
| 164 | + if (string.IsNullOrEmpty(gid)) throw new ArgumentNullException(nameof(gid)); |
| 165 | + |
| 166 | + var url = string.Concat(_dtmOptions.DtmUrl.TrimEnd(Slash), Constant.Request.URL_Query, $"?gid={gid}"); |
| 167 | + var client = _httpClientFactory.CreateClient(Constant.DtmClientHttpName); |
| 168 | + var response = await client.GetAsync(url, cancellationToken).ConfigureAwait(false); |
| 169 | + var dtmContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 170 | + DtmImp.Utils.CheckStatus(response.StatusCode, dtmContent); |
| 171 | + var graph = JsonSerializer.Deserialize<TransGlobalForStatus>(dtmContent, _jsonOptions); |
| 172 | + return graph.Transaction == null |
| 173 | + ? string.Empty |
| 174 | + : graph.Transaction.Status; |
| 175 | + } |
| 176 | + |
136 | 177 | public class DtmGid |
137 | 178 | { |
138 | 179 | [JsonPropertyName("gid")] |
|
0 commit comments