C# Client Library
A C# Client Library for the AnalyzeRe REST API
Loading...
Searching...
No Matches
ExtensionMethods.IStoredAPIResource_WithStatus.cs
Go to the documentation of this file.
1using System.Diagnostics;
2
6
7namespace AnalyzeRe
8{
10 public static partial class ExtensionMethods
11 {
13 private struct StatusStruct
14 {
15 public TaskStatus status { get; set; }
16 public string status_message { get; set; }
17 }
18
20 private static readonly string[] PollFields =
21 {
24 };
25
58 {
59 API.ValidateExistingResource(resource);
60 if (resource.status.IsProcessingComplete())
61 Debug.WriteLine($"{resource.GetType().NiceTypeName()} {resource.id} already " +
62 $"has a finalized status of \"{resource.status}\"!");
63 else
64 {
65 StatusStruct lastStatus = new StatusStruct
66 {
67 status = resource.status,
68 status_message = resource.status_message
69 };
70 try
71 {
74 () => lastStatus = resource.Get_AsType<StatusStruct>(requestParams),
75 status => !status.status.IsBusy(),
77 }
78 // Intercept the NotWaitingException and re-raise with a more meaningful message.
80 {
81 throw new NotWaitingException(
82 $"The {resource.GetType().NiceTypeName()} {resource.id} is still " +
83 $"{(lastStatus.status == TaskStatus.Queued ? "queued for " : "")}processing " +
84 $"after {ex.TimeWaited} seconds, which exceeds the timeout of {ex.MaxWaitTime}ms.",
85 ex.TimeWaited, ex.QueuePosition, ex.RetryTime, ex.MaxWaitTime, ex, ex.RestResponse);
86 }
87 finally
88 {
89 // Update the original resource with the last available status and status_message
90 resource.status = lastStatus.status;
91 resource.status_message = lastStatus.status_message;
92 }
93 }
94
95 if (resource.status == TaskStatus.Success)
96 return resource;
97
98 string errorMessage = $"The {resource.GetType().NiceTypeName()} {resource.id} " +
99 (resource.status.IsError() ? "failed processing." :
100 $"is no longer processing, but the returned status of {resource.status} is not expected.") +
101 (resource.status_message == null ? " No message was provided." :
102 $" The following message was provided: {resource.status_message}");
104 }
105 }
106}
A custom exception class that includes the RestSharp.IRestResponse that generated the exception,...
Describes a collection of resources which can be listed.
Parameters that can be added to your REST requests to access additional API features.
static RequestParameters Fields(IEnumerable< string > fieldNames)
Can be added to your GET requests to return only the specified fields in the response body....
API methods / requests made available to the user.
static void PollUntil(Func< bool > request, AnalyzeRe.PollingOptions pollingOptions=null)
Poll the specified request until it returns true.
Provides the REST request methods available to data endpoints.
static T PollUntilReady< T >(this T resource, PollingOptions pollingOptions=null)
Poll the IStoredAPIResource_WithStatus.status of a resource until it is TaskStatus....
Thrown when a request requires additional time to complete, but it exceeds the time we are willing to...
Determines the behaviour of the API when automatically retrying a request whose result is not yet rea...
Helper class which makes it easier to build a set of request parameters.
Describes an APIResource class that has a "status" property and corresponding "status_message" which ...
string status_message
Resource validation status message (if any).
TaskStatus status
Validation status of this resource.
TaskStatus
The status of a data upload which may be in progress.
Definition TaskStatus.cs:9