Beispiel #1
0
        static public async Task <ToCustomBotSnapshot> RequestSnapshotAsync(
            string ApiUri,
            FromCustomBotSnapshot FromBotSnapshot = null)
        {
            string RequestData = null;

            if (null != FromBotSnapshot)
            {
                RequestData = ToCustomBotSnapshot.SerializeToString(FromBotSnapshot);
            }

            string ResponseData = null;

            using (var client = new WebClient())
            {
                client.Encoding = Encoding.UTF8;
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                ResponseData = await client.UploadStringTaskAsync(ApiUri, "POST", RequestData ?? "");
            }

            if (null == ResponseData)
            {
                return(null);
            }

            return(ToCustomBotSnapshot.DeserializeFromString <ToCustomBotSnapshot>(ResponseData));
        }
Beispiel #2
0
 public SnapshotRequest(
     string ApiUri,
     int DurationLimit,
     FromCustomBotSnapshot FromCustomBotSnapshot = null)
 {
     this.ApiUri                = ApiUri;
     this.DurationLimit         = DurationLimit;
     this.FromCustomBotSnapshot = FromCustomBotSnapshot;
 }
Beispiel #3
0
        static public async Task <SnapshotRequestResult> RequestSnapshotAsyncEncapsulated(
            string ApiUri,
            int DurationLimit,
            FromCustomBotSnapshot FromBotSnapshot = null)
        {
            var Time = Bib3.Glob.StopwatchZaitMiliSictInt();

            System.Exception    Exception        = null;
            ToCustomBotSnapshot ResponseSnapshot = null;

            try
            {
                if (null == ApiUri)
                {
                    throw new ArgumentNullException("ApiUrl");
                }

                var ResponseSnapshotTask =
                    RequestSnapshotAsync(ApiUri, FromBotSnapshot)
                    .TimeoutAfter(DurationLimit);

                ResponseSnapshot = await ResponseSnapshotTask;
            }
            catch (System.Exception tException)
            {
                Exception = tException;
            }
            finally
            {
            }

            return(new SnapshotRequestResult(
                       Time,
                       Exception,
                       ResponseSnapshot));
        }